-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into develop-airbyte
- Loading branch information
Showing
11 changed files
with
686 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,9 @@ | ||
import Permission from '@permission'; | ||
import debug from 'debug'; | ||
import { Binary, ObjectId } from 'mongodb'; | ||
import { TeamRoles } from 'permissions/roles'; | ||
|
||
const log = debug('webapp:migration:1.10.0'); | ||
import { CollectionName } from 'lib/struct/db'; | ||
const log = debug('webapp:migration:1.11.0'); | ||
|
||
export default async function (db) { | ||
log('unsetting all account level perms'); | ||
const blankPermission = new Permission(); | ||
await db.collection('accounts').updateMany( | ||
{}, | ||
{ | ||
$set: { | ||
permissions: new Binary(blankPermission.array) | ||
} | ||
} | ||
); | ||
|
||
log('setting all accounts team permissions to be TEAM_MEMBER'); | ||
const accounts = await db.collection('accounts').find().toArray(); | ||
|
||
const teamMemberPermission = new Binary(new Permission(TeamRoles.TEAM_MEMBER.base64).array); | ||
|
||
const bulkWrites = []; | ||
|
||
for (const account of accounts) { | ||
if (!account.orgs || account.orgs.length === 0) continue; | ||
|
||
for (const org of account.orgs) { | ||
if (!org.teams || org.teams.length === 0) continue; | ||
|
||
for (const team of org.teams) { | ||
bulkWrites.push({ | ||
updateOne: { | ||
filter: { _id: new ObjectId(team.id) }, | ||
update: { | ||
$set: { | ||
[`permissions.${account._id}`]: teamMemberPermission | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
if (bulkWrites.length > 0) { | ||
log('executing bulk write for teams'); | ||
await db.collection('teams').bulkWrite(bulkWrites); | ||
} else { | ||
log('no teams to update'); | ||
} | ||
log('add indexes to checkpoints collection'); | ||
await db.collection(CollectionName.Checkpoints).createIndex({ checkpoint_id: 1 }); | ||
await db.collection(CollectionName.Checkpoints).createIndex({ thread_id: 1 }); | ||
} |
Oops, something went wrong.