Skip to content

feat(routes): add remove user from congregation for admin #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/v3/controllers/admin_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,42 @@ export const congregationResetSpeakersKey = async (req: Request, res: Response)
res.locals.message = `admin reset the congregation speakers key`;
res.status(200).json(result);
};

export const userRemoveCongregation = async (req: Request, res: Response) => {
const { id } = req.params;

if (!id || id === 'undefined') {
res.locals.type = 'warn';
res.locals.message = 'the user request id params is undefined';
res.status(400).json({ message: 'REQUEST_ID_INVALID' });

return;
}

const user = UsersList.findById(id);

if (!user) {
res.locals.type = 'warn';
res.locals.message = 'no user could not be found with the provided id';
res.status(404).json({ message: 'USER_NOT_FOUND' });
return;
}

const userCong = user.profile.congregation?.id;

await user.removeCongregation();

if (userCong) {
const cong = CongregationsList.findById(userCong);

if (cong) {
cong.reloadMembers();
}
}

const result = await adminUsersGet(req.signedCookies.visitorid);

res.locals.type = 'info';
res.locals.message = 'admin removed a user from a congregation';
res.status(200).json(result);
};
4 changes: 4 additions & 0 deletions src/v3/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
userDelete,
userDisable2FA,
userFlagToggle,
userRemoveCongregation,
userRevokeToken,
userSessionDelete,
usersGetAll,
Expand Down Expand Up @@ -97,6 +98,9 @@ router.patch('/users/:id/feature-flags', body('flagid').isString(), userFlagTogg
// delete user session
router.delete('/users/:id/sessions', body('identifiers').isArray(), userSessionDelete);

// remove user congregation
router.delete('/users/:id/congregation', userRemoveCongregation);

// delete an user
router.delete('/users/:id', userDelete);

Expand Down