- v2 token format changed
- DisableUser - clear all tokens when disable user - handle ding ding user leave event
This commit is contained in:
@@ -3,12 +3,15 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -111,3 +114,37 @@ func CreateUser(user *model.User) (err error) {
|
||||
user.Status = model.UserStatusNormal
|
||||
return dao.CreateEntity(nil, user)
|
||||
}
|
||||
|
||||
func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if _, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Status": model.UserStatusDisabled,
|
||||
}, userName, map[string]interface{}{
|
||||
"UserID": userID,
|
||||
}); err == nil {
|
||||
auth2.DisableUser(userID, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.CallbackResponse) {
|
||||
eventType := utils.Interface2String(msg[dingdingapi.KeyEventType])
|
||||
if eventType == dingdingapi.CBTagUserLeaveOrg {
|
||||
var (
|
||||
authBind *model.AuthBind
|
||||
err error
|
||||
)
|
||||
db := dao.GetDB()
|
||||
for _, userID := range msg[dingdingapi.KeyUserID].([]interface{}) {
|
||||
userIDStr := utils.Interface2String(userID)
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s left company", userIDStr)
|
||||
if authBind, err = dao.GetAuthBind(db, "", dingding.AuthTypeStaff, userIDStr); err == nil { // 直接找到了
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s, userID:%s left company", userIDStr, authBind.UserID)
|
||||
if err = DisableUser(jxcontext.AdminCtx, authBind.UserID); err != nil {
|
||||
globals.SugarLogger.Errorf("OnDingDingMsg failed with error:%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return api.DingDingAPI.Err2CallbackResponse(nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user