? ? Pending

User tests: Successful: Unsuccessful:

avatar f-hamel
f-hamel
19 Jul 2019

Summary of Changes

Hello everyone,

This is my first PR (reopened for #20095)here and I want to add something what could help a lot of people.

I'm working as a technical consultant for a German hosting provider.
Often customers contact me because they forget there backend credentials and they are not
able to handle this issue on a easy way.

So I thought if we have already a CLI in Joomla 4, why don't get the possibility to add an new admin user(Suprer User) or change the password of an existing admin.
For this I add commands to CLI to create an admin user or change his password.

I tried to do everything correct like described in https://developer.joomla.org/coding-standards.html
and https://developer.joomla.org/news/586-joomla-development-strategy.html.

As this is my first PR please be patient with me, if there is something wrong.
I really would like to get some feedback and hint how to contribute right.

Testing Instructions

After getting this CLI patch use:
Add user:

 php joomla.php 
Joomla! 4.0.0-alpha7-dev

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display the help information
  -q, --quiet           Flag indicating that all output should be silenced
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Flag to disable interacting with the user
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help                            Show the help for a command
  list                            List the application's available commands
 cache
  cache:clean                     Cleans expired cache entries
 session
  session:gc                      Performs session garbage collection
  session:metadata:gc             Performs session metadata garbage collection
 update
  update:extensions:check         Checks for pending extension updates
  update:joomla:remove-old-files  Removes old system files
 user
  user:add                        Adds an user
  user:addtogroup                 Add an user to group
  user:delete                     Delete an user
  user:list                       List all users
  user:removefromgroup            Remove an user from group
  user:reset-password             Changes a users password

Try the user:commands. Use -hflag to get information about parameter

avatar f-hamel f-hamel - open - 19 Jul 2019
avatar f-hamel f-hamel - change - 19 Jul 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 19 Jul 2019
Category Libraries
avatar brianteeman
brianteeman - comment - 19 Jul 2019

@f-hamel Thanks for this PR
I have made a few minor english language corrections
Tomorrow I hope to have time to actually test the code. I suspect there may be some more english changes to the messages when I can see them on the screen.

avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Jul 2019
Title
[4.0] Add user management to CLI reopened for #20095
[4.0] Add user management to CLI
avatar franz-wohlkoenig franz-wohlkoenig - edited - 20 Jul 2019
avatar f-hamel f-hamel - change - 20 Jul 2019
Labels Added: ?
avatar brianteeman
brianteeman - comment - 22 Jul 2019

Is it possible to do the validation at each step so that you dont have to go right back to the beginning and start again
image

avatar brianteeman
brianteeman - comment - 22 Jul 2019

Is it possible to do the validation at each step so that you dont have to go right back to the beginning and start again
image

avatar brianteeman
brianteeman - comment - 22 Jul 2019

addtogroup

If I undertand this correctly then after I have entered the user I should get a list of groups. I dont
image

avatar brianteeman
brianteeman - comment - 22 Jul 2019

When you have a user who is in multiple groups and the try user:addtogroup or user:removefromgroup you get a mysql error

image

avatar f-hamel
f-hamel - comment - 23 Jul 2019

When you have a user who is in multiple groups and the try user:addtogroup or user:removefromgroup you get a mysql error

image

@HLeithner this seems to be a problem in the database frame work. This works the last weeks without any problem. Is this maybe caused by one of these change:
joomla-framework/database#163
joomla-framework/database#164
joomla-framework/database#171

Since one of them whereIn and whereNotIn are not working anymore.

avatar HLeithner
HLeithner - comment - 23 Jul 2019

Can you show me the database query and the function call?

avatar f-hamel
f-hamel - comment - 23 Jul 2019

@HLeithner

Can you show me the database query and the function call?

// Generate select list for user
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__usergroups'))
->whereNotIn($db->quoteName('id'), $user->groups)
->order($db->quoteName('id') . ' ASC');
$db->setQuery($query);
$list = $db->loadColumn();

$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__usergroups'))
->whereIn($db->quoteName('id'), $user->groups);
$db->setQuery($query);
$result = $db->loadColumn();

avatar alikon
alikon - comment - 23 Jul 2019

looking quickly ... you must be sure that $user->groups is an array

avatar f-hamel
f-hamel - comment - 23 Jul 2019

looking quickly ... you must be sure that $user->groups is an array

Tanks for your help. Yes that's right, and I am aware of that. $user is a Joomla user-object, which is given to function "getGroups". So $user->groups is an array with all group ids of the user:

$userId = UserHelper::getUserId($this->username);
if (empty($userId))
{
$this->ioStyle->error("The user " . $this->username . " does not exist!");
return 1;
}
$user = User::getInstance($userId);
$this->userGroups = $this->getGroups($user);

So this should be correct. And this was working all the time. Or maybe I miss something.

avatar alikon
alikon - comment - 23 Jul 2019

can you do a quick test assigning to a variable $usergroups =$user->groups; and then ->whereIn($db->quoteName('id'),$usergroup);

avatar f-hamel
f-hamel - comment - 23 Jul 2019

@HLeithner and @alikon thanks for your help.
Found the problem. $user->groups is now returning an "unsorted"(?) array:

php joomla.php user:addtogroup --username fhamel

Add user to group
=================

array(1) {
  [8]=>
  string(1) "8"
}

array_values() will fix this.

avatar f-hamel
f-hamel - comment - 23 Jul 2019

@brianteeman thanks for your language suggestions. I fixed them.
Checking each step before completing all of them is not so easy, because we are getting the error message from the $user->save call. But I'll look in to it. May we can trigger the specific validation check, before trigger $user->save

avatar twister65
twister65 - comment - 23 Jul 2019

I have tested this item successfully on 138211e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar twister65 twister65 - test_item - 23 Jul 2019 - Tested successfully
avatar richard67
richard67 - comment - 23 Jul 2019

@SniperSister Is that ok from the security point of view, adding users or changing passwords via CLI? I think it should be ok, but wanted to ask an expert ;-)

avatar brianteeman
brianteeman - comment - 23 Jul 2019

If someone already has CLI access then they can do what they want anyway

avatar richard67
richard67 - comment - 23 Jul 2019

I have tested this item successfully on 138211e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar richard67 richard67 - test_item - 23 Jul 2019 - Tested successfully
avatar franz-wohlkoenig franz-wohlkoenig - change - 24 Jul 2019
Status Pending Ready to Commit
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Jul 2019

Status "Ready To Commit".

avatar SniperSister
SniperSister - comment - 24 Jul 2019

Is that ok from the security point of view, adding users or changing passwords via CLI? I think it should be ok, but wanted to ask an expert ;-)

@richard67 that's perfectly fine. If you have CLI access, you have access to the configuration.php = full access anyway

avatar f-hamel f-hamel - change - 24 Jul 2019
Labels Added: ?
avatar richard67
richard67 - comment - 24 Jul 2019

@f-hamel Is it ready for being tested?

avatar f-hamel
f-hamel - comment - 24 Jul 2019

@f-hamel Is it ready for being tested?

@richard67 Of course. You can test this any time. ;-)

avatar richard67
richard67 - comment - 24 Jul 2019

I have tested this item successfully on fe8597f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar richard67 richard67 - test_item - 24 Jul 2019 - Tested successfully
avatar f-hamel
f-hamel - comment - 24 Jul 2019

@twister65 and @richard67 thanks for testing.

avatar richard67
richard67 - comment - 24 Jul 2019

@f-hamel Well, because your last commits haven't changed cody style only but also code, @twister65 's test is not valid anymore, so he should re-test or someone else should test to get the required 2nd test.

avatar f-hamel
f-hamel - comment - 24 Jul 2019

Ok. @twister65 could yo test again? And maybe approve your requested changes I mad?

avatar richard67
richard67 - comment - 26 Jul 2019

@f-hamel Good and nice work by the way. Hope to see you contribute more to Joomla.

avatar Hackwar
Hackwar - comment - 26 Jul 2019

Hi @f-hamel, thanks for this feature. I like this and think it is a good addition. However, I'm very unhappy with just using $user->groups. I see that the API currently is inadequate to retrieve this directly from there, but I would really prefer if we would either use \Joomla\CMS\Access\Access::getGroupsByUser($user->id, false) or extend User::getAuthorisedGroups() with a parameter to not get any indirect groups, instead of relying on that groups attribute. That has been unstable since Joomla 1.5 and I really would want that to be dropped rather sooner than later...

avatar Hackwar
Hackwar - comment - 26 Jul 2019

And would you be able to create tests for this feature in the Codeception API tests?

avatar alikon
alikon - comment - 26 Jul 2019

I have tested this item successfully on fe8597f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar alikon
alikon - comment - 26 Jul 2019

I have tested this item successfully on fe8597f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar alikon alikon - test_item - 26 Jul 2019 - Tested successfully
avatar f-hamel
f-hamel - comment - 26 Jul 2019

Hi @f-hamel, thanks for this feature. I like this and think it is a good addition. However, I'm very unhappy with just using $user->groups. I see that the API currently is inadequate to retrieve this directly from there, but I would really prefer if we would either use \Joomla\CMS\Access\Access::getGroupsByUser($user->id, false) or extend User::getAuthorisedGroups() with a parameter to not get any indirect groups, instead of relying on that groups attribute. That has been unstable since Joomla 1.5 and I really would want that to be dropped rather sooner than later...

I wil change this to Access::getGroupsByUser().

And would you be able to create tests for this feature in the Codeception API tests?
Sadly I don't know how to create such tests

avatar alikon
alikon - comment - 26 Jul 2019

@wilsonge please evaluate this PR, personal opinion it's ready to go in core

avatar richard67
richard67 - comment - 26 Jul 2019

Ok, looks good. Not sure if I can test later today, but if not then I will for sure tomorrow.

avatar f-hamel
f-hamel - comment - 26 Jul 2019

@alikon thanks for your feedback here.
Would you test this again. This becomes necessary because I change the code the way @Hackwar described. Hannes maybe you could also test this, and if it's got mark as successful.

@richard67 would be great if you could test this later.
And yes I looking forward to contributing more to Joomla. There still some ideas in mind.
Even more CLI features.

avatar Hackwar
Hackwar - comment - 26 Jul 2019

Right now adding tests is not mandatory for a PR, but as I said, it would be nice to support this with tests. If you are interested, I'd be happy to give you an introduction on how to create these tests. So far there is no objection from me to this PR. Unfortunately, I've only done a cursory code review and don't have the time to give this an indepth test, so I can't mark this as tested by me.

avatar Hackwar
Hackwar - comment - 26 Jul 2019

Oh, and welcome in the circle of Joomla devs. One of us, one of us, one of us... ?

avatar richard67
richard67 - comment - 26 Jul 2019

Well I hope he will not ONLY do CLI stuff .. otherwise the CLI might be soon better than the backend ;-)

avatar richard67
richard67 - comment - 26 Jul 2019

I have tested this item successfully on c6e3dd9

Thanks god I had all these commands still in the command buffer of the shell ;-)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar richard67 richard67 - test_item - 26 Jul 2019 - Tested successfully
avatar alikon
alikon - comment - 26 Jul 2019

I have tested this item successfully on c6e3dd9


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25649.

avatar alikon alikon - test_item - 26 Jul 2019 - Tested successfully
avatar alikon
alikon - comment - 26 Jul 2019

RTC

@f-hamel welcome in the CLI club

avatar wilsonge wilsonge - change - 27 Jul 2019
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-07-27 13:29:03
Closed_By wilsonge
avatar wilsonge wilsonge - close - 27 Jul 2019
avatar wilsonge wilsonge - merge - 27 Jul 2019
avatar wilsonge
wilsonge - comment - 27 Jul 2019

Thanks!

avatar f-hamel
f-hamel - comment - 27 Jul 2019

@wilsonge thanks for merging.

Also a lot of thanks to all who helped me. Thats whats the meaning of joomla is: all together ?

Add a Comment

Login with GitHub to post a comment