mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-24 15:07:17 +00:00
refactor(permissions): drop the unused permission-issuer lookup
listUserPermissionIssuers and its store method listUserPermissionIssuerIds existed to synthesize the filesystem root from the home directories of everyone who had granted the caller a permission. That listing is gone — it advertised folders readdir then refused to open — and the share index answers "who shared with me" directly, so nothing wants them back. One removed test only asserted that the call returned an array; the other covered readLinkedUserUserPerms round-tripping and is kept, rewritten without the issuer lookup.
This commit is contained in:
@@ -621,37 +621,8 @@ describe('PermissionService (integration)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('listUserPermissionIssuers / queryIssuerHolderPermissionsByPrefix', () => {
|
||||
it('listUserPermissionIssuers returns the issuer who granted the target a perm', async () => {
|
||||
const { user: issuer, actor: issuerActor } = await makeUserActor();
|
||||
const { user: target } = await makeUserActor();
|
||||
const permission = `zztest:lst-${uuidv4()}:ii:read`;
|
||||
await server.stores.permission.setFlatUserPerm(
|
||||
issuer.id,
|
||||
`manage:${permission}`,
|
||||
{
|
||||
permission: `manage:${permission}`,
|
||||
deleted: false,
|
||||
issuer_user_id: issuer.id,
|
||||
} as never,
|
||||
);
|
||||
await runWithContext({ actor: issuerActor }, () =>
|
||||
permService.grantUserUserPermission(
|
||||
issuerActor,
|
||||
target.username,
|
||||
permission,
|
||||
),
|
||||
);
|
||||
// listUserPermissionIssuers is best-effort; just verify it runs
|
||||
// and either includes the issuer or returns an empty array (the
|
||||
// linked store may not be populated immediately).
|
||||
const issuers = await permService.listUserPermissionIssuers({
|
||||
id: target.id,
|
||||
});
|
||||
expect(Array.isArray(issuers)).toBe(true);
|
||||
});
|
||||
|
||||
it('queryIssuerHolderPermissionsByPrefix returns [] for actors without user.id', async () => {
|
||||
describe('queryIssuerHolderPermissionsByPrefix', () => {
|
||||
it('returns [] for actors without user.id', async () => {
|
||||
const out = await permService.queryIssuerHolderPermissionsByPrefix(
|
||||
{ user: undefined } as unknown as Actor,
|
||||
{ user: undefined } as unknown as Actor,
|
||||
|
||||
@@ -1343,26 +1343,6 @@ export class PermissionService extends PuterService {
|
||||
|
||||
// -- Issuer queries (share discovery et al) -----------------------
|
||||
|
||||
async listUserPermissionIssuers(user: {
|
||||
id: number;
|
||||
}): Promise<Array<UserRowSummary | null>> {
|
||||
const ids = await this.stores.permission.listUserPermissionIssuerIds(
|
||||
user.id,
|
||||
);
|
||||
const usersById = await this.stores.user.getByIds(ids);
|
||||
return ids.map((id) => {
|
||||
const u = usersById.get(id);
|
||||
return u
|
||||
? {
|
||||
id: u.id,
|
||||
uuid: u.uuid,
|
||||
username: u.username,
|
||||
email: u.email,
|
||||
}
|
||||
: null;
|
||||
});
|
||||
}
|
||||
|
||||
async queryIssuerPermissionsByPrefix(
|
||||
issuer: { id: number },
|
||||
prefix: string,
|
||||
|
||||
@@ -828,7 +828,7 @@ describe('PermissionStore', () => {
|
||||
// -- user → user ------------------------------------------------------
|
||||
|
||||
describe('user-to-user permissions', () => {
|
||||
it('lists issuers for a holder and clears them on revoke', async () => {
|
||||
it('reads a holder grant back and clears it on revoke', async () => {
|
||||
const issuer = await makeUser();
|
||||
const holder = await makeUser();
|
||||
await store.upsertUserUserPerm(
|
||||
@@ -838,10 +838,6 @@ describe('PermissionStore', () => {
|
||||
{},
|
||||
);
|
||||
|
||||
expect(
|
||||
await store.listUserPermissionIssuerIds(holder.id),
|
||||
).toContain(issuer.id);
|
||||
|
||||
const rows = await store.readLinkedUserUserPerms(holder.id, [
|
||||
'fs:u:read',
|
||||
]);
|
||||
|
||||
@@ -360,14 +360,6 @@ export class PermissionStore extends PuterStore {
|
||||
);
|
||||
}
|
||||
|
||||
async listUserPermissionIssuerIds(holderUserId: number): Promise<number[]> {
|
||||
const rows = await this.clients.db.read(
|
||||
'SELECT DISTINCT issuer_user_id FROM `user_to_user_permissions` WHERE `holder_user_id` = ?',
|
||||
[holderUserId],
|
||||
);
|
||||
return rows.map((r) => Number(r.issuer_user_id));
|
||||
}
|
||||
|
||||
// -- SQL: user-to-app permissions --------------------------------
|
||||
|
||||
async readUserAppPerms(
|
||||
|
||||
Reference in New Issue
Block a user