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

Adds checking of reserved keywords against team names #22

merged 5 commits into from Nov 6, 2016

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2016

This fixes and solves gogit/gogs#3789

@ghost ghost added the type/bug label Nov 3, 2016
@tboerger
Copy link
Member

tboerger commented Nov 3, 2016

LGTM but needs to be rebased

@tboerger tboerger closed this Nov 3, 2016
@tboerger
Copy link
Member

tboerger commented Nov 3, 2016

Please reopen against master.

@tboerger tboerger added invalid and removed type/bug labels Nov 3, 2016
@bkcsoft bkcsoft changed the base branch from develop to master November 4, 2016 04:05
@bkcsoft bkcsoft reopened this Nov 4, 2016
@strk
Copy link
Member

strk commented Nov 4, 2016

Would it make sense for the empty name case to be handled by the IsUsableTeamName directly ?
Also, it looks like the IsUsableTeamName function is a perfect candidate for an automated test, how about adding an models/org_team_test.go ?

@strk
Copy link
Member

strk commented Nov 4, 2016

Full link to original issue: gogs/gogs#3789

@thibaultmeyer
Copy link
Contributor

thibaultmeyer commented Nov 4, 2016

I agree with @strk , if the team name is empty, don't enter on IsUsableTeamName function. If empty, you are sure at 100% it was an invalid team name, no need to check if is forbidden or not.

Maybe forbidden team names could be move to app.ini file (or a special file just for this purpose) or into database to allow users to edit list without recompile project.

var reservedTeamNames = []string{"new"}

for i := range reservedTeamNames {
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.

@tboerger
Copy link
Member

tboerger commented Nov 4, 2016

Maybe forbidden team names could be move to app.ini file (or a special file just for this purpose) or into database to allow users to edit list without recompile project.

This list contains only names that are forbidden to prevent issues with the routes.

// 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 err = IsUsableTeamName(t.Name); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Yes, the others are right, move that below the if len(t.Name) == 0 { check.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion was actually to move the len(t.Name) == 0 check inside IsUsableTeamName (as empty is clearly not a usable team name)

@tboerger tboerger added this to the 1.0.0 milestone Nov 4, 2016
@ghost
Copy link
Author

ghost commented Nov 4, 2016

@tboerger Fixed.

@codecov-io
Copy link

Current coverage is 2.18% (diff: 0.00%)

Merging #22 into master will decrease coverage by <.01%

@@            master       #22   diff @@
========================================
  Files           31        31          
  Lines         7508      7516     +8   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
  Hits           164       164          
- Misses        7327      7335     +8   
  Partials        17        17          

Powered by Codecov. Last update 03902bb...6662e9a

@strk
Copy link
Member

strk commented Nov 5, 2016

LGTM

var reservedTeamNames = []string{"new"}

for i := range reservedTeamNames {
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.

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

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

  }
}

@tboerger
Copy link
Member

tboerger commented Nov 5, 2016

Sorry, but after seeing the comment of @lunny I changed my opinion :D

@strk
Copy link
Member

strk commented Nov 5, 2016

@tboerger changed your mind so you want to Dismiss review ?
@LefsFlarey we still need tests, according to codecov (and it'd be worth a rebase)

@strk
Copy link
Member

strk commented Nov 6, 2016

Assuming everyone is happy with this, merging (since github lets me)

@strk strk merged commit 55a4d46 into go-gitea:master Nov 6, 2016
@tboerger
Copy link
Member

I didn't realized that before, but why have that been merged when there are still requests for changes left? I requested to do always a downcase check...

@ghost ghost deleted the issue/3789 branch November 25, 2016 01:38
@tboerger tboerger added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Nov 29, 2016
@ghost ghost restored the issue/3789 branch December 11, 2016 05:39
lunny referenced this pull request in lunny/gitea Feb 7, 2019
* Don't trim trailing whitespaces for markdown

* Update .drone.yml.sig
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants