applied some of the changes from #149

This commit is contained in:
Gani Georgiev 2022-07-18 01:03:09 +03:00
parent 7f959011b8
commit 9a231ba7b3
6 changed files with 15 additions and 17 deletions

View File

@ -77,7 +77,7 @@ func RequireAdminAuth() echo.MiddlewareFunc {
} }
} }
// RequireAdminAuthIfAny middleware requires a request to have // RequireAdminAuthOnlyIfAny middleware requires a request to have
// a valid admin Authorization header set (aka. `Authorization: Admin ...`) // a valid admin Authorization header set (aka. `Authorization: Admin ...`)
// ONLY if the application has at least 1 existing Admin model. // ONLY if the application has at least 1 existing Admin model.
func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc { func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc {

View File

@ -115,9 +115,8 @@ func (dao *Dao) Delete(m models.Model) error {
} }
} }
deleteErr := dao.db.Model(m).Delete() if err := dao.db.Model(m).Delete(); err != nil {
if deleteErr != nil { return err
return deleteErr
} }
if dao.AfterDeleteFunc != nil { if dao.AfterDeleteFunc != nil {
@ -162,8 +161,7 @@ func (dao *Dao) update(m models.Model) error {
return err return err
} }
} else { } else {
err := dao.db.Model(m).Update() if err := dao.db.Model(m).Update(); err != nil {
if err != nil {
return err return err
} }
} }
@ -203,8 +201,7 @@ func (dao *Dao) create(m models.Model) error {
return err return err
} }
} else { } else {
err := dao.db.Model(m).Insert() if err := dao.db.Model(m).Insert(); err != nil {
if err != nil {
return err return err
} }
} }

View File

@ -40,7 +40,7 @@ func (dao *Dao) SaveParam(key string, value any, optEncryptionKey ...string) err
param = &models.Param{Key: key} param = &models.Param{Key: key}
} }
var normalizedValue any normalizedValue := value
// encrypt if optEncryptionKey is set // encrypt if optEncryptionKey is set
if len(optEncryptionKey) > 0 && optEncryptionKey[0] != "" { if len(optEncryptionKey) > 0 && optEncryptionKey[0] != "" {
@ -55,8 +55,6 @@ func (dao *Dao) SaveParam(key string, value any, optEncryptionKey ...string) err
} }
normalizedValue = encryptVal normalizedValue = encryptVal
} else {
normalizedValue = value
} }
encodedValue := types.JsonRaw{} encodedValue := types.JsonRaw{}

View File

@ -153,7 +153,7 @@ func (s *System) DeletePrefix(prefix string) []error {
// (this operation usually is optional and there is no need to strictly check the result) // (this operation usually is optional and there is no need to strictly check the result)
// --- // ---
// fill dirs slice // fill dirs slice
dirs := []string{} dirs := make([]string, 0, len(dirsMap))
for d := range dirsMap { for d := range dirsMap {
dirs = append(dirs, d) dirs = append(dirs, d)
} }

View File

@ -32,15 +32,14 @@ func Sentenize(str string) string {
return "" return ""
} }
s := []rune(str) str = UcFirst(str)
sentence := string(unicode.ToUpper(s[0])) + string(s[1:])
lastChar := string(s[len(s)-1:]) lastChar := str[len(str)-1:]
if lastChar != "." && lastChar != "?" && lastChar != "!" { if lastChar != "." && lastChar != "?" && lastChar != "!" {
return sentence + "." return str + "."
} }
return sentence return str
} }
// Sanitize sanitizes `str` by removing all characters satisfying `removePattern`. // Sanitize sanitizes `str` by removing all characters satisfying `removePattern`.

View File

@ -12,6 +12,7 @@ func TestUcFirst(t *testing.T) {
expected string expected string
}{ }{
{"", ""}, {"", ""},
{" ", " "},
{"Test", "Test"}, {"Test", "Test"},
{"test", "Test"}, {"test", "Test"},
{"test test2", "Test test2"}, {"test test2", "Test test2"},
@ -55,6 +56,9 @@ func TestSentenize(t *testing.T) {
}{ }{
{"", ""}, {"", ""},
{" ", ""}, {" ", ""},
{".", "."},
{"?", "?"},
{"!", "!"},
{"Test", "Test."}, {"Test", "Test."},
{" test ", "Test."}, {" test ", "Test."},
{"hello world", "Hello world."}, {"hello world", "Hello world."},