Sha256: 75b6e6238d22ce6183a7e67617e2e48e6349df9ff79d0226b5dcee59241c74bd

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # A controller to handle the adminstration of site admin users
  class AdminUsersController < Spotlight::ApplicationController
    before_action :authenticate_user!
    before_action :load_site
    load_and_authorize_resource :site, class: 'Spotlight::Site'

    def index; end

    def create
      if update_roles
        Spotlight::InviteUsersService.call(resource: @site)
        flash[:notice] = t('spotlight.admin_users.create.success')
      else
        flash[:error] = t('spotlight.admin_users.create.error')
      end
      redirect_to spotlight.admin_users_path
    end

    def destroy
      user = Spotlight::Engine.user_class.find(params[:id])
      if user.roles.where(resource: @site).first.destroy
        flash[:notice] = t('spotlight.admin_users.destroy.success')
      else
        flash[:error] = t('spotlight.admin_users.destroy.error')
      end
      redirect_to spotlight.admin_users_path
    end

    private

    def load_site
      @site ||= Spotlight::Site.instance
    end

    def create_params
      params.require(:user).permit(:email)
    end

    def update_roles
      Spotlight::Role.create(user_key: create_params[:email], role: 'admin', resource: @site).save
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-2.10.0 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.9.0 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.8.0 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.7.2 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.7.1 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.7.0 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.6.1.1 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.6.1 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.6.0 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.5.2 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.5.1 app/controllers/spotlight/admin_users_controller.rb
blacklight-spotlight-2.5.0 app/controllers/spotlight/admin_users_controller.rb