summaryrefslogtreecommitdiffstats
path: root/routers/repo/setting.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-20 15:10:34 -0500
committerUnknwon <u@gogs.io>2016-02-20 15:10:34 -0500
commit7140dbac95a96849a7f82166439fd72a7b56f9bf (patch)
treea3ca327c473d9e3ed7664c2597f513acf0e56ab3 /routers/repo/setting.go
parentacf094fb0734a1c046a2d68583f95647444a799c (diff)
downloadgitea-7140dbac95a96849a7f82166439fd72a7b56f9bf.tar.gz
gitea-7140dbac95a96849a7f82166439fd72a7b56f9bf.zip
Fix #857
Diffstat (limited to 'routers/repo/setting.go')
-rw-r--r--routers/repo/setting.go90
1 files changed, 48 insertions, 42 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index ac3f534bbc..5f268f3bfb 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -233,48 +233,6 @@ func Collaboration(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsCollaboration"] = true
- if ctx.Req.Method == "POST" {
- name := strings.ToLower(ctx.Query("collaborator"))
- if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
- ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
- return
- }
-
- u, err := models.GetUserByName(name)
- if err != nil {
- if models.IsErrUserNotExist(err) {
- ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
- ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
- } else {
- ctx.Handle(500, "GetUserByName", err)
- }
- return
- }
-
- // Check if user is organization member.
- if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) {
- ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member"))
- ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
- return
- }
-
- if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
- ctx.Handle(500, "AddCollaborator", err)
- return
- }
-
- if setting.Service.EnableNotifyMail {
- if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
- ctx.Handle(500, "SendCollaboratorMail", err)
- return
- }
- }
-
- ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success"))
- ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
- return
- }
-
// Delete collaborator.
remove := strings.ToLower(ctx.Query("remove"))
if len(remove) > 0 && remove != ctx.Repo.Owner.LowerName {
@@ -302,6 +260,54 @@ func Collaboration(ctx *middleware.Context) {
ctx.HTML(200, COLLABORATION)
}
+func CollaborationPost(ctx *middleware.Context) {
+ name := strings.ToLower(ctx.Query("collaborator"))
+ if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
+ ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
+ return
+ }
+
+ u, err := models.GetUserByName(name)
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
+ ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
+ } else {
+ ctx.Handle(500, "GetUserByName", err)
+ }
+ return
+ }
+
+ // Organization is not allowed to be added as a collaborator.
+ if u.IsOrganization() {
+ ctx.Flash.Error(ctx.Tr("repo.settings.org_not_allowed_to_be_collaborator"))
+ ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
+ return
+ }
+
+ // Check if user is organization member.
+ if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) {
+ ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member"))
+ ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
+ return
+ }
+
+ if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
+ ctx.Handle(500, "AddCollaborator", err)
+ return
+ }
+
+ if setting.Service.EnableNotifyMail {
+ if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
+ ctx.Handle(500, "SendCollaboratorMail", err)
+ return
+ }
+ }
+
+ ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success"))
+ ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
+}
+
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {
owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil {