fix bug: can't show the role of member

This commit is contained in:
Wenkai Yin 2017-06-22 17:22:58 +08:00
parent 283792e7c3
commit 419cf8dfc3
5 changed files with 38 additions and 13 deletions

View File

@ -54,9 +54,8 @@ func DeleteProjectMember(projectID int64, userID int) error {
} }
// GetUserByProject gets all members of the project. // 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() o := GetOrmer()
u := []models.User{}
sql := `select u.user_id, u.username, u.creation_time, u.update_time, r.name as rolename, sql := `select u.user_id, u.username, u.creation_time, u.update_time, r.name as rolename,
r.role_id as role r.role_id as role
from user u from user u
@ -74,6 +73,9 @@ func GetUserByProject(projectID int64, queryUser models.User) ([]models.User, er
queryParam = append(queryParam, "%"+escape(queryUser.Username)+"%") queryParam = append(queryParam, "%"+escape(queryUser.Username)+"%")
} }
sql += ` order by u.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
} }

View 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"`
}

View File

@ -76,12 +76,12 @@ type ProjectQueryParam struct {
Name string // the name of project Name string // the name of project
Owner string // the username of project owner Owner string // the username of project owner
Public *bool // the project is public or not, can be ture, false and nil Public *bool // the project is public or not, can be ture, false and nil
Member *Member // the member of project Member *MemberQuery // the member of project
Pagination *Pagination // pagination information Pagination *Pagination // pagination information
} }
// Member fitler by member's username and role // MemberQuery fitler by member's username and role
type Member struct { type MemberQuery struct {
Name string // the username of member Name string // the username of member
Role int // the role of the member has to the project Role int // the role of the member has to the project
} }

View File

@ -95,7 +95,7 @@ func (s *StatisticAPI) Get() {
statistic[TRC] = n statistic[TRC] = n
} else { } else {
projects, err := s.ProjectMgr.GetAll(&models.ProjectQueryParam{ projects, err := s.ProjectMgr.GetAll(&models.ProjectQueryParam{
Member: &models.Member{ Member: &models.MemberQuery{
Name: s.username, Name: s.username,
}, },
}) })

View File

@ -116,7 +116,7 @@ func (p *ProjectManager) GetPublic() ([]*models.Project, error) {
func (p *ProjectManager) GetByMember(username string) ( func (p *ProjectManager) GetByMember(username string) (
[]*models.Project, error) { []*models.Project, error) {
return p.GetAll(&models.ProjectQueryParam{ return p.GetAll(&models.ProjectQueryParam{
Member: &models.Member{ Member: &models.MemberQuery{
Name: username, Name: username,
}, },
}) })