-
Notifications
You must be signed in to change notification settings - Fork 399
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(examples): finalize acl package #2987
base: master
Are you sure you want to change the base?
Conversation
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.
I left some comments. Please check and address them. thank you!
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
bucket := "u:" + addr.String() | ||
p := perm{ | ||
verbs: []string{verb}, | ||
resources: []string{resource}, | ||
} | ||
d.addPermToBucket(bucket, p) | ||
d.addPermsToBucket(bucket, []perm{p}) | ||
return true |
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.
useless returned value
} | ||
|
||
func (d *Directory) AddGroupPerm(name string, verb, resource string) { | ||
func (d *Directory) AddUserPerms(addr std.Address, verbs []string, resource string) bool { |
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.
this helper should take multiple verbs AND resources, or multiple structs, not just multiple verbs.
func (d *Directory) ResetUserPerms(addr std.Address) bool { | ||
bucket := "u:" + addr.String() | ||
d.permBuckets.Remove(bucket) | ||
return true |
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.
useless returned value
return true | ||
} | ||
|
||
func (d *Directory) ResetUserGroups(addr std.Address) bool { |
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.
invalid function name, the code isn't resetting a user group,but removing a specific address from a group
for _, pd := range newPerms { | ||
if !p.Contains(pd) { |
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.
gas inefficient
package acl | ||
|
||
// Helper function to append without duplicates | ||
func appendGroupsWithoutDuplicates(slice []string, items []string) []string { |
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.
this is a generic strings helper, do not create a groups.gno file with this function containing group in the title as it's generic enough to keep the code lighter.
return d.removePermsFromBucket(bucket, []perm{p}) | ||
} | ||
|
||
func (d *Directory) RemoveGroupPerms(name string, verbs []string, resource string) bool { |
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.
return foundGroups == len(groups) | ||
} | ||
|
||
func (d *Directory) removePermsFromBucket(bucket string, p []perm) bool { |
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.
we should switch to a map or a tree instead of a slice.
most of the code is hard to read and gas inefficient. let's just change how we store the data.
edit: let's use a tree directly.
return true | ||
} | ||
|
||
func (d *Directory) RemoveUserFromGroups(user std.Address, groups []string) bool { |
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.
remove this helper, just call RemoveUserFromGroup several times.
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.
Improving this package is a worthwhile endeavor. However, the current implementation is difficult to read, gas-inefficient, not scalable, and the API does not seem optimized. New helpers appear to lack practical use cases, while other important helpers are missing.
If you want to enhance this package by adding more flexibility (thank you), please start by refactoring our data storage. I suggest using the recent libraries I added:
- https://gno.land/p/moul/addreset for lists of addresses
- https://gno.land/p/moul/ulist for sets
Alternatively, feel free to fork this ACL package under your username if you believe your API could better serve some users.
This PR adds missing functionalities from the acl package:
Everything can be tested by running
gno test examples/gno.land/p/demo/acl
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description