Commit edc18e777ca72442986c9843624934f248a8a2fe
Exists in
spb-stable
and in
3 other branches
Merge branch 'bug/filtering' into 'master'
Bug in issue and merge request filtering Fixes #1006
Showing
3 changed files
with
150 additions
and
9 deletions
Show diff stats
app/services/filtering_service.rb
... | ... | @@ -24,7 +24,8 @@ class FilteringService |
24 | 24 | @current_user = current_user |
25 | 25 | @params = params |
26 | 26 | |
27 | - items = by_scope | |
27 | + items = init_collection | |
28 | + items = by_scope(items) | |
28 | 29 | items = by_state(items) |
29 | 30 | items = by_group(items) |
30 | 31 | items = by_project(items) |
... | ... | @@ -37,20 +38,30 @@ class FilteringService |
37 | 38 | |
38 | 39 | private |
39 | 40 | |
40 | - def by_scope | |
41 | + def init_collection | |
41 | 42 | table_name = klass.table_name |
42 | 43 | |
44 | + return klass.of_projects(Project.public_only) unless current_user | |
45 | + | |
46 | + if project | |
47 | + if current_user.can?(:read_project, project) | |
48 | + project.send(table_name) | |
49 | + else | |
50 | + [] | |
51 | + end | |
52 | + else | |
53 | + klass.of_projects(current_user.authorized_projects) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + def by_scope(items) | |
43 | 58 | case params[:scope] |
44 | 59 | when 'created-by-me', 'authored' then |
45 | - current_user.send(table_name) | |
60 | + klass.where(author_id: current_user.id) | |
46 | 61 | when 'all' then |
47 | - if current_user | |
48 | - klass.of_projects(current_user.authorized_projects.pluck(:id)) | |
49 | - else | |
50 | - klass.of_projects(Project.public_only) | |
51 | - end | |
62 | + klass | |
52 | 63 | when 'assigned-to-me' then |
53 | - current_user.send("assigned_#{table_name}") | |
64 | + klass.where(assignee_id: current_user.id) | |
54 | 65 | else |
55 | 66 | raise 'You must specify default scope' |
56 | 67 | end |
... | ... | @@ -120,4 +131,8 @@ class FilteringService |
120 | 131 | |
121 | 132 | items |
122 | 133 | end |
134 | + | |
135 | + def project | |
136 | + Project.where(id: params[:project_id]).first if params[:project_id].present? | |
137 | + end | |
123 | 138 | end | ... | ... |
features/public/public_projects.feature
... | ... | @@ -62,3 +62,40 @@ Feature: Public Projects Feature |
62 | 62 | Given public empty project "Empty Public Project" |
63 | 63 | When I visit empty project page |
64 | 64 | Then I should see empty public project details |
65 | + | |
66 | + Scenario: I visit public project issues page as a non authorized user | |
67 | + Given I visit project "Community" page | |
68 | + And I visit "Community" issues page | |
69 | + Then I should see list of issues for "Community" project | |
70 | + | |
71 | + Scenario: I visit public project issues page as authorized user | |
72 | + Given I sign in as a user | |
73 | + Given I visit project "Community" page | |
74 | + And I visit "Community" issues page | |
75 | + Then I should see list of issues for "Community" project | |
76 | + | |
77 | + Scenario: I visit internal project issues page as authorized user | |
78 | + Given I sign in as a user | |
79 | + Given I visit project "Internal" page | |
80 | + And I visit "Internal" issues page | |
81 | + Then I should see list of issues for "Internal" project | |
82 | + | |
83 | + Scenario: I visit public project merge requests page as an authorized user | |
84 | + Given I sign in as a user | |
85 | + Given I visit project "Community" page | |
86 | + And I visit "Community" merge requests page | |
87 | + And project "Community" has "Bug fix" open merge request | |
88 | + Then I should see list of merge requests for "Community" project | |
89 | + | |
90 | + Scenario: I visit public project merge requests page as a non authorized user | |
91 | + Given I visit project "Community" page | |
92 | + And I visit "Community" merge requests page | |
93 | + And project "Community" has "Bug fix" open merge request | |
94 | + Then I should see list of merge requests for "Community" project | |
95 | + | |
96 | + Scenario: I visit internal project merge requests page as an authorized user | |
97 | + Given I sign in as a user | |
98 | + Given I visit project "Internal" page | |
99 | + And I visit "Internal" merge requests page | |
100 | + And project "Internal" has "Feature implemented" open merge request | |
101 | + Then I should see list of merge requests for "Internal" project | ... | ... |
features/steps/public/projects_feature.rb
... | ... | @@ -107,5 +107,94 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
107 | 107 | project = Project.find_by(name: 'Community') |
108 | 108 | page.should have_field('project_clone', with: project.url_to_repo) |
109 | 109 | end |
110 | + | |
111 | + step 'I visit "Community" issues page' do | |
112 | + create(:issue, | |
113 | + title: "Bug", | |
114 | + project: public_project | |
115 | + ) | |
116 | + create(:issue, | |
117 | + title: "New feature", | |
118 | + project: public_project | |
119 | + ) | |
120 | + visit project_issues_path(public_project) | |
121 | + end | |
122 | + | |
123 | + | |
124 | + step 'I should see list of issues for "Community" project' do | |
125 | + page.should have_content "Bug" | |
126 | + page.should have_content public_project.name | |
127 | + page.should have_content "New feature" | |
128 | + end | |
129 | + | |
130 | + step 'I visit "Internal" issues page' do | |
131 | + create(:issue, | |
132 | + title: "Internal Bug", | |
133 | + project: internal_project | |
134 | + ) | |
135 | + create(:issue, | |
136 | + title: "New internal feature", | |
137 | + project: internal_project | |
138 | + ) | |
139 | + visit project_issues_path(internal_project) | |
140 | + end | |
141 | + | |
142 | + | |
143 | + step 'I should see list of issues for "Internal" project' do | |
144 | + page.should have_content "Internal Bug" | |
145 | + page.should have_content internal_project.name | |
146 | + page.should have_content "New internal feature" | |
147 | + end | |
148 | + | |
149 | + step 'I visit "Community" merge requests page' do | |
150 | + visit project_merge_requests_path(public_project) | |
151 | + end | |
152 | + | |
153 | + step 'project "Community" has "Bug fix" open merge request' do | |
154 | + create(:merge_request, | |
155 | + title: "Bug fix for public project", | |
156 | + source_project: public_project, | |
157 | + target_project: public_project, | |
158 | + ) | |
159 | + end | |
160 | + | |
161 | + step 'I should see list of merge requests for "Community" project' do | |
162 | + page.should have_content public_project.name | |
163 | + page.should have_content public_merge_request.source_project.name | |
164 | + end | |
165 | + | |
166 | + step 'I visit "Internal" merge requests page' do | |
167 | + visit project_merge_requests_path(internal_project) | |
168 | + end | |
169 | + | |
170 | + step 'project "Internal" has "Feature implemented" open merge request' do | |
171 | + create(:merge_request, | |
172 | + title: "Feature implemented", | |
173 | + source_project: internal_project, | |
174 | + target_project: internal_project | |
175 | + ) | |
176 | + end | |
177 | + | |
178 | + step 'I should see list of merge requests for "Internal" project' do | |
179 | + page.should have_content internal_project.name | |
180 | + page.should have_content internal_merge_request.source_project.name | |
181 | + end | |
182 | + | |
183 | + def internal_project | |
184 | + @internal_project ||= Project.find_by!(name: 'Internal') | |
185 | + end | |
186 | + | |
187 | + def public_project | |
188 | + @public_project ||= Project.find_by!(name: 'Community') | |
189 | + end | |
190 | + | |
191 | + | |
192 | + def internal_merge_request | |
193 | + @internal_merge_request ||= MergeRequest.find_by!(title: 'Feature implemented') | |
194 | + end | |
195 | + | |
196 | + def public_merge_request | |
197 | + @public_merge_request ||= MergeRequest.find_by!(title: 'Bug fix for public project') | |
198 | + end | |
110 | 199 | end |
111 | 200 | ... | ... |