Sha256: a31ef32edf1abf8bd7638def7b9b0caa244b243c9c258be769284094c9c998a7

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Pbw
  class RolesController < ApplicationController
    respond_to :json

    before_filter :authenticate_user!
    before_filter :is_super_admin?

    def index
      @roles = Role.all.keep_if{|i| i.name != "Super Admin"}
      render json: @roles
    end

    def show
      @role = Role.find(params[:id])
      @permissions = @role.permissions
      render json: {role: @role, permissions: @permissions}
    end

    def edit
      @role = Role.find(params[:id])
      @permissions = Permission.all.keep_if{|i| ["Part"].include? i.subject_class}.compact
      @role_permissions = @role.permissions.collect{|p| p.id}
      render json: {role: @role, permissions: @permissions, role_permissions: @role_permissions}
    end

    def update
      @role = Role.find(params[:id])
      @role.permissions = []
      @role.set_permissions(params[:permissions]) if params[:permissions]
      if @role.save
        render json: {notice: "Role updated"}
        return
      end
      render 'edit'
    end

    private

    def is_super_admin?
      redirect_to root_path and return unless current_user.super_admin?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pbw-0.0.2 app/controllers/pbw/roles_controller.rb