Sha256: 2489ff2798144b138d548b04bf357a612af708339baa89a6769f9c1e4cfda159
Contents?: true
Size: 1.72 KB
Versions: 11
Compression:
Stored size: 1.72 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 before_action :load_users 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 update user = Spotlight::Engine.user_class.find(params[:id]) if user Spotlight::Role.create(user_key: user.email, role: 'admin', resource: @site).save 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_users @users ||= ::User.all.reject(&:guest?) end 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
11 entries across 11 versions & 1 rubygems