A platform for community discussion. Free, open, simple.
FIX: `RouteFormat` is a better class name than `RouteFormats`
Robin Ward063e449ce520
diff --git a/config/routes.rb b/config/routes.rbindex 08d7dbd38f6..468baf467e8 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -4,7 +4,7 @@ require_dependency "admin_constraint"require_dependency "staff_constraint"require_dependency "homepage_constraint"require_dependency "permalink_constraint"-require_dependency "route_formats"+require_dependency "route_format"Discourse::Application.routes.draw do@@ -90,7 +90,7 @@ Discourse::Application.routes.draw doget "moderation_history" => "moderation_history#index"- resources :users, id: RouteFormats.username, except: [:show] do+ resources :users, id: RouteFormat.username, except: [:show] docollection doget "list" => "users#index"get "list/:query" => "users#index"@@ -128,7 +128,7 @@ Discourse::Application.routes.draw dopost "reset_bounce_score"endget "users/:id.json" => 'users#show', defaults: { format: 'json' }- get 'users/:id/:username' => 'users#show', constraints: { username: RouteFormats.username }+ get 'users/:id/:username' => 'users#show', constraints: { username: RouteFormat.username }get 'users/:id/:username/badges' => 'users#show'get 'users/:id/:username/tl3_requirements' => 'users#show'@@ -249,10 +249,10 @@ Discourse::Application.routes.draw doresources :backups, only: [:index, :create], constraints: AdminConstraint.new domember do- get "" => "backups#show", constraints: { id: RouteFormats.backup }- put "" => "backups#email", constraints: { id: RouteFormats.backup }- delete "" => "backups#destroy", constraints: { id: RouteFormats.backup }- post "restore" => "backups#restore", constraints: { id: RouteFormats.backup }+ get "" => "backups#show", constraints: { id: RouteFormat.backup }+ put "" => "backups#email", constraints: { id: RouteFormat.backup }+ delete "" => "backups#destroy", constraints: { id: RouteFormat.backup }+ post "restore" => "backups#restore", constraints: { id: RouteFormat.backup }endcollection doget "logs" => "backups#logs"@@ -286,7 +286,7 @@ Discourse::Application.routes.draw doget "extra-locales/:bundle" => "extra_locales#show"- resources :session, id: RouteFormats.username, only: [:create, :destroy, :become] do+ resources :session, id: RouteFormat.username, only: [:create, :destroy, :become] doget 'become'collection dopost "forgot_password"@@ -349,64 +349,64 @@ Discourse::Application.routes.draw doconstraints: { token: /[0-9a-f]+/ }}.merge(index == 1 ? { as: 'confirm_admin' } : {}))post "#{root_path}/confirm-admin/:token" => "users#confirm_admin", constraints: { token: /[0-9a-f]+/ }- get "#{root_path}/:username/private-messages" => "user_actions#private_messages", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/private-messages/:filter" => "user_actions#private_messages", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/messages" => "user_actions#private_messages", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/messages/:filter" => "user_actions#private_messages", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: { username: RouteFormats.username, group_name: RouteFormats.username }- get "#{root_path}/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: { username: RouteFormats.username, group_name: RouteFormats.username }- get "#{root_path}/:username.json" => "users#show", constraints: { username: RouteFormats.username }, defaults: { format: :json }- get({ "#{root_path}/:username" => "users#show", constraints: { username: RouteFormats.username, format: /(json|html)/ } }.merge(index == 1 ? { as: 'user' } : {}))- put "#{root_path}/:username" => "users#update", constraints: { username: RouteFormats.username }, defaults: { format: :json }- get "#{root_path}/:username/emails" => "users#check_emails", constraints: { username: RouteFormats.username }- get({ "#{root_path}/:username/preferences" => "users#preferences", constraints: { username: RouteFormats.username } }.merge(index == 1 ? { as: :email_preferences } : {}))- get "#{root_path}/:username/preferences/email" => "users_email#index", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/account" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/profile" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/emails" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/notifications" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/categories" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/tags" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/interface" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/apps" => "users#preferences", constraints: { username: RouteFormats.username }- put "#{root_path}/:username/preferences/email" => "users_email#update", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/about-me" => "users#preferences", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/badge_title" => "users#preferences", constraints: { username: RouteFormats.username }- put "#{root_path}/:username/preferences/badge_title" => "users#badge_title", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/username" => "users#preferences", constraints: { username: RouteFormats.username }- put "#{root_path}/:username/preferences/username" => "users#username", constraints: { username: RouteFormats.username }- delete "#{root_path}/:username/preferences/user_image" => "users#destroy_user_image", constraints: { username: RouteFormats.username }- put "#{root_path}/:username/preferences/avatar/pick" => "users#pick_avatar", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/preferences/card-badge" => "users#card_badge", constraints: { username: RouteFormats.username }- put "#{root_path}/:username/preferences/card-badge" => "users#update_card_badge", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/staff-info" => "users#staff_info", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/summary" => "users#summary", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/invited" => "users#invited", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/invited_count" => "users#invited_count", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/invited/:filter" => "users#invited", constraints: { username: RouteFormats.username }+ get "#{root_path}/:username/private-messages" => "user_actions#private_messages", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/private-messages/:filter" => "user_actions#private_messages", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/messages" => "user_actions#private_messages", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/messages/:filter" => "user_actions#private_messages", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: { username: RouteFormat.username, group_name: RouteFormat.username }+ get "#{root_path}/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: { username: RouteFormat.username, group_name: RouteFormat.username }+ get "#{root_path}/:username.json" => "users#show", constraints: { username: RouteFormat.username }, defaults: { format: :json }+ get({ "#{root_path}/:username" => "users#show", constraints: { username: RouteFormat.username, format: /(json|html)/ } }.merge(index == 1 ? { as: 'user' } : {}))+ put "#{root_path}/:username" => "users#update", constraints: { username: RouteFormat.username }, defaults: { format: :json }+ get "#{root_path}/:username/emails" => "users#check_emails", constraints: { username: RouteFormat.username }+ get({ "#{root_path}/:username/preferences" => "users#preferences", constraints: { username: RouteFormat.username } }.merge(index == 1 ? { as: :email_preferences } : {}))+ get "#{root_path}/:username/preferences/email" => "users_email#index", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/account" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/profile" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/emails" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/notifications" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/categories" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/tags" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/interface" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/apps" => "users#preferences", constraints: { username: RouteFormat.username }+ put "#{root_path}/:username/preferences/email" => "users_email#update", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/about-me" => "users#preferences", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/badge_title" => "users#preferences", constraints: { username: RouteFormat.username }+ put "#{root_path}/:username/preferences/badge_title" => "users#badge_title", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/username" => "users#preferences", constraints: { username: RouteFormat.username }+ put "#{root_path}/:username/preferences/username" => "users#username", constraints: { username: RouteFormat.username }+ delete "#{root_path}/:username/preferences/user_image" => "users#destroy_user_image", constraints: { username: RouteFormat.username }+ put "#{root_path}/:username/preferences/avatar/pick" => "users#pick_avatar", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/preferences/card-badge" => "users#card_badge", constraints: { username: RouteFormat.username }+ put "#{root_path}/:username/preferences/card-badge" => "users#update_card_badge", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/staff-info" => "users#staff_info", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/summary" => "users#summary", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/invited" => "users#invited", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/invited_count" => "users#invited_count", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/invited/:filter" => "users#invited", constraints: { username: RouteFormat.username }post "#{root_path}/action/send_activation_email" => "users#send_activation_email"- get "#{root_path}/:username/summary" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/activity/topics.rss" => "list#user_topics_feed", format: :rss, constraints: { username: RouteFormats.username }- get "#{root_path}/:username/activity.rss" => "posts#user_posts_feed", format: :rss, constraints: { username: RouteFormats.username }- get "#{root_path}/:username/activity" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/activity/:filter" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/badges" => "users#badges", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/notifications" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/notifications/:filter" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/activity/pending" => "users#show", constraints: { username: RouteFormats.username }- delete "#{root_path}/:username" => "users#destroy", constraints: { username: RouteFormats.username }+ get "#{root_path}/:username/summary" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/activity/topics.rss" => "list#user_topics_feed", format: :rss, constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/activity.rss" => "posts#user_posts_feed", format: :rss, constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/activity" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/activity/:filter" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/badges" => "users#badges", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/notifications" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/notifications/:filter" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/activity/pending" => "users#show", constraints: { username: RouteFormat.username }+ delete "#{root_path}/:username" => "users#destroy", constraints: { username: RouteFormat.username }get "#{root_path}/by-external/:external_id" => "users#show", constraints: { external_id: /[^\/]+/ }- get "#{root_path}/:username/flagged-posts" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/deleted-posts" => "users#show", constraints: { username: RouteFormats.username }- get "#{root_path}/:username/topic-tracking-state" => "users#topic_tracking_state", constraints: { username: RouteFormats.username }+ get "#{root_path}/:username/flagged-posts" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/deleted-posts" => "users#show", constraints: { username: RouteFormat.username }+ get "#{root_path}/:username/topic-tracking-state" => "users#topic_tracking_state", constraints: { username: RouteFormat.username }end- get "user-badges/:username.json" => "user_badges#username", constraints: { username: RouteFormats.username }, defaults: { format: :json }- get "user-badges/:username" => "user_badges#username", constraints: { username: RouteFormats.username }+ get "user-badges/:username.json" => "user_badges#username", constraints: { username: RouteFormat.username }, defaults: { format: :json }+ get "user-badges/:username" => "user_badges#username", constraints: { username: RouteFormat.username }- post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: { username: RouteFormats.username }- get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormats.username }- get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormats.username }+ post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: { username: RouteFormat.username }+ get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username }+ get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username }# in most production settings this is bypassedget "letter_avatar_proxy/:version/letter/:letter/:color/:size.png" => "user_avatars#show_proxy_letter"@@ -431,10 +431,10 @@ Discourse::Application.routes.draw doget "posts/by_number/:topic_id/:post_number" => "posts#by_number"get "posts/:id/reply-history" => "posts#reply_history"get "posts/:id/reply-ids" => "posts#reply_ids"- get "posts/:username/deleted" => "posts#deleted_posts", constraints: { username: RouteFormats.username }- get "posts/:username/flagged" => "posts#flagged_posts", constraints: { username: RouteFormats.username }+ get "posts/:username/deleted" => "posts#deleted_posts", constraints: { username: RouteFormat.username }+ get "posts/:username/flagged" => "posts#flagged_posts", constraints: { username: RouteFormat.username }- resources :groups, id: RouteFormats.username do+ resources :groups, id: RouteFormat.username doget "posts.rss" => "groups#posts_feed", format: :rssget "mentions.rss" => "groups#mentions_feed", format: :rss@@ -580,19 +580,19 @@ Discourse::Application.routes.draw doresources :similar_topicsget "topics/feature_stats"- get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: { username: RouteFormats.username }- get "topics/private-messages/:username" => "list#private_messages", as: "topics_private_messages", constraints: { username: RouteFormats.username }- get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: { username: RouteFormats.username }- get "topics/private-messages-archive/:username" => "list#private_messages_archive", as: "topics_private_messages_archive", constraints: { username: RouteFormats.username }- get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: { username: RouteFormats.username }+ get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: { username: RouteFormat.username }+ get "topics/private-messages/:username" => "list#private_messages", as: "topics_private_messages", constraints: { username: RouteFormat.username }+ get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: { username: RouteFormat.username }+ get "topics/private-messages-archive/:username" => "list#private_messages_archive", as: "topics_private_messages_archive", constraints: { username: RouteFormat.username }+ get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: { username: RouteFormat.username }get "topics/private-messages-group/:username/:group_name.json" => "list#private_messages_group", as: "topics_private_messages_group", constraints: {- username: RouteFormats.username,- group_name: RouteFormats.username+ username: RouteFormat.username,+ group_name: RouteFormat.username}get "topics/private-messages-group/:username/:group_name/archive.json" => "list#private_messages_group_archive", as: "topics_private_messages_group_archive", constraints: {- username: RouteFormats.username,- group_name: RouteFormats.username+ username: RouteFormat.username,+ group_name: RouteFormat.username}get 'embed/comments' => 'embed#comments'diff --git a/lib/route_formats.rb b/lib/route_format.rbsimilarity index 84%rename from lib/route_formats.rbrename to lib/route_format.rbindex 9278f879e3c..0ebd43fbdf0 100644--- a/lib/route_formats.rb+++ b/lib/route_format.rb@@ -1,4 +1,4 @@-module RouteFormats+module RouteFormatdef self.username/[\w.\-]+?/