mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
117 lines
4.0 KiB
Ruby
117 lines
4.0 KiB
Ruby
class AdminConstraint
|
||
def self.matches?(request)
|
||
return false unless request.session[:user_id]
|
||
|
||
user = User.find_by(id: request.session[:user_id])
|
||
user&.admin?
|
||
end
|
||
end
|
||
|
||
Rails.application.routes.draw do
|
||
constraints AdminConstraint do
|
||
mount Avo::Engine, at: Avo.configuration.root_path
|
||
mount GoodJob::Engine => "good_job"
|
||
|
||
get "/impersonate/:id", to: "sessions#impersonate", as: :impersonate_user
|
||
end
|
||
get "/stop_impersonating", to: "sessions#stop_impersonating", as: :stop_impersonating
|
||
|
||
if Rails.env.development?
|
||
mount LetterOpenerWeb::Engine, at: "/letter_opener"
|
||
end
|
||
|
||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
||
# Can be used by load balancers and uptime monitors to verify that the app is live.
|
||
get "up" => "rails/health#show", as: :rails_health_check
|
||
|
||
# Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
|
||
# get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
|
||
# get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
|
||
|
||
root "static_pages#index"
|
||
|
||
resources :static_pages, only: [ :index ] do
|
||
collection do
|
||
get :project_durations
|
||
get :activity_graph
|
||
get :currently_hacking
|
||
get :filterable_dashboard_content
|
||
get :filterable_dashboard
|
||
get :my_projects
|
||
get "🃏", to: "static_pages#🃏", as: :wildcard
|
||
get :streak
|
||
end
|
||
end
|
||
|
||
# Auth routes
|
||
get "/auth/slack", to: "sessions#new", as: :slack_auth
|
||
get "/auth/slack/callback", to: "sessions#create"
|
||
get "/auth/github", to: "sessions#github_new", as: :github_auth
|
||
get "/auth/github/callback", to: "sessions#github_create"
|
||
post "/auth/email", to: "sessions#email", as: :email_auth
|
||
post "/auth/email/add", to: "sessions#add_email", as: :add_email_auth
|
||
get "/auth/token/:token", to: "sessions#token", as: :auth_token
|
||
get "/auth/close_window", to: "sessions#close_window", as: :close_window
|
||
delete "signout", to: "sessions#destroy", as: "signout"
|
||
|
||
resources :leaderboards, only: [ :index ]
|
||
|
||
# Nested under users for admin access
|
||
resources :users, only: [] do
|
||
get "settings", on: :member, to: "users#edit"
|
||
end
|
||
|
||
# Namespace for current user actions
|
||
get "my/settings", to: "users#edit", as: :my_settings
|
||
patch "my/settings", to: "users#update"
|
||
post "my/settings/migrate_heartbeats", to: "users#migrate_heartbeats", as: :my_settings_migrate_heartbeats
|
||
|
||
namespace :my do
|
||
resources :project_repo_mappings, param: :project_name, only: [ :edit, :update ]
|
||
end
|
||
|
||
get "my/wakatime_setup", to: "users#wakatime_setup"
|
||
get "my/wakatime_setup/step-2", to: "users#wakatime_setup_step_2"
|
||
get "my/wakatime_setup/step-3", to: "users#wakatime_setup_step_3"
|
||
get "my/wakatime_setup/step-4", to: "users#wakatime_setup_step_4"
|
||
|
||
post "/sailors_log/slack/commands", to: "slack#create"
|
||
post "/timedump/slack/commands", to: "slack#create"
|
||
|
||
# API routes
|
||
namespace :api do
|
||
# This is our own API– don't worry about compatibility.
|
||
namespace :v1 do
|
||
get "stats", to: "stats#show"
|
||
get "users/:username/stats", to: "stats#user_stats"
|
||
get "users/:username/heartbeats/spans", to: "stats#user_spans"
|
||
|
||
# External service Slack OAuth integration
|
||
post "external/slack/oauth", to: "external_slack#create_user"
|
||
|
||
resources :ysws_programs, only: [ :index ] do
|
||
post :claim, on: :collection
|
||
end
|
||
|
||
namespace :my do
|
||
get "heartbeats/most_recent", to: "heartbeats#most_recent"
|
||
get "heartbeats", to: "heartbeats#index"
|
||
end
|
||
end
|
||
|
||
# wakatime compatible summary
|
||
get "summary", to: "summary#index"
|
||
|
||
# Everything in this namespace conforms to wakatime.com's API.
|
||
namespace :hackatime do
|
||
namespace :v1 do
|
||
get "/", to: "hackatime#index" # many clients seem to link this as the user's dashboard
|
||
get "/users/:id/statusbar/today", to: "hackatime#status_bar_today"
|
||
post "/users/:id/heartbeats", to: "hackatime#push_heartbeats"
|
||
end
|
||
end
|
||
end
|
||
|
||
resources :scrapyard_leaderboards, only: [ :index, :show ]
|
||
end
|