From 7e9b42c87d2276dec2f1789e1296c2ac51533657 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 11 Aug 2016 11:35:46 -0700 Subject: [PATCH] #2780 code clean up --- .gopmfile | 2 +- cmd/web.go | 2 +- glide.lock | 2 +- models/repo_collaboration.go | 5 ++++- routers/api/v1/repo/collaborators.go | 23 ++++++----------------- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.gopmfile b/.gopmfile index b13868918..2b11213fe 100644 --- a/.gopmfile +++ b/.gopmfile @@ -19,7 +19,7 @@ github.com/go-xorm/xorm = commit:c6c7056 github.com/gogits/chardet = commit:2404f77 github.com/gogits/cron = commit:7f3990a github.com/gogits/git-module = commit:efc90b5 -github.com/gogits/go-gogs-client = commit:d1020b4 +github.com/gogits/go-gogs-client = commit:1fef67c github.com/issue9/identicon = commit:d36b545 github.com/jaytaylor/html2text = commit:52d9b78 github.com/kardianos/minwinsvc = commit:cad6b2b diff --git a/cmd/web.go b/cmd/web.go index 78fadd225..a0b53981c 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -88,7 +88,7 @@ func checkVersion() { {"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, {"github.com/gogits/git-module", git.Version, "0.3.5"}, - {"github.com/gogits/go-gogs-client", gogs.Version, "0.10.3"}, + {"github.com/gogits/go-gogs-client", gogs.Version, "0.10.4"}, } for _, c := range checkers { if !version.Compare(c.Version(), c.Expected, ">=") { diff --git a/glide.lock b/glide.lock index a7561fbc7..d7803f0a1 100644 --- a/glide.lock +++ b/glide.lock @@ -43,7 +43,7 @@ imports: - name: github.com/gogits/git-module version: efc90b5ea1f7b7e404673dcc19674b2a6856e0d3 - name: github.com/gogits/go-gogs-client - version: d1020b4da5474f7533f5b11084dcfd5536cf2e71 + version: 1fef67c1910680405ebb3a2f1aecce35e1575b4d - name: github.com/issue9/identicon version: d36b54562f4cf70c83653e13dc95c220c79ef521 - name: github.com/jaytaylor/html2text diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go index 2a530f875..f4b23f9eb 100644 --- a/models/repo_collaboration.go +++ b/models/repo_collaboration.go @@ -29,7 +29,7 @@ func (c *Collaboration) ModeI18nKey() string { } } -// AddCollaborator adds new collaboration relation between an individual and a repository. +// AddCollaborator adds new collaboration to a repository with default access mode. func (repo *Repository) AddCollaborator(u *User) error { collaboration := &Collaboration{ RepoID: repo.ID, @@ -120,6 +120,9 @@ func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode return nil } + if collaboration.Mode == mode { + return nil + } collaboration.Mode = mode sess := x.NewSession() diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 83c27aece..e14875cbe 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2016 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -13,7 +13,6 @@ import ( func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) { collaborator, err := models.GetUserByName(ctx.Params(":collaborator")) - if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(422, "", err) @@ -28,22 +27,12 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) { return } - mode := models.ACCESS_MODE_WRITE - if form.Permission != nil && *form.Permission == "pull" { - mode = models.ACCESS_MODE_READ - } else if form.Permission != nil && *form.Permission == "push" { - mode = models.ACCESS_MODE_WRITE - } else if form.Permission != nil && *form.Permission == "admin" { - mode = models.ACCESS_MODE_ADMIN - } else if form.Permission != nil { - ctx.Error(500, "Permission", "Invalid permission type") - return - } - if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.Id, mode); err != nil { - ctx.Error(500, "ChangeCollaborationAccessMode", err) - return + if form.Permission != nil { + if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil { + ctx.Error(500, "ChangeCollaborationAccessMode", err) + return + } } ctx.Status(204) - return }