Skip to content

Commit

Permalink
Merge pull request #1709 from samvera/collections-1689-default-partic…
Browse files Browse the repository at this point in the history
…ipants

Add default participants when new collection type created
  • Loading branch information
elrayle authored Sep 22, 2017
2 parents f6a2fd5 + b0d2fb1 commit a35269f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/hyrax/admin/collection_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def new
def create
@collection_type = Hyrax::CollectionType.new(collection_type_params)
if @collection_type.save
Hyrax::CollectionTypes::PermissionsService.add_default_participants(@collection_type.id)
redirect_to hyrax.edit_admin_collection_type_path(@collection_type), notice: t(:'hyrax.admin.collection_types.create.notification', name: @collection_type.title)
else
setup_form
Expand Down
12 changes: 12 additions & 0 deletions app/services/hyrax/collection_types/permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def self.group_edit_grants_for_collection_of_type(collection_type: nil)
groups | ['admin']
end

# @param collection_type_id [Integer]
def self.add_default_participants(collection_type_id)
return unless collection_type_id
default_participants = [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE,
agent_id: ::Ability.admin_group_name,
access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS },
{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE,
agent_id: ::Ability.registered_group_name,
access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }]
add_participants(collection_type_id, default_participants)
end

# @param collection_type_id [Integer]
# @param participants [Array]
def self.add_participants(collection_type_id, participants)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
post :create, params: { collection_type: valid_attributes }, session: valid_session
expect(assigns[:collection_type].attributes.symbolize_keys).to include(valid_attributes)
end

it "assigns default participants" do
expect do
post :create, params: { collection_type: valid_attributes }, session: valid_session
end.to change(Hyrax::CollectionTypeParticipant, :count).by(2)
end
end

context "with invalid params" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@
end
end

describe '.add_default_participants' do
let(:coltype) { create(:collection_type) }

it 'adds the default participants to a collection type' do
expect(Hyrax::CollectionTypeParticipant).to receive(:create!).exactly(2).times
described_class.add_default_participants(coltype.id)
end
end

describe ".add_participants" do
let(:participants) { [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: 'test_group', access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS }] }
let(:coltype) { create(:collection_type) }
Expand Down

0 comments on commit a35269f

Please sign in to comment.