Adds checking of reserved keywords against team names (#22)

release/v1.15
LefsFlare 2016-11-06 17:07:03 +08:00 committed by Sandro Santilli
parent fe8bfa54de
commit 55a4d46f5d
1 changed files with 17 additions and 1 deletions

View File

@ -194,13 +194,29 @@ func (t *Team) RemoveRepository(repoID int64) error {
return sess.Commit() return sess.Commit()
} }
func IsUsableTeamName(name string) (err error) {
var reservedTeamNames = []string{"new"}
for i := range reservedTeamNames {
if name == reservedTeamNames[i] {
return ErrNameReserved{name}
}
}
return nil
}
// NewTeam creates a record of new team. // NewTeam creates a record of new team.
// It's caller's responsibility to assign organization ID. // It's caller's responsibility to assign organization ID.
func NewTeam(t *Team) error { func NewTeam(t *Team) (err error) {
if len(t.Name) == 0 { if len(t.Name) == 0 {
return errors.New("empty team name") return errors.New("empty team name")
} }
if err = IsUsableTeamName(t.Name); err != nil {
return err
}
has, err := x.Id(t.OrgID).Get(new(User)) has, err := x.Id(t.OrgID).Get(new(User))
if err != nil { if err != nil {
return err return err