Updated functionality for group join requests approve, reject, leave
• Updated: - functionality for group join requests approve, reject, leave
This commit is contained in:
@@ -37,12 +37,15 @@ class Api::V1::Groups::AccountsController < Api::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize @group, :leave?
|
||||
|
||||
GroupAccount.where(group: @group, account_id: current_account.id).destroy_all
|
||||
|
||||
if current_user.allows_group_in_home_feed?
|
||||
current_user.force_regeneration!
|
||||
@join_request = GroupJoinRequest.where(group: @group, account_id: current_account.id)
|
||||
if @join_request.count > 0
|
||||
@join_request.destroy_all
|
||||
else
|
||||
authorize @group, :leave?
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def create
|
||||
authorize @group, :leave?
|
||||
GroupJoinRequest.where(group: @group, account_id: current_account.id).destroy_all
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
end
|
||||
|
||||
def approve_request
|
||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||
GroupAccount.create(group: @group, account_id: params[:accountId])
|
||||
render json: {"message": "ok"}
|
||||
end
|
||||
|
||||
def reject_request
|
||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||
render json: {"message": "ok"}
|
||||
def respond_to_request
|
||||
if params[:type] === 'reject'
|
||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||
render json: { message: "ok", type: 'reject', accountId: params[:accountId] }
|
||||
elsif params[:type] === 'approve'
|
||||
GroupJoinRequest.where(group: @group, account_id: params[:accountId]).destroy_all
|
||||
GroupAccount.create(group: @group, account_id: params[:accountId])
|
||||
render json: { message: "ok", type: 'approve', accountId: params[:accountId] }
|
||||
else
|
||||
render json: { message: "error", error: true }, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def relationships
|
||||
GroupRelationshipsPresenter.new([@group.id], current_user.account_id)
|
||||
end
|
||||
|
||||
def set_group
|
||||
@group = Group.find(params[:group_id])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user