Make tests great again !
(Also use only one field for public/private key pem) Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -17,8 +17,8 @@ defmodule EventosWeb.ActivityPubController do
|
||||
end
|
||||
end
|
||||
|
||||
def event(conn, %{"name" => name, "slug" => slug}) do
|
||||
with %Event{} = event <- Events.get_event_full_by_name_and_slug!(name, slug) do
|
||||
def event(conn, %{"uuid" => uuid}) do
|
||||
with %Event{} = event <- Events.get_event_full_by_uuid(uuid) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ObjectView.render("event.json", %{event: event}))
|
||||
|
||||
@@ -2,7 +2,7 @@ defmodule EventosWeb.BotController do
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Actors
|
||||
alias Eventos.Actors.Bot
|
||||
alias Eventos.Actors.{Bot, Actor}
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
@@ -12,9 +12,9 @@ defmodule EventosWeb.BotController do
|
||||
end
|
||||
|
||||
def create(conn, %{"bot" => bot_params}) do
|
||||
with user <- Guardian.Plug.current_resource,
|
||||
with user <- Guardian.Plug.current_resource(conn),
|
||||
bot_params <- Map.put(bot_params, "user_id", user.id),
|
||||
{:ok, actor} <- Actors.register_bot_account(%{name: bot_params["name"], summary: bot_params["summary"]}),
|
||||
%Actor{} = actor <- Actors.register_bot_account(%{name: bot_params["name"], summary: bot_params["summary"]}),
|
||||
bot_params <- Map.put(bot_params, "actor_id", actor.id),
|
||||
{:ok, %Bot{} = bot} <- Actors.create_bot(bot_params) do
|
||||
conn
|
||||
|
||||
@@ -20,21 +20,21 @@ defmodule EventosWeb.CommentController do
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
comment = Events.get_comment!(id)
|
||||
def show(conn, %{"uuid" => uuid}) do
|
||||
comment = Events.get_comment_with_uuid!(uuid)
|
||||
render(conn, "show.json", comment: comment)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "comment" => comment_params}) do
|
||||
comment = Events.get_comment!(id)
|
||||
def update(conn, %{"uuid" => uuid, "comment" => comment_params}) do
|
||||
comment = Events.get_comment_with_uuid!(uuid)
|
||||
|
||||
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, comment_params) do
|
||||
render(conn, "show.json", comment: comment)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
comment = Events.get_comment!(id)
|
||||
def delete(conn, %{"uuid" => uuid}) do
|
||||
comment = Events.get_comment_with_uuid!(uuid)
|
||||
with {:ok, %Comment{}} <- Events.delete_comment(comment) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
|
||||
@@ -9,6 +9,8 @@ defmodule EventosWeb.EventController do
|
||||
alias Eventos.Export.ICalendar
|
||||
alias Eventos.Addresses
|
||||
|
||||
import Logger
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
@@ -32,11 +34,7 @@ defmodule EventosWeb.EventController do
|
||||
end
|
||||
|
||||
defp process_address(address) do
|
||||
import Logger
|
||||
Logger.debug("process address")
|
||||
Logger.debug(inspect address)
|
||||
geom = EventosWeb.AddressController.process_geom(address["geom"])
|
||||
Logger.debug(inspect geom)
|
||||
case geom do
|
||||
nil ->
|
||||
address
|
||||
@@ -53,8 +51,12 @@ defmodule EventosWeb.EventController do
|
||||
end
|
||||
|
||||
def show(conn, %{"uuid" => uuid}) do
|
||||
event = Events.get_event_full_by_uuid(uuid)
|
||||
render(conn, "show.json", event: event)
|
||||
case Events.get_event_full_by_uuid(uuid) do
|
||||
nil ->
|
||||
send_resp(conn, 404, "")
|
||||
event ->
|
||||
render(conn, "show.json", event: event)
|
||||
end
|
||||
end
|
||||
|
||||
def export_to_ics(conn, %{"uuid" => uuid}) do
|
||||
@@ -71,8 +73,8 @@ defmodule EventosWeb.EventController do
|
||||
end
|
||||
|
||||
def delete(conn, %{"uuid" => uuid}) do
|
||||
event = Events.get_event_by_uuid(uuid)
|
||||
with {:ok, %Event{}} <- Events.delete_event(event) do
|
||||
with event <- Events.get_event_by_uuid(uuid),
|
||||
{:ok, %Event{}} <- Events.delete_event(event) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,8 +28,8 @@ defmodule EventosWeb.SessionController do
|
||||
render(conn, "show.json", session: session)
|
||||
end
|
||||
|
||||
def show_sessions_for_event(conn, %{"id" => event_id}) do
|
||||
sessions = Events.list_sessions_for_event(event_id)
|
||||
def show_sessions_for_event(conn, %{"uuid" => event_uuid}) do
|
||||
sessions = Events.list_sessions_for_event(event_uuid)
|
||||
render(conn, "index.json", sessions: sessions)
|
||||
end
|
||||
|
||||
|
||||
@@ -16,16 +16,11 @@ defmodule EventosWeb.UserController do
|
||||
end
|
||||
|
||||
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
|
||||
case Actors.register(%{email: email, password: password, username: username}) do
|
||||
{:ok, %User{} = user} ->
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
with {:ok, %User{} = user} <- Actors.register(%{email: email, password: password, username: username}),
|
||||
{:ok, token, _claims} <- EventosWeb.Guardian.encode_and_sign(user) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> render("show_with_token.json", %{token: token, user: user})
|
||||
{:error, error} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(400, Poison.encode!(%{"msg" => handle_changeset_errors(error)}))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ defmodule EventosWeb.Router do
|
||||
get "/events/:uuid/tracks", TrackController, :show_tracks_for_event
|
||||
get "/events/:uuid/sessions", SessionController, :show_sessions_for_event
|
||||
get "/events/:uuid", EventController, :show
|
||||
resources "/comments", CommentController, only: [:show]
|
||||
get "/bots/:id", BotController, :view
|
||||
get "/comments/:uuid", CommentController, :show
|
||||
get "/bots/:id", BotController, :show
|
||||
get "/bots", BotController, :index
|
||||
|
||||
get "/actors", ActorController, :index
|
||||
get "/actors/search/:name", ActorController, :search
|
||||
@@ -74,10 +75,13 @@ defmodule EventosWeb.Router do
|
||||
patch "/events/:uuid", EventController, :update
|
||||
put "/events/:uuid", EventController, :update
|
||||
delete "/events/:uuid", EventController, :delete
|
||||
resources "/comments", CommentController, except: [:new, :edit, :show]
|
||||
post "/comments", CommentController, :create
|
||||
patch "/comments/:uuid", CommentController, :update
|
||||
put "/comments/:uuid", CommentController, :update
|
||||
delete "/comments/:uuid", CommentController, :delete
|
||||
#post "/events/:id/request", EventRequestController, :create_for_event
|
||||
resources "/participant", ParticipantController
|
||||
resources "/bots", BotController, except: [:new, :edit, :show]
|
||||
resources "/bots", BotController, except: [:new, :edit, :show, :index]
|
||||
#resources "/requests", EventRequestController
|
||||
post "/groups", GroupController, :create
|
||||
post "/groups/:name/join", GroupController, :join
|
||||
@@ -110,7 +114,7 @@ defmodule EventosWeb.Router do
|
||||
get "/@:name/outbox", ActivityPubController, :outbox
|
||||
get "/@:name/following", ActivityPubController, :following
|
||||
get "/@:name/followers", ActivityPubController, :followers
|
||||
get "/@:name/:slug", ActivityPubController, :event
|
||||
get "/events/:uuid", ActivityPubController, :event
|
||||
post "/@:name/inbox", ActivityPubController, :inbox
|
||||
post "/inbox", ActivityPubController, :inbox
|
||||
end
|
||||
|
||||
@@ -13,7 +13,8 @@ defmodule EventosWeb.ActivityPub.ActorView do
|
||||
import Ecto.Query
|
||||
|
||||
def render("actor.json", %{actor: actor}) do
|
||||
{:ok, public_key} = Actor.get_public_key_for_actor(actor)
|
||||
pem = Actor.get_keys_for_actor(actor)
|
||||
public_key = Eventos.Service.ActivityPub.Utils.pem_to_public_key_pem(pem)
|
||||
|
||||
%{
|
||||
"id" => actor.url,
|
||||
|
||||
@@ -12,7 +12,9 @@ defmodule EventosWeb.CommentView do
|
||||
|
||||
def render("comment.json", %{comment: comment}) do
|
||||
%{id: comment.id,
|
||||
uuid: comment.uuid,
|
||||
url: comment.url,
|
||||
text: comment.text}
|
||||
text: comment.text
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user