Skip to content

Commit

Permalink
Merge pull request #566 from systemcrash/user_enable_boolean
Browse files Browse the repository at this point in the history
Add new user property: enabled
  • Loading branch information
adubovikov authored Oct 11, 2024
2 parents 8a1f00a + 8f85203 commit 0043176
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions controller/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ func (uc *UserController) LoginUser(c echo.Context) error {
response, _ := json.Marshal(loginObject)
return httpresponse.CreateBadResponseWithJson(&c, http.StatusUnauthorized, response)
}
if !userData.Enabled {
loginObject := model.UserTokenBadResponse{}
loginObject.StatusCode = http.StatusUnauthorized
loginObject.Message = webmessages.Unauthorized
loginObject.Error = webmessages.Unauthorized
response, _ := json.Marshal(loginObject)
return httpresponse.CreateBadResponseWithJson(&c, http.StatusUnauthorized, response)
}

loginObject := model.UserTokenSuccessfulResponse{}
loginObject.Token = token
Expand Down
4 changes: 2 additions & 2 deletions data/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ func (us *UserService) UpdateUser(user *model.TableUser, UserName string, isAdmi
}
if !isAdmin {
err := us.Session.Debug().Table("users").Model(&model.TableUser{}).Where(sqlWhere).Update(model.TableUser{Email: user.Email, FirstName: user.FirstName,
LastName: user.LastName, Department: user.Department, Hash: user.Hash, CreatedAt: user.CreatedAt}).Error
LastName: user.LastName, Department: user.Department, Hash: user.Hash, CreatedAt: user.CreatedAt, Enabled: user.Enabled}).Error
if err != nil {
return err
}
} else {
err := us.Session.Debug().Table("users").Model(&model.TableUser{}).Where(sqlWhere).Update(model.TableUser{UserName: user.UserName,
PartId: user.PartId, Email: user.Email, FirstName: user.FirstName, LastName: user.LastName, Department: user.Department, UserGroup: user.UserGroup,
Hash: user.Hash, CreatedAt: user.CreatedAt}).Error
Hash: user.Hash, CreatedAt: user.CreatedAt, Enabled: user.Enabled}).Error
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type TableUser struct {
Password string `gorm:"-" json:"password"`
// required: true

Enabled bool `gorm:"column:enabled;type:bool;default:true" json:"enabled"`
// required: true

FirstName string `gorm:"column:firstname;type:varchar(50);not null" json:"firstname" validate:"required"`
// required: true
LastName string `gorm:"column:lastname;type:varchar(50);not null" json:"lastname"`
Expand Down
5 changes: 5 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6172,6 +6172,11 @@
"x-go-name": "Partid",
"example": 10
},
"enabled": {
"type": "boolean",
"x-go-name": "Enabled",
"example": true
},
"usergroup": {
"type": "string",
"x-go-name": "Usergroup",
Expand Down

0 comments on commit 0043176

Please sign in to comment.