Class: Argus::Trail::RolesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/argus/trail/roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/argus/trail/roles_controller.rb', line 20

def create
  @role = role_class.new(role_params)
  authorize_access!(@role)

  if @role.save
    @role.sync_permissions!(params[:permission_ids], changed_by: current_actor)
    redirect_to role_path(@role), notice: "Role '#{@role.name}' created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



44
45
46
47
48
49
50
51
52
# File 'app/controllers/argus/trail/roles_controller.rb', line 44

def destroy
  if @role.actors.any?
    redirect_to roles_path,
                alert: "Cannot delete role '#{@role.name}' — it is assigned to #{@role.actors.count} record(s)."
  else
    @role.destroy
    redirect_to roles_path, notice: "Role '#{@role.name}' deleted."
  end
end

#editObject



32
33
# File 'app/controllers/argus/trail/roles_controller.rb', line 32

def edit
end

#indexObject



7
8
9
10
# File 'app/controllers/argus/trail/roles_controller.rb', line 7

def index
  authorize_access!(role_class)
  @roles = authorized_scope(role_class).includes(:permissions).order(:name)
end

#newObject



15
16
17
18
# File 'app/controllers/argus/trail/roles_controller.rb', line 15

def new
  @role = role_class.new
  authorize_access!(@role)
end

#showObject



12
13
# File 'app/controllers/argus/trail/roles_controller.rb', line 12

def show
end

#updateObject



35
36
37
38
39
40
41
42
# File 'app/controllers/argus/trail/roles_controller.rb', line 35

def update
  if @role.update(role_params)
    @role.sync_permissions!(params[:permission_ids], changed_by: current_actor)
    redirect_to role_path(@role), notice: "Role '#{@role.name}' updated."
  else
    render :edit, status: :unprocessable_entity
  end
end