Module: Sufia::UsersControllerBehavior

Extended by:
ActiveSupport::Concern
Included in:
UsersController
Defined in:
app/controllers/concerns/sufia/users_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#editObject

Display form for users to edit their profile information



28
29
30
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 28

def edit
  @trophies = Sufia::TrophyPresenter.find_by_user(@user)
end

#indexObject



14
15
16
17
18
19
20
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 14

def index
  @users = search(params[:uq])
  respond_to do |format|
    format.html
    format.json { render json: @users.to_json }
  end
end

#notifications_numberObject



56
57
58
59
60
61
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 56

def notifications_number
  @notify_number = 0
  return if action_name == "index" && controller_name == "mailbox"
  return unless user_signed_in?
  @notify_number = current_user.mailbox.inbox(unread: true).count
end

#showObject

Display user profile



23
24
25
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 23

def show
  @presenter = Sufia::UserProfilePresenter.new(@user, current_ability)
end

#updateObject

Process changes from profile form



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 33

def update
  if params[:user]
    @user.attributes = user_params
    @user.populate_attributes if update_directory?
  end

  unless @user.save
    redirect_to sufia.edit_profile_path(@user.to_param), alert: @user.errors.full_messages
    return
  end
  # TODO: this should be moved to TrophiesController
  params.keys.select { |k, _v| k.starts_with? 'remove_trophy_' }.each do |smash_trophy|
    smash_trophy = smash_trophy.sub(/^remove_trophy_/, '')
    current_user.trophies.where(work_id: smash_trophy).destroy_all
  end
  UserEditProfileEventJob.perform_later(@user)
  redirect_to sufia.profile_path(@user.to_param), notice: "Your profile has been updated"
end

#update_directory?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/controllers/concerns/sufia/users_controller_behavior.rb', line 52

def update_directory?
  ['1', 'true'].include? params[:user][:update_directory]
end