2016-11-28 06:36:47 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-31 14:59:03 -05:00
|
|
|
require 'sidekiq_unique_jobs/web'
|
2017-05-07 20:52:57 -05:00
|
|
|
require 'sidekiq-scheduler/web'
|
2016-03-24 20:50:48 -05:00
|
|
|
|
2016-02-20 15:53:20 -06:00
|
|
|
Rails.application.routes.draw do
|
2022-10-26 07:01:02 -05:00
|
|
|
# Paths of routes on the web app that to not require to be indexed or
|
|
|
|
# have alternative format representations requiring separate controllers
|
|
|
|
web_app_paths = %w(
|
|
|
|
/getting-started
|
2023-03-19 11:26:02 -05:00
|
|
|
/getting-started-misc
|
2022-10-26 07:01:02 -05:00
|
|
|
/keyboard-shortcuts
|
|
|
|
/home
|
|
|
|
/public
|
|
|
|
/public/local
|
|
|
|
/conversations
|
|
|
|
/lists/(*any)
|
|
|
|
/notifications
|
|
|
|
/favourites
|
|
|
|
/bookmarks
|
|
|
|
/pinned
|
|
|
|
/start
|
|
|
|
/directory
|
|
|
|
/explore/(*any)
|
|
|
|
/search
|
|
|
|
/publish
|
|
|
|
/follow_requests
|
|
|
|
/blocks
|
|
|
|
/domain_blocks
|
|
|
|
/mutes
|
2023-01-18 09:44:33 -06:00
|
|
|
/followed_tags
|
2022-11-08 10:29:14 -06:00
|
|
|
/statuses/(*any)
|
2022-10-26 07:01:02 -05:00
|
|
|
).freeze
|
|
|
|
|
2019-08-29 18:34:33 -05:00
|
|
|
root 'home#index'
|
|
|
|
|
2017-01-21 15:19:13 -06:00
|
|
|
mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
|
2016-08-18 08:49:51 -05:00
|
|
|
|
2021-04-02 19:39:04 -05:00
|
|
|
get 'health', to: 'health#show'
|
2019-09-06 19:47:51 -05:00
|
|
|
|
2022-07-04 19:41:40 -05:00
|
|
|
authenticate :user, lambda { |u| u.role&.can?(:view_devops) } do
|
2016-12-13 06:42:10 -06:00
|
|
|
mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
|
|
|
|
mount PgHero::Engine, at: 'pghero', as: :pghero
|
2016-03-24 20:50:48 -05:00
|
|
|
end
|
|
|
|
|
2016-10-22 12:38:47 -05:00
|
|
|
use_doorkeeper do
|
2018-05-19 14:05:08 -05:00
|
|
|
controllers authorizations: 'oauth/authorizations',
|
|
|
|
authorized_applications: 'oauth/authorized_applications',
|
|
|
|
tokens: 'oauth/tokens'
|
2016-10-22 12:38:47 -05:00
|
|
|
end
|
2016-03-07 05:42:33 -06:00
|
|
|
|
2017-04-13 06:09:07 -05:00
|
|
|
get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
|
2019-09-29 14:31:51 -05:00
|
|
|
get '.well-known/nodeinfo', to: 'well_known/nodeinfo#index', as: :nodeinfo, defaults: { format: 'json' }
|
2017-04-17 12:58:03 -05:00
|
|
|
get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
|
2018-09-29 12:14:48 -05:00
|
|
|
get '.well-known/change-password', to: redirect('/auth/edit')
|
2019-03-18 15:00:55 -05:00
|
|
|
|
2019-09-29 14:31:51 -05:00
|
|
|
get '/nodeinfo/2.0', to: 'well_known/nodeinfo#show', as: :nodeinfo_schema
|
|
|
|
|
2017-06-06 12:29:42 -05:00
|
|
|
get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
|
2017-08-13 21:53:31 -05:00
|
|
|
get 'intent', to: 'intents#show'
|
2018-08-23 21:33:27 -05:00
|
|
|
get 'custom.css', to: 'custom_css#show', as: :custom_css
|
2016-02-22 09:00:20 -06:00
|
|
|
|
2019-07-18 18:44:42 -05:00
|
|
|
resource :instance_actor, path: 'actor', only: [:show] do
|
|
|
|
resource :inbox, only: [:create], module: :activitypub
|
2020-09-02 11:42:50 -05:00
|
|
|
resource :outbox, only: [:show], module: :activitypub
|
2019-07-18 18:44:42 -05:00
|
|
|
end
|
|
|
|
|
2017-11-27 09:07:59 -06:00
|
|
|
devise_scope :user do
|
|
|
|
get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 03:48:50 -05:00
|
|
|
|
2023-06-12 07:22:46 -05:00
|
|
|
resource :unsubscribe, only: [:show, :create], controller: :mail_subscriptions
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 03:48:50 -05:00
|
|
|
namespace :auth do
|
|
|
|
resource :setup, only: [:show, :update], controller: :setup
|
2019-09-18 09:37:27 -05:00
|
|
|
resource :challenge, only: [:create], controller: :challenges
|
Add WebAuthn as an alternative 2FA method (#14466)
* feat: add possibility of adding WebAuthn security keys to use as 2FA
This adds a basic UI for enabling WebAuthn 2FA. We did a little refactor
to the Settings page for editing the 2FA methods – now it will list the
methods that are available to the user (TOTP and WebAuthn) and from
there they'll be able to add or remove any of them.
Also, it's worth mentioning that for enabling WebAuthn it's required to
have TOTP enabled, so the first time that you go to the 2FA Settings
page, you'll be asked to set it up.
This work was inspired by the one donde by Github in their platform, and
despite it could be approached in different ways, we decided to go with
this one given that we feel that this gives a great UX.
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
* feat: add request for WebAuthn as second factor at login if enabled
This commits adds the feature for using WebAuthn as a second factor for
login when enabled.
If users have WebAuthn enabled, now a page requesting for the use of a
WebAuthn credential for log in will appear, although a link redirecting
to the old page for logging in using a two-factor code will also be
present.
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
* feat: add possibility of deleting WebAuthn Credentials
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
* feat: disable WebAuthn when an Admin disables 2FA for a user
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
* feat: remove ability to disable TOTP leaving only WebAuthn as 2FA
Following examples form other platforms like Github, we decided to make
Webauthn 2FA secondary to 2FA with TOTP, so that we removed the
possibility of removing TOTP authentication only, leaving users with
just WEbAuthn as 2FA. Instead, users will have to click on 'Disable 2FA'
in order to remove second factor auth.
The reason for WebAuthn being secondary to TOPT is that in that way,
users will still be able to log in using their code from their phone's
application if they don't have their security keys with them – or maybe
even lost them.
* We had to change a little the flow for setting up TOTP, given that now
it's possible to setting up again if you already had TOTP, in order to
let users modify their authenticator app – given that now it's not
possible for them to disable TOTP and set it up again with another
authenticator app.
So, basically, now instead of storing the new `otp_secret` in the
user, we store it in the session until the process of set up is
finished.
This was because, as it was before, when users clicked on 'Edit' in
the new two-factor methods lists page, but then went back without
finishing the flow, their `otp_secret` had been changed therefore
invalidating their previous authenticator app, making them unable to
log in again using TOTP.
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
* refactor: fix eslint errors
The PR build was failing given that linting returning some errors.
This commit attempts to fix them.
* refactor: normalize i18n translations
The build was failing given that i18n translations files were not
normalized.
This commits fixes that.
* refactor: avoid having the webauthn gem locked to a specific version
* refactor: use symbols for routes without '/'
* refactor: avoid sending webauthn disabled email when 2FA is disabled
When an admins disable 2FA for users, we were sending two mails
to them, one notifying that 2FA was disabled and the other to notify
that WebAuthn was disabled.
As the second one is redundant since the first email includes it, we can
remove it and send just one email to users.
* refactor: avoid creating new env variable for webauthn_origin config
* refactor: improve flash error messages for webauthn pages
Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
2020-08-24 09:46:27 -05:00
|
|
|
get 'sessions/security_key_options', to: 'sessions#webauthn_options'
|
2022-01-25 15:37:12 -06:00
|
|
|
post 'captcha_confirmation', to: 'confirmations#confirm_captcha', as: :captcha_confirmation
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 03:48:50 -05:00
|
|
|
end
|
2017-11-27 09:07:59 -06:00
|
|
|
end
|
|
|
|
|
2022-11-14 13:26:31 -06:00
|
|
|
devise_for :users, path: 'auth', format: false, controllers: {
|
2018-02-03 22:42:13 -06:00
|
|
|
omniauth_callbacks: 'auth/omniauth_callbacks',
|
2016-03-05 15:43:05 -06:00
|
|
|
sessions: 'auth/sessions',
|
|
|
|
registrations: 'auth/registrations',
|
2016-10-03 09:38:22 -05:00
|
|
|
passwords: 'auth/passwords',
|
2016-11-28 06:36:47 -06:00
|
|
|
confirmations: 'auth/confirmations',
|
2016-03-05 15:43:05 -06:00
|
|
|
}
|
2016-03-05 06:12:24 -06:00
|
|
|
|
2017-07-24 01:46:29 -05:00
|
|
|
get '/users/:username', to: redirect('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
|
2023-04-30 02:01:42 -05:00
|
|
|
get '/users/:username/following', to: redirect('/@%{username}/following'), constraints: lambda { |req| req.format.nil? || req.format.html? }
|
|
|
|
get '/users/:username/followers', to: redirect('/@%{username}/followers'), constraints: lambda { |req| req.format.nil? || req.format.html? }
|
2022-11-04 07:19:57 -05:00
|
|
|
get '/users/:username/statuses/:id', to: redirect('/@%{username}/%{id}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
|
2018-09-02 17:10:28 -05:00
|
|
|
get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
|
2017-03-22 13:26:22 -05:00
|
|
|
|
2016-02-29 12:42:08 -06:00
|
|
|
resources :accounts, path: 'users', only: [:show], param: :username do
|
2017-07-14 20:01:39 -05:00
|
|
|
resources :statuses, only: [:show] do
|
|
|
|
member do
|
|
|
|
get :activity
|
2017-08-30 03:23:43 -05:00
|
|
|
get :embed
|
2017-07-14 20:01:39 -05:00
|
|
|
end
|
2019-07-08 05:03:45 -05:00
|
|
|
|
|
|
|
resources :replies, only: [:index], module: :activitypub
|
2017-07-14 20:01:39 -05:00
|
|
|
end
|
|
|
|
|
2017-04-19 06:52:37 -05:00
|
|
|
resources :followers, only: [:index], controller: :follower_accounts
|
|
|
|
resources :following, only: [:index], controller: :following_accounts
|
2018-01-08 03:57:52 -06:00
|
|
|
resource :follow, only: [:create], controller: :account_follow
|
2017-04-19 06:52:37 -05:00
|
|
|
resource :unfollow, only: [:create], controller: :account_unfollow
|
2018-03-04 02:19:11 -06:00
|
|
|
|
2017-07-14 20:01:39 -05:00
|
|
|
resource :outbox, only: [:show], module: :activitypub
|
2017-08-08 14:52:15 -05:00
|
|
|
resource :inbox, only: [:create], module: :activitypub
|
2020-06-02 12:24:53 -05:00
|
|
|
resource :claim, only: [:create], module: :activitypub
|
2018-03-04 02:19:11 -06:00
|
|
|
resources :collections, only: [:show], module: :activitypub
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 11:04:09 -05:00
|
|
|
resource :followers_synchronization, only: [:show], module: :activitypub
|
2016-02-29 12:42:08 -06:00
|
|
|
end
|
2016-02-22 09:00:20 -06:00
|
|
|
|
2017-08-30 17:02:59 -05:00
|
|
|
resource :inbox, only: [:create], module: :activitypub
|
|
|
|
|
2023-02-14 12:05:57 -06:00
|
|
|
get '/:encoded_at(*path)', to: redirect("/@%{path}"), constraints: { encoded_at: /%40/ }
|
|
|
|
|
2023-06-06 07:50:51 -05:00
|
|
|
constraints(username: %r{[^@/.]+}) do
|
2022-10-20 07:35:29 -05:00
|
|
|
get '/@:username', to: 'accounts#show', as: :short_account
|
|
|
|
get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
|
|
|
|
get '/@:username/media', to: 'accounts#show', as: :short_account_media
|
|
|
|
get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
|
|
|
|
end
|
2017-03-22 13:26:22 -05:00
|
|
|
|
2023-06-06 07:50:51 -05:00
|
|
|
constraints(account_username: %r{[^@/.]+}) do
|
2022-10-20 07:35:29 -05:00
|
|
|
get '/@:account_username/following', to: 'following_accounts#index'
|
|
|
|
get '/@:account_username/followers', to: 'follower_accounts#index'
|
|
|
|
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
|
|
|
|
get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
|
|
|
|
end
|
2018-08-17 20:03:12 -05:00
|
|
|
|
2023-06-06 07:50:51 -05:00
|
|
|
get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, format: false
|
2019-06-07 09:51:08 -05:00
|
|
|
get '/settings', to: redirect('/settings/profile')
|
2019-06-06 20:39:24 -05:00
|
|
|
|
2023-05-02 08:41:20 -05:00
|
|
|
draw(:settings)
|
2016-10-13 19:28:49 -05:00
|
|
|
|
2022-02-14 14:27:53 -06:00
|
|
|
namespace :disputes do
|
2022-03-01 12:37:47 -06:00
|
|
|
resources :strikes, only: [:show, :index] do
|
2022-02-14 14:27:53 -06:00
|
|
|
resource :appeal, only: [:create]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-16 00:22:20 -06:00
|
|
|
resources :media, only: [:show] do
|
|
|
|
get :player
|
|
|
|
end
|
|
|
|
|
2017-10-07 10:43:42 -05:00
|
|
|
resources :tags, only: [:show]
|
|
|
|
resources :emojis, only: [:show]
|
2017-11-27 09:07:59 -06:00
|
|
|
resources :invites, only: [:index, :create, :destroy]
|
2022-08-24 21:27:47 -05:00
|
|
|
resources :filters, except: [:show] do
|
|
|
|
resources :statuses, only: [:index], controller: 'filters/statuses' do
|
|
|
|
collection do
|
|
|
|
post :batch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-16 05:23:22 -05:00
|
|
|
resource :relationships, only: [:show, :update]
|
2021-08-09 16:11:50 -05:00
|
|
|
resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
|
2016-10-02 09:14:21 -05:00
|
|
|
|
2022-11-14 13:26:31 -06:00
|
|
|
get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
|
2023-03-16 16:46:52 -05:00
|
|
|
get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
|
2017-09-15 20:01:45 -05:00
|
|
|
|
2018-08-17 20:03:12 -05:00
|
|
|
resource :authorize_interaction, only: [:show, :create]
|
2017-08-13 21:53:31 -05:00
|
|
|
resource :share, only: [:show, :create]
|
2016-12-29 09:54:54 -06:00
|
|
|
|
2023-05-02 08:41:20 -05:00
|
|
|
draw(:admin)
|
2016-11-28 11:45:13 -06:00
|
|
|
|
2018-07-15 18:11:53 -05:00
|
|
|
get '/admin', to: redirect('/admin/dashboard', status: 302)
|
2017-01-26 01:59:35 -06:00
|
|
|
|
2023-05-02 08:41:20 -05:00
|
|
|
draw(:api)
|
2016-02-22 09:00:20 -06:00
|
|
|
|
2022-10-26 07:01:02 -05:00
|
|
|
web_app_paths.each do |path|
|
2022-10-20 07:35:29 -05:00
|
|
|
get path, to: 'home#index'
|
|
|
|
end
|
2016-11-13 07:01:21 -06:00
|
|
|
|
2022-11-08 18:30:33 -06:00
|
|
|
get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
|
2022-10-26 09:56:37 -05:00
|
|
|
get '/about', to: 'about#show'
|
|
|
|
get '/about/more', to: redirect('/about')
|
2022-09-28 23:22:12 -05:00
|
|
|
|
|
|
|
get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
|
|
|
|
get '/terms', to: redirect('/privacy-policy')
|
2017-01-19 18:00:14 -06:00
|
|
|
|
2019-08-29 18:34:33 -05:00
|
|
|
match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
|
|
|
|
match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
|
2016-02-20 15:53:20 -06:00
|
|
|
end
|