feat: Collection admins (#5273
* Split permissions for reading documents from updating collection * fix: Admins should have collection read permission, tests * tsc * Add admin option to permission selector * Combine publish and create permissions, update -> createDocuments where appropriate * Plural -> singular * wip * Quick version of collection structure loading, will revisit * Remove documentIds method * stash * fixing tests to account for admin creation * Add self-hosted migration * fix: Allow groups to have admin permission * Prefetch collection documents * fix: Document explorer (move/publish) not working with async documents * fix: Cannot re-parent document to collection by drag and drop * fix: Cannot drag to import into collection item without admin permission * Remove unused isEditor getter
This commit is contained in:
56
server/migrations/20230429005039-collection-admins.js
Normal file
56
server/migrations/20230429005039-collection-admins.js
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
if (process.env.DEPLOYMENT === "hosted") {
|
||||
return;
|
||||
}
|
||||
|
||||
await queryInterface.sequelize.transaction(async (transaction) => {
|
||||
// Convert collection members to admins where the user is the only
|
||||
// membership in the collection.
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE collection_users cu
|
||||
SET permission = 'admin'
|
||||
WHERE (
|
||||
SELECT COUNT(*)
|
||||
FROM collection_users
|
||||
WHERE "collectionId" = cu."collectionId"
|
||||
AND permission = 'read_write'
|
||||
) = 1;`,
|
||||
{
|
||||
type: queryInterface.sequelize.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
// Convert collection members to admins where the collection is private
|
||||
// and they currently have read_write permission
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE collection_users
|
||||
SET permission = 'admin'
|
||||
WHERE permission = 'read_write'
|
||||
AND "collectionId" IN (
|
||||
SELECT c."id"
|
||||
FROM collections c
|
||||
WHERE c.permission IS NULL
|
||||
);`,
|
||||
{
|
||||
type: queryInterface.sequelize.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
if (process.env.DEPLOYMENT === "hosted") {
|
||||
return;
|
||||
}
|
||||
|
||||
await queryInterface.sequelize.query(
|
||||
"UPDATE collection_users SET permission = 'read_write' WHERE permission = 'admin'",
|
||||
{
|
||||
type: queryInterface.sequelize.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user