From fc8fbbcb983568874a3da0b3bb419ccfb731664f Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 15 Jun 2016 13:31:00 +0800 Subject: [PATCH 1/2] bug fix: modify the implements of checking whether project name is in lower case --- api/project.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/project.go b/api/project.go index 073fcdab0..75ba05342 100644 --- a/api/project.go +++ b/api/project.go @@ -18,6 +18,7 @@ package api import ( "fmt" "net/http" + "strings" "unicode" "github.com/vmware/harbor/dao" @@ -294,10 +295,10 @@ func validateProjectReq(req projectReq) error { if isContainIllegalChar(req.ProjectName, []string{"~", "-", "$", "\\", "[", "]", "{", "}", "(", ")", "&", "^", "%", "*", "<", ">", "\"", "'", "/", "?", "@"}) { return fmt.Errorf("project name contains illegal characters") } - for _, v := range pn { - if !unicode.IsLower(v) { - return fmt.Errorf("project name must be in lower case") - } + + if pn != strings.ToLower(pn) { + return fmt.Errorf("project name must be in lower case") } + return nil } From 836598f5c9551a46afe6587e21c5728a7cd43246 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 15 Jun 2016 13:42:19 +0800 Subject: [PATCH 2/2] remove useless import --- api/project.go | 1 - api/utils.go | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/api/project.go b/api/project.go index 75ba05342..3d57abb02 100644 --- a/api/project.go +++ b/api/project.go @@ -19,7 +19,6 @@ import ( "fmt" "net/http" "strings" - "unicode" "github.com/vmware/harbor/dao" "github.com/vmware/harbor/models" diff --git a/api/utils.go b/api/utils.go index fead92469..e0f5d13cc 100644 --- a/api/utils.go +++ b/api/utils.go @@ -59,11 +59,13 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) { roles := make([]models.Role, 0, 1) isSysAdmin, err := dao.IsAdminRole(userID) if err != nil { + log.Errorf("failed to determine whether the user %d is system admin: %v", userID, err) return roles, err } if isSysAdmin { role, err := dao.GetRoleByID(models.PROJECTADMIN) if err != nil { + log.Errorf("failed to get role %d: %v", models.PROJECTADMIN, err) return roles, err } roles = append(roles, *role) @@ -72,6 +74,7 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) { rs, err := dao.GetUserProjectRoles(userID, projectID) if err != nil { + log.Errorf("failed to get user %d 's roles for project %d: %v", userID, projectID, err) return roles, err } roles = append(roles, rs...)