[#394] Refactoring (using Ecto.Multi; "untag" route change).
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 alias Pleroma.{Repo, User, Web.Router}
5
6 pipeline :api do
7 plug(:accepts, ["json"])
8 plug(:fetch_session)
9 plug(Pleroma.Plugs.OAuthPlug)
10 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
11 plug(Pleroma.Plugs.UserFetcherPlug)
12 plug(Pleroma.Plugs.SessionAuthenticationPlug)
13 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
14 plug(Pleroma.Plugs.AuthenticationPlug)
15 plug(Pleroma.Plugs.UserEnabledPlug)
16 plug(Pleroma.Plugs.SetUserSessionIdPlug)
17 plug(Pleroma.Plugs.EnsureUserKeyPlug)
18 end
19
20 pipeline :authenticated_api do
21 plug(:accepts, ["json"])
22 plug(:fetch_session)
23 plug(Pleroma.Plugs.OAuthPlug)
24 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
25 plug(Pleroma.Plugs.UserFetcherPlug)
26 plug(Pleroma.Plugs.SessionAuthenticationPlug)
27 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
28 plug(Pleroma.Plugs.AuthenticationPlug)
29 plug(Pleroma.Plugs.UserEnabledPlug)
30 plug(Pleroma.Plugs.SetUserSessionIdPlug)
31 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
32 end
33
34 pipeline :admin_api do
35 plug(:accepts, ["json"])
36 plug(:fetch_session)
37 plug(Pleroma.Plugs.OAuthPlug)
38 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
39 plug(Pleroma.Plugs.UserFetcherPlug)
40 plug(Pleroma.Plugs.SessionAuthenticationPlug)
41 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
42 plug(Pleroma.Plugs.AuthenticationPlug)
43 plug(Pleroma.Plugs.UserEnabledPlug)
44 plug(Pleroma.Plugs.SetUserSessionIdPlug)
45 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
46 plug(Pleroma.Plugs.UserIsAdminPlug)
47 end
48
49 pipeline :mastodon_html do
50 plug(:accepts, ["html"])
51 plug(:fetch_session)
52 plug(Pleroma.Plugs.OAuthPlug)
53 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
54 plug(Pleroma.Plugs.UserFetcherPlug)
55 plug(Pleroma.Plugs.SessionAuthenticationPlug)
56 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
57 plug(Pleroma.Plugs.AuthenticationPlug)
58 plug(Pleroma.Plugs.UserEnabledPlug)
59 plug(Pleroma.Plugs.SetUserSessionIdPlug)
60 plug(Pleroma.Plugs.EnsureUserKeyPlug)
61 end
62
63 pipeline :pleroma_html do
64 plug(:accepts, ["html"])
65 plug(:fetch_session)
66 plug(Pleroma.Plugs.OAuthPlug)
67 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
68 plug(Pleroma.Plugs.UserFetcherPlug)
69 plug(Pleroma.Plugs.SessionAuthenticationPlug)
70 plug(Pleroma.Plugs.AuthenticationPlug)
71 plug(Pleroma.Plugs.EnsureUserKeyPlug)
72 end
73
74 pipeline :well_known do
75 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
76 end
77
78 pipeline :config do
79 plug(:accepts, ["json", "xml"])
80 end
81
82 pipeline :oauth do
83 plug(:accepts, ["html", "json"])
84 end
85
86 pipeline :pleroma_api do
87 plug(:accepts, ["html", "json"])
88 end
89
90 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
91 pipe_through(:pleroma_api)
92 get("/password_reset/:token", UtilController, :show_password_reset)
93 post("/password_reset", UtilController, :password_reset)
94 get("/emoji", UtilController, :emoji)
95 end
96
97 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
98 pipe_through(:admin_api)
99 delete("/user", AdminAPIController, :user_delete)
100 post("/user", AdminAPIController, :user_create)
101 put("/users/tag", AdminAPIController, :tag_users)
102 delete("/users/tag", AdminAPIController, :untag_users)
103
104 get("/permission_group/:nickname", AdminAPIController, :right_get)
105 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
106 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
107 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
108
109 post("/relay", AdminAPIController, :relay_follow)
110 delete("/relay", AdminAPIController, :relay_unfollow)
111
112 get("/invite_token", AdminAPIController, :get_invite_token)
113 get("/password_reset", AdminAPIController, :get_password_reset)
114 end
115
116 scope "/", Pleroma.Web.TwitterAPI do
117 pipe_through(:pleroma_html)
118 get("/ostatus_subscribe", UtilController, :remote_follow)
119 post("/ostatus_subscribe", UtilController, :do_remote_follow)
120 post("/main/ostatus", UtilController, :remote_subscribe)
121 end
122
123 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
124 pipe_through(:authenticated_api)
125 post("/follow_import", UtilController, :follow_import)
126 post("/change_password", UtilController, :change_password)
127 post("/delete_account", UtilController, :delete_account)
128 end
129
130 scope "/oauth", Pleroma.Web.OAuth do
131 get("/authorize", OAuthController, :authorize)
132 post("/authorize", OAuthController, :create_authorization)
133 post("/token", OAuthController, :token_exchange)
134 post("/revoke", OAuthController, :token_revoke)
135 end
136
137 scope "/api/v1", Pleroma.Web.MastodonAPI do
138 pipe_through(:authenticated_api)
139
140 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
141 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
142 get("/accounts/relationships", MastodonAPIController, :relationships)
143 get("/accounts/search", MastodonAPIController, :account_search)
144 post("/accounts/:id/follow", MastodonAPIController, :follow)
145 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
146 post("/accounts/:id/block", MastodonAPIController, :block)
147 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
148 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
149 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
150 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
151
152 get("/follow_requests", MastodonAPIController, :follow_requests)
153 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
154 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
155
156 post("/follows", MastodonAPIController, :follow)
157
158 get("/blocks", MastodonAPIController, :blocks)
159
160 get("/mutes", MastodonAPIController, :empty_array)
161
162 get("/timelines/home", MastodonAPIController, :home_timeline)
163
164 get("/timelines/direct", MastodonAPIController, :dm_timeline)
165
166 get("/favourites", MastodonAPIController, :favourites)
167
168 post("/statuses", MastodonAPIController, :post_status)
169 delete("/statuses/:id", MastodonAPIController, :delete_status)
170
171 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
172 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
173 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
174 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
175
176 post("/notifications/clear", MastodonAPIController, :clear_notifications)
177 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
178 get("/notifications", MastodonAPIController, :notifications)
179 get("/notifications/:id", MastodonAPIController, :get_notification)
180
181 post("/media", MastodonAPIController, :upload)
182 put("/media/:id", MastodonAPIController, :update_media)
183
184 get("/lists", MastodonAPIController, :get_lists)
185 get("/lists/:id", MastodonAPIController, :get_list)
186 delete("/lists/:id", MastodonAPIController, :delete_list)
187 post("/lists", MastodonAPIController, :create_list)
188 put("/lists/:id", MastodonAPIController, :rename_list)
189 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
190 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
191 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
192
193 get("/domain_blocks", MastodonAPIController, :domain_blocks)
194 post("/domain_blocks", MastodonAPIController, :block_domain)
195 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
196
197 get("/filters", MastodonAPIController, :get_filters)
198 post("/filters", MastodonAPIController, :create_filter)
199 get("/filters/:id", MastodonAPIController, :get_filter)
200 put("/filters/:id", MastodonAPIController, :update_filter)
201 delete("/filters/:id", MastodonAPIController, :delete_filter)
202
203 get("/suggestions", MastodonAPIController, :suggestions)
204
205 get("/endorsements", MastodonAPIController, :empty_array)
206 end
207
208 scope "/api/web", Pleroma.Web.MastodonAPI do
209 pipe_through(:authenticated_api)
210
211 put("/settings", MastodonAPIController, :put_settings)
212 end
213
214 scope "/api/v1", Pleroma.Web.MastodonAPI do
215 pipe_through(:api)
216 get("/instance", MastodonAPIController, :masto_instance)
217 get("/instance/peers", MastodonAPIController, :peers)
218 post("/apps", MastodonAPIController, :create_app)
219 get("/custom_emojis", MastodonAPIController, :custom_emojis)
220
221 get("/timelines/public", MastodonAPIController, :public_timeline)
222 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
223 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
224
225 get("/statuses/:id", MastodonAPIController, :get_status)
226 get("/statuses/:id/context", MastodonAPIController, :get_context)
227 get("/statuses/:id/card", MastodonAPIController, :empty_object)
228 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
229 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
230
231 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
232 get("/accounts/:id/followers", MastodonAPIController, :followers)
233 get("/accounts/:id/following", MastodonAPIController, :following)
234 get("/accounts/:id", MastodonAPIController, :user)
235
236 get("/trends", MastodonAPIController, :empty_array)
237
238 get("/search", MastodonAPIController, :search)
239 end
240
241 scope "/api/v2", Pleroma.Web.MastodonAPI do
242 pipe_through(:api)
243 get("/search", MastodonAPIController, :search2)
244 end
245
246 scope "/api", Pleroma.Web do
247 pipe_through(:config)
248
249 get("/help/test", TwitterAPI.UtilController, :help_test)
250 post("/help/test", TwitterAPI.UtilController, :help_test)
251 get("/statusnet/config", TwitterAPI.UtilController, :config)
252 get("/statusnet/version", TwitterAPI.UtilController, :version)
253 end
254
255 scope "/api", Pleroma.Web do
256 pipe_through(:api)
257
258 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
259 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
260 get("/users/show", TwitterAPI.Controller, :show_user)
261
262 get("/statuses/followers", TwitterAPI.Controller, :followers)
263 get("/statuses/friends", TwitterAPI.Controller, :friends)
264 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
265 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
266
267 post("/account/register", TwitterAPI.Controller, :register)
268
269 get("/search", TwitterAPI.Controller, :search)
270 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
271 end
272
273 scope "/api", Pleroma.Web do
274 pipe_through(:api)
275
276 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
277
278 get(
279 "/statuses/public_and_external_timeline",
280 TwitterAPI.Controller,
281 :public_and_external_timeline
282 )
283
284 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
285 end
286
287 scope "/api", Pleroma.Web, as: :twitter_api_search do
288 pipe_through(:api)
289 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
290 end
291
292 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
293 pipe_through(:authenticated_api)
294
295 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
296 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
297
298 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
299 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
300 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
301
302 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
303 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
304 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
305 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
306 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
307 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
308
309 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
310 # for now.
311 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
312
313 post("/statuses/update", TwitterAPI.Controller, :status_update)
314 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
315 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
316 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
317
318 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
319 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
320 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
321
322 post("/friendships/create", TwitterAPI.Controller, :follow)
323 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
324 post("/blocks/create", TwitterAPI.Controller, :block)
325 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
326
327 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
328 post("/media/upload", TwitterAPI.Controller, :upload_json)
329 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
330
331 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
332 post("/favorites/create", TwitterAPI.Controller, :favorite)
333 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
334
335 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
336
337 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
338 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
339
340 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
341 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
342
343 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
344 end
345
346 pipeline :ap_relay do
347 plug(:accepts, ["activity+json"])
348 end
349
350 pipeline :ostatus do
351 plug(:accepts, ["xml", "atom", "html", "activity+json"])
352 end
353
354 scope "/", Pleroma.Web do
355 pipe_through(:ostatus)
356
357 get("/objects/:uuid", OStatus.OStatusController, :object)
358 get("/activities/:uuid", OStatus.OStatusController, :activity)
359 get("/notice/:id", OStatus.OStatusController, :notice)
360 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
361 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
362
363 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
364 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
365 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
366 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
367 end
368
369 pipeline :activitypub do
370 plug(:accepts, ["activity+json"])
371 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
372 end
373
374 scope "/", Pleroma.Web.ActivityPub do
375 # XXX: not really ostatus
376 pipe_through(:ostatus)
377
378 get("/users/:nickname/followers", ActivityPubController, :followers)
379 get("/users/:nickname/following", ActivityPubController, :following)
380 get("/users/:nickname/outbox", ActivityPubController, :outbox)
381 end
382
383 scope "/relay", Pleroma.Web.ActivityPub do
384 pipe_through(:ap_relay)
385 get("/", ActivityPubController, :relay)
386 end
387
388 scope "/", Pleroma.Web.ActivityPub do
389 pipe_through(:activitypub)
390 post("/users/:nickname/inbox", ActivityPubController, :inbox)
391 post("/inbox", ActivityPubController, :inbox)
392 end
393
394 scope "/.well-known", Pleroma.Web do
395 pipe_through(:well_known)
396
397 get("/host-meta", WebFinger.WebFingerController, :host_meta)
398 get("/webfinger", WebFinger.WebFingerController, :webfinger)
399 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
400 end
401
402 scope "/nodeinfo", Pleroma.Web do
403 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
404 end
405
406 scope "/", Pleroma.Web.MastodonAPI do
407 pipe_through(:mastodon_html)
408
409 get("/web/login", MastodonAPIController, :login)
410 post("/web/login", MastodonAPIController, :login_post)
411 get("/web/*path", MastodonAPIController, :index)
412 delete("/auth/sign_out", MastodonAPIController, :logout)
413 end
414
415 pipeline :remote_media do
416 end
417
418 scope "/proxy/", Pleroma.Web.MediaProxy do
419 pipe_through(:remote_media)
420 get("/:sig/:url", MediaProxyController, :remote)
421 get("/:sig/:url/:filename", MediaProxyController, :remote)
422 end
423
424 scope "/", Fallback do
425 get("/registration/:token", RedirectController, :registration_page)
426 get("/*path", RedirectController, :redirector)
427
428 options("/*path", RedirectController, :empty)
429 end
430 end
431
432 defmodule Fallback.RedirectController do
433 use Pleroma.Web, :controller
434
435 def redirector(conn, _params) do
436 conn
437 |> put_resp_content_type("text/html")
438 |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html"))
439 end
440
441 def registration_page(conn, params) do
442 redirector(conn, params)
443 end
444
445 def empty(conn, _params) do
446 conn
447 |> put_status(204)
448 |> text("")
449 end
450 end