Updated ListsAccountsController to check if account blocks current_account
• Updated: - ListsAccountsController to check if account blocks current_account - Lists action and controller to only allow singular account_id instead of array
This commit is contained in:
parent
af7c82221d
commit
5b852ae10e
|
@ -15,17 +15,19 @@ class Api::V1::Lists::AccountsController < Api::BaseController
|
|||
end
|
||||
|
||||
def create
|
||||
ApplicationRecord.transaction do
|
||||
list_accounts.each do |account|
|
||||
@list.accounts << account
|
||||
puts "tilly create"
|
||||
if Block.where(account_id: params[:account_id], target_account: current_account).exists?
|
||||
raise GabSocial::NotPermittedError
|
||||
else
|
||||
ApplicationRecord.transaction do
|
||||
@list.accounts << list_account
|
||||
end
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def destroy
|
||||
ListAccount.where(list: @list, account_id: account_ids).destroy_all
|
||||
ListAccount.where(list: @list, account_id: params[:account_id]).destroy_all
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
|
@ -43,16 +45,12 @@ class Api::V1::Lists::AccountsController < Api::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def list_accounts
|
||||
Account.find(account_ids)
|
||||
end
|
||||
|
||||
def account_ids
|
||||
Array(resource_params[:account_ids])
|
||||
def list_account
|
||||
Account.find(params[:account_id])
|
||||
end
|
||||
|
||||
def resource_params
|
||||
params.permit(account_ids: [])
|
||||
params.permit(:account_id)
|
||||
end
|
||||
|
||||
def insert_pagination_headers
|
||||
|
|
|
@ -341,7 +341,7 @@ export const addToList = (listId, accountId) => (dispatch, getState) => {
|
|||
|
||||
dispatch(addToListRequest(listId, accountId))
|
||||
|
||||
api(getState).post(`/api/v1/lists/${listId}/accounts`, { account_ids: [accountId] })
|
||||
api(getState).post(`/api/v1/lists/${listId}/accounts`, { account_id: accountId })
|
||||
.then(() => dispatch(addToListSuccess(listId, accountId)))
|
||||
.catch((err) => dispatch(addToListFail(listId, accountId, err)))
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ export const removeFromList = (listId, accountId) => (dispatch, getState) => {
|
|||
|
||||
dispatch(removeFromListRequest(listId, accountId))
|
||||
|
||||
api(getState).delete(`/api/v1/lists/${listId}/accounts`, { params: { account_ids: [accountId] } })
|
||||
api(getState).delete(`/api/v1/lists/${listId}/accounts`, { params: { account_id: accountId } })
|
||||
.then(() => dispatch(removeFromListSuccess(listId, accountId)))
|
||||
.catch((err) => dispatch(removeFromListFail(listId, accountId, err)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue