tianxiaoliang commented on a change in pull request #1000:
URL:
https://github.com/apache/servicecomb-service-center/pull/1000#discussion_r637345732
##########
File path: server/service/rbac/dao/account_dao.go
##########
@@ -33,6 +33,33 @@ func CreateAccount(ctx context.Context, a
*rbacmodel.Account) error {
return datasource.Instance().CreateAccount(ctx, a)
}
+// UpdateAccount updates an account's info, except the password
+func UpdateAccount(ctx context.Context, name string, a *rbacmodel.Account)
error {
+ // todo params validation
+ exist, err := datasource.Instance().AccountExist(ctx, name)
+ if err != nil {
+ log.Errorf(err, "check account [%s] exit failed", name)
+ return err
+ }
+ if !exist {
+ return datasource.ErrAccountNotExist
+ }
+ oldAccount, err := GetAccount(ctx, name)
+ if err != nil {
+ log.Errorf(err, "get account [%s] failed", name)
+ return err
+ }
+ oldAccount.Roles = a.Roles
+ oldAccount.Status = a.Status
+ err = datasource.Instance().UpdateAccount(ctx, name, oldAccount)
+ if err != nil {
+ log.Errorf(err, "can not edit account info")
+ return err
+ }
+ log.Info("account is edit")
Review comment:
审计日志要打印账号id
##########
File path: server/service/rbac/dao/account_dao.go
##########
@@ -33,6 +33,33 @@ func CreateAccount(ctx context.Context, a
*rbacmodel.Account) error {
return datasource.Instance().CreateAccount(ctx, a)
}
+// UpdateAccount updates an account's info, except the password
+func UpdateAccount(ctx context.Context, name string, a *rbacmodel.Account)
error {
+ // todo params validation
+ exist, err := datasource.Instance().AccountExist(ctx, name)
+ if err != nil {
+ log.Errorf(err, "check account [%s] exit failed", name)
+ return err
+ }
+ if !exist {
+ return datasource.ErrAccountNotExist
+ }
+ oldAccount, err := GetAccount(ctx, name)
+ if err != nil {
+ log.Errorf(err, "get account [%s] failed", name)
+ return err
+ }
+ oldAccount.Roles = a.Roles
Review comment:
因为更新可能涉及到部分更新,得判断下这个字段是否为空,帐号必须带角色,必须具备状态,所以为空就是意味着,客户端并不希望更新这个字段
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]