Class: AdminController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- AdminController
- Defined in:
- lib/generators/connector/templates/admin_controller.rb
Overview
TODO This controller is given as an example of a possible admin implementation The admin functions should be restricted to admin users Admin funcitons :
* Link account to external application
* Disconnect account from external application
* Launch a manual syncrhonization for all entities or a sub-part of them
* Chose which entities are synchronized by the connector
* Access a list of the organization's idmaps
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
12 13 14 15 16 17 |
# File 'lib/generators/connector/templates/admin_controller.rb', line 12 def index if is_admin @organization = current_organization @idmaps = Maestrano::Connector::Rails::IdMap.where(organization_id: @organization.id).order(:connec_entity) end end |
#synchronize ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/generators/connector/templates/admin_controller.rb', line 36 def synchronize if is_admin Maestrano::Connector::Rails::SynchronizationJob.perform_later(current_organization, params['opts'] || {}) end redirect_to root_path end |
#toggle_sync ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/connector/templates/admin_controller.rb', line 44 def toggle_sync if is_admin current_organization = Maestrano::Connector::Rails::Organization.first current_organization.update(sync_enabled: !current_organization.sync_enabled) flash[:notice] = current_organization.sync_enabled ? 'Synchronization enabled' : 'Synchronization disabled' end redirect_to admin_index_path end |
#update ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/connector/templates/admin_controller.rb', line 19 def update organization = Maestrano::Connector::Rails::Organization.find_by_id(params[:id]) if organization && is_admin?(current_user, organization) organization.synchronized_entities.keys.each do |entity| if !!params["#{entity}"] organization.synchronized_entities[entity] = true else organization.synchronized_entities[entity] = false end end organization.save end redirect_to admin_index_path end |