Class: Spree::Admin::AdminUsersController
- Inherits:
-
BaseController
- Object
- BaseController
- BaseController
- Spree::Admin::AdminUsersController
- Includes:
- SettingsConcern
- Defined in:
- app/controllers/spree/admin/admin_users_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/admin_users this is a self signup flow for admin users from the invitation email.
-
#destroy ⇒ Object
DELETE /admin/admin_users/:id.
-
#edit ⇒ Object
GET /admin/admin_users/:id/edit.
-
#index ⇒ Object
GET /admin/admin_users.
-
#new ⇒ Object
GET /admin/admin_users/new?token=<token> this is a self signup flow for admin users from the invitation email.
-
#select_options ⇒ Object
GET /admin/admin_users/select_options.json.
-
#show ⇒ Object
GET /admin/admin_users/:id.
-
#update ⇒ Object
PUT /admin/admin_users/:id.
Methods included from BreadcrumbConcern
#add_breadcrumb_icon_instance_var
Instance Method Details
#create ⇒ Object
POST /admin/admin_users this is a self signup flow for admin users from the invitation email
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 48 def create @admin_user = Spree.admin_user_class.new(permitted_params) @invitation.invitee = @admin_user if @admin_user.save && @invitation.accept! # Automatically log in the user after successful signup # if Devise is installed if defined?(sign_in) sign_in(Spree.admin_user_class.model_name.singular_route_key, @admin_user) end redirect_to spree.admin_path else render :new, status: :unprocessable_content end end |
#destroy ⇒ Object
DELETE /admin/admin_users/:id
82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 82 def destroy :destroy, @admin_user if @admin_user.destroy redirect_to spree.admin_admin_users_path, status: :see_other, notice: (@admin_user, :successfully_removed) else flash[:error] = @admin_user.errors..to_sentence redirect_to spree.admin_admin_users_path, status: :see_other end end |
#edit ⇒ Object
GET /admin/admin_users/:id/edit
64 65 66 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 64 def edit :update, @admin_user end |
#index ⇒ Object
GET /admin/admin_users
15 16 17 18 19 20 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 15 def index @search = scope.includes(role_users: :role, avatar_attachment: :blob). where(role_users: { resource: @parent }). ransack(params[:q]) @collection = @search.result end |
#new ⇒ Object
GET /admin/admin_users/new?token=<token> this is a self signup flow for admin users from the invitation email
41 42 43 44 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 41 def new @admin_user = Spree.admin_user_class.new @admin_user.email = @invitation.email end |
#select_options ⇒ Object
GET /admin/admin_users/select_options.json
23 24 25 26 27 28 29 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 23 def q = params[:q] ransack_params = q.is_a?(String) ? { email_cont: q } : q users = Spree.admin_user_class.accessible_by(current_ability).ransack(ransack_params).result.order(:email).limit(50) render json: users.pluck(:id, :email).map { |id, email| { id: id, name: email } } end |
#show ⇒ Object
GET /admin/admin_users/:id
32 33 34 35 36 37 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 32 def show :read, @admin_user @role_users = @admin_user.role_users.includes(:role).where(resource: @parent) @admin_user.email, spree.admin_admin_user_path(@admin_user) end |
#update ⇒ Object
PUT /admin/admin_users/:id
69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/spree/admin/admin_users_controller.rb', line 69 def update :update, @admin_user permitted_params = params.require(:admin_user).permit(permitted_user_attributes | [spree_role_ids: []]) if @admin_user.update(permitted_params) redirect_to spree.admin_admin_user_path(@admin_user), status: :see_other, notice: (@admin_user, :successfully_updated) else render :edit, status: :unprocessable_content end end |