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: ADR-012: Subspaces sections #866

Merged
merged 51 commits into from
Jun 1, 2022

Conversation

RiccardoM
Copy link
Contributor

@RiccardoM RiccardoM commented May 17, 2022

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@github-actions github-actions bot added x/CLI x/relationships x/subspaces Issue on the x/subspaces module labels May 17, 2022
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #866 (986bad3) into master (8379c67) will increase coverage by 0.82%.
The diff coverage is 87.02%.

❗ Current head 986bad3 differs from pull request most recent head c6e4946. Consider uploading reports for the commit c6e4946 to get more accurate results

@@            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     
Impacted Files Coverage Δ
x/relationships/keeper/hooks.go 66.66% <0.00%> (-5.34%) ⬇️
x/subspaces/types/models.go 95.05% <ø> (+13.36%) ⬆️
x/subspaces/types/msgs.go 99.00% <ø> (+0.47%) ⬆️
x/subspaces/types/permissions.go 73.52% <ø> (ø)
x/subspaces/legacy/v2/models.go 30.76% <30.76%> (ø)
x/posts/keeper/subspaces_hooks.go 57.69% <41.66%> (-16.00%) ⬇️
x/posts/types/models.go 71.28% <50.00%> (-0.87%) ⬇️
x/posts/keeper/alias_functions.go 58.78% <51.28%> (-7.22%) ⬇️
x/subspaces/types/codec.go 53.65% <64.28%> (+5.51%) ⬆️
x/subspaces/legacy/v3/store.go 73.91% <73.91%> (ø)
... and 41 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8379c67...c6e4946. Read the comment docs.

RiccardoM and others added 9 commits May 18, 2022 10:02
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
…ementation' into riccardo/subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@RiccardoM RiccardoM changed the title feat: ADR-012: Subspaces sections feat!: ADR-012: Subspaces sections May 18, 2022
@RiccardoM RiccardoM marked this pull request as ready for review May 18, 2022 09:08
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
x/subspaces/keeper/alias_functions.go Outdated Show resolved Hide resolved
x/subspaces/keeper/genesis.go Outdated Show resolved Hide resolved
x/subspaces/keeper/genesis.go Outdated Show resolved Hide resolved
x/relationships/keeper/hooks.go Show resolved Hide resolved
x/subspaces/keeper/hooks.go Show resolved Hide resolved
x/subspaces/keeper/msg_server.go Outdated Show resolved Hide resolved
x/subspaces/keeper/sections_test.go Outdated Show resolved Hide resolved
// 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 {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

x/subspaces/types/keys_test.go Show resolved Hide resolved
RiccardoM and others added 5 commits May 19, 2022 08:26
Co-authored-by: Leonardo Bragagnolo <leo.braga95@gmail.com>
Co-authored-by: Leonardo Bragagnolo <leo.braga95@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
…ementation' into riccardo/subspaces-sections-implementation
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@RiccardoM RiccardoM requested a review from leobragaz May 19, 2022 07:13
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@github-actions github-actions bot added the x/profiles Module that allows to create and manage decentralized social profiles label May 31, 2022
@RiccardoM RiccardoM requested a review from dadamu May 31, 2022 09:04
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()) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

x/subspaces/types/msgs.go Outdated Show resolved Hide resolved
x/subspaces/types/msgs.go Outdated Show resolved Hide resolved
nil,
),
name: "invalid user returns no error",
entry: types.NewUserPermission(1, 0, "", types.PermissionWrite),
shouldErr: true,
},
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

@dadamu
Copy link
Contributor

dadamu commented May 31, 2022

Overall looks great to me. Just some minor things can be improved.

RiccardoM and others added 5 commits May 31, 2022 14:15
Co-authored-by: Paul <p22626262@gmail.com>
Co-authored-by: Paul <p22626262@gmail.com>
Co-authored-by: Paul <p22626262@gmail.com>
Co-authored-by: Paul <p22626262@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@RiccardoM RiccardoM requested a review from dadamu May 31, 2022 12:40
@RiccardoM RiccardoM added the automerge Automatically merge PR once all prerequisites pass label May 31, 2022
}

// 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()) {
Copy link
Contributor

@dadamu dadamu May 31, 2022

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.

Copy link
Contributor Author

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 👍

RiccardoM and others added 2 commits May 31, 2022 17:31
Co-authored-by: Paul <p22626262@gmail.com>
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@RiccardoM RiccardoM requested a review from dadamu May 31, 2022 16:15
Copy link
Contributor

@dadamu dadamu left a 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 <riccardo.montagnin@gmail.com>
@mergify mergify bot merged commit d9a708d into master Jun 1, 2022
@mergify mergify bot deleted the riccardo/subspaces-sections-implementation branch June 1, 2022 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once all prerequisites pass x/CLI x/profiles Module that allows to create and manage decentralized social profiles x/relationships x/subspaces Issue on the x/subspaces module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to create subspace sections
3 participants