Class: Workarea::Admin::UsersController

Inherits:
ApplicationController show all
Includes:
UserParams
Defined in:
app/controllers/workarea/admin/users_controller.rb

Instance Method Summary collapse

Methods included from UserParams

#user_params

Methods inherited from ApplicationController

#current_user, #find_sort, #wrap_in_view_model, wrap_in_view_model

Methods included from Publishing

#allow_publishing!, #allow_publishing?, #set_publishing_options

Methods included from Visiting

#most_visited

Instance Method Details

#addressesObject



55
56
# File 'app/controllers/workarea/admin/users_controller.rb', line 55

def addresses
end

#editObject



34
35
# File 'app/controllers/workarea/admin/users_controller.rb', line 34

def edit
end

#indexObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/workarea/admin/users_controller.rb', line 12

def index
  search_params = params.merge(autocomplete: request.xhr?)

  respond_to do |format|
    format.html do
      search = Search::AdminUsers.new(search_params)
      @search = Admin::UserSearchViewModel.new(search, view_model_options)
    end

    format.json do
      search = Search::AdminUsers.new(search_params.merge(role: ['Administrator']))
      @results =
        Admin::UserSearchViewModel.new(search, view_model_options).results.reject do |result|
          result.id == current_user.id && params[:exclude_current_user]
        end
    end
  end
end

#insightsObject



58
59
60
61
# File 'app/controllers/workarea/admin/users_controller.rb', line 58

def insights
  models = Workarea::Insights::Base.by_customer(@user.email)
  @insights = InsightViewModel.wrap(models, view_model_options)
end

#ordersObject



48
49
# File 'app/controllers/workarea/admin/users_controller.rb', line 48

def orders
end

#permissionsObject



51
52
53
# File 'app/controllers/workarea/admin/users_controller.rb', line 51

def permissions
  unauthorized_user and return unless current_user.permissions_manager?
end

#send_password_resetObject



63
64
65
66
67
68
69
# File 'app/controllers/workarea/admin/users_controller.rb', line 63

def send_password_reset
  password_reset = User::PasswordReset.create!(user: @user.model)
  Storefront::AccountMailer.password_reset(password_reset.id.to_s).deliver_later

  flash[:success] = t('workarea.admin.users.flash_messages.password_reset')
  redirect_to user_path(@user)
end

#showObject



31
32
# File 'app/controllers/workarea/admin/users_controller.rb', line 31

def show
end

#unlockObject



71
72
73
74
75
# File 'app/controllers/workarea/admin/users_controller.rb', line 71

def unlock
  @user.unlock_login!
  flash[:success] = t('workarea.admin.users.flash_messages.unlocked')
  redirect_to user_path(@user)
end

#updateObject



37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/workarea/admin/users_controller.rb', line 37

def update
  if @user.update_attributes(user_params)
    
    @user.payment_profile.update_attributes(params[:payment])
    flash[:success] = t('workarea.admin.users.flash_messages.saved')
    redirect_to user_path(@user)
  else
    render :edit, status: :unprocessable_entity
  end
end