2022-07-23 12:06:05 +02:00
# frozen_string_literal: true
require " sidekiq/web "
2014-08-01 11:23:47 +02:00
Rails . application . routes . draw do
2022-07-23 12:06:05 +02:00
start = Time . zone . now
2014-12-05 07:02:23 +01:00
2022-07-03 23:50:17 +02:00
# Routes only accessible by admins (admin panels, sidekiq, pghero)
authenticate :user , - > ( user ) { user . has_role? ( :administrator ) } do
2020-04-19 22:35:58 +02:00
# Admin panel
2022-07-23 12:06:05 +02:00
mount RailsAdmin :: Engine = > " /justask_admin " , :as = > " rails_admin "
2020-04-19 22:35:58 +02:00
2014-12-12 18:35:14 +01:00
mount Sidekiq :: Web , at : " /sidekiq "
2020-04-19 22:35:58 +02:00
mount PgHero :: Engine , at : " /pghero " , as : " pghero "
2020-04-19 23:58:47 +02:00
2022-11-20 17:58:44 +01:00
get " /admin " , to : " admin/dashboard # index " , as : :admin_dashboard
2022-11-20 18:58:19 +01:00
get " /admin/announcements " , to : " admin/announcement # index " , as : :announcement_index
post " /admin/announcements " , to : " admin/announcement # create " , as : :announcement_create
get " /admin/announcements/new " , to : " admin/announcement # new " , as : :announcement_new
get " /admin/announcements/:id/edit " , to : " admin/announcement # edit " , as : :announcement_edit
patch " /admin/announcements/:id " , to : " admin/announcement # update " , as : :announcement_update
delete " /admin/announcements/:id " , to : " admin/announcement # destroy " , as : :announcement_destroy
2014-12-12 18:35:14 +01:00
end
2022-07-03 23:50:17 +02:00
# Routes only accessible by moderators (moderation panel)
authenticate :user , - > ( user ) { user . mod? } do
2022-07-23 12:06:05 +02:00
post " /moderation/unmask " , to : " moderation # toggle_unmask " , as : :moderation_toggle_unmask
2022-08-13 20:01:22 +02:00
get " /moderation/blocks " , to : " moderation/anonymous_block # index " , as : :mod_anon_block_index
2023-01-21 19:18:31 +01:00
get " /moderation/inbox/:user " , to : " moderation/inbox # index " , as : :mod_inbox_index
2023-01-21 19:26:23 +01:00
get " /moderation/reports(/:type) " , to : " moderation/reports # index " , as : :moderation_reports , defaults : { type : " all " }
2022-08-21 12:58:58 +02:00
get " /moderation/questions/:author_identifier " , to : " moderation/questions # show " , as : :moderation_questions
2014-12-28 23:26:16 +01:00
namespace :ajax do
2022-07-23 12:06:05 +02:00
post " /mod/destroy_report " , to : " moderation # destroy_report " , as : :mod_destroy_report
post " /mod/privilege " , to : " moderation # privilege " , as : :mod_privilege
post " /mod/ban " , to : " moderation # ban " , as : :mod_ban
2014-12-28 23:26:16 +01:00
end
2014-12-26 13:46:47 +01:00
end
2022-07-18 16:26:11 +02:00
unauthenticated :user do
2022-07-23 12:06:05 +02:00
root to : " about # index "
2022-07-18 16:26:11 +02:00
end
authenticate :user do
2023-01-21 20:07:15 +01:00
root to : " timeline # index " , as : :timeline
2022-07-18 16:26:11 +02:00
end
2014-08-01 11:23:47 +02:00
2022-07-23 12:06:05 +02:00
get " /about " , to : " about # about "
get " /privacy " , to : " about # privacy_policy " , as : :privacy_policy
get " /terms " , to : " about # terms " , as : :terms
get " /linkfilter " , to : " link_filter # index " , as : :linkfilter
get " /manifest.json " , to : " manifests # show " , as : :webapp_manifest
2014-11-02 17:58:27 +01:00
2023-02-13 21:53:40 +01:00
constraints ( Constraints :: LocalNetwork ) do
get " /metrics " , to : " metrics # show "
end
2023-02-13 20:13:32 +01:00
2014-11-02 17:58:27 +01:00
# Devise routes
2022-07-23 12:06:05 +02:00
devise_for :users , path : " user " , skip : % i [ sessions registrations ]
2014-11-02 17:58:27 +01:00
as :user do
# :sessions
2022-07-23 12:06:05 +02:00
get " sign_in " = > " user/sessions # new " , :as = > :new_user_session
post " sign_in " = > " user/sessions # create " , :as = > :user_session
delete " sign_out " = > " devise/sessions # destroy " , :as = > :destroy_user_session
2014-11-02 17:58:27 +01:00
# :registrations
2022-07-23 12:06:05 +02:00
get " settings/delete_account " = > " devise/registrations # cancel " , :as = > :cancel_user_registration
post " /user/create " = > " user/registrations # create " , :as = > :user_registration
get " /sign_up " = > " devise/registrations # new " , :as = > :new_user_registration
get " /settings/account " = > " devise/registrations # edit " , :as = > :edit_user_registration
patch " /settings/account " = > " devise/registrations # update " , :as = > :update_user_registration
put " /settings/account " = > " devise/registrations # update "
delete " /settings/account " = > " user/registrations # destroy "
2014-11-02 17:58:27 +01:00
end
2022-06-26 13:28:35 +02:00
namespace :settings do
2022-07-23 12:06:05 +02:00
get :theme , to : redirect ( " /settings/theme/edit " )
2022-06-26 13:36:30 +02:00
resource :theme , controller : :theme , only : % i [ edit update destroy ]
2022-06-26 19:16:31 +02:00
2022-07-23 12:06:05 +02:00
get :profile , to : redirect ( " /settings/profile/edit " )
2022-06-26 19:45:31 +02:00
resource :profile , controller : :profile , only : % i [ edit update ]
resource :profile_picture , controller : :profile_picture , only : % i [ update ]
2022-06-28 01:50:20 +02:00
2022-07-23 12:06:05 +02:00
get :privacy , to : redirect ( " /settings/privacy/edit " )
2022-06-28 01:50:20 +02:00
resource :privacy , controller : :privacy , only : % i [ edit update ]
2022-07-02 06:15:00 +02:00
2023-02-05 19:15:20 +01:00
get :sharing , to : redirect ( " /settings/sharing/edit " )
resource :sharing , controller : :sharing , only : % i [ edit update ]
2022-07-23 12:06:05 +02:00
get :export , to : " export # index "
post :export , to : " export # create "
2022-07-02 23:35:58 +02:00
2022-07-23 12:06:05 +02:00
get :muted , to : " mutes # index "
2022-11-18 21:48:12 +01:00
post :muted , to : " mutes # create "
delete " muted/:id " , to : " mutes # destroy " , as : :muted_destroy
2022-07-03 21:11:17 +02:00
2022-07-23 12:06:05 +02:00
get :blocks , to : " blocks # index "
2022-07-03 21:31:39 +02:00
2022-07-23 12:06:05 +02:00
get :data , to : " data # index "
2022-07-03 21:41:50 +02:00
2022-10-20 19:02:12 +02:00
resources :push_notifications , only : % i [ index ]
2022-07-02 23:35:58 +02:00
namespace :two_factor_authentication do
2022-07-23 12:06:05 +02:00
get :otp_authentication , to : " otp_authentication # index "
patch :otp_authentication , to : " otp_authentication # update "
delete :otp_authentication , to : " otp_authentication # destroy "
delete " otp_authentication/reset " , to : " otp_authentication # reset "
2022-07-02 23:35:58 +02:00
end
2022-06-26 13:28:35 +02:00
end
2022-07-23 12:06:05 +02:00
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
resolve ( " Profile " ) { [ :settings_profile ] }
2015-08-25 10:26:36 +02:00
2014-11-10 13:04:10 +01:00
namespace :ajax do
2022-07-23 12:06:05 +02:00
post " /ask " , to : " question # create " , as : :ask
post " /destroy_question " , to : " question # destroy " , as : :destroy_question
post " /delete_inbox " , to : " inbox # remove " , as : :delete_inbox
post " /delete_all_inbox " , to : " inbox # remove_all " , as : :delete_all_inbox
post " /delete_all_inbox/:author " , to : " inbox # remove_all_author " , as : :delete_all_author
post " /answer " , to : " answer # create " , as : :answer
post " /destroy_answer " , to : " answer # destroy " , as : :destroy_answer
post " /create_relationship " , to : " relationship # create " , as : :create_relationship
post " /destroy_relationship " , to : " relationship # destroy " , as : :destroy_relationship
post " /create_smile " , to : " smile # create " , as : :create_smile
post " /destroy_smile " , to : " smile # destroy " , as : :destroy_smile
post " /create_comment_smile " , to : " smile # create_comment " , as : :create_comment_smile
post " /destroy_comment_smile " , to : " smile # destroy_comment " , as : :destroy_comment_smile
post " /create_comment " , to : " comment # create " , as : :create_comment
post " /destroy_comment " , to : " comment # destroy " , as : :destroy_comment
post " /report " , to : " report # create " , as : :report
post " /create_list " , to : " list # create " , as : :create_list
post " /destroy_list " , to : " list # destroy " , as : :destroy_list
post " /list_membership " , to : " list # membership " , as : :list_membership
post " /subscribe " , to : " subscription # subscribe " , as : :subscribe_answer
post " /unsubscribe " , to : " subscription # unsubscribe " , as : :unsubscribe_answer
2022-09-11 20:12:42 +02:00
get " /webpush/key " , to : " web_push # key " , as : :webpush_key
2023-01-01 21:34:49 +01:00
post " /webpush/check " , to : " web_push # check " , as : :webpush_check
2022-09-11 20:12:42 +02:00
post " /webpush " , to : " web_push # subscribe " , as : :webpush_subscribe
2022-10-21 22:37:52 +02:00
delete " /webpush " , to : " web_push # unsubscribe " , as : :webpush_unsubscribe
2014-11-10 13:04:10 +01:00
end
2014-11-03 13:21:41 +01:00
2022-11-21 22:29:47 +01:00
resource :anonymous_block , controller : :anonymous_block , only : % i [ create destroy ]
2022-07-23 12:06:05 +02:00
get " /discover " , to : " discover # index " , as : :discover
2023-01-21 19:11:05 +01:00
get " /public " , to : " timeline # public " , as : :public_timeline if APP_CONFIG . dig ( :features , :public , :enabled )
get " /list/:list_name " , to : " timeline # list " , as : :list_timeline
2022-07-23 12:06:05 +02:00
2023-01-21 19:36:08 +01:00
get " /notifications(/:type) " , to : " notifications # index " , as : :notifications , defaults : { type : " new " }
2023-03-07 19:53:57 +01:00
post " /notifications " , to : " notifications # read " , as : :notifications_read
2022-07-23 12:06:05 +02:00
2022-11-17 21:55:01 +01:00
post " /inbox/create " , to : " inbox # create " , as : :inbox_create
2023-01-18 08:11:00 +01:00
get " /inbox " , to : " inbox # show " , as : :inbox
2022-07-23 12:06:05 +02:00
2023-01-21 20:07:15 +01:00
get " /user/:username " , to : " user # show "
get " /@:username " , to : " user # show " , as : :user
get " /@:username/a/:id " , to : " answer # show " , as : :answer
2023-02-07 08:32:25 +01:00
post " /@:username/a/:id/pin " , to : " answer # pin " , as : :pin_answer
2023-02-07 08:36:29 +01:00
delete " /@:username/a/:id/pin " , to : " answer # unpin " , as : :unpin_answer
2023-03-11 19:48:04 +01:00
get " /@:username/a/:id/comments " , to : " comment # index " , as : :comments
2023-09-14 00:21:59 +02:00
get " /@:username/a/:id/reactions " , to : " reaction # index " , as : :reactions
2023-01-21 19:55:57 +01:00
get " /@:username/q/:id " , to : " question # show " , as : :question
2023-01-21 20:07:15 +01:00
get " /@:username/followers " , to : " user # followers " , as : :show_user_followers
get " /@:username/followings " , to : " user # followings " , as : :show_user_followings
2023-01-28 11:08:16 +01:00
get " /@:username/friends " , to : redirect ( " /@%{username}/followings " )
2023-01-21 20:07:15 +01:00
get " /@:username/questions " , to : " user # questions " , as : :show_user_questions
get " /:username " , to : " user # show " , as : :user_alt
2022-07-23 12:06:05 +02:00
get " /:username/a/:id " , to : " answer # show " , as : :answer_alt
get " /:username/q/:id " , to : " question # show " , as : :question_alt
2023-01-21 20:07:15 +01:00
get " /:username/followers " , to : " user # followers " , as : :show_user_followers_alt
get " /:username/followings " , to : " user # followings " , as : :show_user_followings_alt
2023-01-28 11:08:16 +01:00
get " /:username/friends " , to : redirect ( " /%{username}/followings " )
2023-01-21 20:07:15 +01:00
get " /:username/questions " , to : " user # questions " , as : :show_user_questions_alt
2022-07-23 12:06:05 +02:00
get " /feedback/consent " , to : " feedback # consent " , as : " feedback_consent "
post " /feedback/consent/update " , to : " feedback # update " , as : " feedback_consent_update "
get " /feedback/bugs(/*any) " , to : " feedback # bugs " , as : " feedback_bugs "
get " /feedback/feature_requests(/*any) " , to : " feedback # features " , as : " feedback_features "
2023-01-04 17:08:05 +01:00
namespace :well_known , path : " /.well-known " do
get " /change-password " , to : redirect ( " /settings/account " )
get " /nodeinfo " , to : " node_info # discovery "
end
get " /nodeinfo/2.1 " , to : " well_known/node_info # nodeinfo " , as : :node_info
2022-07-23 12:06:05 +02:00
puts " processing time of routes.rb: #{ " #{ ( Time . zone . now - start ) . round ( 3 ) . to_s . ljust ( 5 , '0' ) } s " . light_green } "
2014-08-01 11:23:47 +02:00
end