Add team renaming functionality to API and frontend. Implement backend logic for renaming teams, including validation and synchronization with event rosters. Update frontend components to allow team name editing and ensure proper state management. Enhance translations and styles for new features.
This commit is contained in:
@@ -37,6 +37,8 @@ type Store interface {
|
||||
DeleteRSVP(context.Context, string, string) error
|
||||
SaveTeams(context.Context, string, []domain.Team) error
|
||||
ListTeams(context.Context, string) ([]domain.Team, error)
|
||||
GetTeam(context.Context, string) (domain.Team, error)
|
||||
RenameTeam(context.Context, string, string) (domain.Team, error)
|
||||
AssignCaptain(context.Context, string, string) (domain.Team, error)
|
||||
SaveRuleset(context.Context, domain.Ruleset) (domain.Ruleset, error)
|
||||
ListRulesets(context.Context) ([]domain.Ruleset, error)
|
||||
@@ -339,6 +341,34 @@ func (s *Service) AssignCaptain(ctx context.Context, actor domain.Account, teamI
|
||||
return team, err
|
||||
}
|
||||
|
||||
func (s *Service) RenameTeam(ctx context.Context, actor domain.Account, player domain.Player, teamID, name string) (domain.Team, error) {
|
||||
team, err := s.Store.GetTeam(ctx, teamID)
|
||||
if err != nil {
|
||||
return team, err
|
||||
}
|
||||
event, err := s.Store.GetEvent(ctx, team.EventID)
|
||||
if err != nil {
|
||||
return team, err
|
||||
}
|
||||
if event.State != domain.Live {
|
||||
return team, fmt.Errorf("%w: team names can only be changed during a live scrim", domain.ErrConflict)
|
||||
}
|
||||
if !CanActForTeam(actor, player, team) {
|
||||
return team, domain.ErrForbidden
|
||||
}
|
||||
name = strings.TrimSpace(name)
|
||||
if len([]rune(name)) < 2 || len([]rune(name)) > 32 {
|
||||
return team, fmt.Errorf("%w: team name must contain 2 to 32 characters", domain.ErrInvalid)
|
||||
}
|
||||
team, err = s.Store.RenameTeam(ctx, teamID, name)
|
||||
if err == nil {
|
||||
_ = s.Store.AppendAudit(ctx, actor.ID, "team.renamed", teamID, map[string]string{"name": name})
|
||||
s.Bus.Publish("team:"+teamID, team)
|
||||
s.Bus.Publish("event:"+team.EventID, team)
|
||||
}
|
||||
return team, err
|
||||
}
|
||||
|
||||
func CanActForTeam(actor domain.Account, player domain.Player, team domain.Team) bool {
|
||||
return actor.IsStaff() || (team.CaptainPlayerID != "" && team.CaptainPlayerID == player.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user