Module: Collavre::UsersController::ProfileAndSettings

Extended by:
ActiveSupport::Concern
Included in:
Collavre::UsersController
Defined in:
app/controllers/concerns/collavre/users_controller/profile_and_settings.rb

Instance Method Summary collapse

Instance Method Details

#edit_passwordObject



48
49
50
51
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 48

def edit_password
  @user = Collavre::User.find(params[:id])
  head :forbidden unless @user == Current.user || Current.user.system_admin?
end

#notification_settingsObject



40
41
42
43
44
45
46
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 40

def notification_settings
  if Current.user.update(notification_settings_params)
    head :no_content
  else
    render json: { errors: Current.user.errors.full_messages }, status: :unprocessable_entity
  end
end

#passkeysObject



53
54
55
56
57
58
59
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 53

def passkeys
  @user = Collavre::User.find(params[:id])

  unless @user == Current.user || Current.user.system_admin?
    redirect_to user_path(Current.user), alert: I18n.t("collavre.users.destroy.not_authorized")
  end
end

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 5

def show
  @user = Collavre::User.find(params[:id])
  @active_tab = params[:tab].presence || "profile"
  @active_tab = "contacts" if @active_tab == "org_chart"
  @contacts_view = params[:contacts_view].presence || "list"
  if Current.user
    if @contacts_view == "org_chart"
      prepare_org_chart
    else
      prepare_contacts
    end
  else
    @contacts = []
    @shared_by_me = {}
    @shared_with_me = {}
    @total_contact_pages = 1
    @contact_page = 1
    @org_chart_roots = []
    @org_chart_shares = {}
    @org_chart_invitations = {}
    @org_chart_children = {}
    @org_chart_unassigned = []
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 30

def update
  @user = Collavre::User.find(params[:id])
  return head :forbidden unless @user == Current.user || Current.user.system_admin?
  if @user.update(profile_params)
    redirect_to user_path(@user), notice: I18n.t("collavre.users.profile_updated")
  else
    render :show, status: :unprocessable_entity
  end
end

#update_passwordObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/concerns/collavre/users_controller/profile_and_settings.rb', line 61

def update_password
  @user = Collavre::User.find(params[:id])
  if @user.authenticate(params[:user][:current_password])
    if @user.update(user_params)
      redirect_to user_path(@user), notice: I18n.t("collavre.users.password_updated")
    else
      flash.now[:alert] = I18n.t("collavre.users.password_update_failed")
      render :edit_password, status: :unprocessable_entity
    end
  else
    @user.errors.add(:current_password, I18n.t("collavre.users.current_password_incorrect"))
    flash.now[:alert] = I18n.t("collavre.users.password_update_failed")
    render :edit_password, status: :unprocessable_entity
  end
end