Class: Caboose::PermissionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::PermissionsController
- Defined in:
- app/controllers/caboose/permissions_controller.rb
Instance Method Summary collapse
- #before_action ⇒ Object
-
#create ⇒ Object
POST /admin/permissions.
-
#destroy ⇒ Object
DELETE /admin/permissions/1.
-
#edit ⇒ Object
GET /admin/permissions/1/edit.
-
#index ⇒ Object
GET /admin/permissions.
-
#new ⇒ Object
GET /admin/permissions/new.
-
#options ⇒ Object
GET /admin/permissions/options.
-
#update ⇒ Object
PUT /admin/permissions/1.
Methods inherited from ApplicationController
#admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#before_action ⇒ Object
5 6 7 |
# File 'app/controllers/caboose/permissions_controller.rb', line 5 def before_action @page = Page.page_with_uri(request.host_with_port, '/admin') end |
#create ⇒ Object
POST /admin/permissions
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/caboose/permissions_controller.rb', line 37 def create return if !user_is_allowed('permissions', 'add') resp = StdClass.new({ 'error' => nil, 'redirect' => nil }) perm = Permission.new() perm.resource = params[:resource] perm.action = params[:action2] if (perm.resource.strip.length == 0) resp.error = "The resource is required." elsif (perm.action.strip.length == 0) resp.error = "The action is required." else perm.save resp.redirect = "/admin/permissions/#{perm.id}/edit" end render json: resp end |
#destroy ⇒ Object
DELETE /admin/permissions/1
82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/caboose/permissions_controller.rb', line 82 def destroy return if !user_is_allowed('permissions', 'delete') perm = Permission.find(params[:id]) perm.destroy resp = StdClass.new({ 'redirect' => '/admin/permissions' }) render json: resp end |
#edit ⇒ Object
GET /admin/permissions/1/edit
31 32 33 34 |
# File 'app/controllers/caboose/permissions_controller.rb', line 31 def edit return if !user_is_allowed('permissions', 'edit') @permission = Permission.find(params[:id]) end |
#index ⇒ Object
GET /admin/permissions
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/caboose/permissions_controller.rb', line 10 def index return if !user_is_allowed('permissions', 'view') @gen = PageBarGenerator.new(params, { 'resource' => nil },{ 'model' => 'Caboose::Permission', 'sort' => 'resource, action', 'desc' => false, 'base_url' => '/admin/permissions' }) @permissions = @gen.items end |
#new ⇒ Object
GET /admin/permissions/new
25 26 27 28 |
# File 'app/controllers/caboose/permissions_controller.rb', line 25 def new return if !user_is_allowed('permissions', 'add') @permission = Permission.new end |
#options ⇒ Object
GET /admin/permissions/options
94 95 96 97 98 99 |
# File 'app/controllers/caboose/permissions_controller.rb', line 94 def return if !user_is_allowed('permissions', 'view') perms = Permission.reorder('resource, action').all = perms.collect { |p| { 'value' => p.id, 'text' => "#{p.resource}_#{p.action}"}} render json: end |
#update ⇒ Object
PUT /admin/permissions/1
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/caboose/permissions_controller.rb', line 61 def update return if !user_is_allowed('permissions', 'edit') resp = StdClass.new perm = Permission.find(params[:id]) save = true params.each do |name,value| case name when "resource" perm.resource = value when "action2" perm.action = value end end resp.success = save && perm.save render json: resp end |