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