Skip to content

Commit

Permalink
user group name can not be empty (#5619)
Browse files Browse the repository at this point in the history
Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj(Daojun Zhang) authored and wy65701436 committed Aug 15, 2018
1 parent 2442c43 commit ccc88f8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ui/api/usergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type UserGroupAPI struct {
id int
}

const (
userNameEmptyMsg = "User group name can not be empty!"
)

// Prepare validates the URL and parms
func (uga *UserGroupAPI) Prepare() {
uga.BaseController.Prepare()
Expand Down Expand Up @@ -96,6 +100,11 @@ func (uga *UserGroupAPI) Post() {
userGroup.ID = 0
userGroup.GroupType = common.LdapGroupType
userGroup.LdapGroupDN = strings.TrimSpace(userGroup.LdapGroupDN)
userGroup.GroupName = strings.TrimSpace(userGroup.GroupName)
if len(userGroup.GroupName) == 0 {
uga.HandleBadRequest(userNameEmptyMsg)
return
}
query := models.UserGroup{GroupType: userGroup.GroupType, LdapGroupDN: userGroup.LdapGroupDN}
result, err := group.QueryUserGroup(query)
if err != nil {
Expand Down Expand Up @@ -134,6 +143,11 @@ func (uga *UserGroupAPI) Put() {
userGroup := models.UserGroup{}
uga.DecodeJSONReq(&userGroup)
ID := uga.id
userGroup.GroupName = strings.TrimSpace(userGroup.GroupName)
if len(userGroup.GroupName) == 0 {
uga.HandleBadRequest(userNameEmptyMsg)
return
}
userGroup.GroupType = common.LdapGroupType
log.Debugf("Updated user group %v", userGroup)
err := group.UpdateUserGroupName(ID, userGroup.GroupName)
Expand Down

0 comments on commit ccc88f8

Please sign in to comment.