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(boards2): initial permissions support #3151

Merged

Conversation

jeronimoalbi
Copy link
Member

Related to #3139

jeronimoalbi and others added 6 commits November 18, 2024 09:02
Interface is defined based on Jae's idea to handle permissioned tasks.

Co-authored-by: Jae Kwon <[email protected]>
Also rename `auth.gno` file to `permission.gno`
The `HasPermission` methods has been removed in favor of using the
permissioner interface.

Currently there is only a global permissioner but once the AdminDAO is
implemented permissions will provably be handled by each individual
board and the realm.
There are function that require checks that should be done by an
implementer, like a DAO. Initially the implementer might choose to use
proposals under the hood making it impossible to return the ID of a
newly created entity syncronically. This change just adds permission
support but the pattern must be improved to handle these cases.
This check might be reintroduced in the default permissioner
implementation.
@jeronimoalbi jeronimoalbi requested a review from ilgooz November 18, 2024 18:23
@jeronimoalbi jeronimoalbi self-assigned this Nov 18, 2024
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Nov 18, 2024
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Removed two methods which are not yet used. These methods can be added
later if boards2 requires them.
This implementation doesn't have support for proposals, it's only
intended to have the minimal initial AdminDAO implementation required to
start writting other boards2 features.
DAO only implementes support for members and eventually proposals.
Roles and permissions should be managed by another entity.
@jeronimoalbi jeronimoalbi marked this pull request as ready for review November 20, 2024 15:21
@jeronimoalbi jeronimoalbi marked this pull request as draft November 20, 2024 18:38
@jeronimoalbi jeronimoalbi marked this pull request as ready for review November 25, 2024 13:36
Role string

// ACL or access control list manages user roles and permissions.
ACL struct {
Copy link
Member Author

@jeronimoalbi jeronimoalbi Nov 25, 2024

Choose a reason for hiding this comment

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

This type could be named Permissions (or DefaultPermissions) instead of ACL. Naming it ACL makes sense thinking that it not only handles permissions but also roles.

Comment on lines 30 to 38
args := Args{name, id}
// TODO: Do the callback really need the args or we could have the same result directly referencing?
gAuth.WithPermission(caller, PermissionBoardCreate, args, func(a Args) { // TODO: Caller could be an extra func arg
name := a[0].(string)
id := a[1].(BoardID)
board := newBoard(id, name, caller)
gBoardsByID.Set(id.Key(), board)
gBoardsByName.Set(name, board)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

Sending the arguments to WithPermission is necessary for the case where the Permissioner interface implementer, for example a DAO, creates a proposal under the hood. The arguments could be considered parameters for the proposal in that case.

Does using the args in the callback function make sense? Code would be cleaner if outer variables are used instead. Or is it better for the VM to use args from the function instead of outer references?

Caller is normally used within the callback, so we could send the caller as an argument for the callback if we don't want to use outer references.

Using `WithPermission` is not needed in many cases at this point and it
can be introduced once the functionalities are better defined.
@jeronimoalbi jeronimoalbi merged commit 4944a7e into gnolang:devx/feature/boardsv2 Nov 26, 2024
93 checks passed
x1unix pushed a commit to gnostudio/gno that referenced this pull request Jan 6, 2025
Related to gnolang#3139

Permissioner interface is defined based on Jae's idea to handle permissioned tasks.
---------

Co-authored-by: Jae Kwon <[email protected]>
@jeronimoalbi jeronimoalbi deleted the feat/authorization branch January 9, 2025 17:06
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
None yet
Development

Successfully merging this pull request may close these issues.

1 participant