2014-12-12 09:35:14 -08:00
require 'sidekiq/web'
2014-08-01 02:23:47 -07:00
Rails . application . routes . draw do
2017-03-31 13:38:23 -07:00
start = Time . now
2014-12-04 22:02:23 -08:00
2022-07-03 14:50:17 -07:00
# Routes only accessible by admins (admin panels, sidekiq, pghero)
authenticate :user , - > ( user ) { user . has_role? ( :administrator ) } do
2020-04-19 13:35:58 -07:00
# Admin panel
mount RailsAdmin :: Engine = > " /justask_admin " , as : " rails_admin "
2014-12-12 09:35:14 -08:00
mount Sidekiq :: Web , at : " /sidekiq "
2020-04-19 13:35:58 -07:00
mount PgHero :: Engine , at : " /pghero " , as : " pghero "
2020-04-19 14:58:47 -07:00
match " /admin/announcements " , to : " announcement # index " , via : :get , as : :announcement_index
match " /admin/announcements " , to : " announcement # create " , via : :post , as : :announcement_create
match " /admin/announcements/new " , to : " announcement # new " , via : :get , as : :announcement_new
match " /admin/announcements/:id/edit " , to : " announcement # edit " , via : :get , as : :announcement_edit
match " /admin/announcements/:id " , to : " announcement # update " , via : :patch , as : :announcement_update
match " /admin/announcements/:id " , to : " announcement # destroy " , via : :delete , as : :announcement_destroy
2014-12-12 09:35:14 -08:00
end
2022-07-03 14:50:17 -07:00
# Routes only accessible by moderators (moderation panel)
authenticate :user , - > ( user ) { user . mod? } do
2022-06-23 14:35:33 -07:00
match '/moderation/unmask' , to : 'moderation#toggle_unmask' , via : :post , as : :moderation_toggle_unmask
2014-12-28 16:25:48 -08:00
match '/moderation(/:type)' , to : 'moderation#index' , via : :get , as : :moderation , defaults : { type : 'all' }
2022-06-19 15:59:47 -07:00
match '/moderation/inbox/:user' , to : 'moderation/inbox#index' , via : :get , as : :mod_inbox_index
2014-12-28 14:26:16 -08:00
namespace :ajax do
2014-12-28 15:21:06 -08:00
match '/mod/destroy_report' , to : 'moderation#destroy_report' , via : :post , as : :mod_destroy_report
2015-02-03 08:48:30 -08:00
match '/mod/privilege' , to : 'moderation#privilege' , via : :post , as : :mod_privilege
2015-04-22 17:56:29 -07:00
match '/mod/ban' , to : 'moderation#ban' , via : :post , as : :mod_ban
2014-12-28 14:26:16 -08:00
end
2014-12-26 04:46:47 -08:00
end
2022-07-18 07:26:11 -07:00
unauthenticated :user do
root to : 'about#index'
end
authenticate :user do
root to : 'timeline#index' , as : :timeline
end
2014-08-01 02:23:47 -07:00
2022-07-18 07:51:03 -07:00
match '/about' , to : 'about#about' , via : 'get'
match '/privacy' , to : 'about#privacy_policy' , via : 'get' , as : :privacy_policy
match '/terms' , to : 'about#terms' , via : 'get' , as : :terms
2022-07-18 13:00:21 -07:00
match '/linkfilter' , to : 'link_filter#index' , via : 'get' , as : :linkfilter
2022-07-18 06:30:45 -07:00
match '/manifest.json' , to : 'manifests#show' , via : 'get' , as : :webapp_manifest
2014-11-02 08:58:27 -08:00
# Devise routes
devise_for :users , path : 'user' , skip : [ :sessions , :registrations ]
as :user do
# :sessions
2020-10-23 12:00:06 -07:00
get 'sign_in' = > 'user/sessions#new' , as : :new_user_session
2020-10-18 01:39:46 -07:00
post 'sign_in' = > 'user/sessions#create' , as : :user_session
2014-11-02 08:58:27 -08:00
delete 'sign_out' = > 'devise/sessions#destroy' , as : :destroy_user_session
# :registrations
get 'settings/delete_account' = > 'devise/registrations#cancel' , as : :cancel_user_registration
2020-05-22 13:29:22 -07:00
post '/user/create' = > 'user/registrations#create' , as : :user_registration
2014-11-02 08:58:27 -08:00
get '/sign_up' = > 'devise/registrations#new' , as : :new_user_registration
get '/settings/account' = > 'devise/registrations#edit' , as : :edit_user_registration
2014-11-03 04:21:41 -08:00
patch '/settings/account' = > 'devise/registrations#update' , as : :update_user_registration
2014-11-02 08:58:27 -08:00
put '/settings/account' = > 'devise/registrations#update'
2015-07-14 16:44:35 -07:00
delete '/settings/account' = > 'user/registrations#destroy'
2014-11-02 08:58:27 -08:00
end
2022-06-26 04:28:35 -07:00
namespace :settings do
get :theme , to : redirect ( '/settings/theme/edit' )
2022-06-26 04:36:30 -07:00
resource :theme , controller : :theme , only : % i [ edit update destroy ]
2022-06-26 10:16:31 -07:00
get :profile , to : redirect ( '/settings/profile/edit' )
2022-06-26 10:45:31 -07:00
resource :profile , controller : :profile , only : % i [ edit update ]
resource :profile_picture , controller : :profile_picture , only : % i [ update ]
2022-06-27 16:50:20 -07:00
get :privacy , to : redirect ( '/settings/privacy/edit' )
resource :privacy , controller : :privacy , only : % i [ edit update ]
2022-07-01 21:15:00 -07:00
get :export , to : 'export#index'
post :export , to : 'export#create'
2022-07-02 14:35:58 -07:00
2022-07-03 12:11:17 -07:00
get :muted , to : 'mutes#index'
2022-07-03 12:31:39 -07:00
get :blocks , to : 'blocks#index'
2022-07-03 12:41:50 -07:00
get :data , to : 'data#index'
2022-07-02 14:35:58 -07:00
namespace :two_factor_authentication do
get :otp_authentication , to : 'otp_authentication#index'
patch :otp_authentication , to : 'otp_authentication#update'
delete :otp_authentication , to : 'otp_authentication#destroy'
match 'otp_authentication/reset' , to : 'otp_authentication#reset' , via : :delete
end
2022-06-26 04:28:35 -07:00
end
resolve ( 'Theme' ) { [ :settings_theme ] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
2022-06-26 10:16:31 -07:00
resolve ( 'Profile' ) { [ :settings_profile ] }
2015-08-25 01:26:36 -07:00
2014-12-12 12:43:09 -08:00
# resources :services, only: [:index, :destroy]
match '/settings/services' , to : 'services#index' , via : 'get' , as : :services
2022-01-04 16:00:18 -08:00
match '/settings/services/:id' , to : 'services#update' , via : 'patch' , as : :update_service
2014-12-12 12:43:09 -08:00
match '/settings/services/:id' , to : 'services#destroy' , via : 'delete' , as : :service
controller :services do
scope " /auth " , as : " auth " do
get ':provider/callback' = > :create
get :failure
end
end
2014-11-10 04:04:10 -08:00
namespace :ajax do
2014-11-10 12:56:30 -08:00
match '/ask' , to : 'question#create' , via : :post , as : :ask
2015-04-25 18:36:25 -07:00
match '/destroy_question' , to : 'question#destroy' , via : :post , as : :destroy_question
2014-12-09 14:21:41 -08:00
match '/generate_question' , to : 'inbox#create' , via : :post , as : :generate_question
2014-11-30 09:05:51 -08:00
match '/delete_inbox' , to : 'inbox#remove' , via : :post , as : :delete_inbox
2014-12-21 04:41:57 -08:00
match '/delete_all_inbox' , to : 'inbox#remove_all' , via : :post , as : :delete_all_inbox
2015-07-17 11:29:19 -07:00
match '/delete_all_inbox/:author' , to : 'inbox#remove_all_author' , via : :post , as : :delete_all_author
2015-01-03 09:40:39 -08:00
match '/answer' , to : 'answer#create' , via : :post , as : :answer
2014-11-26 08:05:46 -08:00
match '/destroy_answer' , to : 'answer#destroy' , via : :post , as : :destroy_answer
2022-01-02 15:31:55 -08:00
match '/create_relationship' , to : 'relationship#create' , via : :post , as : :create_relationship
match '/destroy_relationship' , to : 'relationship#destroy' , via : :post , as : :destroy_relationship
2014-11-30 11:31:22 -08:00
match '/create_smile' , to : 'smile#create' , via : :post , as : :create_smile
match '/destroy_smile' , to : 'smile#destroy' , via : :post , as : :destroy_smile
2015-05-03 18:39:41 -07:00
match '/create_comment_smile' , to : 'smile#create_comment' , via : :post , as : :create_comment_smile
match '/destroy_comment_smile' , to : 'smile#destroy_comment' , via : :post , as : :destroy_comment_smile
2014-12-07 05:29:35 -08:00
match '/create_comment' , to : 'comment#create' , via : :post , as : :create_comment
2014-12-28 12:14:01 -08:00
match '/destroy_comment' , to : 'comment#destroy' , via : :post , as : :destroy_comment
2014-12-28 10:55:50 -08:00
match '/report' , to : 'report#create' , via : :post , as : :report
2020-05-25 09:04:54 -07:00
match '/create_list' , to : 'list#create' , via : :post , as : :create_list
match '/destroy_list' , to : 'list#destroy' , via : :post , as : :destroy_list
match '/list_membership' , to : 'list#membership' , via : :post , as : :list_membership
2015-04-20 18:12:11 -07:00
match '/subscribe' , to : 'subscription#subscribe' , via : :post , as : :subscribe_answer
match '/unsubscribe' , to : 'subscription#unsubscribe' , via : :post , as : :unsubscribe_answer
2021-12-22 14:15:47 -08:00
match '/mute' , to : 'mute_rule#create' , via : :post , as : :create_mute_rule
match '/mute/:id' , to : 'mute_rule#update' , via : :post , as : :update_mute_rule
match '/mute/:id' , to : 'mute_rule#destroy' , via : :delete , as : :delete_mute_rule
2022-06-14 14:16:55 -07:00
match '/block_anon' , to : 'anonymous_block#create' , via : :post , as : :block_anon
2022-06-14 14:30:27 -07:00
match '/block_anon/:id' , to : 'anonymous_block#destroy' , via : :delete , as : :unblock_anon
2014-11-10 04:04:10 -08:00
end
2014-11-03 04:21:41 -08:00
2020-04-19 04:55:13 -07:00
match '/discover' , to : 'discover#index' , via : :get , as : :discover
2022-07-18 13:26:13 -07:00
match '/public' , to : 'timeline#public' , via : :get , as : :public_timeline if APP_CONFIG . dig ( :features , :public , :enabled )
match '/list/:list_name' , to : 'timeline#list' , via : :get , as : :list_timeline
2014-12-10 21:39:35 -08:00
2015-09-16 13:18:40 -07:00
match '/notifications(/:type)' , to : 'notifications#index' , via : :get , as : :notifications , defaults : { type : 'new' }
2014-12-14 06:17:52 -08:00
2014-11-10 22:10:41 -08:00
match '/inbox' , to : 'inbox#show' , via : 'get'
2015-07-17 12:02:53 -07:00
match '/inbox/:author' , to : 'inbox#show' , via : 'get'
2015-04-18 15:17:13 -07:00
2014-11-12 11:40:24 -08:00
match '/user/:username(/p/:page)' , to : 'user#show' , via : 'get' , defaults : { page : 1 }
2015-01-17 07:29:11 -08:00
match '/@:username(/p/:page)' , to : 'user#show' , via : 'get' , as : :show_user_profile_alt , defaults : { page : 1 }
match '/@:username/a/:id' , to : 'answer#show' , via : 'get' , as : :show_user_answer_alt
match '/@:username/q/:id' , to : 'question#show' , via : 'get' , as : :show_user_question_alt
match '/@:username/followers(/p/:page)' , to : 'user#followers' , via : 'get' , as : :show_user_followers_alt , defaults : { page : 1 }
2021-12-31 13:19:21 -08:00
match '/@:username/followings(/p/:page)' , to : 'user#followings' , via : 'get' , as : :show_user_followings_alt , defaults : { page : 1 }
2022-01-22 13:48:55 -08:00
match '/@:username/friends(/p/:page)' , to : redirect ( '/@%{username}/followings/p/%{page}' ) , via : 'get' , defaults : { page : 1 }
2015-01-17 07:29:11 -08:00
match '/:username(/p/:page)' , to : 'user#show' , via : 'get' , as : :show_user_profile , defaults : { page : 1 }
match '/:username/a/:id' , to : 'answer#show' , via : 'get' , as : :show_user_answer
match '/:username/q/:id' , to : 'question#show' , via : 'get' , as : :show_user_question
match '/:username/followers(/p/:page)' , to : 'user#followers' , via : 'get' , as : :show_user_followers , defaults : { page : 1 }
2021-12-31 13:19:21 -08:00
match '/:username/followings(/p/:page)' , to : 'user#followings' , via : 'get' , as : :show_user_followings , defaults : { page : 1 }
2022-01-22 13:48:55 -08:00
match '/:username/friends(/p/:page)' , to : redirect ( '/%{username}/followings/p/%{page}' ) , via : 'get' , defaults : { page : 1 }
2014-12-19 13:34:24 -08:00
match '/:username/questions(/p/:page)' , to : 'user#questions' , via : 'get' , as : :show_user_questions , defaults : { page : 1 }
2017-03-31 13:38:23 -07:00
2022-01-22 13:37:01 -08:00
match '/feedback/consent' , to : 'feedback#consent' , via : 'get' , as : 'feedback_consent'
match '/feedback/consent/update' , to : 'feedback#update' , via : 'post' , as : 'feedback_consent_update'
2022-01-21 15:33:37 -08:00
match '/feedback/bugs(/*any)' , to : 'feedback#bugs' , via : 'get' , as : 'feedback_bugs'
2022-01-22 12:30:39 -08:00
match '/feedback/feature_requests(/*any)' , to : 'feedback#features' , via : 'get' , as : 'feedback_features'
2022-01-21 15:33:37 -08:00
2022-06-27 13:10:39 -07:00
get '/.well-known/change-password' , to : redirect ( '/settings/account' )
2017-03-31 13:38:23 -07:00
puts 'processing time of routes.rb: ' + " #{ ( Time . now - start ) . round ( 3 ) . to_s . ljust ( 5 , '0' ) } s " . light_green
2014-08-01 02:23:47 -07:00
end