Changeset 0.29.0 (#195)
This commit is contained in:
@@ -126,10 +126,7 @@ func (h *AdminHandler) UpdateUserRole(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if user.Role == models.UserRoleAdmin {
|
||||
var adminCount int
|
||||
database.DB.QueryRowContext(c.Request.Context(),
|
||||
database.Q(`SELECT COUNT(*) FROM users WHERE role = $1`),
|
||||
models.UserRoleAdmin).Scan(&adminCount)
|
||||
adminCount, _ := h.stores.Users.CountByRole(c.Request.Context(), models.UserRoleAdmin)
|
||||
if adminCount <= 1 {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "cannot demote the last admin"})
|
||||
return
|
||||
@@ -203,7 +200,7 @@ func (h *AdminHandler) destroyVault(c *gin.Context, userID string) {
|
||||
return
|
||||
}
|
||||
|
||||
deleted := DestroyVaultDB(c.Request.Context(), userID)
|
||||
deleted := DestroyVaultDB(c.Request.Context(), h.stores, userID)
|
||||
|
||||
// Evict from session cache (if user is currently logged in)
|
||||
h.uekCache.Evict(userID)
|
||||
@@ -236,7 +233,7 @@ func (h *AdminHandler) ResetVault(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
deleted := DestroyVaultDB(c.Request.Context(), userID)
|
||||
deleted := DestroyVaultDB(c.Request.Context(), h.stores, userID)
|
||||
h.uekCache.Evict(userID)
|
||||
|
||||
h.auditLog(c, "user.vault_reset", "user", userID, models.JSONMap{
|
||||
@@ -261,10 +258,7 @@ func (h *AdminHandler) DeleteUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if user.Role == models.UserRoleAdmin {
|
||||
var adminCount int
|
||||
database.DB.QueryRowContext(c.Request.Context(),
|
||||
database.Q(`SELECT COUNT(*) FROM users WHERE role = $1`),
|
||||
models.UserRoleAdmin).Scan(&adminCount)
|
||||
adminCount, _ := h.stores.Users.CountByRole(c.Request.Context(), models.UserRoleAdmin)
|
||||
if adminCount <= 1 {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "cannot delete the last admin"})
|
||||
return
|
||||
@@ -769,10 +763,9 @@ func (h *AdminHandler) GetStats(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
stats := gin.H{}
|
||||
|
||||
var userCount, channelCount, messageCount int
|
||||
database.DB.QueryRowContext(ctx, "SELECT COUNT(*) FROM users").Scan(&userCount)
|
||||
database.DB.QueryRowContext(ctx, "SELECT COUNT(*) FROM channels").Scan(&channelCount)
|
||||
database.DB.QueryRowContext(ctx, "SELECT COUNT(*) FROM messages").Scan(&messageCount)
|
||||
userCount, _ := h.stores.Users.CountAll(ctx)
|
||||
channelCount, _ := h.stores.Channels.CountAll(ctx)
|
||||
messageCount, _ := h.stores.Messages.CountAll(ctx)
|
||||
|
||||
stats["users"] = userCount
|
||||
stats["channels"] = channelCount
|
||||
|
||||
Reference in New Issue
Block a user