From 3e98f1a8a8476ebea20bcddfd2e86f485c23c6c8 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Wed, 19 Jun 2024 00:10:29 -0400 Subject: [PATCH] tweak: acl update --- packages/backend/src/filesystem/FSNodeContext.js | 8 ++++++++ packages/backend/src/helpers.js | 13 +++++++++---- packages/backend/src/services/auth/ACLService.js | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/filesystem/FSNodeContext.js b/packages/backend/src/filesystem/FSNodeContext.js index a7677157b..28e15d6b8 100644 --- a/packages/backend/src/filesystem/FSNodeContext.js +++ b/packages/backend/src/filesystem/FSNodeContext.js @@ -165,6 +165,14 @@ module.exports = class FSNodeContext { return ! this.entry.parent_uid; } + async isPublic () { + if ( this.isRoot ) return false; + const components = await this.getPathComponents(); + if ( await this.isUserDirectory() ) return false; + if ( components[1] === 'Public' ) return true; + return false; + } + async getPathComponents () { if ( this.isRoot ) return []; diff --git a/packages/backend/src/helpers.js b/packages/backend/src/helpers.js index 3ceb9efc6..575632ff3 100644 --- a/packages/backend/src/helpers.js +++ b/packages/backend/src/helpers.js @@ -1433,6 +1433,7 @@ async function generate_system_fsentries(user){ let documents_uuid = uuidv4(); let pictures_uuid = uuidv4(); let videos_uuid = uuidv4(); + let public_uuid = uuidv4(); const insert_res = await db.write( `INSERT INTO fsentries @@ -1442,6 +1443,7 @@ async function generate_system_fsentries(user){ ( ?, ?, ?, ?, ?, true, ?, ?, true), ( ?, ?, ?, ?, ?, true, ?, ?, true), ( ?, ?, ?, ?, ?, true, ?, ?, true), + ( ?, ?, ?, ?, ?, true, ?, ?, true), ( ?, ?, ?, ?, ?, true, ?, ?, true) `, [ @@ -1457,6 +1459,8 @@ async function generate_system_fsentries(user){ pictures_uuid, root_dir.uid, user.id, 'Pictures', `/${user.username}/Pictures`, ts, ts, // Videos videos_uuid, root_dir.uid, user.id, 'Videos', `/${user.username}/Videos`, ts, ts, + // Public + public_uuid, root_dir.uid, user.id, 'Public', `/${user.username}/Public`, ts, ts, ] ); @@ -1467,6 +1471,7 @@ async function generate_system_fsentries(user){ let documents_id = insert_res.insertId + 3; let pictures_id = insert_res.insertId + 4; let videos_id = insert_res.insertId + 5; + let public_id = insert_res.insertId + 6; // Asynchronously set the user's system folders uuids in database // This is for caching purposes, so we don't have to query the DB every time we need to access these folders @@ -1476,13 +1481,13 @@ async function generate_system_fsentries(user){ // (IIAFE manager doesn't exist yet, hence this is a TODO) db.write( `UPDATE user SET - trash_uuid=?, appdata_uuid=?, desktop_uuid=?, documents_uuid=?, pictures_uuid=?, videos_uuid=?, - trash_id=?, appdata_id=?, desktop_id=?, documents_id=?, pictures_id=?, videos_id=? + trash_uuid=?, appdata_uuid=?, desktop_uuid=?, documents_uuid=?, pictures_uuid=?, videos_uuid=?, public_uuid=?, + trash_id=?, appdata_id=?, desktop_id=?, documents_id=?, pictures_id=?, videos_id=?, public_id=? WHERE id=?`, [ - trash_uuid, appdata_uuid, desktop_uuid, documents_uuid, pictures_uuid, videos_uuid, - trash_id, appdata_id, desktop_id, documents_id, pictures_id, videos_id, + trash_uuid, appdata_uuid, desktop_uuid, documents_uuid, pictures_uuid, videos_uuid, public_uuid, + trash_id, appdata_id, desktop_id, documents_id, pictures_id, videos_id, public_id, user.id ] ); diff --git a/packages/backend/src/services/auth/ACLService.js b/packages/backend/src/services/auth/ACLService.js index 163048636..84594cc05 100644 --- a/packages/backend/src/services/auth/ACLService.js +++ b/packages/backend/src/services/auth/ACLService.js @@ -53,6 +53,12 @@ class ACLService extends BaseService { } return false; } + + // Hard rule: anyone and anything can read /user/public directories + const public_modes = ['read', 'list', 'see']; + if ( public_modes.includes(mode) ) { + if ( await fsNode.isPublic() ) return true; + } // Access tokens only work if the authorizer has permission if ( actor.type instanceof AccessTokenActorType ) {