Skip to content

Commit

Permalink
feat: add readdir delegate for sharing user homedirs
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jun 16, 2024
1 parent 8424d44 commit 19a5eb0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/backend/src/filesystem/hl_operations/hl_readdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
const APIError = require("../../api/APIError");
const { chkperm } = require("../../helpers");
const { TYPE_DIRECTORY } = require("../FSNodeContext");
const { LLListUsers } = require("../ll_operations/ll_listusers");
const { LLReadDir } = require("../ll_operations/ll_readdir");
const { LLReadShares } = require("../ll_operations/ll_readshares");
const { HLFilesystemOperation } = require("./definitions");
Expand Down Expand Up @@ -48,7 +49,10 @@ class HLReadDir extends HLFilesystemOperation {
namediff: await subject.get('name') !== user.username
}
);
if (
if ( subject.isRoot ) {
const ll_listusers = new LLListUsers();
children = await ll_listusers.run(this.values);
} else if (
await subject.isUserDirectory() &&
await subject.get('name') !== user.username
) {
Expand Down
39 changes: 39 additions & 0 deletions packages/backend/src/filesystem/ll_operations/ll_listusers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { RootNodeSelector, NodeChildSelector } = require("../node/selectors");
const { LLFilesystemOperation } = require("./definitions");

class LLListUsers extends LLFilesystemOperation {
static description = `
List user directories which are relevant to the
current actor.
`;

async _run () {
const { context } = this;
const svc = context.get('services');
const svc_permission = svc.get('permission');
const svc_fs = svc.get('filesystem');

const user = this.values.user;
const issuers = await svc_permission.list_user_permission_issuers(user);

const nodes = [];

nodes.push(await svc_fs.node(new NodeChildSelector(
new RootNodeSelector(),
user.username,
)));

for ( const issuer of issuers ) {
const node = await svc_fs.node(new NodeChildSelector(
new RootNodeSelector(),
issuer.username));
nodes.push(node);
}

return nodes;
}
}

module.exports = {
LLListUsers,
};
19 changes: 19 additions & 0 deletions packages/backend/src/services/auth/PermissionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,25 @@ class PermissionService extends BaseService {
]
);
}

/**
* List the users that have any permissions granted to the
* specified user.
*/
async list_user_permission_issuers (user) {
const rows = await this.db.read(
'SELECT DISTINCT issuer_user_id FROM `user_to_user_permissions` ' +
'WHERE `holder_user_id` = ?',
[ user.id ],
);

const users = [];
for ( const row of rows ) {
users.push(await get_user({ id: row.issuer_user_id }));
}

return users;
}

get_parent_permissions (permission) {
const parent_perms = [];
Expand Down

0 comments on commit 19a5eb0

Please sign in to comment.