From b29a41034c48f943adfeab5d8c1f9332bd099bb2 Mon Sep 17 00:00:00 2001 From: wemeya Date: Fri, 27 May 2016 17:54:25 +0800 Subject: [PATCH] modify code according to review --- dao/register.go | 5 ++++- dao/user.go | 4 ++++ docs/swagger.yaml | 22 ++++++++++++++++++++-- ui/router.go | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dao/register.go b/dao/register.go index 0e3c3b140..5f1bfb04c 100644 --- a/dao/register.go +++ b/dao/register.go @@ -25,7 +25,10 @@ import ( // Register is used for user to register, the password is encrypted before the record is inserted into database. func Register(user models.User) (int64, error) { - + //when register from ldap, email may be empty + if user.Email == "" || len(user.Email) == 0 { + user.Email = user.Username + "@vmware.com" + } o := GetOrmer() p, err := o.Raw("insert into user (username, password, realname, email, comment, salt, sysadmin_flag, creation_time, update_time) values (?, ?, ?, ?, ?, ?, ?, ?, ?)").Prepare() if err != nil { diff --git a/dao/user.go b/dao/user.go index 9a4a8a0c1..2be121a96 100644 --- a/dao/user.go +++ b/dao/user.go @@ -232,6 +232,10 @@ func DeleteUser(userID int) error { // ChangeUserProfile ... func ChangeUserProfile(user models.User) error { + //email is null is permitted + if user.Email == "" || len(user.Email) == 0 { + user.Email = user.Username + "@vmware.com" + } o := GetOrmer() if _, err := o.Update(&user, "Email", "Realname", "Comment"); err != nil { log.Errorf("update user failed, error: %v", err) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b0697a667..dbc64a853 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -119,7 +119,7 @@ paths: description: Project name already exists. 500: description: Unexpected internal errors. - /projects/{project_id}/toggle_project_public: + /projects/{project_id}/publicity: post: summary: Update properties for a selected project. description: | @@ -444,6 +444,24 @@ paths: format: int32 required: true description: Registered user ID + - name: email + in: body + type: string + format: string + required: false + description: Email of the user + - name: realname + in: body + type: string + format: string + required: true + description: Realname of the user + - name: comment + in: body + type: string + format: string + required: false + description: Comment of the user tags: - Products responses: @@ -517,7 +535,7 @@ paths: description: Guests can only change their own account. 500: description: Unexpected internal errors. - /users/{user_id}/toggle_user_admin: + /users/{user_id}/sysadmin: post: summary: Update a registered user to change to be an administrator of Harbor. description: | diff --git a/ui/router.go b/ui/router.go index 512932728..c110e22b7 100644 --- a/ui/router.go +++ b/ui/router.go @@ -55,12 +55,12 @@ func initRouters() { beego.Router("/api/projects/:pid/members/?:mid", &api.ProjectMemberAPI{}) beego.Router("/api/projects/", &api.ProjectAPI{}, "get:List") beego.Router("/api/projects/?:id", &api.ProjectAPI{}) - beego.Router("/api/projects/:id/toggle_project_public", &api.ProjectAPI{}, "post:ToggleProjectPublic") + beego.Router("/api/projects/:id/publicity", &api.ProjectAPI{}, "post:ToggleProjectPublic") beego.Router("/api/statistics", &api.StatisticAPI{}) beego.Router("/api/projects/:id/logs/filter", &api.ProjectAPI{}, "post:FilterAccessLog") beego.Router("/api/users/?:id", &api.UserAPI{}) beego.Router("/api/users/:id/password", &api.UserAPI{}, "put:ChangePassword") - beego.Router("/api/users/:id/toggle_user_admin", &api.UserAPI{}, "post:ToggleUserAdminRole") + beego.Router("/api/users/:id/sysadmin", &api.UserAPI{}, "post:ToggleUserAdminRole") beego.Router("/api/repositories", &api.RepositoryAPI{}) beego.Router("/api/repositories/tags", &api.RepositoryAPI{}, "get:GetTags") beego.Router("/api/repositories/manifests", &api.RepositoryAPI{}, "get:GetManifests")