MM-32471: Use created user to update roles (#16895)

During user creation via CLI, we would create the user,
but pass the user ID instead when updating the roles.

This falls into the category of read-after-write within a single request.
We fix this by passing the already created user and
directly update the roles.

https://mattermost.atlassian.net/browse/MM-32471

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-02-10 23:41:34 +05:30
коммит произвёл GitHub
родитель 1e3b6b56a6
Коммит d8b94836cf
5 изменённых файлов: 51 добавлений и 3 удалений

Просмотреть файл

@@ -377,13 +377,13 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
}
if systemAdmin {
if _, err := a.UpdateUserRoles(ruser.Id, "system_user system_admin", false); err != nil {
if _, err := a.UpdateUserRolesWithUser(ruser, "system_user system_admin", false); err != nil {
return errors.New("Unable to make user system admin. Error: " + err.Error())
}
} else {
// This else case exists to prevent the first user created from being
// created as a system admin unless explicitly specified.
if _, err := a.UpdateUserRoles(ruser.Id, "system_user", false); err != nil {
if _, err := a.UpdateUserRolesWithUser(ruser, "system_user", false); err != nil {
return errors.New("If this is the first user: Unable to prevent user from being system admin. Error: " + err.Error())
}
}