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 }