Browse Source

Fix #857

pull/2674/head
Unknwon 9 years ago
parent
commit
7140dbac95
  1. 2
      cmd/web.go
  2. 1
      conf/locale/locale_en-US.ini
  3. 1085
      modules/bindata/bindata.go
  4. 64
      routers/repo/setting.go
  5. 2
      templates/repo/settings/collaboration.tmpl

2
cmd/web.go

@ -398,7 +398,7 @@ func runWeb(ctx *cli.Context) {
m.Group("/settings", func() { m.Group("/settings", func() {
m.Combo("").Get(repo.Settings). m.Combo("").Get(repo.Settings).
Post(bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost) Post(bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost)
m.Route("/collaboration", "GET,POST", repo.Collaboration) m.Combo("/collaboration").Get(repo.Collaboration).Post(repo.CollaborationPost)
m.Group("/hooks", func() { m.Group("/hooks", func() {
m.Get("", repo.Webhooks) m.Get("", repo.Webhooks)

1
conf/locale/locale_en-US.ini

@ -612,6 +612,7 @@ settings.add_collaborator = Add New Collaborator
settings.add_collaborator_success = New collaborator has been added. settings.add_collaborator_success = New collaborator has been added.
settings.remove_collaborator_success = Collaborator has been removed. settings.remove_collaborator_success = Collaborator has been removed.
settings.search_user_placeholder = Search user... settings.search_user_placeholder = Search user...
settings.org_not_allowed_to_be_collaborator = Organization is not allowed to be added as a collaborator.
settings.user_is_org_member = User is organization member who cannot be added as a collaborator. settings.user_is_org_member = User is organization member who cannot be added as a collaborator.
settings.add_webhook = Add Webhook settings.add_webhook = Add Webhook
settings.hooks_desc = Webhooks are much like basic HTTP POST event triggers. Whenever something occurs in Gogs, we will handle the notification to the target host you specify. Learn more in this <a target="_blank" href="%s">Webhooks Guide</a>. settings.hooks_desc = Webhooks are much like basic HTTP POST event triggers. Whenever something occurs in Gogs, we will handle the notification to the target host you specify. Learn more in this <a target="_blank" href="%s">Webhooks Guide</a>.

1085
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

64
routers/repo/setting.go

@ -233,7 +233,34 @@ func Collaboration(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsCollaboration"] = true ctx.Data["PageIsSettingsCollaboration"] = true
if ctx.Req.Method == "POST" { // Delete collaborator.
remove := strings.ToLower(ctx.Query("remove"))
if len(remove) > 0 && remove != ctx.Repo.Owner.LowerName {
u, err := models.GetUserByName(remove)
if err != nil {
ctx.Handle(500, "GetUserByName", err)
return
}
if err := ctx.Repo.Repository.DeleteCollaborator(u); err != nil {
ctx.Handle(500, "DeleteCollaborator", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
return
}
users, err := ctx.Repo.Repository.GetCollaborators()
if err != nil {
ctx.Handle(500, "GetCollaborators", err)
return
}
ctx.Data["Collaborators"] = users
ctx.HTML(200, COLLABORATION)
}
func CollaborationPost(ctx *middleware.Context) {
name := strings.ToLower(ctx.Query("collaborator")) name := strings.ToLower(ctx.Query("collaborator"))
if len(name) == 0 || ctx.Repo.Owner.LowerName == name { if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
@ -251,6 +278,13 @@ func Collaboration(ctx *middleware.Context) {
return 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. // Check if user is organization member.
if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) { if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) {
ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member")) ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member"))
@ -272,34 +306,6 @@ func Collaboration(ctx *middleware.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success")) ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success"))
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) 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 {
u, err := models.GetUserByName(remove)
if err != nil {
ctx.Handle(500, "GetUserByName", err)
return
}
if err := ctx.Repo.Repository.DeleteCollaborator(u); err != nil {
ctx.Handle(500, "DeleteCollaborator", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
return
}
users, err := ctx.Repo.Repository.GetCollaborators()
if err != nil {
ctx.Handle(500, "GetCollaborators", err)
return
}
ctx.Data["Collaborators"] = users
ctx.HTML(200, COLLABORATION)
} }
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) { func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {

2
templates/repo/settings/collaboration.tmpl

@ -28,7 +28,7 @@
<div class="inline field ui left"> <div class="inline field ui left">
<div id="search-user-box"> <div id="search-user-box">
<div class="ui input"> <div class="ui input">
<input class="prompt" name="collaborator" placeholder="{{.i18n.Tr "repo.settings.search_user_placeholder"}}" autocomplete="off" required> <input class="prompt" name="collaborator" placeholder="{{.i18n.Tr "repo.settings.search_user_placeholder"}}" autocomplete="off" autofocus required>
</div> </div>
<div class="ui segment results hide"></div> <div class="ui segment results hide"></div>
</div> </div>

Loading…
Cancel
Save