Moar coverage

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-11-27 17:54:54 +01:00
parent b99625afab
commit da378633ac
13 changed files with 287 additions and 84 deletions

View File

@@ -69,9 +69,8 @@ defmodule MobilizonWeb.ActivityPubController do
end
def following(conn, %{"name" => name, "page" => page}) do
with %Actor{} = actor <- Actors.get_local_actor_by_name(name) do
{page, _} = Integer.parse(page)
with {page, ""} = Integer.parse(page),
%Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ActorView.render("following.json", %{actor: actor, page: page}))
@@ -79,7 +78,7 @@ defmodule MobilizonWeb.ActivityPubController do
end
def following(conn, %{"name" => name}) do
with %Actor{} = actor <- Actors.get_local_actor_by_name(name) do
with %Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ActorView.render("following.json", %{actor: actor}))
@@ -87,9 +86,8 @@ defmodule MobilizonWeb.ActivityPubController do
end
def followers(conn, %{"name" => name, "page" => page}) do
with %Actor{} = actor <- Actors.get_local_actor_by_name(name) do
{page, _} = Integer.parse(page)
with {page, ""} = Integer.parse(page),
%Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ActorView.render("followers.json", %{actor: actor, page: page}))
@@ -97,7 +95,7 @@ defmodule MobilizonWeb.ActivityPubController do
end
def followers(conn, %{"name" => name}) do
with %Actor{} = actor <- Actors.get_local_actor_by_name(name) do
with %Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ActorView.render("followers.json", %{actor: actor}))
@@ -157,6 +155,6 @@ defmodule MobilizonWeb.ActivityPubController do
def errors(conn, _e) do
conn
|> put_status(500)
|> json("error")
|> json("Unknown Error")
end
end

View File

@@ -87,12 +87,13 @@ defmodule MobilizonWeb.Resolvers.User do
"""
def send_reset_password(_parent, %{email: email, locale: locale}, _resolution) do
with {:ok, user} <- Actors.get_user_by_email(email, false),
{:ok, email} <-
{:ok, %Bamboo.Email{} = _email_html} <-
Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user, locale) do
{:ok, email}
else
{:error, :user_not_found} ->
{:error, "No user to validate with this email was found"}
# TODO : implement rate limits for this endpoint
{:error, "No user with this email was found"}
{:error, :email_too_soon} ->
{:error, "You requested again a confirmation email too soon"}

View File

@@ -47,7 +47,7 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
def render("following.json", %{actor: actor, page: page}) do
actor
|> Actor.get_followings()
|> Actor.get_followings(page)
|> collection(actor.following_url, page)
|> Map.merge(Utils.make_json_ld_header())
end
@@ -66,7 +66,7 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
def render("followers.json", %{actor: actor, page: page}) do
actor
|> Actor.get_followers()
|> Actor.get_followers(page)
|> collection(actor.followers_url, page)
|> Map.merge(Utils.make_json_ld_header())
end
@@ -77,7 +77,8 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
%{
"id" => actor.followers_url,
"type" => "OrderedCollection",
"totalItems" => length(followers),
# TODO put me back
# "totalItems" => length(followers),
"first" => collection(followers, actor.followers_url, 1)
}
|> Map.merge(Utils.make_json_ld_header())
@@ -148,22 +149,22 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|> Map.merge(Utils.make_json_ld_header())
end
def collection(collection, iri, page, total \\ nil) do
offset = (page - 1) * 10
items = Enum.slice(collection, offset, 10)
items = Enum.map(items, fn account -> account.url end)
total = total || length(collection)
def collection(collection, iri, page, _total \\ nil) do
items = Enum.map(collection, fn account -> account.url end)
map = %{
# TODO : Add me back
# total = total || length(collection)
%{
"id" => "#{iri}?page=#{page}",
"type" => "OrderedCollectionPage",
"partOf" => iri,
"totalItems" => total,
# "totalItems" => total,
"orderedItems" => items
}
if offset < total do
Map.put(map, "next", "#{iri}?page=#{page + 1}")
end
# if offset < total do
# Map.put(map, "next", "#{iri}?page=#{page + 1}")
# end
end
end