20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/kaui/role_definitions_controller.rb', line 20
def create
@role_definition = Kaui::RoleDefinition.new(params.require(:role_definition))
@role_definition.permissions = @role_definition.permissions.split(',')
begin
@role_definition = @role_definition.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
return_context = session.delete(:role_return_context)
if return_context.present?
existing_roles = return_context[:roles].to_s.split(',').compact_blank
existing_roles << @role_definition.role unless existing_roles.include?(@role_definition.role)
return_context[:roles] = existing_roles.join(',')
if return_context[:allowed_user_id].present? && return_context[:allowed_user_id] != ''
redirect_to edit_admin_allowed_user_path(return_context[:allowed_user_id], user_context: return_context),
notice: "Role '#{@role_definition.role}' was successfully created"
else
redirect_to new_admin_allowed_user_path(user_context: return_context),
notice: "Role '#{@role_definition.role}' was successfully created"
end
else
redirect_to admin_allowed_users_path, notice: 'Role was successfully created'
end
rescue StandardError => e
flash.now[:error] = "Error while creating role: #{as_string(e)}"
render action: :new
end
end
|