-
Notifications
You must be signed in to change notification settings - Fork 62
api: disallow a guest to change his role to member/manager #7740
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,11 @@ public static function of( | |
| if (self::hasOneParameter($extractProperty)) { | ||
| throw new \InvalidArgumentException('extractProperty must have exactly one parameter'); | ||
| } | ||
| if (self::hasOneParameter($beforeAction)) { | ||
| throw new \InvalidArgumentException('afterAction must have exactly one parameter'); | ||
| if (self::hasAtMostTwoParameter($beforeAction)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming of these parameter checking functions seems backwards to me. It's not returning whether the callback has at most two parameters, it's returning whether it has more than two or less than one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i also ran into it when developing. e.g.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up to you. Since you had to rewrite the PropertyChangeListener for this feature anyways, I'd have no problem accepting this refactoring in the same PR. But we can also do it later to get things moving here. |
||
| throw new \InvalidArgumentException('afterAction must have between 1 and 2 parameters'); | ||
| } | ||
| if (self::hasOneParameter($afterAction)) { | ||
| throw new \InvalidArgumentException('afterAction must have exactly one parameter'); | ||
| if (self::hasAtMostTwoParameter($afterAction)) { | ||
| throw new \InvalidArgumentException('afterAction must have between 1 and 2 parameters'); | ||
| } | ||
|
|
||
| return new PropertyChangeListener($extractProperty, $beforeAction, $afterAction); | ||
|
|
@@ -56,4 +56,15 @@ private static function hasOneParameter(?\Closure $beforeAction): bool { | |
|
|
||
| return 1 != $beforeActionReflectionFunction->getNumberOfParameters(); | ||
| } | ||
|
|
||
| /** | ||
| * @throws \ReflectionException | ||
| */ | ||
| private static function hasAtMostTwoParameter(?\Closure $beforeAction): bool { | ||
| $beforeActionReflectionFunction = new \ReflectionFunction($beforeAction); | ||
|
|
||
| $numberOfParameters = $beforeActionReflectionFunction->getNumberOfParameters(); | ||
|
|
||
| return $numberOfParameters < 1 || $numberOfParameters > 2; | ||
| } | ||
| } | ||
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.
Members also aren't allowed to change their own role, or are they? Doesn't the same apply for members?
And is there some camp collaboration
statewhich has the same flaw?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.
They are with the current implementation.
A similar issue: #3440
https://github.com/ecamp/ecamp3/blob/devel/api/src/Entity/Camp.php#L39
https://github.com/ecamp/ecamp3/blob/devel/api/src/Entity/CampCollaboration.php#L44
I did not wan't to change that too in the same PR.
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.
So, this PR is only concerned with restricting guests, not members. I'm fine with that, as long as we don't keep the equivalent flaw for members around for long.