diff --git a/app/controllers/api/v1/stats_controller.rb b/app/controllers/api/v1/stats_controller.rb index 4055aca62..6c37c91ec 100644 --- a/app/controllers/api/v1/stats_controller.rb +++ b/app/controllers/api/v1/stats_controller.rb @@ -167,6 +167,35 @@ def trust_factor render json: { trust_level: level, trust_value: User.trust_levels[level] } end + def banned_users_counts + now = Time.current + + day_ago = now - 1.day + week_ago = now - 1.week + month_ago = now - 1.month + + day_count = TrustLevelAuditLog.where(new_trust_level: "red") + .where("created_at >= ?", day_ago) + .distinct + .count(:user_id) + + week_count = TrustLevelAuditLog.where(new_trust_level: "red") + .where("created_at >= ?", week_ago) + .distinct + .count(:user_id) + + month_count = TrustLevelAuditLog.where(new_trust_level: "red") + .where("created_at >= ?", month_ago) + .distinct + .count(:user_id) + + render json: { + day: day_count, + week: week_count, + month: month_count + } + end + def user_projects return render json: { error: "User not found" }, status: :not_found unless @user diff --git a/config/routes.rb b/config/routes.rb index 1b207a01f..d32fc3095 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -182,6 +182,8 @@ def matches?(request) get "users/lookup_email/:email", to: "users#lookup_email", constraints: { email: /[^\/]+/ } get "users/lookup_slack_uid/:slack_uid", to: "users#lookup_slack_uid" + get "banned_users/counts", to: "stats#banned_users_counts" + # External service Slack OAuth integration post "external/slack/oauth", to: "external_slack#create_user"