2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Router do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2018-10-11 17:37:39 +02:00
|
|
|
Router for mobilizon app
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2020-01-26 21:36:50 +01:00
|
|
|
use Mobilizon.Web, :router
|
2022-03-29 11:27:53 +02:00
|
|
|
import Mobilizon.Web.RequestContext
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
pipeline :graphql do
|
2019-05-22 14:12:11 +02:00
|
|
|
# plug(:accepts, ["json"])
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2020-01-26 21:36:50 +01:00
|
|
|
plug(Mobilizon.Web.Auth.Pipeline)
|
2021-07-27 19:47:54 +02:00
|
|
|
plug(Mobilizon.Web.Plugs.SetLocalePlug)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2021-06-28 11:57:11 +02:00
|
|
|
pipeline :graphiql do
|
|
|
|
plug(Mobilizon.Web.Auth.Pipeline)
|
2021-07-27 19:47:54 +02:00
|
|
|
plug(Mobilizon.Web.Plugs.SetLocalePlug)
|
2021-06-28 11:57:11 +02:00
|
|
|
|
|
|
|
plug(Mobilizon.Web.Plugs.HTTPSecurityPlug,
|
2021-08-12 16:21:42 +02:00
|
|
|
script_src: ["cdn.jsdelivr.net 'sha256-zkCwvTwqwJMew/8TKv7bTLh94XRSNBvT/o/NZCuf5Kc='"],
|
|
|
|
style_src: ["cdn.jsdelivr.net 'unsafe-inline'"],
|
2021-06-28 11:57:11 +02:00
|
|
|
font_src: ["cdn.jsdelivr.net"]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-03-23 19:28:19 +01:00
|
|
|
pipeline :host_meta do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2021-03-23 19:28:19 +01:00
|
|
|
plug(:accepts, ["xrd-xml"])
|
|
|
|
end
|
|
|
|
|
2018-05-17 11:32:23 +02:00
|
|
|
pipeline :well_known do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2018-11-07 16:45:11 +01:00
|
|
|
plug(:accepts, ["json", "jrd-json"])
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
pipeline :activity_pub_signature do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2020-01-26 21:36:50 +01:00
|
|
|
plug(Mobilizon.Web.Plugs.HTTPSignatures)
|
|
|
|
plug(Mobilizon.Web.Plugs.MappedSignatureToIdentity)
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
2019-07-30 16:40:59 +02:00
|
|
|
pipeline :relay do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2020-01-26 21:36:50 +01:00
|
|
|
plug(Mobilizon.Web.Plugs.HTTPSignatures)
|
|
|
|
plug(Mobilizon.Web.Plugs.MappedSignatureToIdentity)
|
2019-07-30 16:40:59 +02:00
|
|
|
plug(:accepts, ["activity-json", "json"])
|
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
pipeline :activity_pub do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2019-03-04 17:20:18 +01:00
|
|
|
plug(:accepts, ["activity-json"])
|
|
|
|
end
|
|
|
|
|
|
|
|
pipeline :activity_pub_and_html do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2019-03-05 12:24:29 +01:00
|
|
|
plug(:accepts, ["html", "activity-json"])
|
2021-01-25 15:55:52 +01:00
|
|
|
plug(:put_secure_browser_headers)
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-07-27 19:47:54 +02:00
|
|
|
plug(Mobilizon.Web.Plugs.SetLocalePlug)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
plug(Cldr.Plug.AcceptLanguage,
|
2021-06-26 17:56:42 +02:00
|
|
|
cldr_backend: Mobilizon.Cldr,
|
|
|
|
no_match_log_level: :debug
|
2020-02-18 08:57:00 +01:00
|
|
|
)
|
2018-11-12 18:17:53 +01:00
|
|
|
end
|
|
|
|
|
2019-03-06 17:07:42 +01:00
|
|
|
pipeline :atom_and_ical do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2021-01-25 15:55:52 +01:00
|
|
|
plug(:put_secure_browser_headers)
|
2022-03-21 12:46:56 +01:00
|
|
|
plug(:accepts, ["atom", "ics", "html", "xml"])
|
2019-02-27 16:28:09 +01:00
|
|
|
end
|
|
|
|
|
2018-01-09 17:52:26 +01:00
|
|
|
pipeline :browser do
|
2022-03-29 11:27:53 +02:00
|
|
|
plug(:put_request_context)
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-07-27 19:47:54 +02:00
|
|
|
plug(Mobilizon.Web.Plugs.SetLocalePlug)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
plug(Cldr.Plug.AcceptLanguage,
|
2021-06-26 17:56:42 +02:00
|
|
|
cldr_backend: Mobilizon.Cldr,
|
|
|
|
no_match_log_level: :debug
|
2020-02-18 08:57:00 +01:00
|
|
|
)
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
plug(:accepts, ["html"])
|
2021-01-25 15:55:52 +01:00
|
|
|
plug(:put_secure_browser_headers)
|
2018-01-09 17:52:26 +01:00
|
|
|
end
|
|
|
|
|
2021-10-04 18:59:41 +02:00
|
|
|
scope "/exports", Mobilizon.Web do
|
|
|
|
pipe_through(:browser)
|
|
|
|
get("/:format/:file", ExportController, :export)
|
|
|
|
end
|
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
scope "/api" do
|
|
|
|
pipe_through(:graphql)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
forward("/", Absinthe.Plug,
|
2020-01-26 20:34:25 +01:00
|
|
|
schema: Mobilizon.GraphQL.Schema,
|
2019-11-15 18:36:47 +01:00
|
|
|
analyze_complexity: true,
|
2021-11-02 19:49:01 +01:00
|
|
|
max_complexity: 250
|
2019-11-15 18:36:47 +01:00
|
|
|
)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/.well-known", Mobilizon.Web do
|
2021-03-23 19:28:19 +01:00
|
|
|
pipe_through(:host_meta)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
get("/host-meta", WebFingerController, :host_meta)
|
2021-03-23 19:28:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scope "/.well-known", Mobilizon.Web do
|
|
|
|
pipe_through(:well_known)
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
get("/webfinger", WebFingerController, :webfinger)
|
2018-11-06 10:30:27 +01:00
|
|
|
get("/nodeinfo", NodeInfoController, :schemas)
|
|
|
|
get("/nodeinfo/:version", NodeInfoController, :nodeinfo)
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2019-03-04 17:20:18 +01:00
|
|
|
pipe_through(:activity_pub_and_html)
|
2019-12-03 11:29:51 +01:00
|
|
|
pipe_through(:activity_pub_signature)
|
|
|
|
|
2019-03-04 17:20:18 +01:00
|
|
|
get("/@:name", PageController, :actor)
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/events/me", PageController, :my_events)
|
2020-08-12 17:55:38 +02:00
|
|
|
get("/events/create", PageController, :create_event)
|
2023-12-11 00:30:39 +01:00
|
|
|
get("/events/calendar", PageController, :calendar)
|
2019-03-04 17:20:18 +01:00
|
|
|
get("/events/:uuid", PageController, :event)
|
|
|
|
get("/comments/:uuid", PageController, :comment)
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/resource/:uuid", PageController, :resource)
|
|
|
|
get("/todo-list/:uuid", PageController, :todo_list)
|
|
|
|
get("/todo/:uuid", PageController, :todo)
|
2020-07-09 17:24:28 +02:00
|
|
|
get("/@:name/todos", PageController, :todos)
|
2020-02-18 08:57:00 +01:00
|
|
|
get("/@:name/resources", PageController, :resources)
|
2020-07-09 17:24:28 +02:00
|
|
|
get("/@:name/posts", PageController, :posts)
|
|
|
|
get("/@:name/discussions", PageController, :discussions)
|
|
|
|
get("/@:name/events", PageController, :events)
|
|
|
|
get("/p/:slug", PageController, :post)
|
2023-10-17 16:41:31 +02:00
|
|
|
get("/conversations/:id", PageController, :conversation)
|
2020-07-09 17:24:28 +02:00
|
|
|
get("/@:name/c/:slug", PageController, :discussion)
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2019-02-27 16:28:09 +01:00
|
|
|
pipe_through(:activity_pub)
|
2020-07-09 17:24:28 +02:00
|
|
|
pipe_through(:activity_pub_signature)
|
2019-02-27 16:28:09 +01:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
get("/@:name/outbox", ActivityPubController, :outbox)
|
|
|
|
get("/@:name/following", ActivityPubController, :following)
|
|
|
|
get("/@:name/followers", ActivityPubController, :followers)
|
2020-02-18 08:57:00 +01:00
|
|
|
get("/@:name/members", ActivityPubController, :members)
|
2020-08-19 11:28:23 +02:00
|
|
|
get("/member/:uuid", ActivityPubController, :member)
|
2018-11-12 18:17:53 +01:00
|
|
|
end
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2018-11-12 18:17:53 +01:00
|
|
|
pipe_through(:activity_pub_signature)
|
2018-07-27 10:45:35 +02:00
|
|
|
post("/@:name/inbox", ActivityPubController, :inbox)
|
|
|
|
post("/inbox", ActivityPubController, :inbox)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
2018-01-09 17:52:26 +01:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/relay", Mobilizon.Web do
|
2019-07-30 16:40:59 +02:00
|
|
|
pipe_through(:relay)
|
|
|
|
|
|
|
|
get("/", ActivityPubController, :relay)
|
|
|
|
post("/inbox", ActivityPubController, :inbox)
|
|
|
|
end
|
|
|
|
|
2020-01-23 21:59:50 +01:00
|
|
|
## FEED
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2020-01-23 21:59:50 +01:00
|
|
|
pipe_through(:atom_and_ical)
|
|
|
|
|
|
|
|
get("/@:name/feed/:format", FeedController, :actor)
|
|
|
|
get("/events/:uuid/export/:format", FeedController, :event)
|
|
|
|
get("/events/going/:token/:format", FeedController, :going)
|
2021-03-26 15:40:10 +01:00
|
|
|
get("/feed/instance/:format", FeedController, :instance)
|
2020-01-23 21:59:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
## MOBILIZON
|
2019-12-20 13:04:34 +01:00
|
|
|
scope "/graphiql" do
|
2021-06-28 11:57:11 +02:00
|
|
|
pipe_through(:graphiql)
|
|
|
|
|
2021-06-28 11:57:27 +02:00
|
|
|
forward("/", Absinthe.Plug.GraphiQL,
|
|
|
|
schema: Mobilizon.GraphQL.Schema,
|
2023-10-17 16:41:31 +02:00
|
|
|
socket: Mobilizon.Web.GraphQLSocket,
|
2021-06-28 11:57:27 +02:00
|
|
|
interface: :playground
|
|
|
|
)
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
2020-01-23 21:59:50 +01:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2020-01-23 21:59:50 +01:00
|
|
|
pipe_through(:browser)
|
|
|
|
|
|
|
|
# Because the "/events/:uuid" route caches all these, we need to force them
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/events/create", PageController, :create_event)
|
|
|
|
get("/events/list", PageController, :list_events)
|
|
|
|
get("/events/me", PageController, :my_events)
|
|
|
|
get("/events/:uuid/edit", PageController, :edit_event)
|
2020-01-23 21:59:50 +01:00
|
|
|
|
|
|
|
# This is a hack to ease link generation into emails
|
2020-09-30 15:25:30 +02:00
|
|
|
get("/moderation/report/:id", PageController, :moderation_report)
|
2019-12-20 13:04:34 +01:00
|
|
|
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/participation/email/confirm/:token", PageController, :participation_email_confirmation)
|
|
|
|
|
2023-12-01 09:52:28 +01:00
|
|
|
get(
|
|
|
|
"/participation/email/cancel/:uuid/:token",
|
|
|
|
PageController,
|
|
|
|
:participation_email_cancellation
|
|
|
|
)
|
|
|
|
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/validate/email/:token", PageController, :user_email_validation)
|
2019-12-20 13:04:34 +01:00
|
|
|
|
2020-08-12 16:05:34 +02:00
|
|
|
get("/groups/me", PageController, :my_groups)
|
2020-02-13 15:48:12 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
get("/interact", PageController, :interact)
|
2020-06-27 19:12:45 +02:00
|
|
|
|
|
|
|
get("/auth/:provider", AuthController, :request)
|
2021-01-22 19:11:13 +01:00
|
|
|
# Have a look at https://github.com/ueberauth/ueberauth/issues/125 some day
|
|
|
|
# Also possible CSRF issue
|
2020-06-27 19:12:45 +02:00
|
|
|
get("/auth/:provider/callback", AuthController, :callback)
|
|
|
|
post("/auth/:provider/callback", AuthController, :callback)
|
2023-02-15 19:31:23 +01:00
|
|
|
|
|
|
|
post("/apps", ApplicationController, :create_application)
|
|
|
|
get("/oauth/authorize", ApplicationController, :authorize)
|
|
|
|
get("/oauth/autorize_approve", PageController, :authorize)
|
2023-02-21 14:50:09 +01:00
|
|
|
get("/login/device", PageController, :auth_device)
|
|
|
|
end
|
|
|
|
|
|
|
|
pipeline :login do
|
|
|
|
plug(:accepts, ["html", "json"])
|
|
|
|
end
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2023-02-21 14:50:09 +01:00
|
|
|
pipe_through(:login)
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
post("/login/device/code", ApplicationController, :device_code)
|
|
|
|
post("/oauth/token", ApplicationController, :generate_access_token)
|
2023-03-23 18:37:53 +01:00
|
|
|
post("/oauth/revoke", ApplicationController, :revoke_token)
|
2020-01-23 21:59:50 +01:00
|
|
|
end
|
|
|
|
|
2021-01-26 10:05:01 +01:00
|
|
|
scope "/proxy/", Mobilizon.Web do
|
|
|
|
get("/:sig/:url", MediaProxyController, :remote)
|
|
|
|
get("/:sig/:url/:filename", MediaProxyController, :remote)
|
|
|
|
end
|
|
|
|
|
2022-09-21 08:53:50 +02:00
|
|
|
if Application.compile_env(:mobilizon, :env) in [:dev, :e2e] do
|
2018-07-04 14:29:17 +02:00
|
|
|
# If using Phoenix
|
2022-04-05 12:16:22 +02:00
|
|
|
forward("/sent_emails", Plug.Swoosh.MailboxPreview)
|
2018-07-04 14:29:17 +02:00
|
|
|
end
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
scope "/", Mobilizon.Web do
|
2018-07-27 10:45:35 +02:00
|
|
|
pipe_through(:browser)
|
2018-01-09 17:52:26 +01:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
get("/*path", PageController, :index)
|
2018-01-09 17:52:26 +01:00
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|