Class: Samvera::Persona::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/samvera/persona/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject

Delete a user from the site



72
73
74
75
76
77
78
79
# File 'app/controllers/samvera/persona/users_controller.rb', line 72

def destroy
  #TODO update hyku user.destroy to do roles.destroy_all instead
  if @user.present? && @user.destroy
    redirect_to main_app.persona_users_path, notice: t('.success', user: @user)
  else
    redirect_to main_app.persona_users_path flash: { error: t('.failure', user: @user) }
  end
end

#editObject

GET /persona/users/1/edit



28
29
30
31
32
33
34
35
# File 'app/controllers/samvera/persona/users_controller.rb', line 28

def edit
  # Hyrax derivitives have breadcrumbs, Avalon does not
  if defined?(add_breadcrumb)
    add_breadcrumb t(:'hyrax.controls.home'), main_app.root_path
    add_breadcrumb t(:'hyrax.admin.sidebar.users'), main_app.persona_users_path
    add_breadcrumb @user.display_name, main_app.edit_persona_user_path(@user)
  end
end

#impersonateObject

Become a user



60
61
62
63
64
# File 'app/controllers/samvera/persona/users_controller.rb', line 60

def impersonate
  user = User.find(params[:id])
  impersonate_user(user)
  redirect_to main_app.root_path
end

#indexObject

NOTE: User creation/invitations handled by devise_invitable



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/samvera/persona/users_controller.rb', line 16

def index
  # Hyrax derivitives have breadcrumbs, Avalon does not
  if defined?(add_breadcrumb)
    add_breadcrumb t(:'hyrax.controls.home'), main_app.root_path
    add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
    add_breadcrumb t(:'samvera.persona.users.index.title'), main_app.persona_users_path
  end

  @presenter = Samvera::Persona::UsersPresenter.new
end

#stop_impersonatingObject



66
67
68
69
# File 'app/controllers/samvera/persona/users_controller.rb', line 66

def stop_impersonating
  stop_impersonating_user
  redirect_to main_app.persona_users_path, notice: t('.become.over')
end

#updateObject

PATCH/PUT persona/users/1 PATCH/PUT persona/users/1.json



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/samvera/persona/users_controller.rb', line 39

def update
  # required for settings form to submit when password is left blank
  if params[:user][:password].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end

  respond_to do |format|
    if @user.update_attributes(user_params)
      @user.save

      format.html { redirect_to main_app.persona_users_path, notice: 'User was successfully updated.' }#move to locales
      format.json { render :show, status: :ok }
    else
      format.html { render :edit }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end