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

Fix Mods being able to edit Admins, Split permissions #2113

Closed
wants to merge 9 commits into from

Conversation

tankerkiller125
Copy link
Contributor

@tankerkiller125 tankerkiller125 commented Apr 2, 2020

**Fixes #1965 **

Changes proposed in this pull request:

  • Currently only prevents non-admins from editing admin
  • Splits the edit.user permission into three (edit.username, edit.credentials, edit.groups)

Reviewers should focus on:

  • Is this the best way of doing this?
  • Do we want to limit what shows up on the edit screen to only what users have permissions to do?

Screenshot

image

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

@tankerkiller125 tankerkiller125 changed the title [WIP] Fix Mods being able to edit Admins, Split permissions Fix Mods being able to edit Admins, Split permissions Apr 3, 2020
Copy link
Member

@luceos luceos left a comment

Choose a reason for hiding this comment

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

For some reason I cannot add comments to the Serializer.

$canEdit = $gate->allows('edit.credentials') || $gate->allows('edit.groups') || $gate->allows('edit.username') ? true : false;

The last ?: is superfluous. I also highly doubt it does what you expect. The condition applies only to the last gate allow method, not all three.

Why exactly are there no new policy methods, are these magically applied? Would you have kept the user as an argument to the allows method and created the methods on the UserPolicy you could have moved the EditUserHandler change to the Policy to enforce it globally, I think that's the better solution here..

@tankerkiller125
Copy link
Contributor Author

tankerkiller125 commented Apr 3, 2020

Thanks for the feedback @luceos I'll work on implementing your suggestions, I think the problem stems from my lack of experience working with Flarums permission systems and not know exactly how policies got applied. With your insight I think I can do this way better.

Copy link
Sponsor Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

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

In theory this could work without a policy: if no policy governs a permission, there'll be a check as to whether the user belongs to a group that has that permission.

However, I agree that a policy could be useful here, as that'd be a better place to put the if user->isAdmin() => assertAdmin($actor) logic, so that we keep the permission layer separate from the editing logic.

src/User/Command/EditUserHandler.php Outdated Show resolved Hide resolved
src/User/Command/EditUserHandler.php Outdated Show resolved Hide resolved
src/Api/Serializer/UserSerializer.php Outdated Show resolved Hide resolved
src/Api/Serializer/UserSerializer.php Show resolved Hide resolved
src/User/Command/EditUserHandler.php Outdated Show resolved Hide resolved
@clarkwinkelmann
Copy link
Member

I agree with the existing comments. Please ping me again and I'll do an actual review when more code is pushed.

@franzliedke franzliedke marked this pull request as draft April 10, 2020 20:04
tankerkiller125 added a commit that referenced this pull request Apr 12, 2020
tankerkiller125 added a commit that referenced this pull request Apr 12, 2020
@tankerkiller125 tankerkiller125 marked this pull request as ready for review April 12, 2020 21:04
@tankerkiller125
Copy link
Contributor Author

@clarkwinkelmann I've refactored it almost completely

@franzliedke
Copy link
Contributor

Because we now auto-format our JS code with Prettier, this branch now has conflicts with master. Sorry about that. 😉

Please take the steps outlined in the forum to resolve the conflicts.

@tankerkiller125
Copy link
Contributor Author

Rebase was completed

@franzliedke
Copy link
Contributor

franzliedke commented Apr 24, 2020

I'd like to discuss the naming convention for the discussions permissions in our next meeting, that's why I'm not merging this yet.

@askvortsov1
Copy link
Sponsor Member

@franzliedke when you get back from vacation, what's the verdict on permission naming?

Copy link
Sponsor Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

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

I think Clark brings up a good point here: #2113 (comment), a warning message would be nice. Other than that, the only thing left is Franz's decision on the ability naming.

@stale
Copy link

stale bot commented Sep 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum.
In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!

@stale stale bot added the stale Issues that have had over 90 days of inactivity label Sep 16, 2020
@luceos luceos added the org/keep Issues we want to keep open label Sep 16, 2020
@stale stale bot removed the stale Issues that have had over 90 days of inactivity label Sep 16, 2020
Copy link
Sponsor Member

@askvortsov1 askvortsov1 left a 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 change it to camel case, and then switch back to dot separated later if we decide that to be the new convention. This also needs to be updated for mithril 2.

One major concern as I thought back to this: we currently have extensions using $actor->can('edit', $user), including our own nicknames. If we remove edit without a BC layer, we could run into issues. I think we should re-think this split, keeping user.edit as the main user edit permission, and requiring individual permissions (like user.editGroups) for higher level things.

@luceos luceos added this to the 0.1.0-beta.16 milestone Dec 22, 2020
@askvortsov1 askvortsov1 removed this from the 0.1.0-beta.16 milestone Jan 12, 2021
@tankerkiller125
Copy link
Contributor Author

Closing in favor of #2620

@tankerkiller125 tankerkiller125 deleted the mk/1965-fix-permissions branch February 21, 2021 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
org/keep Issues we want to keep open
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users with edit user permission can make themselves admins
5 participants