2019-12-10 04:59:35 +00:00
|
|
|
class Api::V1::ProfilesController < Api::BaseController
|
2020-02-16 11:50:38 +00:00
|
|
|
before_action :set_user
|
2019-12-10 04:59:35 +00:00
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
def show; end
|
2019-12-10 04:59:35 +00:00
|
|
|
|
|
|
|
def update
|
2021-06-02 12:22:24 +00:00
|
|
|
if password_params[:password].present?
|
|
|
|
render_could_not_create_error('Invalid current password') and return unless @user.valid_password?(password_params[:current_password])
|
|
|
|
|
|
|
|
@user.update!(password_params.except(:current_password))
|
|
|
|
end
|
|
|
|
|
2019-12-10 04:59:35 +00:00
|
|
|
@user.update!(profile_params)
|
|
|
|
end
|
|
|
|
|
2021-11-26 19:26:07 +00:00
|
|
|
def avatar
|
|
|
|
@user.avatar.attachment.destroy! if @user.avatar.attached?
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
def availability
|
|
|
|
@user.account_users.find_by!(account_id: availability_params[:account_id]).update!(availability: availability_params[:availability])
|
|
|
|
end
|
|
|
|
|
2019-12-10 04:59:35 +00:00
|
|
|
private
|
|
|
|
|
2020-02-16 11:50:38 +00:00
|
|
|
def set_user
|
2019-12-10 04:59:35 +00:00
|
|
|
@user = current_user
|
|
|
|
end
|
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
def availability_params
|
|
|
|
params.require(:profile).permit(:account_id, :availability)
|
|
|
|
end
|
|
|
|
|
2019-12-10 04:59:35 +00:00
|
|
|
def profile_params
|
2020-07-27 16:49:26 +00:00
|
|
|
params.require(:profile).permit(
|
|
|
|
:email,
|
|
|
|
:name,
|
|
|
|
:display_name,
|
|
|
|
:avatar,
|
2022-02-02 14:07:33 +00:00
|
|
|
:message_signature,
|
2021-01-10 13:55:33 +00:00
|
|
|
ui_settings: {}
|
2020-07-27 16:49:26 +00:00
|
|
|
)
|
2019-12-10 04:59:35 +00:00
|
|
|
end
|
2021-06-02 12:22:24 +00:00
|
|
|
|
|
|
|
def password_params
|
|
|
|
params.require(:profile).permit(
|
|
|
|
:current_password,
|
|
|
|
:password,
|
|
|
|
:password_confirmation
|
|
|
|
)
|
|
|
|
end
|
2019-12-10 04:59:35 +00:00
|
|
|
end
|