-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Emit postSetEnabled for user #26984
Emit postSetEnabled for user #26984
Conversation
@PVince81 is it good enough? |
@VicDeo yeah. A unit test would be nice if possible. |
0c3f1b3
to
d4f79f5
Compare
@PVince81 possible. Added. |
👍 |
This will not help. The emitter is on the user object. In order to consume the event a listener needs to be attached to each and every user. Pointless. This is why the whole emitter concept is 💩 Please use the EventDispatcher - THX |
Untrue. Tested both auto and manually, and works. ;)
OK |
show me the code which will listen to enabling of all users - good luck 😉 |
@DeepDiver1975 enabling / disabling is NOT a backend method anyway:
It can be done on per user level only. Because backend knows nothing about this operation. With or without EventDispatcher IDK how to do it for all users ATM. |
lib/private/User/User.php
Outdated
@@ -337,6 +337,9 @@ public function setEnabled($enabled) { | |||
$this->enabled = $enabled; | |||
$enabled = ($enabled) ? 'true' : 'false'; | |||
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled); | |||
if ($this->emitter) { | |||
$this->emitter->emit('\OC\User', 'postSetEnabled', [$this, $enabled]); |
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.
replace this with something like:
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->dispatch('OC\User::postSetEnabled', $this');
then to listen, an app just does this:
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
'OC\User::postSetEnabled',
function(IUser $user) {
// ...
});
(the param of the callback might be something else, I don't remember exactly)
@VicDeo see https://github.com/owncloud/core/pull/26984/files#r97399288 |
@PVince81 Ok, let it be EventDispatcher. |
tests/lib/User/UserTest.php
Outdated
$test->assertEquals('foo', $event->getSubject()->getUID()); | ||
}; | ||
|
||
$eventDispatcher = \OC::$server->getEventDispatcher(); |
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.
please don't use the event listener from the container - this can cause side effects.
It should be enough to use a mock and assert on the dispatch function
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.
@VicDeo please take care so that we can merge this one - THX
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.
to do so I need to inject EventDispatcher next to \OC\Hooks\Emitter 😭
*/ | ||
public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { | ||
public function __construct($uid, $backend, $emitter = null, IConfig $config = null, | ||
$urlGenerator = null, EventDispatcher $eventDispatcher = null |
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.
is $eventDispatcher ever passed into this ctor?
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.
@VicDeo ^^^
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.
@DeepDiver1975 passed now.
👍 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Implements user enabled/disabled event
Related Issue
#23970
Types of changes
Checklist: