Skip to content

Commit 19a5eb0

Browse files
committed
feat: add readdir delegate for sharing user homedirs
1 parent 8424d44 commit 19a5eb0

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

packages/backend/src/filesystem/hl_operations/hl_readdir.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const APIError = require("../../api/APIError");
2020
const { chkperm } = require("../../helpers");
2121
const { TYPE_DIRECTORY } = require("../FSNodeContext");
22+
const { LLListUsers } = require("../ll_operations/ll_listusers");
2223
const { LLReadDir } = require("../ll_operations/ll_readdir");
2324
const { LLReadShares } = require("../ll_operations/ll_readshares");
2425
const { HLFilesystemOperation } = require("./definitions");
@@ -48,7 +49,10 @@ class HLReadDir extends HLFilesystemOperation {
4849
namediff: await subject.get('name') !== user.username
4950
}
5051
);
51-
if (
52+
if ( subject.isRoot ) {
53+
const ll_listusers = new LLListUsers();
54+
children = await ll_listusers.run(this.values);
55+
} else if (
5256
await subject.isUserDirectory() &&
5357
await subject.get('name') !== user.username
5458
) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { RootNodeSelector, NodeChildSelector } = require("../node/selectors");
2+
const { LLFilesystemOperation } = require("./definitions");
3+
4+
class LLListUsers extends LLFilesystemOperation {
5+
static description = `
6+
List user directories which are relevant to the
7+
current actor.
8+
`;
9+
10+
async _run () {
11+
const { context } = this;
12+
const svc = context.get('services');
13+
const svc_permission = svc.get('permission');
14+
const svc_fs = svc.get('filesystem');
15+
16+
const user = this.values.user;
17+
const issuers = await svc_permission.list_user_permission_issuers(user);
18+
19+
const nodes = [];
20+
21+
nodes.push(await svc_fs.node(new NodeChildSelector(
22+
new RootNodeSelector(),
23+
user.username,
24+
)));
25+
26+
for ( const issuer of issuers ) {
27+
const node = await svc_fs.node(new NodeChildSelector(
28+
new RootNodeSelector(),
29+
issuer.username));
30+
nodes.push(node);
31+
}
32+
33+
return nodes;
34+
}
35+
}
36+
37+
module.exports = {
38+
LLListUsers,
39+
};

packages/backend/src/services/auth/PermissionService.js

+19
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,25 @@ class PermissionService extends BaseService {
583583
]
584584
);
585585
}
586+
587+
/**
588+
* List the users that have any permissions granted to the
589+
* specified user.
590+
*/
591+
async list_user_permission_issuers (user) {
592+
const rows = await this.db.read(
593+
'SELECT DISTINCT issuer_user_id FROM `user_to_user_permissions` ' +
594+
'WHERE `holder_user_id` = ?',
595+
[ user.id ],
596+
);
597+
598+
const users = [];
599+
for ( const row of rows ) {
600+
users.push(await get_user({ id: row.issuer_user_id }));
601+
}
602+
603+
return users;
604+
}
586605

587606
get_parent_permissions (permission) {
588607
const parent_perms = [];

0 commit comments

Comments
 (0)