Add a writing role to the shortcuts controller

This commit is contained in:
Fosco Marotto 2021-02-18 16:57:34 -05:00
parent be5fc25544
commit fea1b9389b

View File

@ -6,7 +6,7 @@ class Api::V1::ShortcutsController < Api::BaseController
def index def index
@shortcuts = Shortcut.where(account: current_account).limit(100) @shortcuts = Shortcut.where(account: current_account).limit(100)
@onlyGroupIds = @shortcuts.select{ |s| s.shortcut_type == 'group' }.map(&:shortcut_id) @onlyGroupIds = @shortcuts.select{ |s| s.shortcut_type == 'group' }.map(&:shortcut_id)
@onlyAccountIds = @shortcuts.select{ |s| s.shortcut_type == 'account' }.map(&:shortcut_id) @onlyAccountIds = @shortcuts.select{ |s| s.shortcut_type == 'account' }.map(&:shortcut_id)
@ -29,7 +29,9 @@ class Api::V1::ShortcutsController < Api::BaseController
elsif s.shortcut_type == 'account' elsif s.shortcut_type == 'account'
@account = @accounts.detect{ |a| a.id == s.shortcut_id } @account = @accounts.detect{ |a| a.id == s.shortcut_id }
if @account.nil? if @account.nil?
s.destroy! ActiveRecord::Base.connected_to(role: :writing) do
s.destroy!
end
else else
value = REST::AccountSerializer.new(@account) value = REST::AccountSerializer.new(@account)
end end
@ -73,7 +75,7 @@ class Api::V1::ShortcutsController < Api::BaseController
} }
render json: r render json: r
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
render json: { error: I18n.t('shortcuts.errors.exists') }, status: 422 render json: { error: I18n.t('shortcuts.errors.exists') }, status: 422
end end