mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 17:47:46 +01:00
Merge pull request #345 from ywk253100/sync_image
bug fix: modify the implements of checking whether project name is in lower case
This commit is contained in:
commit
805c85fabb
@ -18,7 +18,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"unicode"
|
"strings"
|
||||||
|
|
||||||
"github.com/vmware/harbor/dao"
|
"github.com/vmware/harbor/dao"
|
||||||
"github.com/vmware/harbor/models"
|
"github.com/vmware/harbor/models"
|
||||||
@ -294,10 +294,10 @@ func validateProjectReq(req projectReq) error {
|
|||||||
if isContainIllegalChar(req.ProjectName, []string{"~", "-", "$", "\\", "[", "]", "{", "}", "(", ")", "&", "^", "%", "*", "<", ">", "\"", "'", "/", "?", "@"}) {
|
if isContainIllegalChar(req.ProjectName, []string{"~", "-", "$", "\\", "[", "]", "{", "}", "(", ")", "&", "^", "%", "*", "<", ">", "\"", "'", "/", "?", "@"}) {
|
||||||
return fmt.Errorf("project name contains illegal characters")
|
return fmt.Errorf("project name contains illegal characters")
|
||||||
}
|
}
|
||||||
for _, v := range pn {
|
|
||||||
if !unicode.IsLower(v) {
|
if pn != strings.ToLower(pn) {
|
||||||
return fmt.Errorf("project name must be in lower case")
|
return fmt.Errorf("project name must be in lower case")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,13 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) {
|
|||||||
roles := make([]models.Role, 0, 1)
|
roles := make([]models.Role, 0, 1)
|
||||||
isSysAdmin, err := dao.IsAdminRole(userID)
|
isSysAdmin, err := dao.IsAdminRole(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to determine whether the user %d is system admin: %v", userID, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
if isSysAdmin {
|
if isSysAdmin {
|
||||||
role, err := dao.GetRoleByID(models.PROJECTADMIN)
|
role, err := dao.GetRoleByID(models.PROJECTADMIN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to get role %d: %v", models.PROJECTADMIN, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
roles = append(roles, *role)
|
roles = append(roles, *role)
|
||||||
@ -72,6 +74,7 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) {
|
|||||||
|
|
||||||
rs, err := dao.GetUserProjectRoles(userID, projectID)
|
rs, err := dao.GetUserProjectRoles(userID, projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to get user %d 's roles for project %d: %v", userID, projectID, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
roles = append(roles, rs...)
|
roles = append(roles, rs...)
|
||||||
|
Loading…
Reference in New Issue
Block a user