mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 10:40:25 +08:00
用户状态发生变化时,同步服务状态
This commit is contained in:
@@ -918,6 +918,7 @@ func (this *ServerDAO) FindAllEnabledServersWithNode(tx *dbs.Tx, nodeId int64) (
|
|||||||
for _, clusterId := range clusterIds {
|
for _, clusterId := range clusterIds {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
Attr("clusterId", clusterId).
|
Attr("clusterId", clusterId).
|
||||||
|
Where("(userId=0 OR userId IN (SELECT id FROM " + SharedUserDAO.Table + " WHERE isOn AND state=1))").
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
AscPk().
|
AscPk().
|
||||||
FindAll()
|
FindAll()
|
||||||
@@ -2526,6 +2527,28 @@ func (this *ServerDAO) FindServerUAM(tx *dbs.Tx, serverId int64) ([]byte, error)
|
|||||||
FindJSONCol()
|
FindJSONCol()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindUserServerClusterIds 获取用户相关服务的集群ID组合
|
||||||
|
func (this *ServerDAO) FindUserServerClusterIds(tx *dbs.Tx, userId int64) ([]int64, error) {
|
||||||
|
if userId <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
ones, err := this.Query(tx).
|
||||||
|
State(ServerStateEnabled).
|
||||||
|
Attr("userId", userId).
|
||||||
|
Gt("clusterId", 0).
|
||||||
|
Result("DISTINCT(clusterId) AS clusterId").
|
||||||
|
FindAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var clusterIds = []int64{}
|
||||||
|
for _, one := range ones {
|
||||||
|
clusterIds = append(clusterIds, int64(one.(*Server).ClusterId))
|
||||||
|
}
|
||||||
|
return clusterIds, nil
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyUpdate 同步服务所在的集群
|
// NotifyUpdate 同步服务所在的集群
|
||||||
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
||||||
// 创建任务
|
// 创建任务
|
||||||
@@ -2608,3 +2631,23 @@ func (this *ServerDAO) NotifyDisable(tx *dbs.Tx, serverId int64) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifyUserClustersChange 通知用户相关集群更新
|
||||||
|
func (this *ServerDAO) NotifyUserClustersChange(tx *dbs.Tx, userId int64) error {
|
||||||
|
if userId <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterIds, err := this.FindUserServerClusterIds(tx, userId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, clusterId := range clusterIds {
|
||||||
|
err = SharedNodeClusterDAO.NotifyUpdate(tx, clusterId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,19 +42,29 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EnableUser 启用条目
|
// EnableUser 启用条目
|
||||||
func (this *UserDAO) EnableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
func (this *UserDAO) EnableUser(tx *dbs.Tx, userId int64) error {
|
||||||
return this.Query(tx).
|
if userId <= 0 {
|
||||||
Pk(id).
|
return errors.New("invalid 'userId'")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(userId).
|
||||||
Set("state", UserStateEnabled).
|
Set("state", UserStateEnabled).
|
||||||
Update()
|
Update()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableUser 禁用条目
|
// DisableUser 禁用条目
|
||||||
func (this *UserDAO) DisableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
func (this *UserDAO) DisableUser(tx *dbs.Tx, userId int64) error {
|
||||||
return this.Query(tx).
|
if userId <= 0 {
|
||||||
Pk(id).
|
return errors.New("invalid 'userId'")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(userId).
|
||||||
Set("state", UserStateDisabled).
|
Set("state", UserStateDisabled).
|
||||||
Update()
|
Update()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindEnabledUser 查找启用的用户
|
// FindEnabledUser 查找启用的用户
|
||||||
@@ -178,6 +188,16 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
|
|||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
return errors.New("invalid userId")
|
return errors.New("invalid userId")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否启用变化
|
||||||
|
oldIsOn, err := this.Query(tx).
|
||||||
|
Pk(userId).
|
||||||
|
Result("isOn").
|
||||||
|
FindBoolCol()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var op = NewUserOperator()
|
var op = NewUserOperator()
|
||||||
op.Id = userId
|
op.Id = userId
|
||||||
op.Username = username
|
op.Username = username
|
||||||
@@ -191,10 +211,18 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
|
|||||||
op.Remark = remark
|
op.Remark = remark
|
||||||
op.ClusterId = nodeClusterId
|
op.ClusterId = nodeClusterId
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
err := this.Save(tx, op)
|
err = this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if oldIsOn != isOn {
|
||||||
|
return SharedServerDAO.NotifyUserClustersChange(tx, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateUserInfo 修改用户基本信息
|
// UpdateUserInfo 修改用户基本信息
|
||||||
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string, mobile string, email string) error {
|
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string, mobile string, email string) error {
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ func (this *UserService) DeleteUser(ctx context.Context, req *pb.DeleteUserReque
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = models.SharedUserDAO.DisableUser(tx, req.UserId)
|
err = models.SharedUserDAO.DisableUser(tx, req.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user