-
Notifications
You must be signed in to change notification settings - Fork 48
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: ADR-012: Subspaces sections #866
Conversation
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #866 +/- ##
==========================================
+ Coverage 81.82% 82.65% +0.82%
==========================================
Files 110 114 +4
Lines 9316 10157 +841
==========================================
+ Hits 7623 8395 +772
- Misses 1373 1429 +56
- Partials 320 333 +13
Continue to review full report at Codecov.
|
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
…subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <[email protected]>
…ementation' into riccardo/subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
// ValidateGenesis validates the given genesis state and returns an error if something is invalid | ||
func ValidateGenesis(data *GenesisState) error { | ||
// Make sure the initial subspace id is valid | ||
if data.InitialSubspaceID <= uint64(len(data.Subspaces)) { | ||
if data.InitialSubspaceID == 0 { |
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 suggest also to switch from 0 to a DefaultSubspace
or RootSubspace
constant
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 don't agree with naming the subspace id 0
with DefaultSubspace
or RootSubspace
since this is an invalid value for pretty much any case (except user blocks). Those naming would somehow tell the user that it should be a valid value, when it really should not
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.
Ah ok, gotcha. Do we have a RootSubspace
concept? Like a default one?
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.
No, there is not a default or root subspace. Every content will need to be placed inside a subspace that DApp developers need to create beforehand. They will not be able to create content if a non-zero subspace is not used.
The only subspace that is going to be different is going to be the one with id 0
. This will be used from users to block people they don't want to be bothered by with DTag transfer requests. But it will not allow to create content inside it.
All the other ones will allow all the operations (content creations, blockage, etc).
@@ -17,13 +17,16 @@ type SubspacesHooks interface { | |||
AfterSubspaceSaved(ctx sdk.Context, subspaceID uint64) // Must be called when a subspace is saved | |||
AfterSubspaceDeleted(ctx sdk.Context, subspaceID uint64) // Must be called when a subspace is deleted | |||
|
|||
AfterSubspaceSectionSaved(ctx sdk.Context, subspaceID uint64, sectionID uint32) // Must be called when a subspace section is saved | |||
AfterSubspaceSectionDeleted(ctx sdk.Context, subspaceID uint64, sectionID uint32) // Must be called when a subspace section is deleted | |||
|
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 think we should we also add AfterSubspaceSectionMoved
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 don't think it's worth it. That would require to have a custom keeper method that deals with moving sections. Instead, the current implementation will simply call AfterSubspaceSectionSaved
when a section is moved (since it's just about changing its ParentID
value). The module using this hook will simply be able to check the previously stored data and react properly if they are interested in doing so.
Co-authored-by: Leonardo Bragagnolo <[email protected]>
Co-authored-by: Leonardo Bragagnolo <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
…ementation' into riccardo/subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <[email protected]>
…subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
account = *acc | ||
|
||
// Make sure the user can change this group's permissions | ||
if subspace.Owner != account.Address.String() && k.IsMemberOfGroup(ctx, subspaceID, groupID, account.Address.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.
It can be replaced with k.HasPermission
.
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.
Thanks for pointing this out. I actually forgot to add this check inside the MsgMoveUserGroup
handler function: we shouldn't allow users that are part of a group to manage that group as they might use this to get more permissions than the ones that were assigned to them. I've now added this check inside the handler as well.
nil, | ||
), | ||
name: "invalid user returns no error", | ||
entry: types.NewUserPermission(1, 0, "", types.PermissionWrite), | ||
shouldErr: 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.
Missing invalid permission test case.
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.
Added!
Overall looks great to me. Just some minor things can be improved. |
Co-authored-by: Paul <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Paul <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
x/subspaces/keeper/msg_server.go
Outdated
} | ||
|
||
// Make sure that the user is not part of the group they want to change the permissions for, unless they are the owner | ||
if subspace.Owner != msg.Signer && k.IsMemberOfGroup(ctx, msg.SubspaceID, msg.GroupID, signer.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.
In the following case, the moderator who has the ManageGroups
permission in A section can move the B section group to the root.
Root
|
A
|
B
Instead of this check, It can be solved by k.HasPermission(ctx, group.SubspaceID, msg.NewSectionID, signer.String(), types.PermissionManageGroups)
, to check permission in the new section.
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.
Updated the checks to include both PermissionManageGroups
and PermissionSetUserPermissions
for the destination section 👍
Co-authored-by: Paul <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
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.
Ready to go to me
…subspaces-sections-implementation � Conflicts: � x/posts/keeper/genesis_test.go
Signed-off-by: Riccardo Montagnin <[email protected]>
Description
This PR implements the subspaces sections as described inside ADR-012.
Closes: #856
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change