diff --git a/remote/gitlab/gitlab.go b/remote/gitlab/gitlab.go index 1ae990071..f20ebf2d8 100644 --- a/remote/gitlab/gitlab.go +++ b/remote/gitlab/gitlab.go @@ -198,6 +198,13 @@ func (g *Gitlab) Perm(u *model.User, owner, name string) (*model.Perm, error) { if err != nil { return nil, err } + + // repo owner is granted full access + if repo.Owner != nil && repo.Owner.Username == u.Login { + return &model.Perm{true, true, true}, nil + } + + // check permission for current user m := &model.Perm{} m.Admin = IsAdmin(repo) m.Pull = IsRead(repo) diff --git a/remote/gitlab/gitlab_test.go b/remote/gitlab/gitlab_test.go index 7d8183a60..2e876d88c 100644 --- a/remote/gitlab/gitlab_test.go +++ b/remote/gitlab/gitlab_test.go @@ -54,13 +54,18 @@ func Test_Gitlab(t *testing.T) { g.Describe("Perm", func() { g.It("Should return repo permissions", func() { perm, err := gitlab.Perm(&user, "diaspora", "diaspora-client") - g.Assert(err == nil).IsTrue() g.Assert(perm.Admin).Equal(true) g.Assert(perm.Pull).Equal(true) g.Assert(perm.Push).Equal(true) }) - + g.It("Should return repo permissions when user is admin", func() { + perm, err := gitlab.Perm(&user, "brightbox", "puppet") + g.Assert(err == nil).IsTrue() + g.Assert(perm.Admin).Equal(true) + g.Assert(perm.Pull).Equal(true) + g.Assert(perm.Push).Equal(true) + }) g.It("Should return error, when repo is not exist", func() { _, err := gitlab.Perm(&user, "not-existed", "not-existed") diff --git a/remote/gitlab/testdata/projects.go b/remote/gitlab/testdata/projects.go index 09bec7366..ebe9bd39f 100644 --- a/remote/gitlab/testdata/projects.go +++ b/remote/gitlab/testdata/projects.go @@ -15,6 +15,7 @@ var projectsPayload = []byte(` "owner": { "id": 3, "name": "Diaspora", + "username": "some_user", "created_at": "2013-09-30T13: 46: 02Z" }, "name": "Diaspora Client", @@ -48,8 +49,9 @@ var projectsPayload = []byte(` "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "owner": { - "id": 4, + "id": 1, "name": "Brightbox", + "username": "test_user", "created_at": "2013-09-30T13:46:02Z" }, "name": "Puppet", @@ -89,6 +91,7 @@ var project4Paylod = []byte(` "owner": { "id": 3, "name": "Diaspora", + "username": "some_user", "created_at": "2013-09-30T13: 46: 02Z" }, "name": "Diaspora Client", @@ -135,8 +138,9 @@ var project6Paylod = []byte(` "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "owner": { - "id": 4, + "id": 1, "name": "Brightbox", + "username": "test_user", "created_at": "2013-09-30T13:46:02Z" }, "name": "Puppet", @@ -160,14 +164,8 @@ var project6Paylod = []byte(` }, "archived": false, "permissions": { - "project_access": { - "access_level": 10, - "notification_level": 3 - }, - "group_access": { - "access_level": 50, - "notification_level": 3 - } + "project_access": null, + "group_access": null } } `) diff --git a/remote/gitlab/testdata/testdata.go b/remote/gitlab/testdata/testdata.go index de36846e1..3702c13db 100644 --- a/remote/gitlab/testdata/testdata.go +++ b/remote/gitlab/testdata/testdata.go @@ -21,6 +21,9 @@ func NewServer() *httptest.Server { case "/api/v3/projects/diaspora/diaspora-client": w.Write(project4Paylod) return + case "/api/v3/projects/brightbox/puppet": + w.Write(project6Paylod) + return case "/api/v3/projects/diaspora/diaspora-client/services/drone-ci": switch r.Method { case "PUT": @@ -38,11 +41,7 @@ func NewServer() *httptest.Server { w.Write(accessTokenPayload) return case "/api/v3/user": - if r.Header.Get("Authorization") == "Bearer valid_token" { - w.Write(currentUserPayload) - } else { - w.WriteHeader(401) - } + w.Write(currentUserPayload) return }