Sha256: 805292d88e46121389c2cca95142a4e7e1395fff5fa6b710af1f4165e10749b2

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require_dependency "authz/application_controller"

module Authz
  class RolesController < ApplicationController

    def index
      @roles = Role.all.page(params[:roles_page])
    end

    def show
      @role = Role.find(params[:id])
      @associated_controller_actions = @role.controller_actions.distinct.page(params[:controller_actions_page]).per(10)
      @associated_business_processes = @role.business_processes.distinct.page(params[:business_processes_page]).per(10)
      @scoping_rules = {}
      ::Authz::Scopables::Base.get_scopables_modules.each do |scoping_module|
        @scoping_rules[scoping_module.to_s] = ScopingRule.find_by(scopable: scoping_module.to_s,
                                                                  role: @role)
      end
    end

    def new
      @role = Role.new
    end

    def create
      @role = Role.new(role_params)
      if @role.save
        redirect_to role_path(@role)
      else
        render 'new'
      end
    end

    def edit
      @role = Role.find(params[:id])
    end

    def update
      @role = Role.find(params[:id])
      if @role.update(role_params)
        redirect_to role_path(@role)
      else
        render 'edit'
      end
    end

    def destroy
      @role = Role.find(params[:id])
      if @role.destroy
        redirect_to roles_path
      else
        render 'show'
      end
    end

    private

    def role_params
      params.require(:role)
            .permit(
              :name,
              :description,
              business_process_ids: [],
              user_ids: [],
            )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authz-0.0.1.alpha4 app/controllers/authz/roles_controller.rb