Remove credo and use mix format, and lint everything

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-07-27 10:45:35 +02:00
parent df3f08c528
commit 979aad5acb
104 changed files with 2278 additions and 1487 deletions

View File

@@ -3,12 +3,12 @@ defmodule EventosWeb.AuthPipeline do
Handles the app sessions
"""
use Guardian.Plug.Pipeline, otp_app: :eventos,
module: EventosWeb.Guardian,
error_handler: EventosWeb.AuthErrorHandler
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}
plug Guardian.Plug.EnsureAuthenticated
plug Guardian.Plug.LoadResource, ensure: true
use Guardian.Plug.Pipeline,
otp_app: :eventos,
module: EventosWeb.Guardian,
error_handler: EventosWeb.AuthErrorHandler
plug(Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"})
plug(Guardian.Plug.EnsureAuthenticated)
plug(Guardian.Plug.LoadResource, ensure: true)
end

View File

@@ -8,7 +8,7 @@ defmodule EventosWeb.UserSocket do
# channel "room:*", EventosWeb.RoomChannel
# Transports
transport :websocket, Phoenix.Transports.WebSocket
transport(:websocket, Phoenix.Transports.WebSocket)
# transport :longpoll, Phoenix.Transports.LongPoll
# Socket params are passed from the client and can

View File

@@ -8,7 +8,7 @@ defmodule EventosWeb.ActorController do
alias Eventos.Actors.{Actor, User}
alias Eventos.Service.ActivityPub
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
actors = Actors.list_actors()
@@ -17,9 +17,9 @@ defmodule EventosWeb.ActorController do
def create(conn, %{"actor" => actor_params}) do
with %User{} = user <- Guardian.Plug.current_resource(conn),
actor_params <- Map.put(actor_params, "user_id", user.id),
actor_params <- Map.put(actor_params, "keys", keys_for_account()),
{:ok, %Actor{} = actor} <- Actors.create_actor(actor_params) do
actor_params <- Map.put(actor_params, "user_id", user.id),
actor_params <- Map.put(actor_params, "keys", keys_for_account()),
{:ok, %Actor{} = actor} <- Actors.create_actor(actor_params) do
conn
|> put_status(:created)
|> put_resp_header("location", actor_path(conn, :show, actor.preferred_username))
@@ -30,6 +30,7 @@ defmodule EventosWeb.ActorController do
defp keys_for_account() do
key = :public_key.generate_key({:rsa, 2048, 65_537})
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
[entry]
|> :public_key.pem_encode()
|> String.trim_trailing()
@@ -42,10 +43,13 @@ defmodule EventosWeb.ActorController do
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
def search(conn, %{"name" => name}) do
case Actors.search(name) do # find already saved accounts
# find already saved accounts
case Actors.search(name) do
{:ok, actors} ->
render(conn, "index.json", actors: actors)
{:error, err} -> json(conn, err)
{:error, err} ->
json(conn, err)
end
end
@@ -57,15 +61,15 @@ defmodule EventosWeb.ActorController do
end
end
# def delete(conn, %{"id" => id_str}) do
# {id, _} = Integer.parse(id_str)
# if Guardian.Plug.current_resource(conn).actor.id == id do
# actor = Actors.get_actor!(id)
# with {:ok, %Actor{}} <- Actors.delete_actor(actor) do
# send_resp(conn, :no_content, "")
# end
# else
# send_resp(conn, 401, "")
# end
# end
# def delete(conn, %{"id" => id_str}) do
# {id, _} = Integer.parse(id_str)
# if Guardian.Plug.current_resource(conn).actor.id == id do
# actor = Actors.get_actor!(id)
# with {:ok, %Actor{}} <- Actors.delete_actor(actor) do
# send_resp(conn, :no_content, "")
# end
# else
# send_resp(conn, 401, "")
# end
# end
end

View File

@@ -8,7 +8,7 @@ defmodule EventosWeb.AddressController do
alias Eventos.Addresses
alias Eventos.Addresses.Address
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
addresses = Addresses.list_addresses()
@@ -18,6 +18,7 @@ defmodule EventosWeb.AddressController do
def create(conn, %{"address" => address_params}) do
with {:ok, geom} <- Addresses.process_geom(address_params["geom"]) do
address_params = %{address_params | "geom" => geom}
with {:ok, %Address{} = address} <- Addresses.create_address(address_params) do
conn
|> put_status(:created)
@@ -30,15 +31,18 @@ defmodule EventosWeb.AddressController do
def process_geom(%{"type" => type, "data" => data}) do
import Logger
Logger.debug("Process geom")
Logger.debug(inspect data)
Logger.debug(inspect type)
Logger.debug(inspect(data))
Logger.debug(inspect(type))
types = [:point]
unless is_atom(type) do
type = String.to_existing_atom(type)
end
case type do
:point ->
%Geo.Point{coordinates: {data["latitude"], data["longitude"]}, srid: 4326}
nil ->
nil
end
@@ -66,6 +70,7 @@ defmodule EventosWeb.AddressController do
def delete(conn, %{"id" => id}) do
address = Addresses.get_address!(id)
with {:ok, %Address{}} <- Addresses.delete_address(address) do
send_resp(conn, :no_content, "")
end

View File

@@ -4,7 +4,7 @@ defmodule EventosWeb.BotController do
alias Eventos.Actors
alias Eventos.Actors.{Bot, Actor}
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
bots = Actors.list_bots()
@@ -14,7 +14,8 @@ defmodule EventosWeb.BotController do
def create(conn, %{"bot" => bot_params}) do
with user <- Guardian.Plug.current_resource(conn),
bot_params <- Map.put(bot_params, "user_id", user.id),
%Actor{} = 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
@@ -39,6 +40,7 @@ defmodule EventosWeb.BotController do
def delete(conn, %{"id" => id}) do
bot = Actors.get_bot!(id)
with {:ok, %Bot{}} <- Actors.delete_bot(bot) do
send_resp(conn, :no_content, "")
end

View File

@@ -7,7 +7,7 @@ defmodule EventosWeb.CategoryController do
alias Eventos.Events
alias Eventos.Events.Category
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
categories = Events.list_categories()
@@ -38,6 +38,7 @@ defmodule EventosWeb.CategoryController do
def delete(conn, %{"id" => id}) do
category = Events.get_category!(id)
with {:ok, %Category{}} <- Events.delete_category(category) do
send_resp(conn, :no_content, "")
end

View File

@@ -4,7 +4,7 @@ defmodule EventosWeb.CommentController do
alias Eventos.Events
alias Eventos.Events.Comment
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
comments = Events.list_comments()
@@ -35,6 +35,7 @@ defmodule EventosWeb.CommentController do
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

View File

@@ -10,27 +10,48 @@ defmodule EventosWeb.EventController do
require Logger
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
ip = "88.161.154.97"
Logger.debug(inspect Geolix.lookup(ip), pretty: true)
with %{city: %Geolix.Result.City{city: city, country: country, location: %Geolix.Record.Location{latitude: latitude, longitude: longitude}}} <- Geolix.lookup(ip) do
Logger.debug(inspect city)
Logger.debug(inspect [latitude, longitude])
distance = case city do
nil -> 500_000
_ -> 50_000
end
Logger.debug(inspect(Geolix.lookup(ip), pretty: true))
with %{
city: %Geolix.Result.City{
city: city,
country: country,
location: %Geolix.Record.Location{latitude: latitude, longitude: longitude}
}
} <- Geolix.lookup(ip) do
distance =
case city do
nil -> 500_000
_ -> 50_000
end
events = Events.find_close_events(longitude, latitude, distance)
render(conn, "index.json", events: events, coord: %{longitude: longitude, latitude: latitude, distance: distance}, city: city, country: country)
render(
conn,
"index.json",
events: events,
coord: %{longitude: longitude, latitude: latitude, distance: distance},
city: city,
country: country
)
end
end
def index_all(conn, _params) do
events = Events.list_events()
render(conn, "index_all.json", events: events)
end
def create(conn, %{"event" => event_params}) do
event_params = process_event_address(event_params)
Logger.debug("creating event with")
Logger.debug(inspect event_params)
Logger.debug(inspect(event_params))
with {:ok, %Event{} = event} <- Events.create_event(event_params) do
conn
|> put_status(:created)
@@ -43,16 +64,22 @@ defmodule EventosWeb.EventController do
cond do
Map.has_key?(event, "address_type") && event["address_type"] !== :physical ->
event
Map.has_key?(event, "physical_address") ->
address = event["physical_address"]
geom = EventosWeb.AddressController.process_geom(address["geom"])
address = case geom do
nil ->
address
_ ->
%{address | "geom" => geom}
end
address =
case geom do
nil ->
address
_ ->
%{address | "geom" => geom}
end
%{event | "physical_address" => address}
true ->
event
end
@@ -67,6 +94,7 @@ defmodule EventosWeb.EventController do
case Events.get_event_full_by_uuid(uuid) do
nil ->
send_resp(conn, 404, "")
event ->
render(conn, "show.json", event: event)
end
@@ -87,7 +115,7 @@ defmodule EventosWeb.EventController do
def delete(conn, %{"uuid" => uuid}) do
with event <- Events.get_event_by_uuid(uuid),
{:ok, %Event{}} <- Events.delete_event(event) do
{:ok, %Event{}} <- Events.delete_event(event) do
send_resp(conn, :no_content, "")
end
end

View File

@@ -1,4 +1,4 @@
#defmodule EventosWeb.EventRequestController do
# defmodule EventosWeb.EventRequestController do
# @moduledoc """
# Controller for Event requests
# """
@@ -49,4 +49,4 @@
# send_resp(conn, :no_content, "")
# end
# end
#end
# end

View File

@@ -7,7 +7,7 @@ defmodule EventosWeb.GroupController do
alias Eventos.Actors
alias Eventos.Actors.{Actor, Member}
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
groups = Actors.list_groups()
@@ -16,7 +16,7 @@ defmodule EventosWeb.GroupController do
def create(conn, %{"group" => group_params}) do
with actor_admin = Guardian.Plug.current_resource(conn).actor,
{:ok, %Actor{} = group} <- Actors.create_group(group_params) do
{:ok, %Actor{} = group} <- Actors.create_group(group_params) do
conn
|> put_status(:created)
|> put_resp_header("location", actor_path(conn, :show, group))
@@ -26,15 +26,16 @@ defmodule EventosWeb.GroupController do
def join(conn, %{"name" => group_name}) do
with actor = Guardian.Plug.current_resource(conn).actor,
group <- Actors.get_group_by_name(group_name),
%Member{} = member <- Actors.create_member(%{"parent_id" => group.id, "actor_id" => actor.id}) do
group <- Actors.get_group_by_name(group_name),
%Member{} = member <-
Actors.create_member(%{"parent_id" => group.id, "actor_id" => actor.id}) do
conn
|> put_status(:created)
|> render(EventosWeb.MemberView, "member.json", member: member)
else
err ->
import Logger
Logger.debug(inspect err)
Logger.debug(inspect(err))
end
end
end

View File

@@ -1,8 +1,6 @@
defmodule EventosWeb.InboxesController do
use EventosWeb, :controller
def create(conn) do
end
end

View File

@@ -22,8 +22,8 @@ defmodule EventosWeb.NodeinfoController do
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
def nodeinfo(conn, %{"version" => "2.0.json"}) do
import Logger
Logger.debug(inspect @instance)
#stats = Stats.get_stats()
Logger.debug(inspect(@instance))
# stats = Stats.get_stats()
response = %{
version: "2.0",
@@ -39,12 +39,12 @@ defmodule EventosWeb.NodeinfoController do
openRegistrations: Keyword.get(@instance, :registrations_open),
usage: %{
users: %{
#total: stats.user_count || 0
# total: stats.user_count || 0
total: Actors.count_users()
},
localPosts: Events.count_local_events(),
localComments: Events.count_local_comments(),
#localPosts: stats.status_count || 0
localComments: Events.count_local_comments()
# localPosts: stats.status_count || 0
},
metadata: %{
nodeName: Keyword.get(@instance, :name)

View File

@@ -1,5 +1,4 @@
defmodule EventosWeb.OutboxesController do
use EventosWeb, :controller
def show(conn) do

View File

@@ -4,9 +4,9 @@ defmodule EventosWeb.PageController do
"""
use EventosWeb, :controller
plug :put_layout, false
plug(:put_layout, false)
def index(conn, _params) do
render conn, "index.html"
render(conn, "index.html")
end
end

View File

@@ -8,9 +8,11 @@ defmodule EventosWeb.ParticipantController do
def join(conn, %{"uuid" => uuid}) do
with event <- Events.get_event_by_uuid(uuid),
%{actor: actor} <- Guardian.Plug.current_resource(conn) do
participant = Events.create_participant(%{"event_id" => event.id, "actor_id" => actor.id, "role" => 1})
render(conn, "participant.json", %{participant: participant})
%{actor: actor} <- Guardian.Plug.current_resource(conn) do
participant =
Events.create_participant(%{"event_id" => event.id, "actor_id" => actor.id, "role" => 1})
render(conn, "participant.json", %{participant: participant})
end
end
end

View File

@@ -7,14 +7,17 @@ defmodule EventosWeb.SearchController do
alias Eventos.Events
alias Eventos.Actors
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def search(conn, %{"name" => name}) do
events = Events.find_events_by_name(name)
case Actors.search(name) do # find already saved accounts
# find already saved accounts
case Actors.search(name) do
{:ok, actors} ->
render(conn, "search.json", events: events, actors: actors)
{:error, err} -> json(conn, err)
{:error, err} ->
json(conn, err)
end
end
end

View File

@@ -7,7 +7,7 @@ defmodule EventosWeb.SessionController do
alias Eventos.Events
alias Eventos.Events.Session
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
sessions = Events.list_sessions()
@@ -48,6 +48,7 @@ defmodule EventosWeb.SessionController do
def delete(conn, %{"id" => id}) do
session = Events.get_session!(id)
with {:ok, %Session{}} <- Events.delete_session(session) do
send_resp(conn, :no_content, "")
end

View File

@@ -7,7 +7,7 @@ defmodule EventosWeb.TagController do
alias Eventos.Events
alias Eventos.Events.Tag
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
tags = Events.list_tags()
@@ -38,6 +38,7 @@ defmodule EventosWeb.TagController do
def delete(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
with {:ok, %Tag{}} <- Events.delete_tag(tag) do
send_resp(conn, :no_content, "")
end

View File

@@ -7,7 +7,7 @@ defmodule EventosWeb.TrackController do
alias Eventos.Events
alias Eventos.Events.Track
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
tracks = Events.list_tracks()
@@ -38,6 +38,7 @@ defmodule EventosWeb.TrackController do
def delete(conn, %{"id" => id}) do
track = Events.get_track!(id)
with {:ok, %Track{}} <- Events.delete_track(track) do
send_resp(conn, :no_content, "")
end

View File

@@ -9,7 +9,7 @@ defmodule EventosWeb.UserController do
alias Eventos.Repo
alias Eventos.Actors.Service.{Activation, ResetPassword}
action_fallback EventosWeb.FallbackController
action_fallback(EventosWeb.FallbackController)
def index(conn, _params) do
users = Actors.list_users_with_actors()
@@ -17,17 +17,20 @@ defmodule EventosWeb.UserController do
end
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
with {:ok, %User{} = user} <- Actors.register(%{email: email, password: password, username: username}) do
with {:ok, %User{} = user} <-
Actors.register(%{email: email, password: password, username: username}) do
Activation.send_confirmation_email(user, "locale")
conn
|> put_status(:created)
|> render("confirmation.json", %{user: user})
|> put_status(:created)
|> render("confirmation.json", %{user: user})
end
end
def validate(conn, %{"token" => token}) do
with {:ok, %User{} = user} <- Activation.check_confirmation_token(token) do
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
conn
|> put_resp_header("location", user_path(conn, :show_current_actor))
|> render("show_with_token.json", %{user: user, token: token})
@@ -42,7 +45,8 @@ defmodule EventosWeb.UserController do
def resend_confirmation(conn, %{"email" => email}) do
with {:ok, %User{} = user} <- Actors.find_by_email(email),
false <- is_nil(user.confirmation_token),
true <- Timex.before?(Timex.shift(user.confirmation_sent_at, hours: 1), DateTime.utc_now()) do
true <-
Timex.before?(Timex.shift(user.confirmation_sent_at, hours: 1), DateTime.utc_now()) do
Activation.resend_confirmation_email(user)
render(conn, "confirmation.json", %{user: user})
else
@@ -50,6 +54,7 @@ defmodule EventosWeb.UserController do
conn
|> put_status(:not_found)
|> json(%{"error" => "Unable to find an user with this email"})
_ ->
conn
|> put_status(:not_found)
@@ -66,6 +71,7 @@ defmodule EventosWeb.UserController do
conn
|> put_status(:not_found)
|> json(%{"errors" => "Unable to find an user with this email"})
{:error, :email_too_soon} ->
conn
|> put_status(:not_found)
@@ -82,6 +88,7 @@ defmodule EventosWeb.UserController do
conn
|> put_status(:not_found)
|> json(%{"errors" => %{"token" => ["Wrong token for password reset"]}})
{:error, %Ecto.Changeset{} = changeset} ->
conn
|> put_status(:unprocessable_entity)
@@ -90,9 +97,11 @@ defmodule EventosWeb.UserController do
end
def show_current_actor(conn, _params) do
user = conn
|> Guardian.Plug.current_resource()
|> Repo.preload(:actors)
user =
conn
|> Guardian.Plug.current_resource()
|> Repo.preload(:actors)
render(conn, "show_simple.json", user: user)
end
@@ -101,14 +110,13 @@ defmodule EventosWeb.UserController do
|> Enum.map(fn {field, detail} ->
"#{field} " <> render_detail(detail)
end)
|> Enum.join
|> Enum.join()
end
defp render_detail({message, values}) do
Enum.reduce values, message, fn {k, v}, acc ->
Enum.reduce(values, message, fn {k, v}, acc ->
String.replace(acc, "%{#{k}}", to_string(v))
end
end)
end
defp render_detail(message) do
@@ -125,6 +133,7 @@ defmodule EventosWeb.UserController do
def delete(conn, %{"id" => id}) do
user = Actors.get_user!(id)
with {:ok, %User{}} <- Actors.delete_user(user) do
send_resp(conn, :no_content, "")
end

View File

@@ -10,17 +10,22 @@ defmodule EventosWeb.UserSessionController do
with {:ok, %User{} = user} <- Actors.find_by_email(email),
{:ok, %User{} = _user} <- User.is_confirmed(user),
{:ok, token, _claims} <- Actors.authenticate(%{user: user, password: password}) do
# Render the token
render conn, "token.json", %{token: token, user: user}
# Render the token
render(conn, "token.json", %{token: token, user: user})
else
{:error, :not_found} ->
conn
|> put_status(401)
|> json(%{"error_msg" => "No such user", "display_error" => "session.error.bad_login"})
{:error, :unconfirmed} ->
conn
|> put_status(401)
|> json(%{"error_msg" => "User is not activated", "display_error" => "session.error.not_activated"})
|> json(%{
"error_msg" => "User is not activated",
"display_error" => "session.error.not_activated"
})
{:error, :unauthorized} ->
conn
|> put_status(401)

View File

@@ -4,45 +4,53 @@ defmodule EventosWeb.Endpoint do
"""
use Phoenix.Endpoint, otp_app: :eventos
socket "/socket", EventosWeb.UserSocket
socket("/socket", EventosWeb.UserSocket)
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/", from: :eventos, gzip: false,
plug(
Plug.Static,
at: "/",
from: :eventos,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt index.html)
)
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug(Phoenix.LiveReloader)
plug(Phoenix.CodeReloader)
end
plug CORSPlug
plug Plug.RequestId
plug Plug.Logger
plug(CORSPlug)
plug(Plug.RequestId)
plug(Plug.Logger)
plug Plug.Parsers,
plug(
Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison
)
plug Plug.MethodOverride
plug Plug.Head
plug(Plug.MethodOverride)
plug(Plug.Head)
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
plug Plug.Session,
plug(
Plug.Session,
store: :cookie,
key: "_eventos_key",
signing_salt: "F9CCTF22"
)
plug EventosWeb.Router
plug(EventosWeb.Router)
@doc """
Callback invoked for dynamically configuring the endpoint.

View File

@@ -2,10 +2,12 @@ defmodule EventosWeb.Guardian do
@moduledoc """
Handles the JWT tokens encoding and decoding
"""
use Guardian, otp_app: :eventos, permissions: %{
superuser: [:moderate, :super],
user: [:base]
}
use Guardian,
otp_app: :eventos,
permissions: %{
superuser: [:moderate, :super],
user: [:base]
}
alias Eventos.Actors
alias Eventos.Actors.User
@@ -23,6 +25,7 @@ defmodule EventosWeb.Guardian do
case Integer.parse(uid_str) do
{uid, ""} ->
{:ok, Actors.get_user_with_actor!(uid)}
_ ->
{:error, :invalid_id}
end

View File

@@ -19,9 +19,11 @@ defmodule EventosWeb.HTTPSignaturePlug do
def call(conn, _opts) do
user = conn.params["actor"]
Logger.debug fn ->
Logger.debug(fn ->
"Checking sig for #{user}"
end
end)
with [signature | _] <- get_req_header(conn, "signature") do
cond do
signature && String.contains?(signature, user) ->
@@ -42,10 +44,10 @@ defmodule EventosWeb.HTTPSignaturePlug do
Logger.debug("No signature header!")
conn
end
else
_ ->
Logger.debug("No signature header!")
conn
else
_ ->
Logger.debug("No signature header!")
conn
end
end
end

View File

@@ -5,107 +5,106 @@ defmodule EventosWeb.Router do
use EventosWeb, :router
pipeline :api do
plug :accepts, ["json"]
plug(:accepts, ["json"])
end
pipeline :well_known do
plug :accepts, ["json/application", "jrd-json"]
plug(:accepts, ["json/application", "jrd-json"])
end
pipeline :activity_pub do
plug :accepts, ["activity-json"]
plug(:accepts, ["activity-json"])
plug(EventosWeb.HTTPSignaturePlug)
end
pipeline :api_auth do
plug :accepts, ["json"]
plug EventosWeb.AuthPipeline
plug(:accepts, ["json"])
plug(EventosWeb.AuthPipeline)
end
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_flash)
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
end
scope "/api", EventosWeb do
pipe_through :api
pipe_through(:api)
scope "/v1" do
post("/users", UserController, :register)
get("/users/validate/:token", UserController, :validate)
post("/users/resend", UserController, :resend_confirmation)
post "/users", UserController, :register
get "/users/validate/:token", UserController, :validate
post "/users/resend", UserController, :resend_confirmation
post("/users/password-reset/send", UserController, :send_reset_password)
post("/users/password-reset/post", UserController, :reset_password)
post "/users/password-reset/send", UserController, :send_reset_password
post "/users/password-reset/post", UserController, :reset_password
post("/login", UserSessionController, :sign_in)
get("/groups", GroupController, :index)
get("/events", EventController, :index)
get("/events/all", EventController, :index_all)
get("/events/search/:name", EventController, :search)
get("/events/:uuid/ics", EventController, :export_to_ics)
get("/events/:uuid/tracks", TrackController, :show_tracks_for_event)
get("/events/:uuid/sessions", SessionController, :show_sessions_for_event)
get("/events/:uuid", EventController, :show)
get("/comments/:uuid", CommentController, :show)
get("/bots/:id", BotController, :show)
get("/bots", BotController, :index)
post "/login", UserSessionController, :sign_in
get "/groups", GroupController, :index
get "/events", EventController, :index
get "/events/search/:name", EventController, :search
get "/events/:uuid/ics", EventController, :export_to_ics
get "/events/:uuid/tracks", TrackController, :show_tracks_for_event
get "/events/:uuid/sessions", SessionController, :show_sessions_for_event
get "/events/:uuid", EventController, :show
get "/comments/:uuid", CommentController, :show
get "/bots/:id", BotController, :show
get "/bots", BotController, :index
get("/actors", ActorController, :index)
get("/actors/search/:name", ActorController, :search)
get("/actors/:name", ActorController, :show)
resources("/tags", TagController, only: [:index, :show])
resources("/categories", CategoryController, only: [:index, :show])
resources("/sessions", SessionController, only: [:index, :show])
resources("/tracks", TrackController, only: [:index, :show])
resources("/addresses", AddressController, only: [:index, :show])
get "/actors", ActorController, :index
get "/actors/search/:name", ActorController, :search
get "/actors/:name", ActorController, :show
resources "/tags", TagController, only: [:index, :show]
resources "/categories", CategoryController, only: [:index, :show]
resources "/sessions", SessionController, only: [:index, :show]
resources "/tracks", TrackController, only: [:index, :show]
resources "/addresses", AddressController, only: [:index, :show]
get "/search/:name", SearchController, :search
get("/search/:name", SearchController, :search)
end
end
# Other scopes may use custom stacks.
scope "/api", EventosWeb do
pipe_through :api_auth
pipe_through(:api_auth)
scope "/v1" do
get "/user", UserController, :show_current_actor
post "/sign-out", UserSessionController, :sign_out
resources "/users", UserController, except: [:new, :edit, :show]
post "/actors", ActorController, :create
patch "/actors/:name", ActorController, :update
post "/events", EventController, :create
patch "/events/:uuid", EventController, :update
put "/events/:uuid", EventController, :update
delete "/events/:uuid", EventController, :delete
post "/events/:uuid/join", ParticipantController, :join
post "/comments", CommentController, :create
patch "/comments/:uuid", CommentController, :update
put "/comments/:uuid", CommentController, :update
delete "/comments/:uuid", CommentController, :delete
resources "/bots", BotController, except: [:new, :edit, :show, :index]
post "/groups", GroupController, :create
post "/groups/:name/join", GroupController, :join
resources "/members", MemberController
resources "/sessions", SessionController, except: [:index, :show]
resources "/tracks", TrackController, except: [:index, :show]
get "/tracks/:id/sessions", SessionController, :show_sessions_for_track
resources "/categories", CategoryController
resources "/tags", TagController
resources "/addresses", AddressController, except: [:index, :show]
end
scope "/v1" do
get("/user", UserController, :show_current_actor)
post("/sign-out", UserSessionController, :sign_out)
resources("/users", UserController, except: [:new, :edit, :show])
post("/actors", ActorController, :create)
patch("/actors/:name", ActorController, :update)
post("/events", EventController, :create)
patch("/events/:uuid", EventController, :update)
put("/events/:uuid", EventController, :update)
delete("/events/:uuid", EventController, :delete)
post("/events/:uuid/join", ParticipantController, :join)
post("/comments", CommentController, :create)
patch("/comments/:uuid", CommentController, :update)
put("/comments/:uuid", CommentController, :update)
delete("/comments/:uuid", CommentController, :delete)
resources("/bots", BotController, except: [:new, :edit, :show, :index])
post("/groups", GroupController, :create)
post("/groups/:name/join", GroupController, :join)
resources("/members", MemberController)
resources("/sessions", SessionController, except: [:index, :show])
resources("/tracks", TrackController, except: [:index, :show])
get("/tracks/:id/sessions", SessionController, :show_sessions_for_track)
resources("/categories", CategoryController)
resources("/tags", TagController)
resources("/addresses", AddressController, except: [:index, :show])
end
end
scope "/.well-known", EventosWeb do
pipe_through :well_known
pipe_through(:well_known)
get "/host-meta", WebFingerController, :host_meta
get "/webfinger", WebFingerController, :webfinger
get "/nodeinfo", NodeinfoController, :schemas
get("/host-meta", WebFingerController, :host_meta)
get("/webfinger", WebFingerController, :webfinger)
get("/nodeinfo", NodeinfoController, :schemas)
end
scope "/nodeinfo", EventosWeb do
@@ -113,25 +112,25 @@ defmodule EventosWeb.Router do
end
scope "/", EventosWeb do
pipe_through :activity_pub
pipe_through(:activity_pub)
get "/@:name", ActivityPubController, :actor
get "/@:name/outbox", ActivityPubController, :outbox
get "/@:name/following", ActivityPubController, :following
get "/@:name/followers", ActivityPubController, :followers
get "/events/:uuid", ActivityPubController, :event
post "/@:name/inbox", ActivityPubController, :inbox
post "/inbox", ActivityPubController, :inbox
get("/@:name", ActivityPubController, :actor)
get("/@:name/outbox", ActivityPubController, :outbox)
get("/@:name/following", ActivityPubController, :following)
get("/@:name/followers", ActivityPubController, :followers)
get("/events/:uuid", ActivityPubController, :event)
post("/@:name/inbox", ActivityPubController, :inbox)
post("/inbox", ActivityPubController, :inbox)
end
if Mix.env == :dev do
if Mix.env() == :dev do
# If using Phoenix
forward "/sent_emails", Bamboo.SentEmailViewerPlug
forward("/sent_emails", Bamboo.SentEmailViewerPlug)
end
scope "/", EventosWeb do
pipe_through :browser
pipe_through(:browser)
get "/*path", PageController, :index
get("/*path", PageController, :index)
end
end

View File

@@ -34,16 +34,16 @@ defmodule EventosWeb.ActivityPub.ActorView do
"publicKeyPem" => public_key
},
"endpoints" => %{
"sharedInbox" => actor.shared_inbox_url,
},
# "icon" => %{
# "type" => "Image",
# "url" => User.avatar_url(actor)
# },
# "image" => %{
# "type" => "Image",
# "url" => User.banner_url(actor)
# }
"sharedInbox" => actor.shared_inbox_url
}
# "icon" => %{
# "type" => "Image",
# "url" => User.avatar_url(actor)
# },
# "image" => %{
# "type" => "Image",
# "url" => User.banner_url(actor)
# }
}
|> Map.merge(Utils.make_json_ld_header())
end
@@ -87,13 +87,14 @@ defmodule EventosWeb.ActivityPub.ActorView do
end
def render("outbox.json", %{actor: actor, page: page}) do
{page, no_page} = if page == 0 do
{1, true}
else
{page, false}
end
{page, no_page} =
if page == 0 do
{1, true}
else
{page, false}
end
{activities, total} = ActivityPub.fetch_public_activities_for_actor(actor, page)
{activities, total} = ActivityPub.fetch_public_activities_for_actor(actor, page)
collection =
Enum.map(activities, fn act ->
@@ -128,7 +129,12 @@ defmodule EventosWeb.ActivityPub.ActorView do
def render("activity.json", %{activity: %Activity{local: local} = activity}) do
%{
"id" => activity.data.url <> "/activity",
"type" => if local do "Create" else "Announce" end,
"type" =>
if local do
"Create"
else
"Announce"
end,
"actor" => activity.data.organizer_actor.url,
"published" => Timex.now(),
"to" => ["https://www.w3.org/ns/activitystreams#Public"],

View File

@@ -2,6 +2,7 @@ defmodule EventosWeb.ActivityPub.ObjectView do
use EventosWeb, :view
alias EventosWeb.ActivityPub.ObjectView
alias Eventos.Service.ActivityPub.Transmogrifier
@base %{
"@context" => [
"https://www.w3.org/ns/activitystreams",
@@ -17,8 +18,6 @@ defmodule EventosWeb.ActivityPub.ObjectView do
}
def render("event.json", %{event: event}) do
event = %{
"type" => "Event",
"id" => event.url,
@@ -27,8 +26,9 @@ defmodule EventosWeb.ActivityPub.ObjectView do
"content" => event.description,
"mediaType" => "text/markdown",
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
"updated" => Timex.format!(event.updated_at, "{ISO:Extended}"),
"updated" => Timex.format!(event.updated_at, "{ISO:Extended}")
}
Map.merge(event, @base)
end

View File

@@ -19,7 +19,8 @@ defmodule EventosWeb.ActorView do
end
def render("actor_basic.json", %{actor: actor}) do
%{id: actor.id,
%{
id: actor.id,
username: actor.preferred_username,
domain: actor.domain,
display_name: actor.name,
@@ -28,12 +29,13 @@ defmodule EventosWeb.ActorView do
# public_key: actor.public_key,
suspended: actor.suspended,
url: actor.url,
avatar: actor.avatar_url,
avatar: actor.avatar_url
}
end
def render("actor.json", %{actor: actor}) do
output = %{id: actor.id,
output = %{
id: actor.id,
username: actor.preferred_username,
domain: actor.domain,
display_name: actor.name,
@@ -46,11 +48,18 @@ defmodule EventosWeb.ActorView do
banner: actor.banner_url,
organized_events: render_many(actor.organized_events, EventView, "event_for_actor.json")
}
import Logger
Logger.debug(inspect actor.type)
Logger.debug(inspect(actor.type))
if actor.type == :Group do
Logger.debug("I'm a group !")
Map.put(output, :members, render_many(Actors.members_for_group(actor), MemberView, "member.json"))
Map.put(
output,
:members,
render_many(Actors.members_for_group(actor), MemberView, "member.json")
)
else
Logger.debug("not a group")
output

View File

@@ -15,7 +15,8 @@ defmodule EventosWeb.AddressView do
end
def render("address.json", %{address: address}) do
%{id: address.id,
%{
id: address.id,
description: address.description,
floor: address.floor,
addressCountry: address.addressCountry,
@@ -29,11 +30,12 @@ defmodule EventosWeb.AddressView do
def render("geom.json", %{address: %Geo.Point{} = point}) do
[lat, lon] = Tuple.to_list(point.coordinates)
%{
type: "point",
data: %{
"latitude": lat,
"longitude": lon,
latitude: lat,
longitude: lon
}
}
end

View File

@@ -11,8 +11,6 @@ defmodule EventosWeb.BotView do
end
def render("bot.json", %{bot: bot}) do
%{id: bot.id,
source: bot.source,
type: bot.type}
%{id: bot.id, source: bot.source, type: bot.type}
end
end

View File

@@ -14,9 +14,11 @@ defmodule EventosWeb.CategoryView do
end
def render("category.json", %{category: category}) do
%{id: category.id,
%{
id: category.id,
title: category.title,
description: category.description,
picture: category.picture}
picture: category.picture
}
end
end

View File

@@ -11,10 +11,6 @@ defmodule EventosWeb.CommentView do
end
def render("comment.json", %{comment: comment}) do
%{id: comment.id,
uuid: comment.uuid,
url: comment.url,
text: comment.text
}
%{id: comment.id, uuid: comment.uuid, url: comment.url, text: comment.text}
end
end

View File

@@ -9,8 +9,8 @@ defmodule EventosWeb.ErrorHelpers do
Generates tag for inlined form input errors.
"""
def error_tag(form, field) do
Enum.map(Keyword.get_values(form.errors, field), fn (error) ->
content_tag :span, translate_error(error), class: "help-block"
Enum.map(Keyword.get_values(form.errors, field), fn error ->
content_tag(:span, translate_error(error), class: "help-block")
end)
end

View File

@@ -19,6 +19,6 @@ defmodule EventosWeb.ErrorView do
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
render "500.html", assigns
render("500.html", assigns)
end
end

View File

@@ -10,7 +10,13 @@ defmodule EventosWeb.EventView do
data: render_many(events, EventView, "event_simple.json"),
coord: coord,
city: city,
country: country,
country: country
}
end
def render("index_all.json", %{events: events}) do
%{
data: render_many(events, EventView, "event_simple.json")
}
end
@@ -23,14 +29,12 @@ defmodule EventosWeb.EventView do
end
def render("event_for_actor.json", %{event: event}) do
%{id: event.id,
title: event.title,
uuid: event.uuid,
}
%{id: event.id, title: event.title, uuid: event.uuid}
end
def render("event_simple.json", %{event: event}) do
%{id: event.id,
%{
id: event.id,
title: event.title,
description: event.description,
begins_on: event.begins_on,
@@ -39,15 +43,16 @@ defmodule EventosWeb.EventView do
organizer: %{
username: event.organizer_actor.preferred_username,
display_name: event.organizer_actor.name,
avatar: event.organizer_actor.avatar_url,
avatar: event.organizer_actor.avatar_url
},
type: "Event",
address_type: event.address_type,
address_type: event.address_type
}
end
def render("event.json", %{event: event}) do
%{id: event.id,
%{
id: event.id,
title: event.title,
description: event.description,
begins_on: event.begins_on,
@@ -57,7 +62,7 @@ defmodule EventosWeb.EventView do
participants: render_many(event.participants, ActorView, "actor_basic.json"),
physical_address: render_one(event.physical_address, AddressView, "address.json"),
type: "Event",
address_type: event.address_type,
address_type: event.address_type
}
end
end

View File

@@ -18,16 +18,18 @@ defmodule EventosWeb.GroupView do
end
def render("group_simple.json", %{group: group}) do
%{id: group.id,
%{
id: group.id,
title: group.title,
description: group.description,
suspended: group.suspended,
url: group.url,
url: group.url
}
end
def render("group.json", %{group: group}) do
%{id: group.id,
%{
id: group.id,
title: group.title,
description: group.description,
suspended: group.suspended,

View File

@@ -14,7 +14,6 @@ defmodule EventosWeb.ParticipantView do
end
def render("participant.json", %{participant: participant}) do
%{id: participant.id,
role: participant.role}
%{id: participant.id, role: participant.role}
end
end

View File

@@ -9,7 +9,7 @@ defmodule EventosWeb.SearchView do
%{
data: %{
events: render_many(events, EventView, "event_simple.json"),
actors: render_many(actors, ActorView, "actor_basic.json"),
actors: render_many(actors, ActorView, "actor_basic.json")
}
}
end

View File

@@ -14,7 +14,8 @@ defmodule EventosWeb.SessionView do
end
def render("session.json", %{session: session}) do
%{id: session.id,
%{
id: session.id,
title: session.title,
subtitle: session.subtitle,
short_abstract: session.short_abstract,
@@ -22,6 +23,7 @@ defmodule EventosWeb.SessionView do
language: session.language,
slides_url: session.slides_url,
videos_urls: session.videos_urls,
audios_urls: session.audios_urls}
audios_urls: session.audios_urls
}
end
end

View File

@@ -14,7 +14,6 @@ defmodule EventosWeb.TagView do
end
def render("tag.json", %{tag: tag}) do
%{id: tag.id,
title: tag.title}
%{id: tag.id, title: tag.title}
end
end

View File

@@ -14,9 +14,6 @@ defmodule EventosWeb.TrackView do
end
def render("track.json", %{track: track}) do
%{id: track.id,
name: track.name,
description: track.description,
color: track.color}
%{id: track.id, name: track.name, description: track.description, color: track.color}
end
end

View File

@@ -26,35 +26,30 @@ defmodule EventosWeb.UserView do
end
def render("user_simple.json", %{user: user}) do
%{id: user.id,
%{
id: user.id,
role: user.role,
actors: render_many(user.actors, ActorView, "actor_basic.json")
}
end
def render("user.json", %{user: user}) do
%{id: user.id,
role: user.role,
actors: render_many(user.actors, ActorView, "actor.json")
}
%{id: user.id, role: user.role, actors: render_many(user.actors, ActorView, "actor.json")}
end
def render("user_private.json", %{user: user}) do
%{id: user.id,
email: user.email,
role: user.role,
}
%{id: user.id, email: user.email, role: user.role}
end
def render("confirmation.json", %{user: user}) do
%{
email: user.email,
email: user.email
}
end
def render("password_reset.json", %{user: user}) do
%{
email: user.email,
email: user.email
}
end
end