Skip to content

Commit

Permalink
Merge pull request #170 from scientist-softserv/inviting-existing-use…
Browse files Browse the repository at this point in the history
…rs-fails

Inviting existing users fails
  • Loading branch information
bkiahstroud authored Oct 13, 2023
2 parents d89f7de + 2e04403 commit fbad81f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/hyku/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def create
authorize! :grant_admin_role, User if params[:user][:role] == ::RolesService::ADMIN_ROLE
self.resource = User.find_by(email: params[:user][:email]) || invite_resource

resource.add_default_group_membership!
resource.add_role(params[:user][:role], Site.instance) if params[:user][:role].present?

yield resource if block_given?
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/hyku/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,31 @@
expect(response).to redirect_to Hyrax::Engine.routes.url_helpers.admin_users_path(locale: 'en')
expect(flash[:notice]).to eq 'An invitation email has been sent to [email protected].'
end

context 'when user already exists' do
let(:user) { create(:user) }

# Mimic the state of a user who is only active in other tenants;
# i.e. a user who has no roles in this tenant
before do
user.roles.destroy_all
end

it 'adds the user to the registered group' do
expect(user.roles).to be_empty
expect(user.groups).to be_empty

post :create, params: {
user: {
email: user.email,
role: ''
}
}

user.reload
expect(user.roles).not_to be_empty
expect(user.groups).to eq([Ability.registered_group_name])
end
end
end
end

0 comments on commit fbad81f

Please sign in to comment.