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
app/models/user.rb
| ... | ... | @@ -90,6 +90,8 @@ class User < ActiveRecord::Base |
| 90 | 90 | |
| 91 | 91 | has_many :personal_projects, through: :namespace, source: :projects |
| 92 | 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 | 95 | has_many :own_projects, foreign_key: :creator_id, class_name: 'Project' |
| 94 | 96 | has_many :owned_projects, through: :namespaces, source: :projects |
| 95 | 97 | |
| ... | ... | @@ -354,7 +356,7 @@ class User < ActiveRecord::Base |
| 354 | 356 | extern_uid && provider == 'ldap' |
| 355 | 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 | 361 | end |
| 360 | 362 | end | ... | ... |
features/steps/project/deploy_keys.rb
| ... | ... | @@ -35,6 +35,7 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps |
| 35 | 35 | |
| 36 | 36 | step 'other project has deploy key' do |
| 37 | 37 | @second_project = create :project, namespace: current_user.namespace |
| 38 | + @second_project.team << [current_user, :master] | |
| 38 | 39 | create(:deploy_keys_project, project: @second_project) |
| 39 | 40 | end |
| 40 | 41 | ... | ... |
lib/api/projects.rb
| ... | ... | @@ -439,7 +439,7 @@ module API |
| 439 | 439 | end |
| 440 | 440 | |
| 441 | 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 | 443 | if key |
| 444 | 444 | user_project.deploy_keys << key |
| 445 | 445 | present key, with: Entities::SSHKey | ... | ... |
spec/models/user_spec.rb
| ... | ... | @@ -106,11 +106,33 @@ describe User do |
| 106 | 106 | ActiveRecord::Base.observers.enable(:user_observer) |
| 107 | 107 | @user = create :user |
| 108 | 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 | 118 | end |
| 110 | 119 | |
| 111 | 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 | 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 | 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 | 136 | end |
| 115 | 137 | |
| 116 | 138 | describe 'groups' do | ... | ... |