Updated functionality for group join requests approve, reject, leave
• Updated: - functionality for group join requests approve, reject, leave
This commit is contained in:
parent
f8e9c99e17
commit
8c4f4899e7
@ -37,12 +37,15 @@ class Api::V1::Groups::AccountsController < Api::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
authorize @group, :leave?
|
@join_request = GroupJoinRequest.where(group: @group, account_id: current_account.id)
|
||||||
|
if @join_request.count > 0
|
||||||
GroupAccount.where(group: @group, account_id: current_account.id).destroy_all
|
@join_request.destroy_all
|
||||||
|
else
|
||||||
if current_user.allows_group_in_home_feed?
|
authorize @group, :leave?
|
||||||
current_user.force_regeneration!
|
GroupAccount.where(group: @group, account_id: current_account.id).destroy_all
|
||||||
|
if current_user.allows_group_in_home_feed?
|
||||||
|
current_user.force_regeneration!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||||
|
@ -16,29 +16,21 @@ class Api::V1::Groups::RequestsController < Api::BaseController
|
|||||||
render json: @accounts, each_serializer: REST::AccountSerializer
|
render json: @accounts, each_serializer: REST::AccountSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def respond_to_request
|
||||||
authorize @group, :leave?
|
if params[:type] === 'reject'
|
||||||
GroupJoinRequest.where(group: @group, account_id: current_account.id).destroy_all
|
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
render json: { message: "ok", type: 'reject', accountId: params[:accountId] }
|
||||||
end
|
elsif params[:type] === 'approve'
|
||||||
|
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||||
def approve_request
|
GroupAccount.create(group: @group, account_id: params[:accountId])
|
||||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
render json: { message: "ok", type: 'approve', accountId: params[:accountId] }
|
||||||
GroupAccount.create(group: @group, account_id: params[:accountId])
|
else
|
||||||
render json: {"message": "ok"}
|
render json: { message: "error", error: true }, status: 422
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject_request
|
|
||||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
|
||||||
render json: {"message": "ok"}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def relationships
|
|
||||||
GroupRelationshipsPresenter.new([@group.id], current_user.account_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_group
|
def set_group
|
||||||
@group = Group.find(params[:group_id])
|
@group = Group.find(params[:group_id])
|
||||||
end
|
end
|
||||||
|
@ -702,8 +702,8 @@ export function expandJoinRequestsFail(id, error) {
|
|||||||
export const approveJoinRequest = (accountId, groupId) => (dispatch, getState) => {
|
export const approveJoinRequest = (accountId, groupId) => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
|
||||||
api(getState).post(`/api/v1/groups/${groupId}/join_requests/approve`, { accountId }).then((response) => {
|
api(getState).post(`/api/v1/groups/${groupId}/join_requests/respond`, { accountId, type: 'approve' }).then((response) => {
|
||||||
dispatch(approveJoinRequestSuccess(accountId, groupId))
|
dispatch(approveJoinRequestSuccess(response.data.accountId, groupId))
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
dispatch(approveJoinRequestFail(accountId, groupId, error))
|
dispatch(approveJoinRequestFail(accountId, groupId, error))
|
||||||
})
|
})
|
||||||
@ -729,8 +729,9 @@ export function approveJoinRequestFail(accountId, groupId, error) {
|
|||||||
export const rejectJoinRequest = (accountId, groupId) => (dispatch, getState) => {
|
export const rejectJoinRequest = (accountId, groupId) => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
|
||||||
api(getState).delete(`/api/v1/groups/${groupId}/join_requests/reject`, { accountId }).then((response) => {
|
api(getState).post(`/api/v1/groups/${groupId}/join_requests/respond`, { accountId, type: 'reject' }).then((response) => {
|
||||||
dispatch(rejectJoinRequestSuccess(accountId, groupId))
|
console.log("response:", response)
|
||||||
|
dispatch(rejectJoinRequestSuccess(response.data.accountId, groupId))
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
dispatch(rejectJoinRequestFail(accountId, groupId, error))
|
dispatch(rejectJoinRequestFail(accountId, groupId, error))
|
||||||
})
|
})
|
||||||
|
@ -179,8 +179,7 @@ export default function userLists(state = initialState, action) {
|
|||||||
return appendToList(state, 'group_join_requests', action.id, action.accounts, action.next);
|
return appendToList(state, 'group_join_requests', action.id, action.accounts, action.next);
|
||||||
case GROUP_JOIN_REQUESTS_APPROVE_SUCCESS:
|
case GROUP_JOIN_REQUESTS_APPROVE_SUCCESS:
|
||||||
case GROUP_JOIN_REQUESTS_REJECT_SUCCESS:
|
case GROUP_JOIN_REQUESTS_REJECT_SUCCESS:
|
||||||
return state.updateIn(['group_join_requests', action.groupId, 'items'], list => list.filterNot(item => item === action.id));
|
return state.updateIn(['group_join_requests', action.groupId, 'items'], list => list.filterNot(item => item === action.accountId));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -440,10 +440,9 @@ Rails.application.routes.draw do
|
|||||||
resources :relationships, only: :index, controller: 'groups/relationships'
|
resources :relationships, only: :index, controller: 'groups/relationships'
|
||||||
resource :accounts, only: [:show, :create, :update, :destroy], controller: 'groups/accounts'
|
resource :accounts, only: [:show, :create, :update, :destroy], controller: 'groups/accounts'
|
||||||
resource :removed_accounts, only: [:show, :create, :destroy], controller: 'groups/removed_accounts'
|
resource :removed_accounts, only: [:show, :create, :destroy], controller: 'groups/removed_accounts'
|
||||||
resource :join_requests, only: [:show, :create], controller: 'groups/requests'
|
resource :join_requests, only: [:show], controller: 'groups/requests'
|
||||||
|
|
||||||
post '/join_requests/approve', to: 'groups/requests#approve_request'
|
post '/join_requests/respond', to: 'groups/requests#respond_to_request'
|
||||||
delete '/join_requests/reject', to: 'groups/requests#reject_request'
|
|
||||||
|
|
||||||
resource :pin, only: :create, controller: 'groups/pins'
|
resource :pin, only: :create, controller: 'groups/pins'
|
||||||
post :unpin, to: 'groups/pins#destroy'
|
post :unpin, to: 'groups/pins#destroy'
|
||||||
|
Loading…
Reference in New Issue
Block a user