Skip to content

UserCreatedEvent emitted twice when creating user via user management webui #23797

Description

@7118path

When creating a user account via the user management web ui, the '\OCP\User\Events\UserCreatedEvent' is emitted twice.

Steps to reproduce

  1. Create a listener for the '\OCP\User\Events\UserCreatedEvent' event and let it log or do something
  2. Create a user via the user management webui
  3. See the handle function of the listener is called twice

Expected behaviour

'\OCP\User\Events\UserCreatedEvent' should be emitted once only.

Actual behaviour

'\OCP\User\Events\UserCreatedEvent' is emitted twice.

Server configuration

Tested in official docker based Nextcloud 19.0.4 and 20.0.1

I think this causes the behaviour:

  • Emit Hook and Event in UserManager:
    if ($user instanceof IUser) {
    $this->emit('\OC\User', 'postCreateUser', [$user, $password]);
    $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
    }
  • React on Hook and emit Event a second time:
    $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
    /** @var \OC\User\User $user */
    \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
    /** @var IEventDispatcher $dispatcher */
    $dispatcher = $this->get(IEventDispatcher::class);
    $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
    });

If commenting L544-L545of Server.php the listener is only triggerd once.

Activity

  1. added
    0. Needs triagePending check for reproducibility or if it fits our roadmap
    on Oct 30, 2020
  2. kesselb commented on Oct 30, 2020

    @kesselb
    Contributor
  3. ChristophWurst commented on Nov 4, 2020

    @ChristophWurst
    Member

    If commenting L544-L545of Server.php the listener is only triggerd once.

    Yep, I guess the latter translation of the hook to the event is the reason for the duplication. If the user manager already emits, there really is no reason to do this translation. Mind sending a PR that removes those lines?

  4. added
    1. to developAccepted and waiting to be taken care of
    and removed
    0. Needs triagePending check for reproducibility or if it fits our roadmap
    on Nov 4, 2020
  5. added this to the Nextcloud 21 milestone on Nov 4, 2020
  6. 7118path commented on Nov 4, 2020

    @7118path
    ContributorAuthor

    Done

  7. added and removed
    1. to developAccepted and waiting to be taken care of
    on Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions