From cf7d098a5f9f8d42a060b3c4d49661a96eab7dfe Mon Sep 17 00:00:00 2001 From: loveuer Date: Fri, 8 Nov 2024 09:57:48 +0800 Subject: [PATCH] wip --- rbac/create.go | 13 +++++++++++++ rbac/rbac.go | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/rbac/create.go b/rbac/create.go index b09b63d..aec5860 100644 --- a/rbac/create.go +++ b/rbac/create.go @@ -94,3 +94,16 @@ func (u *Urbac) newPrivilege(ctx context.Context, code, label string, parent str return p, nil } + +func (u *Urbac) newUser(target *model.User) (*model.User, error) { + result := u.store.Session().Create(target) + if result.Error != nil { + return nil, result.Error + } + + if result.RowsAffected != 1 { + return nil, fmt.Errorf("invalid rows affected") + } + + return target, nil +} diff --git a/rbac/rbac.go b/rbac/rbac.go index 21dc01a..de20844 100644 --- a/rbac/rbac.go +++ b/rbac/rbac.go @@ -66,10 +66,10 @@ func New(opts ...Option) (*Urbac, error) { Password: tool.NewPassword("123456"), Status: model.StatusActive, Nickname: "管理员", - RoleNames: []string{"admin"}, + RoleNames: []string{rootRole.Code}, } - u.newUser() + _, err = u.newUser(rootUser) - return u, nil + return u, err }