diff --git a/frontend/src/lib/editRights.test.ts b/frontend/src/lib/editRights.test.ts index ef344d7d6d..1498c6d194 100644 --- a/frontend/src/lib/editRights.test.ts +++ b/frontend/src/lib/editRights.test.ts @@ -71,4 +71,11 @@ describe('edit rights', () => { expect(canEditItem('flow', 'f/demo/sum', {}, user({}), builder)).toBe(false) expect(canEditItem('flow', 'u/op/sum', {}, user({}), builder)).toBe(true) }) + + it('does not take a folder or user whose name starts the same for the writable one', () => { + const writer = user({ folders: ['fin'] }) + expect(canEditItem('flow', 'f/fin/sum', {}, writer, FULL_CAPABILITIES)).toBe(true) + expect(canEditItem('flow', 'f/finance/sum', {}, writer, FULL_CAPABILITIES)).toBe(false) + expect(canEditItem('flow', 'u/ops/sum', {}, writer, FULL_CAPABILITIES)).toBe(false) + }) }) diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index be5761b357..0e442549e4 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -1187,14 +1187,16 @@ export function isObviousOwner(path: string, user?: UserExt): boolean { if (user.is_admin || user.is_super_admin) { return true } - let userOwner = `u/${user.username}` + // The trailing slash keeps folder `fin` from matching `f/finance/...`, and user + // `dev` from matching `u/devops/...`. + let userOwner = `u/${user.username}/` if (path.startsWith(userOwner)) { return true } - if (user.pgroups.findIndex((x) => path.startsWith(x)) != -1) { + if (user.pgroups.findIndex((x) => path.startsWith(x + '/')) != -1) { return true } - if (user.folders.findIndex((x) => path.startsWith('f/' + x)) != -1) { + if (user.folders.findIndex((x) => path.startsWith('f/' + x + '/')) != -1) { return true } return false