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. |
| $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.
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. |
| $test->assertEquals('foo', $event->getSubject()->getUID()); | ||
| }; | ||
|
|
||
| $eventDispatcher = \OC::$server->getEventDispatcher(); |
There was a problem hiding this comment.
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.
@VicDeo please take care so that we can merge this one - THX
There was a problem hiding this comment.
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.
is $eventDispatcher ever passed into this ctor?
|
👍 |
|
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: