PR comments.
This commit is contained in:
parent
3da3bccc01
commit
2ae1836b9a
|
@ -76,11 +76,9 @@ export class Role implements RoleDoc {
|
||||||
if (inherits && typeof inherits === "string") {
|
if (inherits && typeof inherits === "string") {
|
||||||
inherits = prefixRoleIDNoBuiltin(inherits)
|
inherits = prefixRoleIDNoBuiltin(inherits)
|
||||||
} else if (inherits && Array.isArray(inherits)) {
|
} else if (inherits && Array.isArray(inherits)) {
|
||||||
inherits = inherits.map(inherit => prefixRoleIDNoBuiltin(inherit))
|
inherits = inherits.map(prefixRoleIDNoBuiltin)
|
||||||
}
|
}
|
||||||
if (inherits) {
|
|
||||||
this.inherits = inherits
|
this.inherits = inherits
|
||||||
}
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +262,7 @@ export async function roleToNumber(id: string) {
|
||||||
return findNumber(foundRole) + 1
|
return findNumber(foundRole) + 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(number => !!number)
|
.filter(number => number)
|
||||||
.sort()
|
.sort()
|
||||||
.pop()
|
.pop()
|
||||||
if (highestBuiltin != undefined) {
|
if (highestBuiltin != undefined) {
|
||||||
|
|
|
@ -78,10 +78,10 @@ export async function find(ctx: UserCtx<void, FindRoleResponse>) {
|
||||||
|
|
||||||
export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
let { _id, name, inherits, permissionId, version, uiMetadata } =
|
let { _id, _rev, name, inherits, permissionId, version, uiMetadata } =
|
||||||
ctx.request.body
|
ctx.request.body
|
||||||
let isCreate = false
|
let isCreate = false
|
||||||
if (!ctx.request.body._rev && !version) {
|
if (!_rev && !version) {
|
||||||
version = roles.RoleIDVersion.NAME
|
version = roles.RoleIDVersion.NAME
|
||||||
}
|
}
|
||||||
const isNewVersion = version === roles.RoleIDVersion.NAME
|
const isNewVersion = version === roles.RoleIDVersion.NAME
|
||||||
|
@ -132,7 +132,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
||||||
ctx.throw(400, "Role inheritance contains a loop, this is not supported")
|
ctx.throw(400, "Role inheritance contains a loop, this is not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundRev = ctx.request.body._rev || dbRole?._rev
|
const foundRev = _rev || dbRole?._rev
|
||||||
if (foundRev) {
|
if (foundRev) {
|
||||||
role._rev = foundRev
|
role._rev = foundRev
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,7 +432,7 @@ export default class TestConfiguration {
|
||||||
async loginAsRole(roleId: string, cb: () => Promise<unknown>) {
|
async loginAsRole(roleId: string, cb: () => Promise<unknown>) {
|
||||||
const roleUser = await this.createUser({
|
const roleUser = await this.createUser({
|
||||||
roles: {
|
roles: {
|
||||||
[this.prodAppId!]: roleId,
|
[this.getProdAppId()]: roleId,
|
||||||
},
|
},
|
||||||
builder: { global: false },
|
builder: { global: false },
|
||||||
admin: { global: false },
|
admin: { global: false },
|
||||||
|
@ -443,18 +443,10 @@ export default class TestConfiguration {
|
||||||
builder: false,
|
builder: false,
|
||||||
prodApp: true,
|
prodApp: true,
|
||||||
})
|
})
|
||||||
const temp = this.user
|
await this.withUser(roleUser, async () => {
|
||||||
this.user = roleUser
|
|
||||||
await cb()
|
await cb()
|
||||||
if (temp) {
|
|
||||||
this.user = temp
|
|
||||||
await this.login({
|
|
||||||
userId: temp._id!,
|
|
||||||
builder: true,
|
|
||||||
prodApp: false,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
defaultHeaders(extras = {}, prodApp = false) {
|
defaultHeaders(extras = {}, prodApp = false) {
|
||||||
const tenantId = this.getTenantId()
|
const tenantId = this.getTenantId()
|
||||||
|
|
|
@ -64,5 +64,10 @@ describe("role utilities", () => {
|
||||||
role1.inherits = "role_2"
|
role1.inherits = "role_2"
|
||||||
check(true)
|
check(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("self reference contains loop", () => {
|
||||||
|
role("role1", "role1")
|
||||||
|
check(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue