invite user with roles

This commit is contained in:
Rahul 2019-07-22 14:11:46 +05:30
parent 770a63e15c
commit 804ebb455f
3 changed files with 29 additions and 4 deletions

View file

@ -7,6 +7,7 @@ module Admin
authorize_resource :role, except: :index
# Show flash message with ajax calls
after_action :prepare_unobtrusive_flash, only: :toggle_user
include Invitation
def index
@roles = Role.where(resource: @conference)
@ -61,13 +62,11 @@ module Admin
else
admin_conference_role_path(@conference.short_title, @role.name)
end
user ||= invite_via_email
unless user
redirect_to url,
error: 'Could not find user. Please provide a valid email!'
redirect_to url, error: 'Could not find user. Please provide a valid email!'
return
end
# The conference must have at least 1 organizer
if @role.name == 'organizer' && state == 'false' && @role.users.count == 1
redirect_to admin_conference_role_path(@conference.short_title, @role.name),

View file

@ -18,4 +18,8 @@ module Invitation
end
end
end
def invite_via_email
User.invite!({ email: user_params[:email] }, current_user)
end
end

View file

@ -95,6 +95,28 @@ describe Admin::RolesController do
end
end
context 'adds role to unregistered user' do
it 'adds a new unregistered user' do
post :toggle_user, params: { conference_id: conference.short_title,
user: { email: 'example@osem.io' },
id: 'cfp' }
expect(User.find_by(email: 'example@osem.io').roles).to eq [cfp_role]
end
it 'assigns two role to an unregsitered user' do
post :toggle_user, params: { conference_id: conference.short_title,
user: { email: 'example@osem.io' },
id: 'cfp' }
post :toggle_user, params: { conference_id: conference.short_title,
user: { email: 'example@osem.io' },
id: 'organizer' }
expect(User.find_by(email: 'example@osem.io').roles).to eq [organizer_role, cfp_role]
end
end
context 'removes role from user' do
it 'removes role from user' do
post :toggle_user, params: { conference_id: conference.short_title,