Merge branch 'deps/upgrade' into 'master'

Deps/upgrade

See merge request framasoft/mobilizon!160
This commit is contained in:
Thomas Citharel 2019-07-23 18:23:54 +02:00
commit de90b028ed
31 changed files with 835 additions and 696 deletions

View File

@ -143,8 +143,7 @@ export const CREATE_EVENT = gql`
$organizerActorId: ID!,
$category: String!,
$beginsOn: DateTime!,
$picture_file: Upload,
$picture_name: String,
$picture: PictureInput!
) {
createEvent(
title: $title,
@ -152,12 +151,7 @@ export const CREATE_EVENT = gql`
beginsOn: $beginsOn,
organizerActorId: $organizerActorId,
category: $category,
picture: {
picture: {
file: $picture_file,
name: $picture_name,
}
}
picture: $picture
) {
id,
uuid,

View File

@ -28,7 +28,7 @@
</b-select>
</b-field>
<picture-upload @change="handlePictureUploadChange" />
<picture-upload v-model="pictureFile" />
<button class="button is-primary">
<translate>Create my event</translate>
@ -50,7 +50,6 @@ import {
import { LOGGED_PERSON } from '@/graphql/actor';
import { IPerson, Person } from '@/types/actor';
import PictureUpload from '@/components/PictureUpload.vue';
import { IPictureUpload } from '@/types/picture.model';
import Editor from '@/components/Editor.vue';
import DateTimePicker from '@/components/Event/DateTimePicker.vue';
@ -68,8 +67,7 @@ export default class CreateEvent extends Vue {
loggedPerson: IPerson = new Person();
categories: string[] = Object.keys(Category);
event: IEvent = new EventModel();
pictureFile?: File;
pictureName?: String;
pictureFile: File | null = null;
created() {
const now = new Date();
@ -81,23 +79,14 @@ export default class CreateEvent extends Vue {
createEvent(e: Event) {
e.preventDefault();
this.event.organizerActor = this.loggedPerson;
this.event.attributedTo = this.loggedPerson;
if (this.event.uuid === '') {
console.log('event', this.event);
this.$apollo
.mutate({
mutation: CREATE_EVENT,
variables: {
title: this.event.title,
description: this.event.description,
beginsOn: this.event.beginsOn.toISOString(),
category: this.event.category,
organizerActorId: this.event.organizerActor.id,
picture_file: this.pictureFile,
picture_name: this.pictureName,
},
variables: this.buildVariables(),
})
.then(data => {
console.log('event created', data);
@ -126,10 +115,35 @@ export default class CreateEvent extends Vue {
}
}
handlePictureUploadChange(picture: IPictureUpload) {
console.log('picture upload change', picture);
this.pictureFile = picture.file;
this.pictureName = picture.name;
/**
* Build variables for Event GraphQL creation query
*/
private buildVariables() {
/**
* Transform general variables
*/
let pictureObj = {};
let obj = {
organizerActorId: this.loggedPerson.id,
beginsOn: this.event.beginsOn.toISOString(),
};
let res = Object.assign({}, this.event, obj);
/**
* Transform picture files
*/
if (this.pictureFile) {
pictureObj = {
picture: {
picture: {
name: this.pictureFile.name,
file: this.pictureFile,
},
},
};
}
return Object.assign({}, res, pictureObj);
}
// getAddressData(addressData) {

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,15 @@ defmodule Mix.Tasks.Mobilizon.Toot do
def run([from, content]) do
Mix.Task.run("app.start")
with {:ok, _} <- MobilizonWeb.API.Comments.create_comment(from, content) do
Mix.shell().info("Tooted")
else
{:local_actor, _} -> Mix.shell().error("Failed to toot.\nActor #{from} doesn't exist")
_ -> Mix.shell().error("Failed to toot.")
case MobilizonWeb.API.Comments.create_comment(from, content) do
{:ok, _} ->
Mix.shell().info("Tooted")
{:local_actor, _} ->
Mix.shell().error("Failed to toot.\nActor #{from} doesn't exist")
_ ->
Mix.shell().error("Failed to toot.")
end
end
end

View File

@ -295,9 +295,10 @@ defmodule Mobilizon.Actors.Actor do
"""
@spec prepare_public_key(String.t()) :: {:ok, tuple()} | {:error, :pem_decode_error}
def prepare_public_key(public_key_code) do
with [public_key_entry] <- :public_key.pem_decode(public_key_code) do
{:ok, :public_key.pem_entry_decode(public_key_entry)}
else
case :public_key.pem_decode(public_key_code) do
[public_key_entry] ->
{:ok, :public_key.pem_entry_decode(public_key_entry)}
_err ->
{:error, :pem_decode_error}
end
@ -423,10 +424,10 @@ defmodule Mobilizon.Actors.Actor do
"""
@spec unfollow(struct(), struct()) :: {:ok, Follower.t()} | {:error, Ecto.Changeset.t()}
def unfollow(%Actor{} = followed, %Actor{} = follower) do
with {:already_following, %Follower{} = follow} <-
{:already_following, following?(follower, followed)} do
Actors.delete_follower(follow)
else
case {:already_following, following?(follower, followed)} do
{:already_following, %Follower{} = follow} ->
Actors.delete_follower(follow)
{:already_following, false} ->
{:error, "Could not unfollow actor: you are not following #{followed.preferred_username}"}
end

View File

@ -281,21 +281,21 @@ defmodule Mobilizon.Actors do
data
|> Actor.remote_actor_creation()
with {:ok, actor} <-
Repo.insert(
cs,
on_conflict: [
set: [
keys: data.keys,
name: data.name,
summary: data.summary
]
],
conflict_target: [:url]
) do
actor = if preload, do: Repo.preload(actor, [:followers]), else: actor
{:ok, actor}
else
case Repo.insert(
cs,
on_conflict: [
set: [
keys: data.keys,
name: data.name,
summary: data.summary
]
],
conflict_target: [:url]
) do
{:ok, actor} ->
actor = if preload, do: Repo.preload(actor, [:followers]), else: actor
{:ok, actor}
err ->
Logger.error(inspect(err))
{:error, err}
@ -474,9 +474,10 @@ defmodule Mobilizon.Actors do
# TODO: Move this to Mobilizon.Service.ActivityPub
@spec get_or_fetch_by_url(String.t(), bool()) :: {:ok, Actor.t()} | {:error, String.t()}
def get_or_fetch_by_url(url, preload \\ false) do
with {:ok, actor} <- get_actor_by_url(url, preload) do
{:ok, actor}
else
case get_actor_by_url(url, preload) do
{:ok, actor} ->
{:ok, actor}
_ ->
case ActivityPub.make_actor_from_url(url, preload) do
{:ok, actor} ->
@ -497,9 +498,10 @@ defmodule Mobilizon.Actors do
# TODO: Move this to Mobilizon.Service.ActivityPub
@spec get_or_fetch_by_url!(String.t(), bool()) :: Actor.t()
def get_or_fetch_by_url!(url, preload \\ false) do
with {:ok, actor} <- get_actor_by_url(url, preload) do
actor
else
case get_actor_by_url(url, preload) do
{:ok, actor} ->
actor
_ ->
case ActivityPub.make_actor_from_url(url, preload) do
{:ok, actor} ->
@ -1001,9 +1003,10 @@ defmodule Mobilizon.Actors do
end
defp safe_remove_file(url, %Actor{} = actor) do
with {:ok, _value} <- MobilizonWeb.Upload.remove(url) do
{:ok, actor}
else
case MobilizonWeb.Upload.remove(url) do
{:ok, _value} ->
{:ok, actor}
{:error, error} ->
Logger.error("Error while removing an upload file")
Logger.error(inspect(error))

View File

@ -187,10 +187,12 @@ defmodule Mobilizon.Events do
def get_cached_event_full_by_uuid(uuid) do
Cachex.fetch(:activity_pub, "event_" <> uuid, fn "event_" <> uuid ->
with %Event{} = event <- get_event_full_by_uuid(uuid) do
{:commit, event}
else
_ -> {:ignore, nil}
case get_event_full_by_uuid(uuid) do
%Event{} = event ->
{:commit, event}
_ ->
{:ignore, nil}
end
end)
end
@ -1133,10 +1135,12 @@ defmodule Mobilizon.Events do
def get_cached_comment_full_by_uuid(uuid) do
Cachex.fetch(:activity_pub, "comment_" <> uuid, fn "comment_" <> uuid ->
with %Comment{} = comment <- get_comment_full_from_uuid(uuid) do
{:commit, comment}
else
_ -> {:ignore, nil}
case get_comment_full_from_uuid(uuid) do
%Comment{} = comment ->
{:commit, comment}
_ ->
{:ignore, nil}
end
end)
end

View File

@ -235,8 +235,9 @@ defmodule Mobilizon.Users do
end
def update_user_default_actor(user_id, actor_id) do
with from(u in User, where: u.id == ^user_id, update: [set: [default_actor_id: ^actor_id]])
|> Repo.update_all([]) do
with _ <-
from(u in User, where: u.id == ^user_id, update: [set: [default_actor_id: ^actor_id]])
|> Repo.update_all([]) do
Repo.get!(User, user_id) |> Repo.preload([:default_actor])
end
end

View File

@ -25,9 +25,10 @@ defmodule MobilizonWeb.API.Search do
# Some URLs could be domain.tld/@username, so keep this condition above handle_search? function
url_search?(search) ->
# If this is not an actor, skip
with %{:total => total, :elements => [%Actor{}] = elements} <- process_from_url(search) do
{:ok, %{total: total, elements: elements}}
else
case process_from_url(search) do
%{:total => total, :elements => [%Actor{}] = elements} ->
{:ok, %{total: total, elements: elements}}
_ ->
{:ok, %{total: 0, elements: []}}
end
@ -55,9 +56,10 @@ defmodule MobilizonWeb.API.Search do
url_search?(search) ->
# If this is not an event, skip
with {total = total, [%Event{} = elements]} <- process_from_url(search) do
{:ok, %{total: total, elements: elements}}
else
case process_from_url(search) do
{total = total, [%Event{} = elements]} ->
{:ok, %{total: total, elements: elements}}
_ ->
{:ok, %{total: 0, elements: []}}
end
@ -70,9 +72,10 @@ defmodule MobilizonWeb.API.Search do
# If the search string is an username
@spec process_from_username(String.t()) :: %{total: integer(), elements: [Actor.t()]}
defp process_from_username(search) do
with {:ok, actor} <- ActivityPub.find_or_make_actor_from_nickname(search) do
%{total: 1, elements: [actor]}
else
case ActivityPub.find_or_make_actor_from_nickname(search) do
{:ok, actor} ->
%{total: 1, elements: [actor]}
{:error, _err} ->
Logger.debug(fn -> "Unable to find or make actor '#{search}'" end)
%{total: 0, elements: []}
@ -85,9 +88,10 @@ defmodule MobilizonWeb.API.Search do
elements: [Actor.t() | Event.t() | Comment.t()]
}
defp process_from_url(search) do
with {:ok, object} <- ActivityPub.fetch_object_from_url(search) do
%{total: 1, elements: [object]}
else
case ActivityPub.fetch_object_from_url(search) do
{:ok, object} ->
%{total: 1, elements: [object]}
{:error, _err} ->
Logger.debug(fn -> "Unable to find or make object from URL '#{search}'" end)
%{total: 0, elements: []}

View File

@ -15,7 +15,7 @@ defmodule MobilizonWeb.ActivityPubController do
action_fallback(:errors)
def following(conn, %{"name" => name, "page" => page}) do
with {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")
@ -32,7 +32,7 @@ defmodule MobilizonWeb.ActivityPubController do
end
def followers(conn, %{"name" => name, "page" => page}) do
with {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")
@ -49,7 +49,7 @@ defmodule MobilizonWeb.ActivityPubController do
end
def outbox(conn, %{"name" => name, "page" => page}) do
with {page, ""} = Integer.parse(page),
with {page, ""} <- Integer.parse(page),
%Actor{} = actor <- Actors.get_local_actor_by_name(name) do
conn
|> put_resp_header("content-type", "application/activity+json")

View File

@ -7,60 +7,60 @@ defmodule MobilizonWeb.FeedController do
action_fallback(MobilizonWeb.FallbackController)
def actor(conn, %{"name" => name, "format" => "atom"}) do
with {status, data} when status in [:ok, :commit] <-
Cachex.fetch(:feed, "actor_" <> name) do
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
else
case Cachex.fetch(:feed, "actor_" <> name) do
{status, data} when status in [:ok, :commit] ->
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end
end
def actor(conn, %{"name" => name, "format" => "ics"}) do
with {status, data} when status in [:ok, :commit] <-
Cachex.fetch(:ics, "actor_" <> name) do
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
else
case Cachex.fetch(:ics, "actor_" <> name) do
{status, data} when status in [:ok, :commit] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end
end
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
with {status, data} when status in [:ok, :commit] <-
Cachex.fetch(:ics, "event_" <> uuid) do
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
else
case Cachex.fetch(:ics, "event_" <> uuid) do
{status, data} when status in [:ok, :commit] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end
end
def going(conn, %{"token" => token, "format" => "ics"}) do
with {status, data} when status in [:ok, :commit] <-
Cachex.fetch(:ics, "token_" <> token) do
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
else
case Cachex.fetch(:ics, "token_" <> token) do
{status, data} when status in [:ok, :commit] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end
end
def going(conn, %{"token" => token, "format" => "atom"}) do
with {status, data} when status in [:ok, :commit] <-
Cachex.fetch(:feed, "token_" <> token) do
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
else
case Cachex.fetch(:feed, "token_" <> token) do
{status, data} when status in [:ok, :commit] ->
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end

View File

@ -176,11 +176,12 @@ defmodule MobilizonWeb.Resolvers.Event do
# and that it's the actor requesting leaving the event we return true
@spec check_that_participant_is_not_only_organizer(integer(), integer()) :: boolean()
defp check_that_participant_is_not_only_organizer(event_id, actor_id) do
with [%Participant{actor: %Actor{id: participant_actor_id}}] <-
Mobilizon.Events.list_organizers_participants_for_event(event_id) do
participant_actor_id == actor_id
else
_ -> false
case Mobilizon.Events.list_organizers_participants_for_event(event_id) do
[%Participant{actor: %Actor{id: participant_actor_id}}] ->
participant_actor_id == actor_id
_ ->
false
end
end

View File

@ -218,17 +218,18 @@ defmodule MobilizonWeb.Resolvers.Group do
# and that it's the actor requesting leaving the group we return true
@spec check_that_member_is_not_only_administrator(integer(), integer()) :: boolean()
defp check_that_member_is_not_only_administrator(group_id, actor_id) do
with [
%Member{
actor: %Actor{
id: member_actor_id
}
}
] <-
Member.list_administrator_members_for_group(group_id) do
actor_id == member_actor_id
else
_ -> false
case Member.list_administrator_members_for_group(group_id) do
[
%Member{
actor: %Actor{
id: member_actor_id
}
}
] ->
actor_id == member_actor_id
_ ->
false
end
end
end

View File

@ -35,10 +35,17 @@ defmodule MobilizonWeb.Resolvers.Picture do
@spec do_fetch_picture(String.t()) :: {:ok, Picture.t()} | {:error, :not_found}
defp do_fetch_picture(picture_id) do
with %Picture{id: id, file: file} = _pic <- Media.get_picture(picture_id) do
{:ok,
%{name: file.name, url: file.url, id: id, content_type: file.content_type, size: file.size}}
else
case Media.get_picture(picture_id) do
%Picture{id: id, file: file} = _pic ->
{:ok,
%{
name: file.name,
url: file.url,
id: id,
content_type: file.content_type,
size: file.size
}}
_err ->
{:error, "Picture with ID #{picture_id} was not found"}
end

View File

@ -91,10 +91,14 @@ defmodule MobilizonWeb.Upload do
def remove(url, opts \\ []) do
with opts <- get_opts(opts),
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
true <- host == MobilizonWeb.Endpoint.host() do
{:same_host, true} <- {:same_host, host == MobilizonWeb.Endpoint.host()} do
MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path)
else
%URI{} = _uri -> {:error, "URL doesn't match pattern"}
%URI{} = _uri ->
{:error, "URL doesn't match pattern"}
{:same_host, _} ->
Logger.error("Media can't be deleted because its URL doesn't match current host")
end
end

View File

@ -289,7 +289,7 @@ defmodule Mobilizon.Service.ActivityPub do
"to" => [actor.url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"]
}
with Events.delete_event(event),
with {:ok, _} <- Events.delete_event(event),
{:ok, activity, _object} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
@ -304,7 +304,7 @@ defmodule Mobilizon.Service.ActivityPub do
"to" => [actor.url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"]
}
with Events.delete_comment(comment),
with {:ok, _} <- Events.delete_comment(comment),
{:ok, activity, _object} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
@ -319,7 +319,7 @@ defmodule Mobilizon.Service.ActivityPub do
"to" => [url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"]
}
with Actors.delete_actor(actor),
with {:ok, _} <- Actors.delete_actor(actor),
{:ok, activity, _object} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
@ -352,9 +352,10 @@ defmodule Mobilizon.Service.ActivityPub do
"""
@spec make_actor_from_url(String.t(), boolean()) :: {:ok, %Actor{}} | {:error, any()}
def make_actor_from_url(url, preload \\ false) do
with {:ok, data} <- fetch_and_prepare_actor_from_url(url) do
Actors.insert_or_update_actor(data, preload)
else
case fetch_and_prepare_actor_from_url(url) do
{:ok, data} ->
Actors.insert_or_update_actor(data, preload)
# Request returned 410
{:error, :actor_deleted} ->
{:error, :actor_deleted}
@ -371,10 +372,12 @@ defmodule Mobilizon.Service.ActivityPub do
"""
@spec find_or_make_actor_from_nickname(String.t(), atom() | nil) :: tuple()
def find_or_make_actor_from_nickname(nickname, type \\ nil) do
with %Actor{} = actor <- Actors.get_actor_by_name(nickname, type) do
{:ok, actor}
else
nil -> make_actor_from_nickname(nickname)
case Actors.get_actor_by_name(nickname, type) do
%Actor{} = actor ->
{:ok, actor}
nil ->
make_actor_from_nickname(nickname)
end
end
@ -389,10 +392,12 @@ defmodule Mobilizon.Service.ActivityPub do
"""
@spec make_actor_from_nickname(String.t()) :: {:ok, %Actor{}} | {:error, any()}
def make_actor_from_nickname(nickname) do
with {:ok, %{"url" => url}} when not is_nil(url) <- WebFinger.finger(nickname) do
make_actor_from_url(url)
else
_e -> {:error, "No ActivityPub URL found in WebFinger"}
case WebFinger.finger(nickname) do
{:ok, %{"url" => url}} when not is_nil(url) ->
make_actor_from_url(url)
_e ->
{:error, "No ActivityPub URL found in WebFinger"}
end
end

View File

@ -37,18 +37,22 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
with {:ok, %Actor{} = reporter} <- Actors.get_actor_by_url(object["actor"]),
%Actor{} = reported <-
Enum.reduce_while(objects, nil, fn url, _ ->
with {:ok, %Actor{} = actor} <- Actors.get_actor_by_url(url) do
{:halt, actor}
else
_ -> {:cont, nil}
case Actors.get_actor_by_url(url) do
{:ok, %Actor{} = actor} ->
{:halt, actor}
_ ->
{:cont, nil}
end
end),
event <-
Enum.reduce_while(objects, nil, fn url, _ ->
with %Event{} = event <- Events.get_event_by_url(url) do
{:halt, event}
else
_ -> {:cont, nil}
case Events.get_event_by_url(url) do
%Event{} = event ->
{:halt, event}
_ ->
{:cont, nil}
end
end),

View File

@ -209,19 +209,20 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
data
)
when object_type in ["Person", "Application", "Service", "Organization"] do
with {:ok, %Actor{url: url}} <- Actors.get_actor_by_url(object["id"]) do
{:ok, new_actor_data} = ActivityPub.actor_data_from_actor_object(object)
case Actors.get_actor_by_url(object["id"]) do
{:ok, %Actor{url: url}} ->
{:ok, new_actor_data} = ActivityPub.actor_data_from_actor_object(object)
Actors.insert_or_update_actor(new_actor_data)
Actors.insert_or_update_actor(new_actor_data)
ActivityPub.update(%{
local: false,
to: data["to"] || [],
cc: data["cc"] || [],
object: object,
actor: url
})
ActivityPub.update(%{
local: false,
to: data["to"] || [],
cc: data["cc"] || [],
object: object,
actor: url
})
else
e ->
Logger.error(inspect(e))
:error

View File

@ -206,10 +206,12 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
Save picture data from %Plug.Upload{} and return AS Link data.
"""
def make_picture_data(%Plug.Upload{} = picture) do
with {:ok, picture} <- MobilizonWeb.Upload.store(picture) do
picture
else
_ -> nil
case MobilizonWeb.Upload.store(picture) do
{:ok, picture} ->
picture
_ ->
nil
end
end

View File

@ -21,9 +21,10 @@ defmodule Mobilizon.Service.Export.Feed do
@spec create_cache(String.t()) :: {:commit, String.t()} | {:ignore, any()}
def create_cache("actor_" <> name) do
with {:ok, res} <- fetch_actor_event_feed(name) do
{:commit, res}
else
case fetch_actor_event_feed(name) do
{:ok, res} ->
{:commit, res}
err ->
{:ignore, err}
end
@ -31,9 +32,10 @@ defmodule Mobilizon.Service.Export.Feed do
@spec create_cache(String.t()) :: {:commit, String.t()} | {:ignore, any()}
def create_cache("token_" <> token) do
with {:ok, res} <- fetch_events_from_token(token) do
{:commit, res}
else
case fetch_events_from_token(token) do
{:ok, res} ->
{:commit, res}
err ->
{:ignore, err}
end
@ -99,21 +101,22 @@ defmodule Mobilizon.Service.Export.Feed do
defp get_entry(%Event{} = event) do
description = event.description || ""
with {:ok, html, []} <- Earmark.as_html(description) do
entry =
Entry.new(event.url, event.publish_at || event.inserted_at, event.title)
|> Entry.link(event.url, rel: "alternate", type: "text/html")
|> Entry.content({:cdata, html}, type: "html")
|> Entry.published(event.publish_at || event.inserted_at)
case Earmark.as_html(description) do
{:ok, html, []} ->
entry =
Entry.new(event.url, event.publish_at || event.inserted_at, event.title)
|> Entry.link(event.url, rel: "alternate", type: "text/html")
|> Entry.content({:cdata, html}, type: "html")
|> Entry.published(event.publish_at || event.inserted_at)
# Add tags
entry =
event.tags
|> Enum.uniq()
|> Enum.reduce(entry, fn tag, acc -> Entry.category(acc, tag.slug, label: tag.title) end)
# Add tags
entry =
event.tags
|> Enum.uniq()
|> Enum.reduce(entry, fn tag, acc -> Entry.category(acc, tag.slug, label: tag.title) end)
Entry.build(entry)
Entry.build(entry)
else
{:error, _html, error_messages} ->
Logger.error("Unable to produce HTML for Markdown", details: inspect(error_messages))
end

View File

@ -87,9 +87,10 @@ defmodule Mobilizon.Service.Export.ICalendar do
Create cache for an actor
"""
def create_cache("token_" <> token) do
with {:ok, res} <- fetch_events_from_token(token) do
{:commit, res}
else
case fetch_events_from_token(token) do
{:ok, res} ->
{:commit, res}
err ->
{:ignore, err}
end

View File

@ -51,8 +51,10 @@ defmodule Mobilizon.Service.Federator do
Logger.info("Handling incoming AP activity")
Logger.debug(inspect(params))
with {:ok, _activity} <- Transmogrifier.handle_incoming(params) do
else
case Transmogrifier.handle_incoming(params) do
{:ok, activity} ->
{:ok, activity}
%Activity{} ->
Logger.info("Already had #{params["id"]}")

View File

@ -23,7 +23,7 @@ defmodule Mobilizon.Service.Geospatial.Addok do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, %{"features" => features}} <- Poison.decode(body) do
processData(features)
process_data(features)
end
end
@ -39,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.Addok do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, %{"features" => features}} <- Poison.decode(body) do
processData(features)
process_data(features)
end
end
@ -59,23 +59,23 @@ defmodule Mobilizon.Service.Geospatial.Addok do
end
end
defp processData(features) do
defp process_data(features) do
features
|> Enum.map(fn %{"geometry" => geometry, "properties" => properties} ->
%Address{
country: Map.get(properties, "country"),
locality: Map.get(properties, "city"),
region: Map.get(properties, "state"),
description: Map.get(properties, "name") || streetAddress(properties),
description: Map.get(properties, "name") || street_address(properties),
floor: Map.get(properties, "floor"),
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
postal_code: Map.get(properties, "postcode"),
street: properties |> streetAddress()
street: properties |> street_address()
}
end)
end
defp streetAddress(properties) do
defp street_address(properties) do
if Map.has_key?(properties, "housenumber") do
Map.get(properties, "housenumber") <> " " <> Map.get(properties, "street")
else

View File

@ -39,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
},#{lon}&maxResults=#{limit}"
),
{:ok, %{"results" => results, "info" => %{"statuscode" => 0}}} <- Poison.decode(body) do
results |> Enum.map(&processData/1)
results |> Enum.map(&process_data/1)
else
{:ok, %HTTPoison.Response{status_code: 403, body: err}} ->
raise(ArgumentError, message: err)
@ -71,14 +71,14 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, %{"results" => results, "info" => %{"statuscode" => 0}}} <- Poison.decode(body) do
results |> Enum.map(&processData/1)
results |> Enum.map(&process_data/1)
else
{:ok, %HTTPoison.Response{status_code: 403, body: err}} ->
raise(ArgumentError, message: err)
end
end
defp processData(
defp process_data(
%{
"locations" => addresses,
"providedLocation" => %{"latLng" => %{"lat" => lat, "lng" => lng}}
@ -86,22 +86,22 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
) do
case addresses do
[] -> nil
addresses -> addresses |> hd |> produceAddress(lat, lng)
addresses -> addresses |> hd |> produce_address(lat, lng)
end
end
defp processData(%{"locations" => addresses}) do
defp process_data(%{"locations" => addresses}) do
case addresses do
[] -> nil
addresses -> addresses |> hd |> produceAddress()
addresses -> addresses |> hd |> produce_address()
end
end
defp produceAddress(%{"latLng" => %{"lat" => lat, "lng" => lng}} = address) do
produceAddress(address, lat, lng)
defp produce_address(%{"latLng" => %{"lat" => lat, "lng" => lng}} = address) do
produce_address(address, lat, lng)
end
defp produceAddress(address, lat, lng) do
defp produce_address(address, lat, lng) do
%Address{
country: Map.get(address, "adminArea1"),
locality: Map.get(address, "adminArea5"),

View File

@ -24,7 +24,7 @@ defmodule Mobilizon.Service.Geospatial.Photon do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, %{"features" => features}} <- Poison.decode(body) do
processData(features)
process_data(features)
end
end
@ -40,7 +40,7 @@ defmodule Mobilizon.Service.Geospatial.Photon do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, %{"features" => features}} <- Poison.decode(body) do
processData(features)
process_data(features)
end
end
@ -61,23 +61,23 @@ defmodule Mobilizon.Service.Geospatial.Photon do
end
end
defp processData(features) do
defp process_data(features) do
features
|> Enum.map(fn %{"geometry" => geometry, "properties" => properties} ->
%Address{
country: Map.get(properties, "country"),
locality: Map.get(properties, "city"),
region: Map.get(properties, "state"),
description: Map.get(properties, "name") || streetAddress(properties),
description: Map.get(properties, "name") || street_address(properties),
floor: Map.get(properties, "floor"),
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
postal_code: Map.get(properties, "postcode"),
street: properties |> streetAddress()
street: properties |> street_address()
}
end)
end
defp streetAddress(properties) do
defp street_address(properties) do
if Map.has_key?(properties, "housenumber") do
Map.get(properties, "housenumber") <> " " <> Map.get(properties, "street")
else

View File

@ -49,19 +49,19 @@ defmodule Mobilizon.Service.HTTPSignatures do
def validate_conn(conn) do
# TODO: How to get the right key and see if it is actually valid for that request.
# For now, fetch the key for the actor.
with {:ok, public_key} <- conn.params["actor"] |> Actor.get_public_key_for_url() do
if validate_conn(conn, public_key) do
true
else
Logger.info("Could not validate request, re-fetching user and trying one more time")
# Fetch user anew and try one more time
with actor_id <- conn.params["actor"],
{:ok, _actor} <- ActivityPub.make_actor_from_url(actor_id),
{:ok, public_key} <- actor_id |> Actor.get_public_key_for_url() do
validate_conn(conn, public_key)
case conn.params["actor"] |> Actor.get_public_key_for_url() do
{:ok, public_key} ->
if validate_conn(conn, public_key) do
true
Logger.info("Could not validate request, re-fetching user and trying one more time")
# Fetch user anew and try one more time
with actor_id <- conn.params["actor"],
{:ok, _actor} <- ActivityPub.make_actor_from_url(actor_id),
{:ok, public_key} <- actor_id |> Actor.get_public_key_for_url() do
validate_conn(conn, public_key)
end
end
end
else
e ->
Logger.debug("Could not found url for actor!")
Logger.debug(inspect(e))
@ -104,9 +104,10 @@ defmodule Mobilizon.Service.HTTPSignatures do
end
def generate_date_header(date \\ Timex.now("GMT")) do
with {:ok, date} <- Timex.format(date, "%a, %d %b %Y %H:%M:%S %Z", :strftime) do
date
else
case Timex.format(date, "%a, %d %b %Y %H:%M:%S %Z", :strftime) do
{:ok, date} ->
date
{:error, err} ->
Logger.error("Unable to generate date header")
Logger.error(inspect(err))

View File

@ -43,9 +43,10 @@ defmodule Mobilizon.Service.WebFinger do
{:ok, represent_actor(actor, "JSON")}
else
_e ->
with {:ok, %Actor{} = actor} when not is_nil(actor) <- Actors.get_actor_by_url(resource) do
{:ok, represent_actor(actor, "JSON")}
else
case Actors.get_actor_by_url(resource) do
{:ok, %Actor{} = actor} when not is_nil(actor) ->
{:ok, represent_actor(actor, "JSON")}
_e ->
{:error, "Couldn't find actor"}
end
@ -94,9 +95,10 @@ defmodule Mobilizon.Service.WebFinger do
actor = String.trim_leading(actor, "@")
domain =
with [_name, domain] <- String.split(actor, "@") do
domain
else
case String.split(actor, "@") do
[_name, domain] ->
domain
_e ->
URI.parse(actor).host
end

View File

@ -62,7 +62,7 @@ defmodule Mobilizon.Mixfile do
{:guardian_db, "~> 2.0"},
{:argon2_elixir, "~> 2.0"},
{:cors_plug, "~> 2.0"},
{:ecto_autoslug_field, "~> 1.0"},
{:ecto_autoslug_field, "~> 2.0"},
{:rsa_ex, "~> 0.1"},
{:geo, "~> 3.0"},
{:geo_postgis, "~> 3.1"},
@ -94,12 +94,12 @@ defmodule Mobilizon.Mixfile do
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:ex_machina, "~> 2.3", only: [:dev, :test]},
{:excoveralls, "~> 0.10", only: :test},
{:ex_doc, "~> 0.20.2", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.21.1", only: [:dev, :test], runtime: false},
{:mix_test_watch, "~> 0.5", only: :dev, runtime: false},
{:ex_unit_notifier, "~> 0.1", only: :test},
{:dialyxir, "~> 1.0.0-rc.4", only: [:dev], runtime: false},
{:exvcr, "~> 0.10", only: :test},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.1.2", only: [:dev, :test], runtime: false},
{:mock, "~> 0.3.0", only: :test},
{:elixir_feed_parser, "~> 2.1.0", only: :test}
]

View File

@ -19,22 +19,22 @@
"cors_plug": {:hex, :cors_plug, "2.0.0", "238ddb479f92b38f6dc1ae44b8d81f0387f9519101a6da442d543ab70ee0e482", [:mix], [{:plug, "~> 1.3 or ~> 1.4 or ~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"cowboy": {:hex, :cowboy, "2.6.3", "99aa50e94e685557cad82e704457336a453d4abcb77839ad22dbe71f311fcc06", [:rebar3], [{:cowlib, "~> 2.7.3", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
"credo": {:hex, :credo, "1.0.5", "fdea745579f8845315fe6a3b43e2f9f8866839cfbc8562bb72778e9fdaa94214", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "1.1.2", "02b6422f3e659eb74b05aca3c20c1d8da0119a05ee82577a82e6c2938bf29f81", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"dataloader": {:hex, :dataloader, "1.0.6", "fb724d6d3fb6acb87d27e3b32dea3a307936ad2d245faf9cf5221d1323d6a4ba", [:mix], [{:ecto, ">= 0.0.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
"db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "2.1.1", "a51e8a2ee54ef2ae6ec41a668c85787ed40cb8944928c191280fe34c15b76ae5", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.3", "5e8be428fcef362692b6dbd7dc55bdc7023da26d995cb3fb19aa4bd682bfd3f9", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.1.7", "fa21d06ef56cdc2fdaa62574e8c3ba34a2751d44ea34c30bc65f0728421043e5", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_autoslug_field": {:hex, :ecto_autoslug_field, "1.0.0", "577eed25e6d045b8d783f82c9872f97c3a84017a4feae50eaf3cf4e1334a19e2", [:mix], [{:ecto, ">= 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:slugger, ">= 0.2.0", [hex: :slugger, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_enum": {:hex, :ecto_enum, "1.3.0", "1ff1195d98de79dbcb4a4659afbb1d801515e17b6f5fb3c9b4df9afcef68a71a", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_autoslug_field": {:hex, :ecto_autoslug_field, "2.0.0", "c4caca7e5f42057e503672feb2e1a7a58ff4c343cd9a5a63050ebabcdebfdcb5", [:mix], [{:ecto, ">= 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:slugger, ">= 0.2.0", [hex: :slugger, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_enum": {:hex, :ecto_enum, "1.3.1", "f63bad8d25a914d9f9a4f6d5aa57aff87149b78fc8ef10c74f0517d63df2779a", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.1.6", "1e80e30d16138a729c717f73dcb938590bcdb3a4502f3012414d0cbb261045d8", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0 or ~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"elixir_feed_parser": {:hex, :elixir_feed_parser, "2.1.0", "bb96fb6422158dc7ad59de62ef211cc69d264acbbe63941a64a5dce97bbbc2e6", [:mix], [{:timex, "~> 3.4", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm"},
"erlex": {:hex, :erlex, "0.2.2", "cb0e6878fdf86dc63509eaf2233a71fa73fc383c8362c8ff8e8b6f0c2bb7017c", [:mix], [], "hexpm"},
"erlex": {:hex, :erlex, "0.2.4", "23791959df45fe8f01f388c6f7eb733cc361668cbeedd801bf491c55a029917b", [:mix], [], "hexpm"},
"eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm"},
"ex_crypto": {:hex, :ex_crypto, "0.10.0", "af600a89b784b36613a989da6e998c1b200ff1214c3cfbaf8deca4aa2f0a1739", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.21.1", "5ac36660846967cd869255f4426467a11672fec3d8db602c429425ce5b613b90", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_ical": {:hex, :ex_ical, "0.2.0", "4b928b554614704016cc0c9ee226eb854da9327a1cc460457621ceacb1ac29a6", [:mix], [{:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm"},
"ex_image_info": {:hex, :ex_image_info, "0.2.4", "610002acba43520a9b1cf1421d55812bde5b8a8aeaf1fe7b1f8823e84e762adb", [:mix], [], "hexpm"},
"ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"},
@ -64,19 +64,19 @@
"json_ld": {:hex, :json_ld, "0.3.0", "92f508ca831b9e4530e3e6c950976fdafcf26323e6817c325b3e1ee78affc4bd", [:mix], [{:jason, "~> 1.1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:rdf, "~> 0.5", [hex: :rdf, repo: "hexpm", optional: false]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"},
"jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"mmdb2_decoder": {:hex, :mmdb2_decoder, "1.0.1", "0d584d7c4e45bb0be5c2399b7526b97b42791db0ff24e0e77d1b0a339646cea7", [:mix], [], "hexpm"},
"mmdb2_decoder": {:hex, :mmdb2_decoder, "1.1.0", "2e2347521bb3bf6b81b9ee58d3be2199cb68ea42dcbafcd0d8eb40214d2844cf", [:mix], [], "hexpm"},
"mock": {:hex, :mock, "0.3.3", "42a433794b1291a9cf1525c6d26b38e039e0d3a360732b5e467bfc77ef26c914", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"mogrify": {:hex, :mogrify, "0.7.2", "4d00b60288e338028e2af4cccff9b0da365d83b7e5da52e58fb2de513ef5fedd", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"phoenix": {:hex, :phoenix, "1.4.8", "c72dc3adeb49c70eb963a0ea24f7a064ec1588e651e84e1b7ad5ed8253c0b4a2", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix": {:hex, :phoenix, "1.4.9", "746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.0.0", "c43117a136e7399ea04ecaac73f8f23ee0ffe3e07acfcb8062fe5f4c9f0f6531", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.13.3", "850e292ff6e204257f5f9c4c54a8cb1f6fbc16ed53d360c2b780a3d0ba333867", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.1", "274a4b07c4adbdd7785d45a8b0bb57634d0b4f45b18d2c508b26c0344bd59b8f", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
@ -86,9 +86,9 @@
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.3", "5754dee2fdf6e9e508cbf49ab138df964278700b764177e8f3871e658b345a1e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"postgrex": {:hex, :postgrex, "0.15.0", "dd5349161019caeea93efa42f9b22f9d79995c3a86bdffb796427b4c9863b0f0", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
"rdf": {:hex, :rdf, "0.6.0", "e0d9098c157b91b9e7318a2fca18cc2e2b178e1290c5cfbb014cf2077c4aa778", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"rdf": {:hex, :rdf, "0.6.1", "e5464a7c0d91719bef6870eafe7efb3786c5622e4de592c84b8a32308de66c89", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"rsa_ex": {:hex, :rsa_ex, "0.4.0", "e28dd7dc5236e156df434af0e4aa822384c8866c928e17b785d4edb7c253b558", [:mix], [], "hexpm"},
"sleeplocks": {:hex, :sleeplocks, "1.1.1", "3d462a0639a6ef36cc75d6038b7393ae537ab394641beb59830a1b8271faeed3", [:rebar3], [], "hexpm"},
"slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm"},

View File

@ -440,9 +440,10 @@ defmodule Mobilizon.ActorsTest do
end
test "create_bot/1 with invalid data returns error changeset" do
with {:error, %Ecto.Changeset{}} <- Actors.create_bot(@invalid_attrs) do
assert true
else
case Actors.create_bot(@invalid_attrs) do
{:error, %Ecto.Changeset{}} ->
assert true
_ ->
assert false
end

View File

@ -92,12 +92,13 @@ defmodule Mobilizon.EventsTest do
|> Map.put(:organizer_actor_id, actor.id)
|> Map.put(:address_id, address.id)
with {:ok, %Event{} = event} <- Events.create_event(valid_attrs) do
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
assert event.description == "some description"
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
assert event.title == "some title"
else
case Events.create_event(valid_attrs) do
{:ok, %Event{} = event} ->
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
assert event.description == "some description"
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
assert event.title == "some title"
err ->
flunk("Failed to create an event #{inspect(err)}")
end
@ -138,10 +139,11 @@ defmodule Mobilizon.EventsTest do
test "get_public_events_for_actor/3", %{actor: actor, event: event} do
event1 = insert(:event, organizer_actor: actor)
with {:ok, events_found, 2} <- Events.get_public_events_for_actor(actor, 1, 10) do
event_ids = MapSet.new(events_found |> Enum.map(& &1.id))
assert event_ids == MapSet.new([event.id, event1.id])
else
case Events.get_public_events_for_actor(actor, 1, 10) do
{:ok, events_found, 2} ->
event_ids = MapSet.new(events_found |> Enum.map(& &1.id))
assert event_ids == MapSet.new([event.id, event1.id])
err ->
flunk("Failed to get events for an actor #{inspect(err)}")
end
@ -150,10 +152,10 @@ defmodule Mobilizon.EventsTest do
test "get_public_events_for_actor/3 with limited results", %{actor: actor, event: event} do
event1 = insert(:event, organizer_actor: actor)
with {:ok, [%Event{id: event_found_id}], 2} <-
Events.get_public_events_for_actor(actor, 1, 1) do
assert event_found_id in [event.id, event1.id]
else
case Events.get_public_events_for_actor(actor, 1, 1) do
{:ok, [%Event{id: event_found_id}], 2} ->
assert event_found_id in [event.id, event1.id]
err ->
flunk("Failed to get limited events for an actor #{inspect(err)}")
end
@ -345,11 +347,12 @@ defmodule Mobilizon.EventsTest do
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
valid_attrs = Map.put(valid_attrs, :actor_id, actor.id)
with {:ok, %Participant{} = participant} <- Events.create_participant(valid_attrs) do
assert participant.event_id == event.id
assert participant.actor_id == actor.id
assert participant.role == :creator
else
case Events.create_participant(valid_attrs) do
{:ok, %Participant{} = participant} ->
assert participant.event_id == event.id
assert participant.actor_id == actor.id
assert participant.role == :creator
err ->
flunk("Failed to create a participant #{inspect(err)}")
end
@ -362,10 +365,10 @@ defmodule Mobilizon.EventsTest do
test "update_participant/2 with valid data updates the participant", %{
participant: participant
} do
with {:ok, %Participant{} = participant} <-
Events.update_participant(participant, @update_attrs) do
assert participant.role == :moderator
else
case Events.update_participant(participant, @update_attrs) do
{:ok, %Participant{} = participant} ->
assert participant.role == :moderator
err ->
flunk("Failed to update a participant #{inspect(err)}")
end
@ -575,10 +578,11 @@ defmodule Mobilizon.EventsTest do
actor = insert(:actor)
comment_data = Map.merge(@valid_attrs, %{actor_id: actor.id})
with {:ok, %Comment{} = comment} <- Events.create_comment(comment_data) do
assert comment.text == "some text"
assert comment.actor_id == actor.id
else
case Events.create_comment(comment_data) do
{:ok, %Comment{} = comment} ->
assert comment.text == "some text"
assert comment.actor_id == actor.id
err ->
flunk("Failed to create a comment #{inspect(err)}")
end
@ -591,9 +595,10 @@ defmodule Mobilizon.EventsTest do
test "update_comment/2 with valid data updates the comment" do
comment = insert(:comment)
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, @update_attrs) do
assert comment.text == "some updated text"
else
case Events.update_comment(comment, @update_attrs) do
{:ok, %Comment{} = comment} ->
assert comment.text == "some updated text"
err ->
flunk("Failed to update a comment #{inspect(err)}")
end