Class: ErpApp::Desktop::SecurityManagement::GroupsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- BaseController
- ErpApp::Desktop::SecurityManagement::GroupsController
- Defined in:
- app/controllers/erp_app/desktop/security_management/groups_controller.rb
Instance Method Summary collapse
- #add ⇒ Object
- #available ⇒ Object
- #available_setup ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #effective_security ⇒ Object
- #remove ⇒ Object
- #selected ⇒ Object
- #selected_setup ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
Methods inherited from BaseController
Instance Method Details
#add ⇒ Object
124 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 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 124 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 |g| group = Group.find(g) case assign_to when 'User' group.add_user(a) when 'SecurityRole' group.add_role(a) when 'Capability' group.add_capability(a) end end render :json => {:success => true, :message => 'Group(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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 34 def available assign_to = params[:assign_to] assign_to_id = params[:id] sort = (params[:sort] || 'description').downcase sort = 'groups.description' if sort == 'description' dir = (params[:dir] || 'asc').downcase query_filter = params[:query_filter].strip rescue nil ar = assign_to_id.blank? ? Group : assign_to.constantize.find(assign_to_id).groups_not ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(groups.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, :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 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 6 def available_setup begin columns = [] columns << DynamicGridColumn.build_column({ :fieldLabel => "Group Name", :name => 'description', :xtype => 'textfield', :width => 395 }) definition = [] definition << DynamicFormField.textfield({ :fieldLabel => "Group Name", :name => 'description' }) 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 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 64 def create begin description = params[:description].strip unless description.blank? Group.create(:description => params[:description]) render :json => {:success => true, :message => 'Group created'} else raise "Group 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 106 def delete begin unless params[:id].blank? Group.destroy(params[:id]) render :json => {:success => true, :message => 'Group deleted'} else raise "No Group 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 |
#effective_security ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 184 def effective_security begin assign_to_id = params[:id] u = Group.find(assign_to_id) render :json => {:success => true, :capabilities => u.class_capabilities_to_hash } 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
154 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 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 154 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 |g| group = Group.find(g) case assign_to when 'User' group.remove_user(a) when 'SecurityRole' group.remove_role(a) when 'Capability' group.remove_capability(a) end end render :json => {:success => true, :message => 'Group(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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 49 def selected assign_to = params[:assign_to] assign_to_id = params[:id] sort = (params[:sort] || 'description').downcase sort = 'groups.description' if sort == 'description' dir = (params[:dir] || 'asc').downcase query_filter = params[:query_filter].strip rescue nil ar = assign_to_id.blank? ? Group : assign_to.constantize.find(assign_to_id).groups ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(groups.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, :id => x.id}}} end |
#selected_setup ⇒ Object
30 31 32 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 30 def selected_setup available_setup end |
#update ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/erp_app/desktop/security_management/groups_controller.rb', line 84 def update begin description = params[:description].strip unless description.blank? or params[:id].blank? g = Group.find(params[:id]) g.description = description g.save render :json => {:success => true, :message => 'Group updated'} else raise "Group name blank or no group 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 |