Skip to content

Commit

Permalink
Merge pull request #3982 from bgeuken/refactor_request_controller__
Browse files Browse the repository at this point in the history
[frontend] Move adding maintainer to model
  • Loading branch information
bgeuken committed Oct 11, 2017
2 parents b47f4d2 + 9bd4a13 commit 9fe3eb3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/api/app/controllers/webui/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def changerequest
if target.can_be_modified_by?(User.current)
# the request action type might be permitted in future, but that doesn't mean we
# are allowed to modify the object
target.add_user(@bs_request.creator, 'maintainer')
target.save
target.store if target.kind_of? Project
target.add_maintainer(@bs_request.creator)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def meta
PackageMetaFile.new(project_name: project.name, package_name: name)
end

def add_maintainer(user)
add_user(user, 'maintainer')
save
end

def check_source_access?
if disabled_for?('sourceaccess', nil, nil) || project.disabled_for?('sourceaccess', nil, nil)
unless User.current && User.current.can_source_access?(self)
Expand Down
5 changes: 5 additions & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ def maintained_project_names
maintained_projects.includes(:project).pluck("projects.name")
end

def add_maintainer(user)
add_user(user, 'maintainer')
store
end

# Check if the project has a path_element matching project and repository
def has_distribution(project_name, repository)
has_local_distribution(project_name, repository) || has_remote_distribution(project_name, repository)
Expand Down
6 changes: 6 additions & 0 deletions src/api/spec/models/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,10 @@
it { expect(package.commit_message(nil, nil)).to include('Lorem ipsum dolorem') }
end
end

describe '#add_maintainer' do
subject { package }

it_behaves_like "makes a user a maintainer of the subject"
end
end
6 changes: 6 additions & 0 deletions src/api/spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,10 @@
expect(Relationship.exists?(relationship.id)).to be_falsey
end
end

describe '#add_maintainer' do
subject { project }

it_behaves_like "makes a user a maintainer of the subject"
end
end
14 changes: 14 additions & 0 deletions src/api/spec/support/shared_examples/relationships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RSpec.shared_examples 'makes a user a maintainer of the subject' do
let(:other_user) { create(:confirmed_user, login: 'bob') }
let(:maintainer_role) { Role.where(title: 'maintainer')}

before do
subject.add_maintainer(other_user)
end

it 'makes a user a maintainer of the package' do
expect(
subject.relationships.where(user: other_user, role: maintainer_role)
).to exist
end
end

0 comments on commit 9fe3eb3

Please sign in to comment.