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

Add "user:invite" command #5

Open
mbrodala opened this issue Nov 1, 2024 · 1 comment · May be fixed by #6
Open

Add "user:invite" command #5

mbrodala opened this issue Nov 1, 2024 · 1 comment · May be fixed by #6

Comments

@mbrodala
Copy link

mbrodala commented Nov 1, 2024

Similar to the web UI a user:invite command would be useful to trigger the regular user invitation workflow from the console.

This way no password must be set for a new user in advance, this should be left to the user in case he accepts the invitation.

Technically Piwik\Plugins\UsersManager\API::inviteUser() exists for this very purpose. Unfortunately there are 1-2 caveats with this API:

  1. It is currently tailored for being called in a web context as indicated by the check for force_api_session:
    https://github.com/matomo-org/matomo/blob/5.1.2/plugins/UsersManager/API.php#L789
  2. In case no "API session" should be used, it will prompt for the password of the current user:
    https://github.com/matomo-org/matomo/blob/5.1.2/plugins/UsersManager/API.php#L790
    This among others calls Piwik::doesUserRequirePasswordConfirmation():
    https://github.com/matomo-org/matomo/blob/5.1.2/core/Piwik.php#L297

Slightly hack-ish but probably the easiest workaround for now would be setting $_GET['force_api_session'] = 1; before calling ::inviteUser():
https://github.com/matomo-org/matomo/blob/5.1.2/plugins/UsersManager/tests/Integration/APITest.php#L1128

@mbrodala mbrodala linked a pull request Nov 1, 2024 that will close this issue
@mbrodala
Copy link
Author

mbrodala commented Nov 1, 2024

Evidently I misunderstood the force_api_session part. Not setting anything and having the default 0 (false) being used actually avoids the password confirmation.

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 a pull request may close this issue.

1 participant