Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds checking of reserved keywords against team names #22

Merged
merged 5 commits into from Nov 6, 2016
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
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
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
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
Member

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
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