MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Delete

Method Delete

service/admin/user.go:210–254  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

208)
209
210func (s *BatchUserService) Delete(c *gin.Context) error {
211 dep := dependency.FromContext(c)
212 userClient := dep.UserClient()
213 fileClient := dep.FileClient()
214
215 current := inventory.UserFromContext(c)
216 ae := serializer.NewAggregateError()
217 for _, id := range s.IDs {
218 if current.ID == id || id == 1 {
219 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeInvalidActionOnDefaultUser, "Cannot delete current user", nil))
220 continue
221 }
222
223 fc, tx, ctx, err := inventory.WithTx(c, fileClient)
224 if err != nil {
225 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err))
226 continue
227 }
228
229 uc, _, ctx, err := inventory.WithTx(ctx, userClient)
230 if err != nil {
231 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err))
232 continue
233 }
234
235 if err := fc.DeleteByUser(ctx, id); err != nil {
236 _ = inventory.Rollback(tx)
237 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to delete user files", err))
238 continue
239 }
240
241 if err := uc.Delete(ctx, id); err != nil {
242 _ = inventory.Rollback(tx)
243 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to delete user", err))
244 continue
245 }
246
247 if err := inventory.Commit(tx); err != nil {
248 ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to commit transaction", err))
249 continue
250 }
251 }
252
253 return ae.Aggregate()
254}

Callers

nothing calls this directly

Calls 13

AddMethod · 0.95
AggregateMethod · 0.95
FromContextFunction · 0.92
UserFromContextFunction · 0.92
NewAggregateErrorFunction · 0.92
NewErrorFunction · 0.92
WithTxFunction · 0.92
RollbackFunction · 0.92
CommitFunction · 0.92
UserClientMethod · 0.65
FileClientMethod · 0.65
DeleteByUserMethod · 0.65

Tested by

no test coverage detected