Class: Spotlight::RolesController
Overview
CRUD actions for assigning exhibit roles to existing users
Instance Method Summary
collapse
Methods included from Controller
#blacklight_config, #current_exhibit, #current_masthead, #current_masthead=, #default_masthead?, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #search_action_url, #search_facet_url
Methods included from Config
#exhibit_specific_blacklight_config
Instance Method Details
#exists ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/spotlight/roles_controller.rb', line 33
def exists
if Spotlight::Engine.user_class.where(email: exists_params).present?
render json: { message: 'User exists' }
else
render json: { message: 'User does not exist' }, status: :not_found
end
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'app/controllers/spotlight/roles_controller.rb', line 10
def index
role = @exhibit.roles.build
authorize! :edit, role
add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit
add_breadcrumb t(:'spotlight.configuration.sidebar.header'), exhibit_dashboard_path(@exhibit)
add_breadcrumb t(:'spotlight.configuration.sidebar.users'), exhibit_roles_path(@exhibit)
end
|
#invite ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/spotlight/roles_controller.rb', line 43
def invite
user = Spotlight::Engine.user_class.invite!(email: invite_params[:user], skip_invitation: true) role = Spotlight::Role.create(exhibit: current_exhibit, user: user, role: invite_params[:role])
if role.save
user.deliver_invitation redirect_to :back, notice: t(:'helpers.submit.role.updated')
else
redirect_to :back, alert: t(:'helpers.submit.role.batch_error')
end
end
|
#update_all ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/spotlight/roles_controller.rb', line 19
def update_all
authorize_nested_attributes! exhibit_params[:roles_attributes], Role
any_deleted = exhibit_params[:roles_attributes].values.any? { |item| item['_destroy'].present? }
if @exhibit.update(exhibit_params)
notice = any_deleted ? t(:'helpers.submit.role.destroyed') : t(:'helpers.submit.role.updated')
redirect_to exhibit_roles_path(@exhibit), notice: notice
else
flash[:alert] = t(:'helpers.submit.role.batch_error')
render action: 'index'
end
end
|