-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
866 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2024 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package admin | ||
|
||
import ( | ||
"github.com/issue9/web" | ||
|
||
"github.com/issue9/cmfx/cmfx/user" | ||
"github.com/issue9/cmfx/locales" | ||
) | ||
|
||
type Config struct { | ||
// SuperUser 超级用户的 ID | ||
SuperUser int64 `json:"superUser" xml:"superUser,attr" yaml:"superUser"` | ||
|
||
// User 用户相关的配置 | ||
User *user.Config `json:"user" xml:"user" yaml:"user"` | ||
} | ||
|
||
func (c *Config) SanitizeConfig() *web.FieldError { | ||
if c.SuperUser <= 0 { | ||
return web.NewFieldError("superUser", locales.MustBeGreaterThan(0)) | ||
} | ||
|
||
if err := c.User.SanitizeConfig(); err != nil { | ||
return err.AddFieldParent("user") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-FileCopyrightText: 2024 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package admin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/issue9/assert/v4" | ||
"github.com/issue9/config" | ||
) | ||
|
||
var _ config.Sanitizer = &Config{} | ||
|
||
func TestConfig_SanitizeConfig(t *testing.T) { | ||
a := assert.New(t, false) | ||
|
||
conf := &Config{} | ||
err := conf.SanitizeConfig() | ||
a.Equal(err.Field, "superUser") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.