mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-28 19:47:58 +01:00
fix bug: can't show the role of member
This commit is contained in:
parent
283792e7c3
commit
419cf8dfc3
@ -54,9 +54,8 @@ func DeleteProjectMember(projectID int64, userID int) error {
|
||||
}
|
||||
|
||||
// GetUserByProject gets all members of the project.
|
||||
func GetUserByProject(projectID int64, queryUser models.User) ([]models.User, error) {
|
||||
func GetUserByProject(projectID int64, queryUser models.User) ([]*models.Member, error) {
|
||||
o := GetOrmer()
|
||||
u := []models.User{}
|
||||
sql := `select u.user_id, u.username, u.creation_time, u.update_time, r.name as rolename,
|
||||
r.role_id as role
|
||||
from user u
|
||||
@ -74,6 +73,9 @@ func GetUserByProject(projectID int64, queryUser models.User) ([]models.User, er
|
||||
queryParam = append(queryParam, "%"+escape(queryUser.Username)+"%")
|
||||
}
|
||||
sql += ` order by u.username `
|
||||
_, err := o.Raw(sql, queryParam).QueryRows(&u)
|
||||
return u, err
|
||||
|
||||
members := []*models.Member{}
|
||||
_, err := o.Raw(sql, queryParam).QueryRows(&members)
|
||||
|
||||
return members, err
|
||||
}
|
||||
|
23
src/common/models/member.go
Normal file
23
src/common/models/member.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package models
|
||||
|
||||
// Member holds the details of a member.
|
||||
type Member struct {
|
||||
ID int `orm:"pk;column(user_id)" json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
Rolename string `json:"role_name"`
|
||||
Role int `json:"role_id"`
|
||||
}
|
@ -73,15 +73,15 @@ func (ps *ProjectSorter) Swap(i, j int) {
|
||||
// List projects which user1 is member of: query := &QueryParam{Member:&Member{Name:"user1"}}
|
||||
// List projects which user1 is the project admin : query := &QueryParam{Memeber:&Member{Name:"user1",Role:1}}
|
||||
type ProjectQueryParam struct {
|
||||
Name string // the name of project
|
||||
Owner string // the username of project owner
|
||||
Public *bool // the project is public or not, can be ture, false and nil
|
||||
Member *Member // the member of project
|
||||
Pagination *Pagination // pagination information
|
||||
Name string // the name of project
|
||||
Owner string // the username of project owner
|
||||
Public *bool // the project is public or not, can be ture, false and nil
|
||||
Member *MemberQuery // the member of project
|
||||
Pagination *Pagination // pagination information
|
||||
}
|
||||
|
||||
// Member fitler by member's username and role
|
||||
type Member struct {
|
||||
// MemberQuery fitler by member's username and role
|
||||
type MemberQuery struct {
|
||||
Name string // the username of member
|
||||
Role int // the role of the member has to the project
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func (s *StatisticAPI) Get() {
|
||||
statistic[TRC] = n
|
||||
} else {
|
||||
projects, err := s.ProjectMgr.GetAll(&models.ProjectQueryParam{
|
||||
Member: &models.Member{
|
||||
Member: &models.MemberQuery{
|
||||
Name: s.username,
|
||||
},
|
||||
})
|
||||
|
@ -116,7 +116,7 @@ func (p *ProjectManager) GetPublic() ([]*models.Project, error) {
|
||||
func (p *ProjectManager) GetByMember(username string) (
|
||||
[]*models.Project, error) {
|
||||
return p.GetAll(&models.ProjectQueryParam{
|
||||
Member: &models.Member{
|
||||
Member: &models.MemberQuery{
|
||||
Name: username,
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user