Commit d431e4339269041784986da40a0e0879baaf96a9
1 parent
00a1f5bc
Exists in
master
and in
4 other branches
Fix few bugs and tests after refactoring ownership logic
Showing
19 changed files
with
58 additions
and
61 deletions
Show diff stats
app/controllers/admin/users_controller.rb
... | ... | @@ -9,7 +9,7 @@ class Admin::UsersController < AdminController |
9 | 9 | def show |
10 | 10 | @admin_user = User.find(params[:id]) |
11 | 11 | |
12 | - @projects = if @admin_user.projects.empty? | |
12 | + @projects = if @admin_user.authorized_projects.empty? | |
13 | 13 | Project |
14 | 14 | else |
15 | 15 | Project.without_user(@admin_user) |
... | ... | @@ -98,7 +98,7 @@ class Admin::UsersController < AdminController |
98 | 98 | |
99 | 99 | def destroy |
100 | 100 | @admin_user = User.find(params[:id]) |
101 | - if @admin_user.my_own_projects.count > 0 | |
101 | + if @admin_user.personal_projects.count > 0 | |
102 | 102 | redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return |
103 | 103 | end |
104 | 104 | @admin_user.destroy | ... | ... |
app/helpers/namespaces_helper.rb
app/models/ability.rb
... | ... | @@ -29,21 +29,10 @@ class Ability |
29 | 29 | rules << project_guest_rules |
30 | 30 | end |
31 | 31 | |
32 | - if project.namespace | |
33 | - # If user own project namespace | |
34 | - # (Ex. group owner or account owner) | |
35 | - if project.namespace.owner == user | |
36 | - rules << project_admin_rules | |
37 | - end | |
38 | - else | |
39 | - # For compatibility with global projects | |
40 | - # use projects.owner_id | |
41 | - if project.owner == user | |
42 | - rules << project_admin_rules | |
43 | - end | |
32 | + if project.owner == user | |
33 | + rules << project_admin_rules | |
44 | 34 | end |
45 | 35 | |
46 | - | |
47 | 36 | rules.flatten |
48 | 37 | end |
49 | 38 | ... | ... |
app/models/key.rb
app/models/project.rb
... | ... | @@ -80,7 +80,7 @@ class Project < ActiveRecord::Base |
80 | 80 | |
81 | 81 | # Scopes |
82 | 82 | scope :public_only, where(private_flag: false) |
83 | - scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } | |
83 | + scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } | |
84 | 84 | scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } |
85 | 85 | scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } |
86 | 86 | scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } | ... | ... |
app/models/user.rb
... | ... | @@ -187,4 +187,9 @@ class User < ActiveRecord::Base |
187 | 187 | (projects.namespace_id IS NULL AND projects.creator_id = :user_id)", |
188 | 188 | namespaces: namespaces.map(&:id), user_id: self.id) |
189 | 189 | end |
190 | + | |
191 | + # Team membership in personal projects | |
192 | + def tm_in_personal_projects | |
193 | + personal_projects.users_projects.where(user_id: self.id) | |
194 | + end | |
190 | 195 | end | ... | ... |
app/roles/account.rb
app/views/admin/projects/index.html.haml
... | ... | @@ -28,7 +28,10 @@ |
28 | 28 | %span.monospace= project.path_with_namespace + ".git" |
29 | 29 | %td= project.users_projects.count |
30 | 30 | %td |
31 | - = link_to project.chief.name, [:admin, project.chief] | |
31 | + - if project.owner | |
32 | + = link_to project.owner.name, [:admin, project.owner] | |
33 | + - else | |
34 | + (deleted) | |
32 | 35 | %td= last_commit(project) |
33 | 36 | %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" |
34 | 37 | %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger" | ... | ... |
app/views/admin/users/show.html.haml
... | ... | @@ -106,8 +106,8 @@ |
106 | 106 | %td= link_to group.name, admin_group_path(group) |
107 | 107 | |
108 | 108 | |
109 | -- if @admin_user.projects.present? | |
110 | - %h5 Projects: | |
109 | +- if @admin_user.personal_projects.present? | |
110 | + %h5 Personal Projects: | |
111 | 111 | %br |
112 | 112 | |
113 | 113 | %table.zebra-striped |
... | ... | @@ -118,7 +118,7 @@ |
118 | 118 | %th |
119 | 119 | %th |
120 | 120 | |
121 | - - @admin_user.users_projects.each do |tm| | |
121 | + - @admin_user.tm_in_personal_projects.each do |tm| | |
122 | 122 | - project = tm.project |
123 | 123 | %tr |
124 | 124 | %td= link_to project.name_with_namespace, admin_project_path(project) | ... | ... |
app/views/profiles/show.html.haml
lib/api/projects.rb
spec/factories.rb
spec/requests/api/issues_spec.rb
... | ... | @@ -4,7 +4,7 @@ describe Gitlab::API do |
4 | 4 | include ApiHelpers |
5 | 5 | |
6 | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | |
7 | + let!(:project) { create(:project, namespace: user.namespace ) } | |
8 | 8 | let!(:issue) { create(:issue, author: user, assignee: user, project: project) } |
9 | 9 | before { project.add_access(user, :read) } |
10 | 10 | ... | ... |
spec/requests/api/merge_requests_spec.rb
... | ... | @@ -4,7 +4,7 @@ describe Gitlab::API do |
4 | 4 | include ApiHelpers |
5 | 5 | |
6 | 6 | let(:user) { create(:user ) } |
7 | - let!(:project) { create(:project, owner: user) } | |
7 | + let!(:project) { create(:project, namespace: user.namespace ) } | |
8 | 8 | let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") } |
9 | 9 | before { project.add_access(user, :read) } |
10 | 10 | ... | ... |
spec/requests/api/milestones_spec.rb
... | ... | @@ -4,7 +4,7 @@ describe Gitlab::API do |
4 | 4 | include ApiHelpers |
5 | 5 | |
6 | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | |
7 | + let!(:project) { create(:project, namespace: user.namespace ) } | |
8 | 8 | let!(:milestone) { create(:milestone, project: project) } |
9 | 9 | |
10 | 10 | before { project.add_access(user, :read) } | ... | ... |
spec/requests/api/notes_spec.rb
... | ... | @@ -4,7 +4,7 @@ describe Gitlab::API do |
4 | 4 | include ApiHelpers |
5 | 5 | |
6 | 6 | let(:user) { create(:user) } |
7 | - let!(:project) { create(:project, owner: user) } | |
7 | + let!(:project) { create(:project, namespace: user.namespace ) } | |
8 | 8 | let!(:issue) { create(:issue, project: project, author: user) } |
9 | 9 | let!(:snippet) { create(:snippet, project: project, author: user) } |
10 | 10 | let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -7,7 +7,7 @@ describe Gitlab::API do |
7 | 7 | let(:user2) { create(:user) } |
8 | 8 | let(:user3) { create(:user) } |
9 | 9 | let!(:hook) { create(:project_hook, project: project, url: "http://example.com") } |
10 | - let!(:project) { create(:project, owner: user ) } | |
10 | + let!(:project) { create(:project, namespace: user.namespace ) } | |
11 | 11 | let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } |
12 | 12 | let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } |
13 | 13 | let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } |
... | ... | @@ -79,7 +79,7 @@ describe Gitlab::API do |
79 | 79 | end |
80 | 80 | |
81 | 81 | it "should return a project by path name" do |
82 | - get api("/projects/#{project.path}", user) | |
82 | + get api("/projects/#{project.id}", user) | |
83 | 83 | response.status.should == 200 |
84 | 84 | json_response['name'].should == project.name |
85 | 85 | end |
... | ... | @@ -93,7 +93,7 @@ describe Gitlab::API do |
93 | 93 | |
94 | 94 | describe "GET /projects/:id/repository/branches" do |
95 | 95 | it "should return an array of project branches" do |
96 | - get api("/projects/#{project.path}/repository/branches", user) | |
96 | + get api("/projects/#{project.id}/repository/branches", user) | |
97 | 97 | response.status.should == 200 |
98 | 98 | json_response.should be_an Array |
99 | 99 | json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name |
... | ... | @@ -102,7 +102,7 @@ describe Gitlab::API do |
102 | 102 | |
103 | 103 | describe "GET /projects/:id/repository/branches/:branch" do |
104 | 104 | it "should return the branch information for a single branch" do |
105 | - get api("/projects/#{project.path}/repository/branches/new_design", user) | |
105 | + get api("/projects/#{project.id}/repository/branches/new_design", user) | |
106 | 106 | response.status.should == 200 |
107 | 107 | |
108 | 108 | json_response['name'].should == 'new_design' |
... | ... | @@ -112,7 +112,7 @@ describe Gitlab::API do |
112 | 112 | |
113 | 113 | describe "GET /projects/:id/members" do |
114 | 114 | it "should return project team members" do |
115 | - get api("/projects/#{project.path}/members", user) | |
115 | + get api("/projects/#{project.id}/members", user) | |
116 | 116 | response.status.should == 200 |
117 | 117 | json_response.should be_an Array |
118 | 118 | json_response.count.should == 2 |
... | ... | @@ -120,7 +120,7 @@ describe Gitlab::API do |
120 | 120 | end |
121 | 121 | |
122 | 122 | it "finds team members with query string" do |
123 | - get api("/projects/#{project.path}/members", user), query: user.username | |
123 | + get api("/projects/#{project.id}/members", user), query: user.username | |
124 | 124 | response.status.should == 200 |
125 | 125 | json_response.should be_an Array |
126 | 126 | json_response.count.should == 1 |
... | ... | @@ -130,7 +130,7 @@ describe Gitlab::API do |
130 | 130 | |
131 | 131 | describe "GET /projects/:id/members/:user_id" do |
132 | 132 | it "should return project team member" do |
133 | - get api("/projects/#{project.path}/members/#{user.id}", user) | |
133 | + get api("/projects/#{project.id}/members/#{user.id}", user) | |
134 | 134 | response.status.should == 200 |
135 | 135 | json_response['email'].should == user.email |
136 | 136 | json_response['access_level'].should == UsersProject::MASTER |
... | ... | @@ -140,7 +140,7 @@ describe Gitlab::API do |
140 | 140 | describe "POST /projects/:id/members" do |
141 | 141 | it "should add user to project team" do |
142 | 142 | expect { |
143 | - post api("/projects/#{project.path}/members", user), user_id: user2.id, | |
143 | + post api("/projects/#{project.id}/members", user), user_id: user2.id, | |
144 | 144 | access_level: UsersProject::DEVELOPER |
145 | 145 | }.to change { UsersProject.count }.by(1) |
146 | 146 | |
... | ... | @@ -152,7 +152,7 @@ describe Gitlab::API do |
152 | 152 | |
153 | 153 | describe "PUT /projects/:id/members/:user_id" do |
154 | 154 | it "should update project team member" do |
155 | - put api("/projects/#{project.path}/members/#{user3.id}", user), access_level: UsersProject::MASTER | |
155 | + put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: UsersProject::MASTER | |
156 | 156 | response.status.should == 200 |
157 | 157 | json_response['email'].should == user3.email |
158 | 158 | json_response['access_level'].should == UsersProject::MASTER |
... | ... | @@ -162,14 +162,14 @@ describe Gitlab::API do |
162 | 162 | describe "DELETE /projects/:id/members/:user_id" do |
163 | 163 | it "should remove user from project team" do |
164 | 164 | expect { |
165 | - delete api("/projects/#{project.path}/members/#{user3.id}", user) | |
165 | + delete api("/projects/#{project.id}/members/#{user3.id}", user) | |
166 | 166 | }.to change { UsersProject.count }.by(-1) |
167 | 167 | end |
168 | 168 | end |
169 | 169 | |
170 | 170 | describe "GET /projects/:id/hooks" do |
171 | 171 | it "should return project hooks" do |
172 | - get api("/projects/#{project.path}/hooks", user) | |
172 | + get api("/projects/#{project.id}/hooks", user) | |
173 | 173 | |
174 | 174 | response.status.should == 200 |
175 | 175 | |
... | ... | @@ -181,7 +181,7 @@ describe Gitlab::API do |
181 | 181 | |
182 | 182 | describe "GET /projects/:id/hooks/:hook_id" do |
183 | 183 | it "should return a project hook" do |
184 | - get api("/projects/#{project.path}/hooks/#{hook.id}", user) | |
184 | + get api("/projects/#{project.id}/hooks/#{hook.id}", user) | |
185 | 185 | response.status.should == 200 |
186 | 186 | json_response['url'].should == hook.url |
187 | 187 | end |
... | ... | @@ -190,7 +190,7 @@ describe Gitlab::API do |
190 | 190 | describe "POST /projects/:id/hooks" do |
191 | 191 | it "should add hook to project" do |
192 | 192 | expect { |
193 | - post api("/projects/#{project.path}/hooks", user), | |
193 | + post api("/projects/#{project.id}/hooks", user), | |
194 | 194 | "url" => "http://example.com" |
195 | 195 | }.to change {project.hooks.count}.by(1) |
196 | 196 | end |
... | ... | @@ -198,7 +198,7 @@ describe Gitlab::API do |
198 | 198 | |
199 | 199 | describe "PUT /projects/:id/hooks/:hook_id" do |
200 | 200 | it "should update an existing project hook" do |
201 | - put api("/projects/#{project.path}/hooks/#{hook.id}", user), | |
201 | + put api("/projects/#{project.id}/hooks/#{hook.id}", user), | |
202 | 202 | url: 'http://example.org' |
203 | 203 | response.status.should == 200 |
204 | 204 | json_response['url'].should == 'http://example.org' |
... | ... | @@ -209,7 +209,7 @@ describe Gitlab::API do |
209 | 209 | describe "DELETE /projects/:id/hooks" do |
210 | 210 | it "should delete hook from project" do |
211 | 211 | expect { |
212 | - delete api("/projects/#{project.path}/hooks", user), | |
212 | + delete api("/projects/#{project.id}/hooks", user), | |
213 | 213 | hook_id: hook.id |
214 | 214 | }.to change {project.hooks.count}.by(-1) |
215 | 215 | end |
... | ... | @@ -217,7 +217,7 @@ describe Gitlab::API do |
217 | 217 | |
218 | 218 | describe "GET /projects/:id/repository/tags" do |
219 | 219 | it "should return an array of project tags" do |
220 | - get api("/projects/#{project.path}/repository/tags", user) | |
220 | + get api("/projects/#{project.id}/repository/tags", user) | |
221 | 221 | response.status.should == 200 |
222 | 222 | json_response.should be_an Array |
223 | 223 | json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name |
... | ... | @@ -229,7 +229,7 @@ describe Gitlab::API do |
229 | 229 | before { project.add_access(user2, :read) } |
230 | 230 | |
231 | 231 | it "should return project commits" do |
232 | - get api("/projects/#{project.path}/repository/commits", user) | |
232 | + get api("/projects/#{project.id}/repository/commits", user) | |
233 | 233 | response.status.should == 200 |
234 | 234 | |
235 | 235 | json_response.should be_an Array |
... | ... | @@ -239,7 +239,7 @@ describe Gitlab::API do |
239 | 239 | |
240 | 240 | context "unauthorized user" do |
241 | 241 | it "should not return project commits" do |
242 | - get api("/projects/#{project.path}/repository/commits") | |
242 | + get api("/projects/#{project.id}/repository/commits") | |
243 | 243 | response.status.should == 401 |
244 | 244 | end |
245 | 245 | end |
... | ... | @@ -247,7 +247,7 @@ describe Gitlab::API do |
247 | 247 | |
248 | 248 | describe "GET /projects/:id/snippets" do |
249 | 249 | it "should return an array of project snippets" do |
250 | - get api("/projects/#{project.path}/snippets", user) | |
250 | + get api("/projects/#{project.id}/snippets", user) | |
251 | 251 | response.status.should == 200 |
252 | 252 | json_response.should be_an Array |
253 | 253 | json_response.first['title'].should == snippet.title |
... | ... | @@ -256,7 +256,7 @@ describe Gitlab::API do |
256 | 256 | |
257 | 257 | describe "GET /projects/:id/snippets/:snippet_id" do |
258 | 258 | it "should return a project snippet" do |
259 | - get api("/projects/#{project.path}/snippets/#{snippet.id}", user) | |
259 | + get api("/projects/#{project.id}/snippets/#{snippet.id}", user) | |
260 | 260 | response.status.should == 200 |
261 | 261 | json_response['title'].should == snippet.title |
262 | 262 | end |
... | ... | @@ -264,7 +264,7 @@ describe Gitlab::API do |
264 | 264 | |
265 | 265 | describe "POST /projects/:id/snippets" do |
266 | 266 | it "should create a new project snippet" do |
267 | - post api("/projects/#{project.path}/snippets", user), | |
267 | + post api("/projects/#{project.id}/snippets", user), | |
268 | 268 | title: 'api test', file_name: 'sample.rb', code: 'test' |
269 | 269 | response.status.should == 201 |
270 | 270 | json_response['title'].should == 'api test' |
... | ... | @@ -273,7 +273,7 @@ describe Gitlab::API do |
273 | 273 | |
274 | 274 | describe "PUT /projects/:id/snippets/:shippet_id" do |
275 | 275 | it "should update an existing project snippet" do |
276 | - put api("/projects/#{project.path}/snippets/#{snippet.id}", user), | |
276 | + put api("/projects/#{project.id}/snippets/#{snippet.id}", user), | |
277 | 277 | code: 'updated code' |
278 | 278 | response.status.should == 200 |
279 | 279 | json_response['title'].should == 'example' |
... | ... | @@ -284,31 +284,31 @@ describe Gitlab::API do |
284 | 284 | describe "DELETE /projects/:id/snippets/:snippet_id" do |
285 | 285 | it "should delete existing project snippet" do |
286 | 286 | expect { |
287 | - delete api("/projects/#{project.path}/snippets/#{snippet.id}", user) | |
287 | + delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) | |
288 | 288 | }.to change { Snippet.count }.by(-1) |
289 | 289 | end |
290 | 290 | end |
291 | 291 | |
292 | 292 | describe "GET /projects/:id/snippets/:snippet_id/raw" do |
293 | 293 | it "should get a raw project snippet" do |
294 | - get api("/projects/#{project.path}/snippets/#{snippet.id}/raw", user) | |
294 | + get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user) | |
295 | 295 | response.status.should == 200 |
296 | 296 | end |
297 | 297 | end |
298 | 298 | |
299 | 299 | describe "GET /projects/:id/:sha/blob" do |
300 | 300 | it "should get the raw file contents" do |
301 | - get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.md", user) | |
301 | + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) | |
302 | 302 | response.status.should == 200 |
303 | 303 | end |
304 | 304 | |
305 | 305 | it "should return 404 for invalid branch_name" do |
306 | - get api("/projects/#{project.path}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) | |
306 | + get api("/projects/#{project.id}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) | |
307 | 307 | response.status.should == 404 |
308 | 308 | end |
309 | 309 | |
310 | 310 | it "should return 404 for invalid file" do |
311 | - get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.invalid", user) | |
311 | + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.invalid", user) | |
312 | 312 | response.status.should == 404 |
313 | 313 | end |
314 | 314 | end | ... | ... |
spec/requests/projects_spec.rb
... | ... | @@ -5,7 +5,7 @@ describe "Projects" do |
5 | 5 | |
6 | 6 | describe "GET /projects/show" do |
7 | 7 | before do |
8 | - @project = create(:project, owner: @user) | |
8 | + @project = create(:project, namespace: @user.namespace) | |
9 | 9 | @project.add_access(@user, :read) |
10 | 10 | |
11 | 11 | visit project_path(@project) |
... | ... | @@ -37,7 +37,7 @@ describe "Projects" do |
37 | 37 | |
38 | 38 | describe "PUT /projects/:id" do |
39 | 39 | before do |
40 | - @project = create(:project, owner: @user) | |
40 | + @project = create(:project, namespace: @user.namespace) | |
41 | 41 | @project.add_access(@user, :admin, :read) |
42 | 42 | |
43 | 43 | visit edit_project_path(@project) |
... | ... | @@ -58,7 +58,7 @@ describe "Projects" do |
58 | 58 | |
59 | 59 | describe "DELETE /projects/:id" do |
60 | 60 | before do |
61 | - @project = create(:project, owner: @user) | |
61 | + @project = create(:project, namespace: @user.namespace) | |
62 | 62 | @project.add_access(@user, :read, :admin) |
63 | 63 | visit edit_project_path(@project) |
64 | 64 | end | ... | ... |
spec/spec_helper.rb
... | ... | @@ -38,7 +38,7 @@ RSpec.configure do |config| |
38 | 38 | stub_gitolite! |
39 | 39 | |
40 | 40 | # !!! Observers disabled by default in tests |
41 | - ActiveRecord::Base.observers.disable(:all) | |
41 | + #ActiveRecord::Base.observers.disable(:all) | |
42 | 42 | # ActiveRecord::Base.observers.enable(:all) |
43 | 43 | |
44 | 44 | # Use tmp dir for FS manipulations | ... | ... |