[MM-47824] fix promoteGuestToUserCmdF to handle the proper errors (#26397)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7337c384a8
Коммит
46bd4599f0
@@ -1024,21 +1024,26 @@ func migrateAuthToLdapCmdF(c client.Client, cmd *cobra.Command, userArgs []strin
|
||||
}
|
||||
|
||||
func promoteGuestToUserCmdF(c client.Client, _ *cobra.Command, userArgs []string) error {
|
||||
var errs *multierror.Error
|
||||
for i, user := range getUsersFromUserArgs(c, userArgs) {
|
||||
if user == nil {
|
||||
printer.PrintError(fmt.Sprintf("can't find guest '%v'", userArgs[i]))
|
||||
err := fmt.Errorf("can't find guest '%s'", userArgs[i])
|
||||
errs = multierror.Append(errs, err)
|
||||
printer.PrintError(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := c.PromoteGuestToUser(context.TODO(), user.Id); err != nil {
|
||||
printer.PrintError(fmt.Sprintf("unable to promote guest %s: %s", userArgs[i], err))
|
||||
err = fmt.Errorf("unable to promote guest %s: %w", userArgs[i], err)
|
||||
errs = multierror.Append(errs, err)
|
||||
printer.PrintError(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
printer.PrintT("User {{.Username}} promoted.", user)
|
||||
}
|
||||
|
||||
return nil
|
||||
return errs.ErrorOrNil()
|
||||
}
|
||||
|
||||
func demoteUserToGuestCmdF(c client.Client, _ *cobra.Command, userArgs []string) error {
|
||||
|
||||
@@ -928,7 +928,7 @@ func (s *MmctlE2ETestSuite) TestPromoteGuestToUserCmd() {
|
||||
printer.Clean()
|
||||
|
||||
err := promoteGuestToUserCmdF(c, nil, []string{user.Email})
|
||||
s.Require().Nil(err)
|
||||
s.Require().NoError(err)
|
||||
defer s.Require().Nil(s.th.App.DemoteUserToGuest(s.th.Context, user))
|
||||
s.Require().Len(printer.GetLines(), 1)
|
||||
s.Require().Len(printer.GetErrorLines(), 0)
|
||||
@@ -938,7 +938,7 @@ func (s *MmctlE2ETestSuite) TestPromoteGuestToUserCmd() {
|
||||
printer.Clean()
|
||||
|
||||
err := promoteGuestToUserCmdF(s.th.Client, nil, []string{user.Email})
|
||||
s.Require().Nil(err)
|
||||
s.Require().Error(err)
|
||||
s.Require().Len(printer.GetLines(), 0)
|
||||
s.Require().Len(printer.GetErrorLines(), 1)
|
||||
s.Require().Equal(fmt.Sprintf("unable to promote guest %s: You do not have the appropriate permissions.", user.Email), printer.GetErrorLines()[0])
|
||||
|
||||
@@ -2747,7 +2747,7 @@ func (s *MmctlUnitTestSuite) TestPromoteGuestToUserCmd() {
|
||||
Times(1)
|
||||
|
||||
err := promoteGuestToUserCmdF(s.client, nil, []string{emailArg})
|
||||
s.Require().NoError(err)
|
||||
s.Require().ErrorContains(err, "unable to promote guest")
|
||||
s.Require().Len(printer.GetLines(), 0)
|
||||
s.Require().Len(printer.GetErrorLines(), 1)
|
||||
s.Require().Equal(fmt.Sprintf("unable to promote guest %s: %s", emailArg, "some-error"), printer.GetErrorLines()[0])
|
||||
|
||||
Ссылка в новой задаче
Block a user