Skip to content
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

feat: remove unnecessary saved object get call #214

Merged

Conversation

wanglam
Copy link
Collaborator

@wanglam wanglam commented Oct 10, 2023

Description

  1. Add in memory validate in permission control
  2. Use in memory validate for object ACL validate

Issues Resolved

Screenshot

Testing the changes

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2023

Codecov Report

Merging #214 (c25a13d) into workspace (8505341) will increase coverage by 0.00%.
Report is 1 commits behind head on workspace.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           workspace     #214   +/-   ##
==========================================
  Coverage      66.21%   66.22%           
==========================================
  Files           3420     3420           
  Lines          65755    65755           
  Branches       10589    10589           
==========================================
+ Hits           43541    43543    +2     
+ Misses         19577    19570    -7     
- Partials        2637     2642    +5     
Flag Coverage Δ
Linux_1 30.42% <ø> (ø)
Linux_2 55.38% <ø> (ø)
Linux_3 42.76% <ø> (+<0.01%) ⬆️
Linux_4 34.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@wanglam wanglam marked this pull request as ready for review October 10, 2023 03:23
Comment on lines 138 to 144
const hasAllPermission = savedObjectsGet.every((savedObject) => {
const hasPermission = this.inMemoryValidate({
savedObject,
permissionModes,
principals,
shouldLogNotPermitted: false,
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hasAllPermission = savedObjectsGet.every((savedObject) => {
const hasPermission = this.inMemoryValidate({
savedObject,
permissionModes,
principals,
shouldLogNotPermitted: false,
});
const hasAllPermission = savedObjectsGet.every((savedObject) => {
const hasPermission = this.inMemoryValidate({
savedObject,
permissionModes,
principals,
});
if (!hasPermission) {
// do log here
this.logNotPermitted(...)
notPermittedSavedObjects.push(savedObject);
}

I tend to make inMemoryValidate a pure util function so it doesn't care about logging, what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to log the not permitted validation when call inMemoryValidate directly. Is that means we need to call the logNotPermitted manually after inMemoryValidate call?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that means we need to call the logNotPermitted manually after inMemoryValidate call?
Yes, just feel passing shouldLogNotPermitted to inMemoryValidate makes the function a bit overwhelming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about change inMemoryValidate accept multi saved objects? So we don't need add shouldLogNotPermitted parameter.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

);
}

public inMemoryValidate({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put some comment on this function?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, can we call it validateObjectACL?

Comment on lines 59 to 61
savedObjectsOrSavedObject:
| Array<Pick<SavedObject<unknown>, 'id' | 'type' | 'workspaces' | 'permissions'>>
| Pick<SavedObject<unknown>, 'id' | 'type' | 'workspaces' | 'permissions'>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
savedObjectsOrSavedObject:
| Array<Pick<SavedObject<unknown>, 'id' | 'type' | 'workspaces' | 'permissions'>>
| Pick<SavedObject<unknown>, 'id' | 'type' | 'workspaces' | 'permissions'>,
savedObjects: Array<Pick<SavedObject<unknown>, 'id' | 'type' | 'workspaces' | 'permissions'>>,

Can we simplify it like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that means we only accept array as paramenter?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but not a big issue, just think this might make it looks simpler.

@wanglam wanglam changed the title feat: add in memory validate remove unnecessary saved object get call feat: remove unnecessary saved object get call Oct 10, 2023
@wanglam wanglam merged commit 2771ff9 into ruanyl:workspace Oct 11, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants