This commit is contained in:
Wenkai Yin 2017-06-14 20:23:29 +08:00
parent 6b4ae098db
commit 802a2fbcce
4 changed files with 5 additions and 55 deletions

View File

@ -63,16 +63,6 @@ paths:
description: The name of project owner.
required: false
type: string
- name: member
in: query
description: The name of project member.
required: false
type: string
- name: role
in: query
description: The role of member, only take effect when member is provided.
required: false
type: integer
- name: page
in: query
type: integer

View File

@ -273,7 +273,6 @@ func projectQueryConditions(owner, name string, public *bool, member string,
// 1. all projects
// 2. public projects
// 3. public projects and projects which the user is a member of
// 4. projects which the user is a member of
collection := `project `
if len(base) != 0 && base[0] != nil {
if len(base[0].Member) > 0 {

View File

@ -278,42 +278,17 @@ func (p *ProjectAPI) List() {
query.Public = &pub
}
member := p.GetString("member")
if len(member) > 0 {
query.Member = &models.Member{
Name: member,
}
role := p.GetString("role")
if len(role) > 0 {
r, err := strconv.Atoi(role)
if err != nil {
if err != nil {
p.HandleBadRequest(fmt.Sprintf("invalid role: %s", role))
return
}
}
query.Member.Role = r
}
}
// base project collection from which filter is done
base := &models.BaseProjectCollection{}
if !p.SecurityCtx.IsAuthenticated() {
if query.Member != nil && len(query.Member.Name) > 0 {
// must login if query member
p.HandleUnauthorized()
return
}
// not login, only get public projects
base.Public = true
} else {
if !p.SecurityCtx.IsSysAdmin() {
// login, but not system admin, get public projects and
// projects that the user is member of
base.Member = p.SecurityCtx.GetUsername()
if query.Member != nil && len(query.Member.Name) > 0 {
base.Public = false
} else {
base.Public = true
}
base.Public = true
}
}

View File

@ -113,24 +113,12 @@ func TestListProjects(t *testing.T) {
//find add projectID
addPID = int(result[0].ProjectId)
//----------------------------case 2 : Response Code=401----------------------------//
fmt.Println("case 2: respose code:401")
httpStatusCode, result, err = apiTest.ProjectsGet(
&apilib.ProjectQuery{
Member: admin.Name,
})
t.Logf("$$$$$$$$$$$$$$$$$$$%v", result)
assert.Nil(err)
assert.Equal(int(401), httpStatusCode)
//-------------------case 3 : check admin project role------------------------//
httpStatusCode, result, err = apiTest.ProjectsGet(
&apilib.ProjectQuery{
Name: addProject.ProjectName,
Owner: admin.Name,
Public: true,
Member: admin.Name,
Role: 1,
}, *admin)
if err != nil {
t.Error("Error while search project by proName and isPublic", err.Error())
@ -155,9 +143,7 @@ func TestListProjects(t *testing.T) {
}
httpStatusCode, result, err = apiTest.ProjectsGet(
&apilib.ProjectQuery{
Name: addProject.ProjectName,
Member: TestUserName,
Role: 2,
Name: addProject.ProjectName,
}, *testUser)
if err != nil {
t.Error("Error while search project by proName and isPublic", err.Error())