Skip to content

fix(classes): reset user data when removing congregation #1646

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 2 commits 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
16 changes: 15 additions & 1 deletion src/v3/classes/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,23 @@ export class User {

const profile = structuredClone(this.profile);
profile.congregation = undefined;

await this.updateProfile(profile);

const settings = structuredClone(this.settings);
settings.backup_automatic = '';
settings.data_view = '';
settings.hour_credits_enabled = '';
settings.theme_follow_os_enabled = '';
await this.updateSettings(settings);

await this.updateSessions([]);

await this.saveFieldServiceReports([]);

await this.saveBibleStudies([]);

await this.saveDelegatedFieldServiceReports([]);

if (cong) {
await cong.reloadMembers();
}
Expand Down
8 changes: 7 additions & 1 deletion src/v3/controllers/admin_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,13 @@ export const userRemoveCongregation = async (req: Request, res: Response) => {

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

await user.removeCongregation();
if (user.profile.role === 'vip') {
await user.removeCongregation();
}

if (user.profile.role === 'pocket') {
await UsersList.delete(user.id);
}

if (userCong) {
const cong = CongregationsList.findById(userCong);
Expand Down
8 changes: 7 additions & 1 deletion src/v3/controllers/congregation_admin_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,13 @@ export const congregationDeleteUser = async (req: Request, res: Response) => {
return;
}

await foundUser.removeCongregation();
if (foundUser.profile.role === 'vip') {
await foundUser.removeCongregation();
}

if (foundUser.profile.role === 'pocket') {
await UsersList.delete(foundUser.id);
}

const cong_members = cong.getMembers(req.signedCookies.visitorid);

Expand Down