mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(api): add namespaces, batch ops, and admin logs
This commit is contained in:
@@ -367,48 +367,13 @@ func (h *AdminHandler) DeleteMaster(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var m model.Master
|
||||
if err := h.db.First(&m, uint(idU64)).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "master not found"})
|
||||
return
|
||||
}
|
||||
|
||||
nextEpoch := m.Epoch + 1
|
||||
if nextEpoch <= 0 {
|
||||
nextEpoch = 1
|
||||
}
|
||||
if err := h.db.Model(&m).Updates(map[string]any{
|
||||
"status": "suspended",
|
||||
"epoch": nextEpoch,
|
||||
}).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to revoke master", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := h.db.First(&m, uint(idU64)).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to reload master", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Revoke all child keys too (defense-in-depth; master status already blocks in DP).
|
||||
if err := h.db.Model(&model.Key{}).Where("master_id = ?", m.ID).Update("status", "suspended").Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to revoke child keys", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.syncService.SyncMaster(&m); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to sync master", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
var keys []model.Key
|
||||
if err := h.db.Where("master_id = ?", m.ID).Find(&keys).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to reload keys for sync", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
for i := range keys {
|
||||
if err := h.syncService.SyncKey(&keys[i]); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to sync key", "details": err.Error()})
|
||||
if err := h.revokeMasterByID(uint(idU64)); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "master not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to revoke master", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"status": "revoked"})
|
||||
|
||||
Reference in New Issue
Block a user