@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"github.com/acmestack/envcd/internal/core/storage/dao"
25
+ "github.com/acmestack/envcd/internal/pkg/constant"
25
26
"github.com/acmestack/envcd/internal/pkg/entity"
26
27
"github.com/acmestack/envcd/pkg/entity/result"
27
28
"github.com/acmestack/godkits/array"
@@ -49,10 +50,6 @@ const (
49
50
hmacSecret = "9C035514A15F78"
50
51
userIdKey = "userId"
51
52
tokenKey = "accessToken"
52
-
53
- userStateEnabled = "enabled"
54
- userStateDisabled = "disabled"
55
- userStateDeleted = "deleted"
56
53
)
57
54
58
55
type pageUserVO struct {
@@ -187,7 +184,7 @@ func (openapi *Openapi) createUser(ginCtx *gin.Context) {
187
184
Password : password ,
188
185
Salt : salt ,
189
186
Identity : param .Identity ,
190
- State : stringsx .DefaultIfEmpty (param .State , userStateEnabled ),
187
+ State : stringsx .DefaultIfEmpty (param .State , constant . EnabledState ),
191
188
CreatedAt : time .Now (),
192
189
UpdatedAt : time .Now (),
193
190
}
@@ -253,14 +250,34 @@ func (openapi *Openapi) removeUser(ginCtx *gin.Context) {
253
250
}
254
251
// update user state to deleted
255
252
// todo tx and catch error @liuzhaowei
256
- user .State = userStateDeleted
253
+ user .State = constant . DeletedState
257
254
daoAction .UpdateUser (user )
258
255
259
- // update user dictionary state to deleted
260
- daoAction .DeleteDictionaryByUserId (entity.Dictionary {UserId : user .Id })
256
+ // get all the user's dictionary and update state to deleted
257
+ dictParam := entity.Dictionary {UserId : user .Id }
258
+ dictionaries , err := daoAction .SelectDictionary (dictParam , nil )
259
+ if err != nil {
260
+ return result .InternalFailure (err )
261
+ }
262
+ if len (dictionaries ) != 0 {
263
+ for i := range dictionaries {
264
+ dictionaries [i ].State = constant .DeletedState
265
+ }
266
+ daoAction .UpdateDictionaryBatch (dictionaries )
267
+ }
261
268
262
- // update user permission state to deleted
263
- daoAction .DeletePermissionByUserId (entity.Permission {UserId : user .Id })
269
+ // get all the user's scopespace and update state to deleted
270
+ spaceParam := entity.ScopeSpace {UserId : user .Id }
271
+ spaces , err := daoAction .SelectScopeSpace (spaceParam )
272
+ if err != nil {
273
+ return result .InternalFailure (err )
274
+ }
275
+ if len (spaces ) != 0 {
276
+ for i := range spaces {
277
+ spaces [i ].State = constant .DeletedState
278
+ }
279
+ daoAction .UpdateScopeSpaceBatch (spaces )
280
+ }
264
281
265
282
return result .Success (nil )
266
283
})
0 commit comments