Skip to content
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
7 changes: 4 additions & 3 deletions lib/AssetsModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class Assetsmodule extends AbstractApiModule {
await this.ensureLibPermissions()
const [authored, mongodb, tags, users] = await this.app.waitForModule('authored', 'mongodb', 'tags', 'users')
await mongodb.setIndex(this.collectionName, 'hash')
await authored.registerModule(this, { accessCheck: false })
await authored.registerModule(this)
await tags.registerModule(this)
// opt into the generic _access model: public access (base) plus per-user sharing.
// Group sharing is wired from the usergroups module. See adapt-authoring-api#98.
// opt into the generic _access model: creator ownership (via authored) plus public
// access (base) and per-user sharing. Group sharing is wired from the usergroups
// module. See adapt-authoring-api#98.
await this.enableAccessControl()
await users.registerUserModule(this)

Expand Down
26 changes: 26 additions & 0 deletions migrations/1.12.0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Backfills the generic `_access` grant on existing assets. Assets predate the access model
* (they were a global, scope-gated pool with no per-asset sharing), so there is no legacy
* field to derive from — they are made public by default, preserving the prior "everyone sees
* every asset" behaviour. New assets get `_access.public: true` from the schema default.
*
* Idempotent: only touches assets that don't yet carry `_access.public`. `_access.users` is
* preserved if already present (e.g. seeded by the usergroups groups backfill), else defaulted.
*/
export default function (migration) {
migration.describe('Backfill _access.public=true / _access.users=[] on existing assets (public by default)')
migration.runCommand(backfillAssetAccess)
}

async function backfillAssetAccess (db, log) {
const res = await db.collection('assets').updateMany(
{ '_access.public': { $exists: false } },
[{
$set: {
'_access.public': true,
'_access.users': { $ifNull: ['$_access.users', []] }
}
}]
)
log('info', 'migrations', `Backfilled _access on ${res.modifiedCount} asset(s)`)
}
Loading