-
Notifications
You must be signed in to change notification settings - Fork 111
Add /api/v1/banned_users/counts #907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Comment on lines
+177
to
+190
|
||
|
|
||
| render json: { | ||
| day: day_count, | ||
| week: week_count, | ||
| month: month_count | ||
| } | ||
| end | ||
|
Comment on lines
+170
to
+197
|
||
|
|
||
| def user_projects | ||
| return render json: { error: "User not found" }, status: :not_found unless @user | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint lacks authentication/authorization. Similar stats endpoints in this controller either require authentication via the
ensure_authenticated!before_action (like theshowaction on line 2) or are scoped to specific users. This endpoint exposes aggregate banned user statistics without any access control, which could be sensitive information. Consider adding authentication or moving this endpoint to the admin namespace (Api::Admin::V1) which has built-in admin authentication via AdminApiKey.