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(examples): finalize acl package #2987

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

0xtekgrinder
Copy link
Contributor

This PR adds missing functionalities from the acl package:

  • helpers to remove permissions.
  • helpers to adds multiple permissions at once -> {verbs: []string{"read","write"}}.
  • helpers to delete users from groups.
  • helpers to quickly reset states.

Everything can be tested by running gno test examples/gno.land/p/demo/acl

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

@0xtekgrinder 0xtekgrinder requested review from a team as code owners October 20, 2024 09:48
@0xtekgrinder 0xtekgrinder requested review from sw360cab and petar-dambovaliev and removed request for a team October 20, 2024 09:48
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Oct 20, 2024
@notJoon notJoon added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 21, 2024
Copy link
Member

@notJoon notJoon left a 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!

@0xtekgrinder 0xtekgrinder requested a review from notJoon October 23, 2024 10:37
@0xtekgrinder 0xtekgrinder requested a review from omarsy January 8, 2025 16:56
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 8, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details
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)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: 0xtekgrinder/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🔴 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@leohhhn leohhhn self-requested a review January 15, 2025 12:09
bucket := "u:" + addr.String()
p := perm{
verbs: []string{verb},
resources: []string{resource},
}
d.addPermToBucket(bucket, p)
d.addPermsToBucket(bucket, []perm{p})
return true
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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

@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Feb 24, 2025
Comment on lines +24 to +25
for _, pd := range newPerms {
if !p.Contains(pd) {
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

@moul moul Feb 24, 2025

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 {
Copy link
Member

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.

Copy link
Member

@moul moul left a 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:

Alternatively, feel free to fork this ACL package under your username if you believe your API could better serve some users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Needs Review
Status: In Review
Development

Successfully merging this pull request may close these issues.

5 participants