fix exist check

This commit is contained in:
Adrian Zürcher
2025-11-07 08:06:54 +01:00
parent 1f60813589
commit 0c37d014a9
5 changed files with 16 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ func (aH *AccessHandler) AddDefaultRole() (err error) {
role := "admin"
// Check if a role with this name already exists
if err := aH.dbHandler.Exists(&models.Role{}, "role", role, false); err == nil {
if aH.dbHandler.Exists(&models.Role{}, "role", role, false) {
// Found a role → skip creation
aH.logger.Debug("AddDefaultRole", "role "+role+" exists already")
return nil
@@ -52,7 +52,7 @@ func (aH *AccessHandler) AddRole(c *gin.Context) {
}
// Check if a role with this name already exists
if err := aH.dbHandler.Exists(&models.Role{}, "role", role.Role, false); err == nil {
if aH.dbHandler.Exists(&models.Role{}, "role", role.Role, false) {
aH.logger.Error("AddRole", fmt.Sprintf("role with name %s already exists", role.Role))
c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse(fmt.Sprintf("role with name %s already exists", role.Role)))
}