Feature: Ability to switch between multiple accounts (#881)
* Feature: Ability to switch between multiple accounts * Fix rubocop * Fix assigned inboxes * fix auth json * Add account switcher in UI * fix ordering on administrate * Add switch accounts to sidebar * add account id * Fix schema.rb timestamp * Revert "add account id" This reverts commit 27570f50ef584cb9a5f69454f43f630b318c8807. * Add a check for account Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -5,8 +5,8 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
skip_before_action :authenticate_user!, :set_current_user, :check_subscription, :handle_with_exception,
|
||||
only: [:create], raise: false
|
||||
before_action :check_signup_enabled, only: [:create]
|
||||
before_action :check_authorization, except: [:create]
|
||||
before_action :fetch_account, except: [:create]
|
||||
before_action :check_authorization, except: [:create]
|
||||
|
||||
rescue_from CustomExceptions::Account::InvalidEmail,
|
||||
CustomExceptions::Account::UserExists,
|
||||
@@ -21,7 +21,7 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
).perform
|
||||
if @user
|
||||
send_auth_headers(@user)
|
||||
render 'devise/auth.json', locals: { resource: @user }
|
||||
render partial: 'devise/auth.json', locals: { resource: @user }
|
||||
else
|
||||
render_error_response(CustomExceptions::Account::SignupFailed.new({}))
|
||||
end
|
||||
@@ -35,6 +35,12 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
@account.update!(account_params.slice(:name, :locale, :domain, :support_email, :domain_emails_enabled))
|
||||
end
|
||||
|
||||
def update_active_at
|
||||
@current_account_user.active_at = Time.now.utc
|
||||
@current_account_user.save!
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_authorization
|
||||
@@ -47,6 +53,7 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
|
||||
def fetch_account
|
||||
@account = current_user.accounts.find(params[:id])
|
||||
@current_account_user = @account.account_users.find_by(user_id: current_user.id)
|
||||
end
|
||||
|
||||
def account_params
|
||||
@@ -56,4 +63,12 @@ class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||
def check_signup_enabled
|
||||
raise ActionController::RoutingError, 'Not Found' if ENV.fetch('ENABLE_ACCOUNT_SIGNUP', true) == 'false'
|
||||
end
|
||||
|
||||
def pundit_user
|
||||
{
|
||||
user: current_user,
|
||||
account: @account,
|
||||
account_user: @current_account_user
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,13 +10,13 @@ class Api::V1::Accounts::AgentsController < Api::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@agent.account_user.destroy
|
||||
@agent.current_account_user.destroy
|
||||
head :ok
|
||||
end
|
||||
|
||||
def update
|
||||
@agent.update!(agent_params.except(:role))
|
||||
@agent.account_user.update!(role: agent_params[:role]) if agent_params[:role]
|
||||
@agent.current_account_user.update!(role: agent_params[:role]) if agent_params[:role]
|
||||
render 'api/v1/models/user.json', locals: { resource: @agent }
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Api::V1::Accounts::Channels::TwilioChannelsController < Api::BaseController
|
||||
before_action :current_account
|
||||
before_action :authorize_request
|
||||
|
||||
def create
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
include Events::Types
|
||||
before_action :current_account
|
||||
before_action :conversation, except: [:index]
|
||||
before_action :contact_inbox, only: [:create]
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class Api::V1::Accounts::InboxesController < Api::BaseController
|
||||
before_action :check_authorization
|
||||
before_action :current_account
|
||||
before_action :fetch_inbox, except: [:index, :create]
|
||||
before_action :fetch_agent_bot, only: [:set_agent_bot]
|
||||
before_action :check_authorization
|
||||
|
||||
def index
|
||||
@inboxes = policy_scope(current_account.inboxes)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Api::V1::Accounts::WebhooksController < Api::BaseController
|
||||
before_action :current_account
|
||||
before_action :check_authorization
|
||||
before_action :fetch_webhook, only: [:update, :destroy]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user