Commit dccd8b6eaa8b2e98b0245262a8e39df8fb8ae634
1 parent
39ba934c
Exists in
master
and in
4 other branches
Continue refactoring. Use repostory and team
Showing
42 changed files
with
219 additions
and
179 deletions
Show diff stats
app/contexts/notes/load_context.rb
... | ... | @@ -9,7 +9,7 @@ module Notes |
9 | 9 | |
10 | 10 | @notes = case target_type |
11 | 11 | when "commit" |
12 | - project.commit_notes(project.commit(target_id)).fresh.limit(20) | |
12 | + project.commit_notes(project.repository.commit(target_id)).fresh.limit(20) | |
13 | 13 | when "issue" |
14 | 14 | project.issues.find(target_id).notes.inc_author.fresh.limit(20) |
15 | 15 | when "merge_request" | ... | ... |
app/contexts/test_hook_context.rb
1 | 1 | class TestHookContext < BaseContext |
2 | 2 | def execute |
3 | 3 | hook = project.hooks.find(params[:id]) |
4 | - commits = project.commits(project.default_branch, nil, 3) | |
4 | + commits = project.repository.commits(project.default_branch, nil, 3) | |
5 | 5 | data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) |
6 | 6 | hook.execute(data) |
7 | 7 | end | ... | ... |
app/controllers/admin/projects_controller.rb
... | ... | @@ -10,6 +10,7 @@ class Admin::ProjectsController < AdminController |
10 | 10 | end |
11 | 11 | |
12 | 12 | def show |
13 | + @repository = @project.repository | |
13 | 14 | @users = User.active |
14 | 15 | @users = @users.not_in_project(@project) if @project.users.present? |
15 | 16 | @users = @users.all |
... | ... | @@ -19,7 +20,7 @@ class Admin::ProjectsController < AdminController |
19 | 20 | end |
20 | 21 | |
21 | 22 | def team_update |
22 | - @project.add_users_ids_to_team(params[:user_ids], params[:project_access]) | |
23 | + @project.team.add_users_ids(params[:user_ids], params[:project_access]) | |
23 | 24 | |
24 | 25 | redirect_to [:admin, @project], notice: 'Project was successfully updated.' |
25 | 26 | end |
... | ... | @@ -36,7 +37,7 @@ class Admin::ProjectsController < AdminController |
36 | 37 | |
37 | 38 | def destroy |
38 | 39 | # Delete team first in order to prevent multiple gitolite calls |
39 | - @project.truncate_team | |
40 | + @project.team.truncate | |
40 | 41 | |
41 | 42 | @project.destroy |
42 | 43 | ... | ... |
app/controllers/merge_requests_controller.rb
... | ... | @@ -83,12 +83,12 @@ class MergeRequestsController < ProjectResourceController |
83 | 83 | end |
84 | 84 | |
85 | 85 | def branch_from |
86 | - @commit = project.commit(params[:ref]) | |
86 | + @commit = @repository.commit(params[:ref]) | |
87 | 87 | @commit = CommitDecorator.decorate(@commit) |
88 | 88 | end |
89 | 89 | |
90 | 90 | def branch_to |
91 | - @commit = project.commit(params[:ref]) | |
91 | + @commit = @repository.commit(params[:ref]) | |
92 | 92 | @commit = CommitDecorator.decorate(@commit) |
93 | 93 | end |
94 | 94 | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -2,6 +2,7 @@ require Rails.root.join('lib', 'gitlab', 'graph', 'json_builder') |
2 | 2 | |
3 | 3 | class ProjectsController < ProjectResourceController |
4 | 4 | skip_before_filter :project, only: [:new, :create] |
5 | + skip_before_filter :repository, only: [:new, :create] | |
5 | 6 | |
6 | 7 | # Authorize |
7 | 8 | before_filter :authorize_read_project!, except: [:index, :new, :create] |
... | ... | @@ -58,7 +59,7 @@ class ProjectsController < ProjectResourceController |
58 | 59 | |
59 | 60 | respond_to do |format| |
60 | 61 | format.html do |
61 | - unless @project.empty_repo? | |
62 | + if @project.repository && !@project.repository.empty? | |
62 | 63 | @last_push = current_user.recent_push(@project.id) |
63 | 64 | render :show |
64 | 65 | else | ... | ... |
app/controllers/services_controller.rb
... | ... | @@ -26,7 +26,7 @@ class ServicesController < ProjectResourceController |
26 | 26 | end |
27 | 27 | |
28 | 28 | def test |
29 | - commits = project.commits(project.default_branch, nil, 3) | |
29 | + commits = project.repository.commits(project.default_branch, nil, 3) | |
30 | 30 | data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) |
31 | 31 | |
32 | 32 | @service = project.gitlab_ci_service | ... | ... |
app/controllers/team_members_controller.rb
... | ... | @@ -16,10 +16,9 @@ class TeamMembersController < ProjectResourceController |
16 | 16 | end |
17 | 17 | |
18 | 18 | def create |
19 | - @project.add_users_ids_to_team( | |
20 | - params[:user_ids], | |
21 | - params[:project_access] | |
22 | - ) | |
19 | + users = User.where(id: params[:user_ids]) | |
20 | + | |
21 | + @project.team << [users, params[:project_access]] | |
23 | 22 | |
24 | 23 | if params[:redirect_to] |
25 | 24 | redirect_to params[:redirect_to] |
... | ... | @@ -50,7 +49,7 @@ class TeamMembersController < ProjectResourceController |
50 | 49 | |
51 | 50 | def apply_import |
52 | 51 | giver = Project.find(params[:source_project_id]) |
53 | - status = UsersProject.import_team(giver, project) | |
52 | + status = @project.team.import(giver) | |
54 | 53 | notice = status ? "Succesfully imported" : "Import failed" |
55 | 54 | |
56 | 55 | redirect_to project_team_members_path(project), notice: notice | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -53,7 +53,7 @@ module ApplicationHelper |
53 | 53 | |
54 | 54 | def last_commit(project) |
55 | 55 | if project.repo_exists? |
56 | - time_ago_in_words(project.commit.committed_date) + " ago" | |
56 | + time_ago_in_words(project.repository.commit.committed_date) + " ago" | |
57 | 57 | else |
58 | 58 | "Never" |
59 | 59 | end |
... | ... | @@ -102,7 +102,7 @@ module ApplicationHelper |
102 | 102 | ] |
103 | 103 | |
104 | 104 | project_nav = [] |
105 | - if @project && !@project.new_record? | |
105 | + if @project && @project.repository && @project.repository.root_ref | |
106 | 106 | project_nav = [ |
107 | 107 | { label: "#{@project.name} Issues", url: project_issues_path(@project) }, |
108 | 108 | { label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) }, |
... | ... | @@ -142,6 +142,7 @@ module ApplicationHelper |
142 | 142 | event.last_push_to_non_root? && |
143 | 143 | !event.rm_ref? && |
144 | 144 | event.project && |
145 | + event.project.repository && | |
145 | 146 | event.project.merge_requests_enabled |
146 | 147 | end |
147 | 148 | ... | ... |
app/helpers/merge_requests_helper.rb
app/models/event.rb
... | ... | @@ -204,7 +204,7 @@ class Event < ActiveRecord::Base |
204 | 204 | |
205 | 205 | # Max 20 commits from push DESC |
206 | 206 | def commits |
207 | - @commits ||= data[:commits].map { |commit| project.commit(commit[:id]) }.reverse | |
207 | + @commits ||= data[:commits].map { |commit| repository.commit(commit[:id]) }.reverse | |
208 | 208 | end |
209 | 209 | |
210 | 210 | def commits_count |
... | ... | @@ -225,14 +225,18 @@ class Event < ActiveRecord::Base |
225 | 225 | end |
226 | 226 | end |
227 | 227 | |
228 | + def repository | |
229 | + project.repository | |
230 | + end | |
231 | + | |
228 | 232 | def parent_commit |
229 | - project.commit(commit_from) | |
233 | + repository.commit(commit_from) | |
230 | 234 | rescue => ex |
231 | 235 | nil |
232 | 236 | end |
233 | 237 | |
234 | 238 | def last_commit |
235 | - project.commit(commit_to) | |
239 | + repository.commit(commit_to) | |
236 | 240 | rescue => ex |
237 | 241 | nil |
238 | 242 | end | ... | ... |
app/models/note.rb
app/models/project.rb
... | ... | @@ -166,7 +166,13 @@ class Project < ActiveRecord::Base |
166 | 166 | end |
167 | 167 | |
168 | 168 | def repository |
169 | - @repository ||= Repository.new(path_with_namespace, default_branch) | |
169 | + if path | |
170 | + @repository ||= Repository.new(path_with_namespace, default_branch) | |
171 | + else | |
172 | + nil | |
173 | + end | |
174 | + rescue Grit::NoSuchPathError | |
175 | + nil | |
170 | 176 | end |
171 | 177 | |
172 | 178 | def git_error? |
... | ... | @@ -279,39 +285,6 @@ class Project < ActiveRecord::Base |
279 | 285 | users_projects.find_by_user_id(user_id) |
280 | 286 | end |
281 | 287 | |
282 | - # Update multiple project users | |
283 | - # to same access role by user ids | |
284 | - def update_users_ids_to_role(users_ids, access_role) | |
285 | - UsersProject.bulk_update(self, users_ids, access_role) | |
286 | - end | |
287 | - | |
288 | - # Delete multiple users from project by user ids | |
289 | - def delete_users_ids_from_team(users_ids) | |
290 | - UsersProject.bulk_delete(self, users_ids) | |
291 | - end | |
292 | - | |
293 | - def repository_readers | |
294 | - repository_members[UsersProject::REPORTER] | |
295 | - end | |
296 | - | |
297 | - def repository_writers | |
298 | - repository_members[UsersProject::DEVELOPER] | |
299 | - end | |
300 | - | |
301 | - def repository_masters | |
302 | - repository_members[UsersProject::MASTER] | |
303 | - end | |
304 | - | |
305 | - def repository_members | |
306 | - keys = Hash.new {|h,k| h[k] = [] } | |
307 | - UsersProject.select("keys.identifier, project_access"). | |
308 | - joins(user: :keys).where(project_id: id). | |
309 | - each {|row| keys[row.project_access] << [row.identifier] } | |
310 | - | |
311 | - keys[UsersProject::REPORTER] += deploy_keys.pluck(:identifier) | |
312 | - keys | |
313 | - end | |
314 | - | |
315 | 288 | def transfer(new_namespace) |
316 | 289 | Project.transaction do |
317 | 290 | old_namespace = namespace |
... | ... | @@ -441,7 +414,7 @@ class Project < ActiveRecord::Base |
441 | 414 | # |
442 | 415 | def post_receive_data(oldrev, newrev, ref, user) |
443 | 416 | |
444 | - push_commits = commits_between(oldrev, newrev) | |
417 | + push_commits = repository.commits_between(oldrev, newrev) | |
445 | 418 | |
446 | 419 | # Total commits count |
447 | 420 | push_commits_count = push_commits.size |
... | ... | @@ -488,7 +461,7 @@ class Project < ActiveRecord::Base |
488 | 461 | def update_merge_requests(oldrev, newrev, ref, user) |
489 | 462 | return true unless ref =~ /heads/ |
490 | 463 | branch_name = ref.gsub("refs/heads/", "") |
491 | - c_ids = self.commits_between(oldrev, newrev).map(&:id) | |
464 | + c_ids = self.repository.commits_between(oldrev, newrev).map(&:id) | |
492 | 465 | |
493 | 466 | # Update code for merge requests |
494 | 467 | mrs = self.merge_requests.opened.find_all_by_branch(branch_name).all |
... | ... | @@ -510,7 +483,7 @@ class Project < ActiveRecord::Base |
510 | 483 | end |
511 | 484 | |
512 | 485 | def empty_repo? |
513 | - !repository || repository.empty_repo? | |
486 | + !repository || repository.empty? | |
514 | 487 | end |
515 | 488 | |
516 | 489 | def satellite | ... | ... |
app/models/protected_branch.rb
app/models/repository.rb
... | ... | @@ -13,9 +13,11 @@ class Repository |
13 | 13 | attr_accessor :root_ref |
14 | 14 | |
15 | 15 | def initialize(path_with_namespace, root_ref = 'master') |
16 | - @root_ref = root_ref | |
16 | + @root_ref = root_ref || "master" | |
17 | 17 | @path_with_namespace = path_with_namespace |
18 | - @repo = Grit::Repo.new(path_to_repo) | |
18 | + | |
19 | + # Init grit repo object | |
20 | + repo | |
19 | 21 | end |
20 | 22 | |
21 | 23 | def raw |
... | ... | @@ -26,6 +28,10 @@ class Repository |
26 | 28 | @path_to_repo ||= File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git") |
27 | 29 | end |
28 | 30 | |
31 | + def repo | |
32 | + @repo ||= Grit::Repo.new(path_to_repo) | |
33 | + end | |
34 | + | |
29 | 35 | def commit(commit_id = nil) |
30 | 36 | Commit.find_or_first(repo, commit_id, root_ref) |
31 | 37 | end |
... | ... | @@ -114,7 +120,7 @@ class Repository |
114 | 120 | false |
115 | 121 | end |
116 | 122 | |
117 | - def empty_repo? | |
123 | + def empty? | |
118 | 124 | !has_commits? |
119 | 125 | end |
120 | 126 | ... | ... |
app/models/team.rb
... | ... | @@ -3,7 +3,22 @@ class Team |
3 | 3 | |
4 | 4 | def initialize(project) |
5 | 5 | @project = project |
6 | - @roles = UsersProject.roles_hash | |
6 | + end | |
7 | + | |
8 | + # Shortcut to add users | |
9 | + # | |
10 | + # Use: | |
11 | + # @team << [@user, :master] | |
12 | + # @team << [@users, :master] | |
13 | + # | |
14 | + def << args | |
15 | + users = args.first | |
16 | + | |
17 | + if users.respond_to?(:each) | |
18 | + add_users(users, args.second) | |
19 | + else | |
20 | + add_user(users, args.second) | |
21 | + end | |
7 | 22 | end |
8 | 23 | |
9 | 24 | def add_user(user, access) |
... | ... | @@ -14,7 +29,7 @@ class Team |
14 | 29 | add_users_ids(users.map(&:id), access) |
15 | 30 | end |
16 | 31 | |
17 | - def add_users_ids(users_ids, access) | |
32 | + def add_users_ids(user_ids, access) | |
18 | 33 | UsersProject.add_users_into_projects( |
19 | 34 | [project.id], |
20 | 35 | user_ids, |
... | ... | @@ -46,4 +61,58 @@ class Team |
46 | 61 | def masters |
47 | 62 | members.masters.map(&:user) |
48 | 63 | end |
64 | + | |
65 | + def repository_readers | |
66 | + repository_members[UsersProject::REPORTER] | |
67 | + end | |
68 | + | |
69 | + def repository_writers | |
70 | + repository_members[UsersProject::DEVELOPER] | |
71 | + end | |
72 | + | |
73 | + def repository_masters | |
74 | + repository_members[UsersProject::MASTER] | |
75 | + end | |
76 | + | |
77 | + def repository_members | |
78 | + keys = Hash.new {|h,k| h[k] = [] } | |
79 | + UsersProject.select("keys.identifier, project_access"). | |
80 | + joins(user: :keys).where(project_id: project.id). | |
81 | + each {|row| keys[row.project_access] << [row.identifier] } | |
82 | + | |
83 | + keys[UsersProject::REPORTER] += project.deploy_keys.pluck(:identifier) | |
84 | + keys | |
85 | + end | |
86 | + | |
87 | + def import(source_project) | |
88 | + target_project = project | |
89 | + | |
90 | + source_team = source_project.users_projects.all | |
91 | + target_team = target_project.users_projects.all | |
92 | + target_user_ids = target_team.map(&:user_id) | |
93 | + | |
94 | + source_team.reject! do |tm| | |
95 | + # Skip if user already present in team | |
96 | + target_user_ids.include?(tm.user_id) | |
97 | + end | |
98 | + | |
99 | + source_team.map! do |tm| | |
100 | + new_tm = tm.dup | |
101 | + new_tm.id = nil | |
102 | + new_tm.project_id = target_project.id | |
103 | + new_tm.skip_git = true | |
104 | + new_tm | |
105 | + end | |
106 | + | |
107 | + UsersProject.transaction do | |
108 | + source_team.each do |tm| | |
109 | + tm.save | |
110 | + end | |
111 | + target_project.update_repository | |
112 | + end | |
113 | + | |
114 | + true | |
115 | + rescue | |
116 | + false | |
117 | + end | |
49 | 118 | end | ... | ... |
app/models/user.rb
... | ... | @@ -188,7 +188,7 @@ class User < ActiveRecord::Base |
188 | 188 | |
189 | 189 | # Team membership in personal projects |
190 | 190 | def tm_in_personal_projects |
191 | - personal_projects.users_projects.where(user_id: self.id) | |
191 | + UsersProject.where(project_id: personal_projects.map(&:id), user_id: self.id) | |
192 | 192 | end |
193 | 193 | |
194 | 194 | # Returns a string for use as a Gitolite user identifier | ... | ... |
app/models/users_project.rb
... | ... | @@ -48,10 +48,23 @@ class UsersProject < ActiveRecord::Base |
48 | 48 | # access can be an integer representing a access code |
49 | 49 | # or symbol like :master representing role |
50 | 50 | # |
51 | + # Ex. | |
52 | + # add_users_into_projects( | |
53 | + # project_ids, | |
54 | + # user_ids, | |
55 | + # UsersProject::MASTER | |
56 | + # ) | |
57 | + # | |
58 | + # add_users_into_projects( | |
59 | + # project_ids, | |
60 | + # user_ids, | |
61 | + # :master | |
62 | + # ) | |
63 | + # | |
51 | 64 | def add_users_into_projects(project_ids, user_ids, access) |
52 | - project_access = if @roles.has_key?(access) | |
53 | - @roles[access] | |
54 | - elsif @roles.values.include?(access) | |
65 | + project_access = if roles_hash.has_key?(access) | |
66 | + roles_hash[access] | |
67 | + elsif roles_hash.values.include?(access.to_i) | |
55 | 68 | access |
56 | 69 | else |
57 | 70 | raise "Non valid access" |
... | ... | @@ -93,36 +106,6 @@ class UsersProject < ActiveRecord::Base |
93 | 106 | truncate_teams [project.id] |
94 | 107 | end |
95 | 108 | |
96 | - def import_team(source_project, target_project) | |
97 | - source_team = source_project.users_projects.all | |
98 | - target_team = target_project.users_projects.all | |
99 | - target_user_ids = target_team.map(&:user_id) | |
100 | - | |
101 | - source_team.reject! do |tm| | |
102 | - # Skip if user already present in team | |
103 | - target_user_ids.include?(tm.user_id) | |
104 | - end | |
105 | - | |
106 | - source_team.map! do |tm| | |
107 | - new_tm = tm.dup | |
108 | - new_tm.id = nil | |
109 | - new_tm.project_id = target_project.id | |
110 | - new_tm.skip_git = true | |
111 | - new_tm | |
112 | - end | |
113 | - | |
114 | - UsersProject.transaction do | |
115 | - source_team.each do |tm| | |
116 | - tm.save | |
117 | - end | |
118 | - target_project.update_repository | |
119 | - end | |
120 | - | |
121 | - true | |
122 | - rescue | |
123 | - false | |
124 | - end | |
125 | - | |
126 | 109 | def bulk_delete(project, user_ids) |
127 | 110 | UsersProject.transaction do |
128 | 111 | UsersProject.where(user_id: user_ids, project_id: project.id).each do |users_project| | ... | ... |
app/views/admin/projects/_form.html.haml
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | - if project.repo_exists? |
23 | 23 | .clearfix |
24 | 24 | = f.label :default_branch, "Default Branch" |
25 | - .input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;") | |
25 | + .input= f.select(:default_branch, repository.heads.map(&:name), {}, style: "width:210px;") | |
26 | 26 | |
27 | 27 | %fieldset.adv_settings |
28 | 28 | %legend Features: | ... | ... |
app/views/admin/projects/show.html.haml
... | ... | @@ -4,15 +4,15 @@ |
4 | 4 | %i.icon-edit |
5 | 5 | Edit |
6 | 6 | |
7 | -- if @project.has_commits? | |
8 | - - if !@project.has_post_receive_file? | |
7 | +- if @repository.has_commits? | |
8 | + - if !@repository.has_post_receive_file? | |
9 | 9 | %br |
10 | 10 | .alert.alert-error |
11 | 11 | %span |
12 | 12 | %strong Project has commits but missing post-receive file. |
13 | 13 | %br |
14 | 14 | If you exported project manually - make a link of post-receive hook file from gitolite to project repository |
15 | - - elsif !@project.valid_post_receive_file? | |
15 | + - elsif !@repository.valid_post_receive_file? | |
16 | 16 | %br |
17 | 17 | .alert.alert-error |
18 | 18 | %span |
... | ... | @@ -76,7 +76,7 @@ |
76 | 76 | %b |
77 | 77 | FS Path: |
78 | 78 | %td |
79 | - %code= @project.path_to_repo | |
79 | + %code= @repository.path_to_repo | |
80 | 80 | %tr |
81 | 81 | %td |
82 | 82 | %b |
... | ... | @@ -100,7 +100,7 @@ |
100 | 100 | %b |
101 | 101 | Post Receive File: |
102 | 102 | %td |
103 | - = check_box_tag :post_receive_file, 1, @project.has_post_receive_file?, disabled: true | |
103 | + = check_box_tag :post_receive_file, 1, @repository.has_post_receive_file?, disabled: true | |
104 | 104 | |
105 | 105 | %br |
106 | 106 | %h5 | ... | ... |
app/views/merge_requests/_form.html.haml
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | .mr_branch_box |
14 | 14 | %h5 From (Head Branch) |
15 | 15 | .body |
16 | - .padded= f.select(:source_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
16 | + .padded= f.select(:source_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
17 | 17 | .mr_source_commit |
18 | 18 | |
19 | 19 | .span2 |
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | .mr_branch_box |
23 | 23 | %h5 To (Base Branch) |
24 | 24 | .body |
25 | - .padded= f.select(:target_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
25 | + .padded= f.select(:target_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
26 | 26 | .mr_target_commit |
27 | 27 | |
28 | 28 | %h4.cdark 2. Fill info | ... | ... |
app/views/projects/_form.html.haml
... | ... | @@ -15,13 +15,13 @@ |
15 | 15 | = f.label :path do |
16 | 16 | Repository |
17 | 17 | .controls |
18 | - = text_field_tag :ppath, @project.path_to_repo, class: "xxlarge", readonly: true | |
18 | + = text_field_tag :ppath, @repository.path_to_repo, class: "xxlarge", readonly: true | |
19 | 19 | |
20 | 20 | |
21 | - - unless @project.heads.empty? | |
21 | + - unless @repository.heads.empty? | |
22 | 22 | .clearfix |
23 | 23 | = f.label :default_branch, "Default Branch" |
24 | - .input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;") | |
24 | + .input= f.select(:default_branch, @repository.heads.map(&:name), {}, style: "width:210px;") | |
25 | 25 | |
26 | 26 | %fieldset.features |
27 | 27 | %legend Features: | ... | ... |
app/workers/post_receive.rb
... | ... | @@ -11,7 +11,7 @@ class PostReceive |
11 | 11 | |
12 | 12 | # Ignore push from non-gitlab users |
13 | 13 | user = if identifier.eql? Gitlab.config.gitolite.admin_key |
14 | - email = project.commit(newrev).author.email rescue nil | |
14 | + email = project.repository.commit(newrev).author.email rescue nil | |
15 | 15 | User.find_by_email(email) if email |
16 | 16 | elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier) |
17 | 17 | User.find_by_email(identifier) | ... | ... |
features/steps/admin/admin_groups.rb
... | ... | @@ -16,7 +16,7 @@ class AdminGroups < Spinach::FeatureSteps |
16 | 16 | @project = create(:project, group: @group) |
17 | 17 | @event = create(:closed_issue_event, project: @project) |
18 | 18 | |
19 | - @project.add_access current_user, :admin | |
19 | + @project.team << [current_user, :master] | |
20 | 20 | end |
21 | 21 | |
22 | 22 | And 'Create gitlab user "John"' do | ... | ... |
features/steps/dashboard/dashboard.rb
... | ... | @@ -61,7 +61,7 @@ class Dashboard < Spinach::FeatureSteps |
61 | 61 | |
62 | 62 | And 'I own project "Shop"' do |
63 | 63 | @project = create :project, name: 'Shop' |
64 | - @project.add_access(@user, :admin) | |
64 | + @project.team << [@user, :master] | |
65 | 65 | end |
66 | 66 | |
67 | 67 | And 'I have group with projects' do |
... | ... | @@ -69,7 +69,7 @@ class Dashboard < Spinach::FeatureSteps |
69 | 69 | @project = create(:project, group: @group) |
70 | 70 | @event = create(:closed_issue_event, project: @project) |
71 | 71 | |
72 | - @project.add_access current_user, :admin | |
72 | + @project.team << [current_user, :master] | |
73 | 73 | end |
74 | 74 | |
75 | 75 | And 'project "Shop" has push event' do | ... | ... |
features/steps/dashboard/dashboard_issues.rb
... | ... | @@ -13,7 +13,7 @@ class DashboardIssues < Spinach::FeatureSteps |
13 | 13 | |
14 | 14 | And 'I have assigned issues' do |
15 | 15 | project = create :project |
16 | - project.add_access(@user, :read, :write) | |
16 | + project.team << [@user, :master] | |
17 | 17 | |
18 | 18 | 2.times { create :issue, author: @user, assignee: @user, project: project } |
19 | 19 | end | ... | ... |
features/steps/dashboard/dashboard_merge_requests.rb
... | ... | @@ -14,8 +14,8 @@ class DashboardMergeRequests < Spinach::FeatureSteps |
14 | 14 | project1 = create :project |
15 | 15 | project2 = create :project |
16 | 16 | |
17 | - project1.add_access(@user, :read, :write) | |
18 | - project2.add_access(@user, :read, :write) | |
17 | + project1.team << [@user, :master] | |
18 | + project2.team << [@user, :master] | |
19 | 19 | |
20 | 20 | merge_request1 = create :merge_request, author: @user, project: project1 |
21 | 21 | merge_request2 = create :merge_request, author: @user, project: project2 | ... | ... |
features/steps/dashboard/dashboard_search.rb
1 | 1 | class DashboardSearch < Spinach::FeatureSteps |
2 | 2 | include SharedAuthentication |
3 | 3 | include SharedPaths |
4 | + include SharedProject | |
4 | 5 | |
5 | 6 | Given 'I search for "Sho"' do |
6 | 7 | fill_in "dashboard_search", with: "Sho" |
... | ... | @@ -11,11 +12,6 @@ class DashboardSearch < Spinach::FeatureSteps |
11 | 12 | page.should have_link "Shop" |
12 | 13 | end |
13 | 14 | |
14 | - And 'I own project "Shop"' do | |
15 | - @project = create(:project, :name => "Shop") | |
16 | - @project.add_access(@user, :admin) | |
17 | - end | |
18 | - | |
19 | 15 | Given 'I search for "Contibuting"' do |
20 | 16 | fill_in "dashboard_search", with: "Contibuting" |
21 | 17 | click_button "Search" | ... | ... |
features/steps/group/group.rb
... | ... | @@ -13,7 +13,7 @@ class Groups < Spinach::FeatureSteps |
13 | 13 | @project = create(:project, group: @group) |
14 | 14 | @event = create(:closed_issue_event, project: @project) |
15 | 15 | |
16 | - @project.add_access current_user, :admin | |
16 | + @project.team << [current_user, :master] | |
17 | 17 | end |
18 | 18 | |
19 | 19 | And 'I should see projects activity feed' do | ... | ... |
features/steps/project/project_team_management.rb
... | ... | @@ -84,18 +84,18 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
84 | 84 | And '"Sam" is "Shop" developer' do |
85 | 85 | user = User.find_by_name("Sam") |
86 | 86 | project = Project.find_by_name("Shop") |
87 | - project.add_access(user, :write) | |
87 | + project.team << [user, :developer] | |
88 | 88 | end |
89 | 89 | |
90 | 90 | Given 'I own project "Website"' do |
91 | 91 | @project = create(:project, :name => "Website") |
92 | - @project.add_access(@user, :admin) | |
92 | + @project.team << [@user, :master] | |
93 | 93 | end |
94 | 94 | |
95 | 95 | And '"Mike" is "Website" reporter' do |
96 | 96 | user = User.find_by_name("Mike") |
97 | 97 | project = Project.find_by_name("Website") |
98 | - project.add_access(user, :read) | |
98 | + project.team << [user, :reporter] | |
99 | 99 | end |
100 | 100 | |
101 | 101 | And 'I click link "Import team from another project"' do | ... | ... |
features/steps/shared/paths.rb
... | ... | @@ -114,15 +114,15 @@ module SharedPaths |
114 | 114 | end |
115 | 115 | |
116 | 116 | Given "I visit my project's files page" do |
117 | - visit project_tree_path(@project, @project.root_ref) | |
117 | + visit project_tree_path(@project, root_ref) | |
118 | 118 | end |
119 | 119 | |
120 | 120 | Given "I visit my project's commits page" do |
121 | - visit project_commits_path(@project, @project.root_ref, {limit: 5}) | |
121 | + visit project_commits_path(@project, root_ref, {limit: 5}) | |
122 | 122 | end |
123 | 123 | |
124 | 124 | Given "I visit my project's commits page for a specific path" do |
125 | - visit project_commits_path(@project, @project.root_ref + "/app/models/project.rb", {limit: 5}) | |
125 | + visit project_commits_path(@project, root_ref + "/app/models/project.rb", {limit: 5}) | |
126 | 126 | end |
127 | 127 | |
128 | 128 | Given 'I visit my project\'s commits stats page' do |
... | ... | @@ -174,7 +174,7 @@ module SharedPaths |
174 | 174 | end |
175 | 175 | |
176 | 176 | Given 'I visit project commits page' do |
177 | - visit project_commits_path(@project, @project.root_ref, {limit: 5}) | |
177 | + visit project_commits_path(@project, root_ref, {limit: 5}) | |
178 | 178 | end |
179 | 179 | |
180 | 180 | Given 'I visit project commits page for stable branch' do |
... | ... | @@ -182,7 +182,7 @@ module SharedPaths |
182 | 182 | end |
183 | 183 | |
184 | 184 | Given 'I visit project source page' do |
185 | - visit project_tree_path(@project, @project.root_ref) | |
185 | + visit project_tree_path(@project, root_ref) | |
186 | 186 | end |
187 | 187 | |
188 | 188 | Given 'I visit blob file from repo' do |
... | ... | @@ -240,4 +240,8 @@ module SharedPaths |
240 | 240 | Given 'I visit project wiki page' do |
241 | 241 | visit project_wiki_path(@project, :index) |
242 | 242 | end |
243 | + | |
244 | + def root_ref | |
245 | + @project.repository.root_ref | |
246 | + end | |
243 | 247 | end | ... | ... |
features/steps/shared/project.rb
... | ... | @@ -4,13 +4,13 @@ module SharedProject |
4 | 4 | # Create a project without caring about what it's called |
5 | 5 | And "I own a project" do |
6 | 6 | @project = create(:project) |
7 | - @project.add_access(@user, :admin) | |
7 | + @project.team << [@user, :master] | |
8 | 8 | end |
9 | 9 | |
10 | 10 | # Create a specific project called "Shop" |
11 | 11 | And 'I own project "Shop"' do |
12 | - @project = create(:project, :name => "Shop") | |
13 | - @project.add_access(@user, :admin) | |
12 | + @project = create(:project, name: "Shop") | |
13 | + @project.team << [@user, :master] | |
14 | 14 | end |
15 | 15 | |
16 | 16 | def current_project | ... | ... |
lib/gitlab/backend/gitolite_config.rb
... | ... | @@ -82,7 +82,7 @@ module Gitlab |
82 | 82 | end |
83 | 83 | |
84 | 84 | def destroy_project(project) |
85 | - FileUtils.rm_rf(project.path_to_repo) | |
85 | + FileUtils.rm_rf(project.repository.path_to_repo) | |
86 | 86 | conf.rm_repo(project.path_with_namespace) |
87 | 87 | end |
88 | 88 | |
... | ... | @@ -138,9 +138,9 @@ module Gitlab |
138 | 138 | ::Gitolite::Config::Repo.new(repo_name) |
139 | 139 | end |
140 | 140 | |
141 | - name_readers = project.repository_readers | |
142 | - name_writers = project.repository_writers | |
143 | - name_masters = project.repository_masters | |
141 | + name_readers = project.team.repository_readers | |
142 | + name_writers = project.team.repository_writers | |
143 | + name_masters = project.team.repository_masters | |
144 | 144 | |
145 | 145 | pr_br = project.protected_branches.map(&:name).join("$ ") |
146 | 146 | ... | ... |
lib/gitlab/markdown.rb
... | ... | @@ -170,7 +170,7 @@ module Gitlab |
170 | 170 | end |
171 | 171 | |
172 | 172 | def reference_commit(identifier) |
173 | - if @project.valid_repo? && commit = @project.commit(identifier) | |
173 | + if @project.valid_repo? && commit = @project.repository.commit(identifier) | |
174 | 174 | link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}")) |
175 | 175 | end |
176 | 176 | end | ... | ... |
lib/gitlab/satellite/merge_action.rb
... | ... | @@ -31,7 +31,7 @@ module Gitlab |
31 | 31 | merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch) |
32 | 32 | |
33 | 33 | # remove source branch |
34 | - if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) | |
34 | + if merge_request.should_remove_source_branch && !project.repository.root_ref?(merge_request.source_branch) | |
35 | 35 | # will raise CommandFailed when push fails |
36 | 36 | merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}") |
37 | 37 | end | ... | ... |
spec/models/project_spec.rb
... | ... | @@ -75,35 +75,19 @@ describe Project do |
75 | 75 | end |
76 | 76 | |
77 | 77 | describe "Respond to" do |
78 | - it { should respond_to(:public?) } | |
79 | - it { should respond_to(:private?) } | |
80 | 78 | it { should respond_to(:url_to_repo) } |
81 | 79 | it { should respond_to(:path_to_repo) } |
82 | 80 | it { should respond_to(:valid_repo?) } |
83 | 81 | it { should respond_to(:repo_exists?) } |
84 | 82 | |
85 | 83 | # Repository Role |
86 | - it { should respond_to(:tree) } | |
87 | - it { should respond_to(:root_ref) } | |
88 | - it { should respond_to(:repo) } | |
89 | - it { should respond_to(:tags) } | |
90 | - it { should respond_to(:commit) } | |
91 | - it { should respond_to(:commits) } | |
92 | - it { should respond_to(:commits_between) } | |
93 | - it { should respond_to(:commits_with_refs) } | |
94 | - it { should respond_to(:commits_since) } | |
95 | - it { should respond_to(:commits_between) } | |
96 | 84 | it { should respond_to(:satellite) } |
97 | 85 | it { should respond_to(:update_repository) } |
98 | 86 | it { should respond_to(:destroy_repository) } |
99 | 87 | it { should respond_to(:archive_repo) } |
100 | 88 | |
101 | 89 | # Authority Role |
102 | - it { should respond_to(:add_access) } | |
103 | 90 | it { should respond_to(:reset_access) } |
104 | - it { should respond_to(:repository_writers) } | |
105 | - it { should respond_to(:repository_masters) } | |
106 | - it { should respond_to(:repository_readers) } | |
107 | 91 | it { should respond_to(:allow_read_for?) } |
108 | 92 | it { should respond_to(:guest_access_for?) } |
109 | 93 | it { should respond_to(:report_access_for?) } | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +describe Repository do | |
2 | + describe "Respond to" do | |
3 | + it { should respond_to(:repo) } | |
4 | + it { should respond_to(:tree) } | |
5 | + it { should respond_to(:root_ref) } | |
6 | + it { should respond_to(:tags) } | |
7 | + it { should respond_to(:commit) } | |
8 | + it { should respond_to(:commits) } | |
9 | + it { should respond_to(:commits_between) } | |
10 | + it { should respond_to(:commits_with_refs) } | |
11 | + it { should respond_to(:commits_since) } | |
12 | + it { should respond_to(:commits_between) } | |
13 | + end | |
14 | +end | ... | ... |
spec/models/system_hook_spec.rb
... | ... | @@ -56,7 +56,7 @@ describe SystemHook do |
56 | 56 | user = create(:user) |
57 | 57 | project = create(:project) |
58 | 58 | with_resque do |
59 | - project.add_access(user, :admin) | |
59 | + project.team << [user, :master] | |
60 | 60 | end |
61 | 61 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
62 | 62 | end |
... | ... | @@ -64,7 +64,7 @@ describe SystemHook do |
64 | 64 | it "project_destroy hook" do |
65 | 65 | user = create(:user) |
66 | 66 | project = create(:project) |
67 | - project.add_access(user, :admin) | |
67 | + project.team << [user, :master] | |
68 | 68 | with_resque do |
69 | 69 | project.users_projects.clear |
70 | 70 | end | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +describe Team do | |
2 | + describe "Respond to" do | |
3 | + it { should respond_to(:developers) } | |
4 | + it { should respond_to(:masters) } | |
5 | + it { should respond_to(:reporters) } | |
6 | + it { should respond_to(:guests) } | |
7 | + it { should respond_to(:repository_writers) } | |
8 | + it { should respond_to(:repository_masters) } | |
9 | + it { should respond_to(:repository_readers) } | |
10 | + end | |
11 | +end | |
12 | + | ... | ... |
spec/models/users_project_spec.rb
... | ... | @@ -48,10 +48,10 @@ describe UsersProject do |
48 | 48 | @user_1 = create :user |
49 | 49 | @user_2 = create :user |
50 | 50 | |
51 | - @project_1.add_access @user_1, :write | |
52 | - @project_2.add_access @user_2, :read | |
51 | + @project_1.team << [ @user_1, :developer ] | |
52 | + @project_2.team << [ @user_2, :reporter ] | |
53 | 53 | |
54 | - @status = UsersProject.import_team(@project_1, @project_2) | |
54 | + @status = @project_2.team.import(@project_1) | |
55 | 55 | end |
56 | 56 | |
57 | 57 | it { @status.should be_true } |
... | ... | @@ -101,8 +101,8 @@ describe UsersProject do |
101 | 101 | @user_1 = create :user |
102 | 102 | @user_2 = create :user |
103 | 103 | |
104 | - @project_1.add_access @user_1, :write | |
105 | - @project_2.add_access @user_2, :read | |
104 | + @project_1.team << [ @user_1, :developer] | |
105 | + @project_2.team << [ @user_2, :reporter] | |
106 | 106 | |
107 | 107 | UsersProject.truncate_teams([@project_1.id, @project_2.id]) |
108 | 108 | end | ... | ... |
spec/requests/issues_spec.rb
... | ... | @@ -7,8 +7,7 @@ describe "Issues" do |
7 | 7 | login_as :user |
8 | 8 | user2 = create(:user) |
9 | 9 | |
10 | - project.add_access(@user, :read, :write) | |
11 | - project.add_access(user2, :read, :write) | |
10 | + project.team << [[@user, user2], :developer] | |
12 | 11 | end |
13 | 12 | |
14 | 13 | describe "Edit issue" do | ... | ... |
spec/requests/projects_spec.rb
... | ... | @@ -6,7 +6,7 @@ describe "Projects" do |
6 | 6 | describe "GET /projects/show" do |
7 | 7 | before do |
8 | 8 | @project = create(:project, namespace: @user.namespace) |
9 | - @project.add_access(@user, :read) | |
9 | + @project.team << [@user, :reporter] | |
10 | 10 | |
11 | 11 | visit project_path(@project) |
12 | 12 | end |
... | ... | @@ -19,7 +19,7 @@ describe "Projects" do |
19 | 19 | describe "GET /projects/:id/edit" do |
20 | 20 | before do |
21 | 21 | @project = create(:project) |
22 | - @project.add_access(@user, :admin, :read) | |
22 | + @project.team << [@user, :master] | |
23 | 23 | |
24 | 24 | visit edit_project_path(@project) |
25 | 25 | end |
... | ... | @@ -38,7 +38,7 @@ describe "Projects" do |
38 | 38 | describe "PUT /projects/:id" do |
39 | 39 | before do |
40 | 40 | @project = create(:project, namespace: @user.namespace) |
41 | - @project.add_access(@user, :admin, :read) | |
41 | + @project.team << [@user, :master] | |
42 | 42 | |
43 | 43 | visit edit_project_path(@project) |
44 | 44 | |
... | ... | @@ -59,7 +59,7 @@ describe "Projects" do |
59 | 59 | describe "DELETE /projects/:id" do |
60 | 60 | before do |
61 | 61 | @project = create(:project, namespace: @user.namespace) |
62 | - @project.add_access(@user, :read, :admin) | |
62 | + @project.team << [@user, :master] | |
63 | 63 | visit edit_project_path(@project) |
64 | 64 | end |
65 | 65 | ... | ... |
spec/support/stubbed_repository.rb
1 | 1 | # Stubs out all Git repository access done by models so that specs can run |
2 | 2 | # against fake repositories without Grit complaining that they don't exist. |
3 | 3 | class Project |
4 | - def path_to_repo | |
5 | - if new_record? || path == 'newproject' | |
6 | - # There are a couple Project specs and features that expect the Project's | |
7 | - # path to be in the returned path, so let's patronize them. | |
8 | - Rails.root.join('tmp', 'repositories', path) | |
9 | - else | |
10 | - # For everything else, just give it the path to one of our real seeded | |
11 | - # repos. | |
12 | - Rails.root.join('tmp', 'repositories', 'gitlabhq') | |
13 | - end | |
14 | - end | |
15 | - | |
16 | 4 | def satellite |
17 | 5 | FakeSatellite.new |
18 | 6 | end |
... | ... | @@ -27,3 +15,9 @@ class Project |
27 | 15 | end |
28 | 16 | end |
29 | 17 | end |
18 | + | |
19 | +class Repository | |
20 | + def repo | |
21 | + @repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq')) | |
22 | + end | |
23 | +end | ... | ... |