mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
report trust factor on api endpoints
This commit is contained in:
@@ -5,7 +5,11 @@ module Api
|
||||
def index
|
||||
render json: {
|
||||
emails: current_user.email_addresses&.map(&:email)|| [],
|
||||
slack_id: current_user.slack_uid
|
||||
slack_id: current_user.slack_uid,
|
||||
trust_factor: {
|
||||
trust_level: current_user.trust_level,
|
||||
trust_value: User.trust_levels[current_user.trust_level]
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Api::V1::StatsController < ApplicationController
|
||||
before_action :ensure_authenticated!, only: [ :show ], unless: -> { Rails.env.development? }
|
||||
before_action :set_user, only: [ :user_stats, :user_spans ]
|
||||
before_action :set_user, only: [ :user_stats, :user_spans, :trust_factor ]
|
||||
|
||||
def show
|
||||
# take either user_id with a start date & end date
|
||||
@@ -53,7 +53,16 @@ class Api::V1::StatsController < ApplicationController
|
||||
end_date: end_date
|
||||
).generate_summary
|
||||
|
||||
render json: { data: summary }
|
||||
# Include trust factor information
|
||||
trust_info = {
|
||||
trust_level: @user.trust_level,
|
||||
trust_value: User.trust_levels[@user.trust_level]
|
||||
}
|
||||
|
||||
render json: {
|
||||
data: summary,
|
||||
trust_factor: trust_info
|
||||
}
|
||||
end
|
||||
|
||||
def user_spans
|
||||
@@ -76,6 +85,15 @@ class Api::V1::StatsController < ApplicationController
|
||||
render json: { spans: heartbeats.to_span }
|
||||
end
|
||||
|
||||
def trust_factor
|
||||
return render json: { error: "User not found" }, status: :not_found unless @user
|
||||
|
||||
render json: {
|
||||
trust_level: @user.trust_level,
|
||||
trust_value: User.trust_levels[@user.trust_level]
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_user
|
||||
|
||||
@@ -118,6 +118,7 @@ Rails.application.routes.draw do
|
||||
get "stats", to: "stats#show"
|
||||
get "users/:username/stats", to: "stats#user_stats"
|
||||
get "users/:username/heartbeats/spans", to: "stats#user_spans"
|
||||
get "users/:username/trust_factor", to: "stats#trust_factor"
|
||||
|
||||
get "users/lookup_email/:email", to: "users#lookup_email", constraints: { email: /[^\/]+/ }
|
||||
get "users/lookup_slack_uid/:slack_uid", to: "users#lookup_slack_uid"
|
||||
|
||||
@@ -94,6 +94,29 @@ GET /api/v1/users/lookup_slack_uid/{slack_uid}
|
||||
|
||||
Find users by their email or Slack ID.
|
||||
|
||||
### User Trust Factor
|
||||
|
||||
```bash
|
||||
GET /api/v1/users/{username}/trust_factor
|
||||
```
|
||||
|
||||
Get a user's trust factor.
|
||||
|
||||
**What you get back**:
|
||||
|
||||
```json
|
||||
{
|
||||
"trust_level": "yellow",
|
||||
"trust_value": 0
|
||||
}
|
||||
```
|
||||
|
||||
Trust levels can be:
|
||||
|
||||
- `yellow` (0): unscored
|
||||
- `red` (1): convicted/untrusted
|
||||
- `green` (2): trusted
|
||||
|
||||
## Try These Examples
|
||||
|
||||
### See Your Recent Activity
|
||||
|
||||
Reference in New Issue
Block a user