2012-10-15 10:45:00 +01:00
|
|
|
class Api::V1::UsersController < Api::V1::BaseController
|
2012-12-29 12:38:14 +00:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
2016-03-24 15:59:12 +00:00
|
|
|
skip_before_action :check_auth, only: [:show] if APP_CONFIG['anonymous_access']
|
2015-03-04 23:19:19 +00:00
|
|
|
skip_before_action :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
|
2015-04-01 22:34:14 +01:00
|
|
|
before_action :load_user, only: %i(show)
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :set_current_user, except: :show
|
2012-10-15 10:45:00 +01:00
|
|
|
|
|
|
|
def show
|
2012-12-29 16:22:21 +00:00
|
|
|
@user = User.opened.find params[:id] # dont show system users
|
2012-10-15 16:47:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_current_user
|
2015-04-01 22:34:14 +01:00
|
|
|
render :show
|
2012-10-15 15:06:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
user_params = params[:user] || {}
|
|
|
|
send_confirmation = user_params[:email] != @user.email
|
2015-05-20 22:03:08 +01:00
|
|
|
if @user.update_without_password(subject_params(User))
|
2012-10-15 15:06:08 +01:00
|
|
|
if send_confirmation
|
|
|
|
@user.confirmed_at, @user.confirmation_sent_at = nil
|
|
|
|
@user.send_confirmation_instructions
|
|
|
|
end
|
|
|
|
render_json_response @user, 'User has been updated successfully'
|
2012-10-15 10:45:00 +01:00
|
|
|
else
|
2012-10-15 15:06:08 +01:00
|
|
|
render_validation_error @user, "#{class_name} has not been updated"
|
2012-10-15 10:45:00 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-15 15:06:08 +01:00
|
|
|
def notifiers
|
|
|
|
if request.put?
|
2015-05-20 22:03:08 +01:00
|
|
|
if @user.notifier.update_attributes(notifier_params)
|
2012-10-15 15:06:08 +01:00
|
|
|
render_json_response @user, 'User notification settings have been updated successfully'
|
|
|
|
else
|
|
|
|
render_json_response @user, error_message(@user.notifier, 'User notification settings have not been updated'), 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2015-05-20 22:03:08 +01:00
|
|
|
def notifier_params
|
|
|
|
permit_params(:notifiers, *policy(SettingsNotifier).permitted_attributes)
|
|
|
|
end
|
|
|
|
|
2012-10-15 15:06:08 +01:00
|
|
|
def set_current_user
|
2015-04-01 22:34:14 +01:00
|
|
|
authorize @user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
# Private: before_action hook which loads User.
|
|
|
|
def load_user
|
|
|
|
authorize @user = User.find(params[:id])
|
2012-10-15 15:06:08 +01:00
|
|
|
end
|
|
|
|
|
2012-12-29 12:38:14 +00:00
|
|
|
end
|