Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,29 @@ func (t *Team) RemoveRepository(repoID int64) error {
return sess.Commit()
}

func IsUsableTeamName(name string) (err error) {
var reservedTeamNames = []string{"new"}

for i := range reservedTeamNames {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _, reservedName := range reservedTeamNames {
  if reservedName == strings.ToLower(name) {

  }
}

if name == reservedTeamNames[i] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case sensitive?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in the same manner as models/user.go#L504:L508.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macaron isn't (apparently) case insensitive ( test by going to /org/CREATE instead of /org/create )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunny is right, you should always downcase the name.

return ErrNameReserved{name}
}
}

return nil
}

// NewTeam creates a record of new team.
// 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 {
return errors.New("empty team name")
}

if err = IsUsableTeamName(t.Name); err != nil {
return err
}

has, err := x.Id(t.OrgID).Get(new(User))
if err != nil {
return err
Expand Down