Skip to content

Allow adding collaborators with (fullname) #3103

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

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func Collaboration(ctx *context.Context) {
// CollaborationPost response for actions for a collaboration of a repository
func CollaborationPost(ctx *context.Context) {
name := strings.ToLower(ctx.Query("collaborator"))
// name may be formatted as "username (fullname)"
if strings.Contains(name, "(") && strings.HasSuffix(name, ")") {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can simplify to

if index := strings.Index(name, " ("); index >= 0 {
	name = name[:index]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just cut-n-pasted @lunny's fix. I agree with you on this. Where can I put a utility method and then refactor all of the usages? Sorry new to Gitea, so want to make sure I'm following your guys' best practices... Thanks

Copy link
Member

Choose a reason for hiding this comment

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

I think adding a routers/utils/utils.go file and putting it there makes the most sense. This proposed function seems specific to route handlers, so I'd prefer to not add it to modules/util.

name = strings.TrimSpace(strings.Split(name, "(")[0])
}
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path)
return
Expand Down