Merge pull request #1401 from skygeo/master

fix: gitlab owner has admin privileges
This commit is contained in:
Brad Rydzewski 2016-01-12 10:49:10 -08:00
commit 8de3184009
4 changed files with 26 additions and 17 deletions

View file

@ -198,6 +198,13 @@ func (g *Gitlab) Perm(u *model.User, owner, name string) (*model.Perm, error) {
if err != nil { if err != nil {
return nil, err 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 := &model.Perm{}
m.Admin = IsAdmin(repo) m.Admin = IsAdmin(repo)
m.Pull = IsRead(repo) m.Pull = IsRead(repo)

View file

@ -54,13 +54,18 @@ func Test_Gitlab(t *testing.T) {
g.Describe("Perm", func() { g.Describe("Perm", func() {
g.It("Should return repo permissions", func() { g.It("Should return repo permissions", func() {
perm, err := gitlab.Perm(&user, "diaspora", "diaspora-client") perm, err := gitlab.Perm(&user, "diaspora", "diaspora-client")
g.Assert(err == nil).IsTrue() g.Assert(err == nil).IsTrue()
g.Assert(perm.Admin).Equal(true) g.Assert(perm.Admin).Equal(true)
g.Assert(perm.Pull).Equal(true) g.Assert(perm.Pull).Equal(true)
g.Assert(perm.Push).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() { g.It("Should return error, when repo is not exist", func() {
_, err := gitlab.Perm(&user, "not-existed", "not-existed") _, err := gitlab.Perm(&user, "not-existed", "not-existed")

View file

@ -15,6 +15,7 @@ var projectsPayload = []byte(`
"owner": { "owner": {
"id": 3, "id": 3,
"name": "Diaspora", "name": "Diaspora",
"username": "some_user",
"created_at": "2013-09-30T13: 46: 02Z" "created_at": "2013-09-30T13: 46: 02Z"
}, },
"name": "Diaspora Client", "name": "Diaspora Client",
@ -48,8 +49,9 @@ var projectsPayload = []byte(`
"http_url_to_repo": "http://example.com/brightbox/puppet.git", "http_url_to_repo": "http://example.com/brightbox/puppet.git",
"web_url": "http://example.com/brightbox/puppet", "web_url": "http://example.com/brightbox/puppet",
"owner": { "owner": {
"id": 4, "id": 1,
"name": "Brightbox", "name": "Brightbox",
"username": "test_user",
"created_at": "2013-09-30T13:46:02Z" "created_at": "2013-09-30T13:46:02Z"
}, },
"name": "Puppet", "name": "Puppet",
@ -89,6 +91,7 @@ var project4Paylod = []byte(`
"owner": { "owner": {
"id": 3, "id": 3,
"name": "Diaspora", "name": "Diaspora",
"username": "some_user",
"created_at": "2013-09-30T13: 46: 02Z" "created_at": "2013-09-30T13: 46: 02Z"
}, },
"name": "Diaspora Client", "name": "Diaspora Client",
@ -135,8 +138,9 @@ var project6Paylod = []byte(`
"http_url_to_repo": "http://example.com/brightbox/puppet.git", "http_url_to_repo": "http://example.com/brightbox/puppet.git",
"web_url": "http://example.com/brightbox/puppet", "web_url": "http://example.com/brightbox/puppet",
"owner": { "owner": {
"id": 4, "id": 1,
"name": "Brightbox", "name": "Brightbox",
"username": "test_user",
"created_at": "2013-09-30T13:46:02Z" "created_at": "2013-09-30T13:46:02Z"
}, },
"name": "Puppet", "name": "Puppet",
@ -160,14 +164,8 @@ var project6Paylod = []byte(`
}, },
"archived": false, "archived": false,
"permissions": { "permissions": {
"project_access": { "project_access": null,
"access_level": 10, "group_access": null
"notification_level": 3
},
"group_access": {
"access_level": 50,
"notification_level": 3
}
} }
} }
`) `)

View file

@ -21,6 +21,9 @@ func NewServer() *httptest.Server {
case "/api/v3/projects/diaspora/diaspora-client": case "/api/v3/projects/diaspora/diaspora-client":
w.Write(project4Paylod) w.Write(project4Paylod)
return return
case "/api/v3/projects/brightbox/puppet":
w.Write(project6Paylod)
return
case "/api/v3/projects/diaspora/diaspora-client/services/drone-ci": case "/api/v3/projects/diaspora/diaspora-client/services/drone-ci":
switch r.Method { switch r.Method {
case "PUT": case "PUT":
@ -38,11 +41,7 @@ func NewServer() *httptest.Server {
w.Write(accessTokenPayload) w.Write(accessTokenPayload)
return return
case "/api/v3/user": case "/api/v3/user":
if r.Header.Get("Authorization") == "Bearer valid_token" {
w.Write(currentUserPayload) w.Write(currentUserPayload)
} else {
w.WriteHeader(401)
}
return return
} }