class Oxen::UsersController < AbstractResourcesController # before_filter :authenticate_user! # after_action :verify_authorized before_filter :check_user_permissions, only: :create def confirm authorize resource if resource.confirm flash[:info] = t('user.confirmed_ok') render :confirm, layout: false, status: 200 and return else flash[:info] = t('user.not_confirmed_ok') render :confirm, layout: false, status: 401 and return end end # def index # @users = User.all # authorize User # end # def index # @resources = policy_scope(User) # authorize User # end # # def show # @user = User.find(params[:id]) # authorize @user # end # # def update # @user = User.find(params[:id]) # authorize @user # if @user.update_attributes(secure_params) # redirect_to users_path, :notice => "User updated." # else # redirect_to users_path, :alert => "Unable to update user." # end # end # # def destroy # user = User.find(params[:id]) # authorize user # user.destroy # redirect_to users_path, :notice => "User deleted." # end def update if params[:user][:password].blank? && params[:user][:password].blank? params[:user].delete :password params[:user].delete :password_confirmation end authorize resource resource.max_role = current_user.role if resource.update_attributes(secure_params) redirect_to users_path, :notice => "User updated." else render :edit, :alert => "Unable to update user." end # super end private def resource_params secure_params end def secure_params params.require(:user).permit(:role,:name,:email,:active,:account_id, :password, :password_confirmation) end def check_user_permissions UserPermission.where(email: params[:user][:email]).count == 1 end # # build options for fixed action button - implement on each controller to customize # raise an exception def set_fab_button_options opt = { items: {}} case params[:action] when 'nothing'; opt = opt when 'edit'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }, print: { ajax: 'get', icon: 'print', class: 'blue lighten-2', url: "/admin/accounts/#{resource.account.id}/print", browser: 'new' } when 'show'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }, print: { ajax: 'get', icon: 'print', class: 'blue lighten-2', url: "/admin/accounts/#{resource.account.id}/print", browser: 'new' } end # = build_print_link(f.object, list: false, print_options: "print_cmd=print_label", button: 'icon-tag', text: 'Udskriv dæk label') @fab_button_options = opt end end