Commit 37a90d5f764231cd765ff38448c6d650e61a4012
Committed by
baba
1 parent
b9d989dc
Exists in
master
and in
4 other branches
Selectable deploy keys contain master projects
Showing
5 changed files
with
29 additions
and
4 deletions
Show diff stats
app/controllers/deploy_keys_controller.rb
@@ -54,6 +54,6 @@ class DeployKeysController < ProjectResourceController | @@ -54,6 +54,6 @@ class DeployKeysController < ProjectResourceController | ||
54 | protected | 54 | protected |
55 | 55 | ||
56 | def available_keys | 56 | def available_keys |
57 | - @available_keys ||= current_user.owned_deploy_keys | 57 | + @available_keys ||= current_user.accessible_deploy_keys |
58 | end | 58 | end |
59 | end | 59 | end |
app/models/user.rb
@@ -90,6 +90,8 @@ class User < ActiveRecord::Base | @@ -90,6 +90,8 @@ class User < ActiveRecord::Base | ||
90 | 90 | ||
91 | has_many :personal_projects, through: :namespace, source: :projects | 91 | has_many :personal_projects, through: :namespace, source: :projects |
92 | has_many :projects, through: :users_projects | 92 | has_many :projects, through: :users_projects |
93 | + has_many :master_projects, through: :users_projects, source: :project, | ||
94 | + conditions: { users_projects: { project_access: UsersProject::MASTER } } | ||
93 | has_many :own_projects, foreign_key: :creator_id, class_name: 'Project' | 95 | has_many :own_projects, foreign_key: :creator_id, class_name: 'Project' |
94 | has_many :owned_projects, through: :namespaces, source: :projects | 96 | has_many :owned_projects, through: :namespaces, source: :projects |
95 | 97 | ||
@@ -354,7 +356,7 @@ class User < ActiveRecord::Base | @@ -354,7 +356,7 @@ class User < ActiveRecord::Base | ||
354 | extern_uid && provider == 'ldap' | 356 | extern_uid && provider == 'ldap' |
355 | end | 357 | end |
356 | 358 | ||
357 | - def owned_deploy_keys | ||
358 | - DeployKey.in_projects(self.owned_projects).uniq | 359 | + def accessible_deploy_keys |
360 | + DeployKey.in_projects(self.master_projects).uniq | ||
359 | end | 361 | end |
360 | end | 362 | end |
features/steps/project/deploy_keys.rb
@@ -35,6 +35,7 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps | @@ -35,6 +35,7 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps | ||
35 | 35 | ||
36 | step 'other project has deploy key' do | 36 | step 'other project has deploy key' do |
37 | @second_project = create :project, namespace: current_user.namespace | 37 | @second_project = create :project, namespace: current_user.namespace |
38 | + @second_project.team << [current_user, :master] | ||
38 | create(:deploy_keys_project, project: @second_project) | 39 | create(:deploy_keys_project, project: @second_project) |
39 | end | 40 | end |
40 | 41 |
lib/api/projects.rb
@@ -439,7 +439,7 @@ module API | @@ -439,7 +439,7 @@ module API | ||
439 | end | 439 | end |
440 | 440 | ||
441 | # Check for available deploy keys in other projects | 441 | # Check for available deploy keys in other projects |
442 | - key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) | 442 | + key = current_user.accessible_deploy_keys.find_by_key(attrs[:key]) |
443 | if key | 443 | if key |
444 | user_project.deploy_keys << key | 444 | user_project.deploy_keys << key |
445 | present key, with: Entities::SSHKey | 445 | present key, with: Entities::SSHKey |
spec/models/user_spec.rb
@@ -106,11 +106,33 @@ describe User do | @@ -106,11 +106,33 @@ describe User do | ||
106 | ActiveRecord::Base.observers.enable(:user_observer) | 106 | ActiveRecord::Base.observers.enable(:user_observer) |
107 | @user = create :user | 107 | @user = create :user |
108 | @project = create :project, namespace: @user.namespace | 108 | @project = create :project, namespace: @user.namespace |
109 | + @project_2 = create :project # Grant MASTER access to the user | ||
110 | + @project_3 = create :project # Grant DEVELOPER access to the user | ||
111 | + | ||
112 | + UsersProject.add_users_into_projects( | ||
113 | + [@project_2.id], [@user.id], UsersProject::MASTER | ||
114 | + ) | ||
115 | + UsersProject.add_users_into_projects( | ||
116 | + [@project_3.id], [@user.id], UsersProject::DEVELOPER | ||
117 | + ) | ||
109 | end | 118 | end |
110 | 119 | ||
111 | it { @user.authorized_projects.should include(@project) } | 120 | it { @user.authorized_projects.should include(@project) } |
121 | + it { @user.authorized_projects.should include(@project_2) } | ||
122 | + it { @user.authorized_projects.should include(@project_3) } | ||
112 | it { @user.owned_projects.should include(@project) } | 123 | it { @user.owned_projects.should include(@project) } |
124 | + it { @user.owned_projects.should_not include(@project_2) } | ||
125 | + it { @user.owned_projects.should_not include(@project_3) } | ||
113 | it { @user.personal_projects.should include(@project) } | 126 | it { @user.personal_projects.should include(@project) } |
127 | + it { @user.personal_projects.should_not include(@project_2) } | ||
128 | + it { @user.personal_projects.should_not include(@project_3) } | ||
129 | + | ||
130 | + # master_projects doesn't check creator/namespace. | ||
131 | + # In real case the users_projects relation will certainly be assigned | ||
132 | + # when the project is created. | ||
133 | + it { @user.master_projects.should_not include(@project) } | ||
134 | + it { @user.master_projects.should include(@project_2) } | ||
135 | + it { @user.master_projects.should_not include(@project_3) } | ||
114 | end | 136 | end |
115 | 137 | ||
116 | describe 'groups' do | 138 | describe 'groups' do |