[Pleroma.Plugs.UserIsAdminPlug]: Check if admin is true instead of false, fix error...
[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
102 # Maybe put a "rights" endpoint instead?
103 post("/moderator", AdminAPIController, :moderator_make)
104 delete("/moderator", AdminAPIController, :moderator_unmake)
105 post("/admin", AdminAPIController, :admin_make)
106 delete("/admin", AdminAPIController, :admin_unmake)
107
108 post("/relay", AdminAPIController, :relay_follow)
109 delete("/relay", AdminAPIController, :relay_unfollow)
110
111 get("/invite_token", AdminAPIController, :get_invite_token)
112 get("/password_reset", AdminAPIController, :get_password_reset)
113 end
114
115 scope "/", Pleroma.Web.TwitterAPI do
116 pipe_through(:pleroma_html)
117 get("/ostatus_subscribe", UtilController, :remote_follow)
118 post("/ostatus_subscribe", UtilController, :do_remote_follow)
119 post("/main/ostatus", UtilController, :remote_subscribe)
120 end
121
122 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
123 pipe_through(:authenticated_api)
124 post("/follow_import", UtilController, :follow_import)
125 post("/change_password", UtilController, :change_password)
126 post("/delete_account", UtilController, :delete_account)
127 end
128
129 scope "/oauth", Pleroma.Web.OAuth do
130 get("/authorize", OAuthController, :authorize)
131 post("/authorize", OAuthController, :create_authorization)
132 post("/token", OAuthController, :token_exchange)
133 post("/revoke", OAuthController, :token_revoke)
134 end
135
136 scope "/api/v1", Pleroma.Web.MastodonAPI do
137 pipe_through(:authenticated_api)
138
139 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
140 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
141 get("/accounts/relationships", MastodonAPIController, :relationships)
142 get("/accounts/search", MastodonAPIController, :account_search)
143 post("/accounts/:id/follow", MastodonAPIController, :follow)
144 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
145 post("/accounts/:id/block", MastodonAPIController, :block)
146 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
147 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
148 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
149 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
150
151 get("/follow_requests", MastodonAPIController, :follow_requests)
152 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
153 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
154
155 post("/follows", MastodonAPIController, :follow)
156
157 get("/blocks", MastodonAPIController, :blocks)
158
159 get("/mutes", MastodonAPIController, :empty_array)
160
161 get("/timelines/home", MastodonAPIController, :home_timeline)
162
163 get("/timelines/direct", MastodonAPIController, :dm_timeline)
164
165 get("/favourites", MastodonAPIController, :favourites)
166
167 post("/statuses", MastodonAPIController, :post_status)
168 delete("/statuses/:id", MastodonAPIController, :delete_status)
169
170 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
171 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
172 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
173 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
174
175 post("/notifications/clear", MastodonAPIController, :clear_notifications)
176 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
177 get("/notifications", MastodonAPIController, :notifications)
178 get("/notifications/:id", MastodonAPIController, :get_notification)
179
180 post("/media", MastodonAPIController, :upload)
181 put("/media/:id", MastodonAPIController, :update_media)
182
183 get("/lists", MastodonAPIController, :get_lists)
184 get("/lists/:id", MastodonAPIController, :get_list)
185 delete("/lists/:id", MastodonAPIController, :delete_list)
186 post("/lists", MastodonAPIController, :create_list)
187 put("/lists/:id", MastodonAPIController, :rename_list)
188 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
189 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
190 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
191
192 get("/domain_blocks", MastodonAPIController, :domain_blocks)
193 post("/domain_blocks", MastodonAPIController, :block_domain)
194 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
195
196 get("/filters", MastodonAPIController, :get_filters)
197 post("/filters", MastodonAPIController, :create_filter)
198 get("/filters/:id", MastodonAPIController, :get_filter)
199 put("/filters/:id", MastodonAPIController, :update_filter)
200 delete("/filters/:id", MastodonAPIController, :delete_filter)
201
202 get("/suggestions", MastodonAPIController, :suggestions)
203
204 get("/endorsements", MastodonAPIController, :empty_array)
205 end
206
207 scope "/api/web", Pleroma.Web.MastodonAPI do
208 pipe_through(:authenticated_api)
209
210 put("/settings", MastodonAPIController, :put_settings)
211 end
212
213 scope "/api/v1", Pleroma.Web.MastodonAPI do
214 pipe_through(:api)
215 get("/instance", MastodonAPIController, :masto_instance)
216 get("/instance/peers", MastodonAPIController, :peers)
217 post("/apps", MastodonAPIController, :create_app)
218 get("/custom_emojis", MastodonAPIController, :custom_emojis)
219
220 get("/timelines/public", MastodonAPIController, :public_timeline)
221 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
222 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
223
224 get("/statuses/:id", MastodonAPIController, :get_status)
225 get("/statuses/:id/context", MastodonAPIController, :get_context)
226 get("/statuses/:id/card", MastodonAPIController, :empty_object)
227 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
228 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
229
230 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
231 get("/accounts/:id/followers", MastodonAPIController, :followers)
232 get("/accounts/:id/following", MastodonAPIController, :following)
233 get("/accounts/:id", MastodonAPIController, :user)
234
235 get("/trends", MastodonAPIController, :empty_array)
236
237 get("/search", MastodonAPIController, :search)
238 end
239
240 scope "/api/v2", Pleroma.Web.MastodonAPI do
241 pipe_through(:api)
242 get("/search", MastodonAPIController, :search2)
243 end
244
245 scope "/api", Pleroma.Web do
246 pipe_through(:config)
247
248 get("/help/test", TwitterAPI.UtilController, :help_test)
249 post("/help/test", TwitterAPI.UtilController, :help_test)
250 get("/statusnet/config", TwitterAPI.UtilController, :config)
251 get("/statusnet/version", TwitterAPI.UtilController, :version)
252 end
253
254 scope "/api", Pleroma.Web do
255 pipe_through(:api)
256
257 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
258 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
259 get("/users/show", TwitterAPI.Controller, :show_user)
260
261 get("/statuses/followers", TwitterAPI.Controller, :followers)
262 get("/statuses/friends", TwitterAPI.Controller, :friends)
263 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
264 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
265
266 post("/account/register", TwitterAPI.Controller, :register)
267
268 get("/search", TwitterAPI.Controller, :search)
269 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
270 end
271
272 scope "/api", Pleroma.Web do
273 pipe_through(:api)
274
275 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
276
277 get(
278 "/statuses/public_and_external_timeline",
279 TwitterAPI.Controller,
280 :public_and_external_timeline
281 )
282
283 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
284 end
285
286 scope "/api", Pleroma.Web, as: :twitter_api_search do
287 pipe_through(:api)
288 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
289 end
290
291 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
292 pipe_through(:authenticated_api)
293
294 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
295 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
296
297 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
298 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
299 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
300
301 post(
302 "/account/most_recent_notification",
303 TwitterAPI.Controller,
304 :update_most_recent_notification
305 )
306
307 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
308 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
309 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
310 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
311 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
312 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
313
314 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
315 # for now.
316 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
317
318 post("/statuses/update", TwitterAPI.Controller, :status_update)
319 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
320 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
321 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
322
323 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
324 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
325 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
326
327 post("/friendships/create", TwitterAPI.Controller, :follow)
328 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
329 post("/blocks/create", TwitterAPI.Controller, :block)
330 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
331
332 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
333 post("/media/upload", TwitterAPI.Controller, :upload_json)
334
335 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
336 post("/favorites/create", TwitterAPI.Controller, :favorite)
337 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
338
339 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
340
341 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
342 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
343
344 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
345 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
346
347 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
348 end
349
350 pipeline :ap_relay do
351 plug(:accepts, ["activity+json"])
352 end
353
354 pipeline :ostatus do
355 plug(:accepts, ["xml", "atom", "html", "activity+json"])
356 end
357
358 scope "/", Pleroma.Web do
359 pipe_through(:ostatus)
360
361 get("/objects/:uuid", OStatus.OStatusController, :object)
362 get("/activities/:uuid", OStatus.OStatusController, :activity)
363 get("/notice/:id", OStatus.OStatusController, :notice)
364 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
365 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
366
367 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
368 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
369 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
370 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
371 end
372
373 pipeline :activitypub do
374 plug(:accepts, ["activity+json"])
375 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
376 end
377
378 scope "/", Pleroma.Web.ActivityPub do
379 # XXX: not really ostatus
380 pipe_through(:ostatus)
381
382 get("/users/:nickname/followers", ActivityPubController, :followers)
383 get("/users/:nickname/following", ActivityPubController, :following)
384 get("/users/:nickname/outbox", ActivityPubController, :outbox)
385 end
386
387 scope "/relay", Pleroma.Web.ActivityPub do
388 pipe_through(:ap_relay)
389 get("/", ActivityPubController, :relay)
390 end
391
392 scope "/", Pleroma.Web.ActivityPub do
393 pipe_through(:activitypub)
394 post("/users/:nickname/inbox", ActivityPubController, :inbox)
395 post("/inbox", ActivityPubController, :inbox)
396 end
397
398 scope "/.well-known", Pleroma.Web do
399 pipe_through(:well_known)
400
401 get("/host-meta", WebFinger.WebFingerController, :host_meta)
402 get("/webfinger", WebFinger.WebFingerController, :webfinger)
403 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
404 end
405
406 scope "/nodeinfo", Pleroma.Web do
407 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
408 end
409
410 scope "/", Pleroma.Web.MastodonAPI do
411 pipe_through(:mastodon_html)
412
413 get("/web/login", MastodonAPIController, :login)
414 post("/web/login", MastodonAPIController, :login_post)
415 get("/web/*path", MastodonAPIController, :index)
416 delete("/auth/sign_out", MastodonAPIController, :logout)
417 end
418
419 pipeline :remote_media do
420 end
421
422 scope "/proxy/", Pleroma.Web.MediaProxy do
423 pipe_through(:remote_media)
424 get("/:sig/:url", MediaProxyController, :remote)
425 get("/:sig/:url/:filename", MediaProxyController, :remote)
426 end
427
428 scope "/", Fallback do
429 get("/registration/:token", RedirectController, :registration_page)
430 get("/*path", RedirectController, :redirector)
431
432 options("/*path", RedirectController, :empty)
433 end
434 end
435
436 defmodule Fallback.RedirectController do
437 use Pleroma.Web, :controller
438
439 def redirector(conn, _params) do
440 if Mix.env() != :test do
441 conn
442 |> put_resp_content_type("text/html")
443 |> send_file(200, "priv/static/index.html")
444 end
445 end
446
447 def registration_page(conn, params) do
448 redirector(conn, params)
449 end
450
451 def empty(conn, _params) do
452 conn
453 |> put_status(204)
454 |> text("")
455 end
456 end