-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Role validation - allow permissionId to be optional #14853
Conversation
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
@@ -214,8 +215,8 @@ export function roleValidator() { | |||
}).optional(), | |||
// this is the base permission ID (for now a built in) | |||
permissionId: Joi.string() | |||
.valid(...Object.values(permissions.BuiltinPermissionID)) | |||
.required(), | |||
.valid(...Object.values(BuiltinPermissionID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of two code changes in this PR.
@@ -134,7 +135,13 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) { | |||
} | |||
// assume write permission level for newly created roles | |||
if (isCreate && !permissionId) { | |||
permissionId = PermissionLevel.WRITE | |||
permissionId = BuiltinPermissionID.WRITE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other Code change in this PR.
@@ -50,7 +51,7 @@ export class Role implements RoleDoc { | |||
_id: string | |||
_rev?: string | |||
name: string | |||
permissionId: string | |||
permissionId: BuiltinPermissionID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this not be used for custom roles, as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is used in all roles, but its never a string
- its just a very old type, we've always validated the Role to make sure it is one of the values in BuiltinPermissionID
.
Description
Frontend now expects to be able to supply role without a
permissionId
, this update makes it so that the validators allow this.Added test cases for the behaviour - also realised the types in this area were pretty incorrect based on the validators,
permissionId
was just astring
when it was actually typed, fixed this.