Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new user property: enabled #566

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading