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:
mgabdev 2020-12-31 19:17:55 -05:00
parent af7c82221d
commit 5b852ae10e
2 changed files with 13 additions and 15 deletions

View File

@ -15,17 +15,19 @@ class Api::V1::Lists::AccountsController < Api::BaseController
end end
def create def create
ApplicationRecord.transaction do puts "tilly create"
list_accounts.each do |account| if Block.where(account_id: params[:account_id], target_account: current_account).exists?
@list.accounts << account raise GabSocial::NotPermittedError
else
ApplicationRecord.transaction do
@list.accounts << list_account
end end
render_empty_success
end end
render_empty_success
end end
def destroy 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 render_empty_success
end end
@ -43,16 +45,12 @@ class Api::V1::Lists::AccountsController < Api::BaseController
end end
end end
def list_accounts def list_account
Account.find(account_ids) Account.find(params[:account_id])
end
def account_ids
Array(resource_params[:account_ids])
end end
def resource_params def resource_params
params.permit(account_ids: []) params.permit(:account_id)
end end
def insert_pagination_headers def insert_pagination_headers

View File

@ -341,7 +341,7 @@ export const addToList = (listId, accountId) => (dispatch, getState) => {
dispatch(addToListRequest(listId, accountId)) 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))) .then(() => dispatch(addToListSuccess(listId, accountId)))
.catch((err) => dispatch(addToListFail(listId, accountId, err))) .catch((err) => dispatch(addToListFail(listId, accountId, err)))
} }
@ -382,7 +382,7 @@ export const removeFromList = (listId, accountId) => (dispatch, getState) => {
dispatch(removeFromListRequest(listId, accountId)) 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))) .then(() => dispatch(removeFromListSuccess(listId, accountId)))
.catch((err) => dispatch(removeFromListFail(listId, accountId, err))) .catch((err) => dispatch(removeFromListFail(listId, accountId, err)))
} }