Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

110 lines
2.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"errors"
"fmt"
"github.com/hashicorp/go-multierror"
"github.com/hanzoteam/server/server/public/model"
"github.com/spf13/cobra"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/client"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/printer"
)
var TeamUsersCmd = &cobra.Command{
Use: "users",
Short: "Management of team users",
}
var TeamUsersRemoveCmd = &cobra.Command{
Use: "remove [team] [users]",
Short: "Remove users from team",
Long: "Remove some users from team",
Example: " team users remove myteam [email protected] username",
Args: cobra.MinimumNArgs(2),
RunE: withClient(teamUsersRemoveCmdF),
}
var TeamUsersAddCmd = &cobra.Command{
Use: "add [team] [users]",
Short: "Add users to team",
Long: "Add some users to team",
Example: " team users add myteam [email protected] username",
Args: cobra.MinimumNArgs(2),
RunE: withClient(teamUsersAddCmdF),
}
func init() {
TeamUsersCmd.AddCommand(
TeamUsersRemoveCmd,
TeamUsersAddCmd,
)
TeamCmd.AddCommand(TeamUsersCmd)
}
func teamUsersRemoveCmdF(c client.Client, cmd *cobra.Command, args []string) error {
team := getTeamFromTeamArg(c, args[0])
if team == nil {
return errors.New("Unable to find team '" + args[0] + "'")
}
var errs *multierror.Error
users := getUsersFromUserArgs(c, args[1:])
for i, user := range users {
if err := removeUserFromTeam(c, team, user, args[i+1]); err != nil {
errs = multierror.Append(errs, err)
}
}
return errs.ErrorOrNil()
}
func removeUserFromTeam(c client.Client, team *model.Team, user *model.User, userArg string) error {
if user == nil {
err := fmt.Errorf("can't find user '%s'", userArg)
printer.PrintError(err.Error())
return err
}
var err error
if _, err = c.RemoveTeamMember(context.TODO(), team.Id, user.Id); err != nil {
err = fmt.Errorf("unable to remove '%s' from %s. Error: %w", userArg, team.Name, err)
printer.PrintError(err.Error())
}
return err
}
func teamUsersAddCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var errs *multierror.Error
team := getTeamFromTeamArg(c, args[0])
if team == nil {
return errors.New("Unable to find team '" + args[0] + "'")
}
users := getUsersFromUserArgs(c, args[1:])
for i, user := range users {
if user == nil {
userErr := fmt.Errorf("can't find user '%s'", args[i+1])
printer.PrintError(userErr.Error())
errs = multierror.Append(errs, userErr)
continue
}
addUserToTeam(c, team, user, args[i+1])
}
return errs.ErrorOrNil()
}
func addUserToTeam(c client.Client, team *model.Team, user *model.User, userArg string) {
if _, _, err := c.AddTeamMember(context.TODO(), team.Id, user.Id); err != nil {
printer.PrintError("Unable to add '" + userArg + "' to " + team.Name + ". Error: " + err.Error())
}
}