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

Deprecate AssertPermissionTrait #2044

Merged

Conversation

askvortsov1
Copy link
Sponsor Member

**Fixes #1320 **

Changes proposed in this pull request:
Deprecate the AssertPermissionTrait. We should merge this in the next release to give extension authors time to adjust prior to stable.

Confirmed

  • Backend changes: tests are green (run composer test).

@askvortsov1 askvortsov1 force-pushed the as/deprecate_assert_permission_trait branch from 336a57a to d9c1756 Compare March 20, 2020 14:40
@clarkwinkelmann
Copy link
Member

What were the motivations behind this change ? Why get rid of AssertPermissionTrait ? This puts even more code into the User model 🤔

@franzliedke
Copy link
Contributor

I believe the idea is encapsulation. These methods all operate on the user/actor objects, so it makes sense that they are owned by the User class.

Yes, this adds more code to User, but as I argue above, it kinda belongs there - to the part of it that is concerned with "actor" stuff. The class inherits from the Eloquent model god class, so this is merely a drop in the bucket. 😆

On a more serious note. I could see us reducing or at least separating the responsibilities by introducing an interface for actor-related things. That would help in e.g. at least decoupling Guest from all the Eloquent stuff. That might help simplify certain tests.

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Looks good, I'd be happy with this change! (Want to wait for others' responses.)

I found two small copy-paste mistakes (?), though...

src/Api/Controller/ListNotificationsController.php Outdated Show resolved Hide resolved
src/Api/Controller/SendConfirmationEmailController.php Outdated Show resolved Hide resolved
@luceos
Copy link
Member

luceos commented Apr 14, 2020

Yes, this adds more code to User, but as I argue above, it kinda belongs there

@franzliedke can't we move this out of the User class into a Concerns/trait please? It's what I proposed in the user preferences as well and it would help keep Users clean.

@franzliedke
Copy link
Contributor

@luceos We could. Personally, I rarely see the benefit in extracting a trait if it's not for the purpose of sharing code. In this case, we would just try to conceal the fact that the class is too big / doing too much. On the downside, I tend to be surprised by traits, because I often forget to consider them (or simply overlook them) when searching for a method's implementation.

Not too strong an opinion, curious to hear what others think.

@askvortsov1 askvortsov1 force-pushed the as/deprecate_assert_permission_trait branch from d9c1756 to c336d56 Compare May 3, 2020 19:14
@askvortsov1
Copy link
Sponsor Member Author

I also see traits as a mechanism for sharing functionality among unrelated classes moreso than a way to split up big classes 👍

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Please squash and rebase, then I'll gladly merge.

@askvortsov1 askvortsov1 force-pushed the as/deprecate_assert_permission_trait branch 2 times, most recently from 0c812e0 to 95623ea Compare July 10, 2020 13:56
@franzliedke
Copy link
Contributor

@askvortsov1 That did not go well. 😱

@askvortsov1 askvortsov1 force-pushed the as/deprecate_assert_permission_trait branch 2 times, most recently from e17965c to 5694438 Compare July 10, 2020 14:07
@askvortsov1
Copy link
Sponsor Member Author

@franzliedke here we go :D 🙈

@askvortsov1 askvortsov1 force-pushed the as/deprecate_assert_permission_trait branch from 5694438 to feb45b9 Compare July 10, 2020 14:08
Copy link
Contributor

@tankerkiller125 tankerkiller125 left a comment

Choose a reason for hiding this comment

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

Looks good, I don't see any more issues and it appears that Franz problem was resolved.

@franzliedke franzliedke merged commit eaac786 into flarum:master Jul 17, 2020
@franzliedke
Copy link
Contributor

Any volunteers for applying this change to all bundled extensions? 😁

@tankerkiller125
Copy link
Contributor

@franzliedke I'll take care of it this weekend once I get done meeting the dog I might be adopting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move AssertPermissionTrait methods directly onto the User model
5 participants