Skip to content

Commit

Permalink
Create 1.13.0.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
iandjx committed Oct 17, 2024
1 parent 9250628 commit 71ed9f3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions webapp/src/migrations/1.13.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Permission from '@permission';
import debug from 'debug';
import { Binary } from 'mongodb';
import { TEAM_MEMBER } from 'permissions/roles';

const log = debug('webapp:migration:1.13.0');

export default async function updateTeamMemberPermissions(db) {
log('add variable permissions to team members');
const teamMemberPermissions = new Permission();
teamMemberPermissions.setAll(TEAM_MEMBER.array);
const accounts = await db.collection('accounts').find().toArray();
for (const account of accounts) {
const accountPermissions = new Permission(account.permissions.buffer);
const isTeamMember = TEAM_MEMBER.array.some(bit => accountPermissions.get(bit));
if (!isTeamMember) {
continue;
}
const hasAllTeamMemberPermissions = TEAM_MEMBER.array.every(bit => accountPermissions.get(bit));
if (!hasAllTeamMemberPermissions) {
accountPermissions.setAll(teamMemberPermissions.array);
await db
.collection('accounts')
.updateOne(
{ _id: account._id },
{ $set: { permissions: new Binary(accountPermissions.array) } }
);
}
}
}

0 comments on commit 71ed9f3

Please sign in to comment.