Feature: API for updating account settings (#645)
* Feature: API for updating account settings - API to update account locale - API to update account name - API to show account info
This commit is contained in:
@@ -4,7 +4,9 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
skip_before_action :verify_authenticity_token, only: [:create]
|
||||
skip_before_action :authenticate_user!, :set_current_user, :check_subscription, :handle_with_exception,
|
||||
only: [:create], raise: false
|
||||
before_action :check_signup_enabled
|
||||
before_action :check_signup_enabled, only: [:create]
|
||||
before_action :check_authorization, except: [:create]
|
||||
before_action :fetch_account, except: [:create]
|
||||
|
||||
rescue_from CustomExceptions::Account::InvalidEmail,
|
||||
CustomExceptions::Account::UserExists,
|
||||
@@ -24,10 +26,26 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
render 'api/v1/accounts/show.json'
|
||||
end
|
||||
|
||||
def update
|
||||
@account.update!(account_params.slice(:name, :locale))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_authorization
|
||||
authorize(Account)
|
||||
end
|
||||
|
||||
def fetch_account
|
||||
@account = current_user.accounts.find(params[:id])
|
||||
end
|
||||
|
||||
def account_params
|
||||
params.permit(:account_name, :email)
|
||||
params.permit(:account_name, :email, :name, :locale)
|
||||
end
|
||||
|
||||
def check_signup_enabled
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# Table name: accounts
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# locale :integer default("English")
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
@@ -30,6 +31,8 @@ class Account < ApplicationRecord
|
||||
has_one :subscription, dependent: :destroy
|
||||
has_many :notification_settings, dependent: :destroy
|
||||
|
||||
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_3_code], key] }.to_h
|
||||
|
||||
after_create :create_subscription
|
||||
after_create :notify_creation
|
||||
after_destroy :notify_deletion
|
||||
|
||||
13
app/policies/account_policy.rb
Normal file
13
app/policies/account_policy.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AccountPolicy < ApplicationPolicy
|
||||
def show?
|
||||
# FIXME : temporary hack to transition over to multiple accounts per user
|
||||
# We should be fetching the current account user relationship here.
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def update?
|
||||
# FIXME : temporary hack to transition over to multiple accounts per user
|
||||
# We should be fetching the current account user relationship here.
|
||||
@user.administrator?
|
||||
end
|
||||
end
|
||||
3
app/views/api/v1/accounts/show.json.jbuilder
Normal file
3
app/views/api/v1/accounts/show.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
json.id @account.id
|
||||
json.name @account.name
|
||||
json.locale @account.locale
|
||||
3
app/views/api/v1/accounts/update.json.jbuilder
Normal file
3
app/views/api/v1/accounts/update.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
json.id @account.id
|
||||
json.name @account.name
|
||||
json.locale @account.locale
|
||||
Reference in New Issue
Block a user