module MnoEnterprise::Concerns::Controllers::ProvisionController

Public Instance Methods

after_provision_path() click to toggle source

The path used after purchased apps have been provisionned

# File lib/mno_enterprise/concerns/controllers/provision_controller.rb, line 14
def after_provision_path
  MnoEnterprise.router.dashboard_path || main_app.root_path
end
create() click to toggle source

POST /provision TODO: check organization accessibility via ability

# File lib/mno_enterprise/concerns/controllers/provision_controller.rb, line 63
def create
  # Avoid double provisioning: previous url would be "/provision/new?apps[]=vtiger&organization_id=1"
  session.delete('previous_url')

  @organization = current_user.organizations.to_a.find { |o| o.id && o.id.to_s == params[:organization_id].to_s }
  authorize! :manage_app_instances, @organization

  app_instances = []
  params[:apps].each do |product_name|
    app_instance = @organization.app_instances.create(product: product_name)
    app_instances << app_instance
    MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance)
  end

  render json: app_instances.map(&:attributes).to_json, status: :created
end
new() click to toggle source
Instance methods
GET /provision/new?apps[]=vtiger&organization_id=1
TODO: check organization accessibility via ability
# File lib/mno_enterprise/concerns/controllers/provision_controller.rb, line 35
def new
  @apps = params[:apps]
  @organizations = current_user.organizations.to_a
  @organization = @organizations.find { |o| o.id && o.id.to_s == params[:organization_id].to_s }

  unless @organization
    @organization = @organizations.one? ? @organizations.first : nil
  end

  if @organization && cannot?(:manage_app_instances, @organization)
    msg = 'Unfortunately you do not have permission to purchase products for this organization'
    if @organizations.one?
      redirect_path = add_param_to_fragment(after_provision_path.to_s, 'flash', [{msg: msg,  type: :error}.to_json])
      redirect_to redirect_path
    else
      @organization = nil
      flash.now.alert = msg
    end
  end

  # Redirect to dashboard if no applications
  unless @apps && @apps.any?
    redirect_to after_provision_path
  end
end