Class: ErpApp::Desktop::SecurityManagement::RolesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- BaseController
- ErpApp::Desktop::SecurityManagement::RolesController
- Defined in:
- app/controllers/erp_app/desktop/security_management/roles_controller.rb
Instance Method Summary collapse
- #add ⇒ Object
- #available ⇒ Object
- #available_setup ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #remove ⇒ Object
- #selected ⇒ Object
- #selected_setup ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
Methods inherited from BaseController
Instance Method Details
#add ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 125 def add begin assign_to = params[:assign_to] assign_to_id = params[:id] selected = JSON.parse(params[:selection]) a = assign_to.constantize.find(assign_to_id) selected.each do |r| role = SecurityRole.find(r) case assign_to when 'User' a.add_role(role) when 'Group' a.add_role(role) when 'Capability' role.add_capability(a) end end render :json => {:success => true, :message => 'Security Roles(s) Added'} rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |
#available ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 36 def available assign_to = params[:assign_to] assign_to_id = params[:id] sort = (params[:sort] || 'description').downcase dir = (params[:dir] || 'asc').downcase query_filter = params[:query_filter].strip rescue nil ar = assign_to_id.blank? ? SecurityRole : assign_to.constantize.find(assign_to_id).roles_not ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(security_roles.description) LIKE UPPER('%#{query_filter}%')")) available = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}") render :json => {:total => ar.count, :data => available.map{|x| {:description => x.description, :internal_identifier => x.internal_identifier, :id => x.id}}} end |
#available_setup ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 6 def available_setup begin columns = [] columns << DynamicGridColumn.build_column({ :fieldLabel => "Security Role Name", :name => 'description', :xtype => 'textfield', :width => 200 }) columns << DynamicGridColumn.build_column({ :fieldLabel => "Internal ID", :name => 'internal_identifier', :xtype => 'textfield', :width => 195 }) definition = [] definition << DynamicFormField.textfield({ :fieldLabel => "Security Role Name", :name => 'description' }) definition << DynamicFormField.textfield({ :fieldLabel => "Internal ID", :name => 'internal_identifier' }) definition << DynamicFormField.hidden({ :fieldLabel => "ID", :name => 'id' }) render :inline => "{ \"success\": true, \"columns\": [#{columns.join(',')}], \"fields\": #{definition.to_json} }" rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |
#create ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 64 def create begin description = params[:description].strip iid = params[:internal_identifier].strip unless description.blank? SecurityRole.create(:description => description, :internal_identifier => iid) render :json => {:success => true, :message => 'Security Role created'} else raise "Role name blank" end rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |
#delete ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 107 def delete begin unless params[:id].blank? SecurityRole.destroy(params[:id]) render :json => {:success => true, :message => 'Security Role deleted'} else raise "No Role ID" end rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |
#remove ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 155 def remove begin assign_to = params[:assign_to] assign_to_id = params[:id] selected = JSON.parse(params[:selection]) a = assign_to.constantize.find(assign_to_id) selected.each do |r| role = SecurityRole.find(r) case assign_to when 'User' a.remove_role(role) when 'Group' a.remove_role(role) when 'Capability' role.remove_capability(a) end end render :json => {:success => true, :message => 'Security Roles(s) Removed'} rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |
#selected ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 50 def selected assign_to = params[:assign_to] assign_to_id = params[:id] sort = (params[:sort] || 'description').downcase dir = (params[:dir] || 'asc').downcase query_filter = params[:query_filter].strip rescue nil ar = assign_to_id.blank? ? SecurityRole : assign_to.constantize.find(assign_to_id).roles ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(security_roles.description) LIKE UPPER('%#{query_filter}%')")) selected = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}") render :json => {:total => ar.count, :data => selected.map{|x| {:description => x.description, :internal_identifier => x.internal_identifier, :id => x.id}}} end |
#selected_setup ⇒ Object
32 33 34 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 32 def selected_setup available_setup end |
#update ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/erp_app/desktop/security_management/roles_controller.rb', line 85 def update begin description = params[:description].strip unless description.blank? or params[:id].blank? r = SecurityRole.find(params[:id]) r.description = description r.save render :json => {:success => true, :message => 'Security Role updated'} else raise "Role name blank or no role ID" end rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :inline => { :success => false, :message => e. }.to_json end end |