-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6a413f
Quick fix for role validation, permissionId is no longer required.
mike12345567 8f21802
Refactor, correct to the BuiltinPermissionID rather than PermissionLe…
mike12345567 3ddd8e1
Comment and test case.
mike12345567 e28357c
Linting.
mike12345567 8ebb02e
Test fix.
mike12345567 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
UserCtx, | ||
UserMetadata, | ||
DocumentType, | ||
PermissionLevel, | ||
BuiltinPermissionID, | ||
} from "@budibase/types" | ||
import { RoleColor, sdk as sharedSdk, helpers } from "@budibase/shared-core" | ||
import sdk from "../../sdk" | ||
|
@@ -134,7 +135,13 @@ | |
} | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Other Code change in this PR. |
||
} else if (!permissionId && dbRole?.permissionId) { | ||
permissionId = dbRole.permissionId | ||
} | ||
|
||
if (!permissionId) { | ||
ctx.throw(400, "Role requires permissionId to be specified.") | ||
} | ||
|
||
const role = new roles.Role(_id, name, permissionId, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
SearchFilters, | ||
Table, | ||
WebhookActionType, | ||
BuiltinPermissionID, | ||
} from "@budibase/types" | ||
import Joi, { CustomValidator } from "joi" | ||
import { ValidSnippetNameRegex, helpers } from "@budibase/shared-core" | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. One of two code changes in this PR. |
||
.optional(), | ||
permissions: Joi.object() | ||
.pattern( | ||
/.*/, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inBuiltinPermissionID
.