forked from potsda.mn/mobilizon
fix some code style and add checks to ci
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
fc89c563ec
commit
1217361b6c
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -14,3 +14,5 @@ erl_crash.dump
|
|||
# secrets files as long as you replace their contents by environment
|
||||
# variables.
|
||||
/config/*.secret.exs
|
||||
|
||||
/doc
|
|
@ -29,5 +29,6 @@ before_script:
|
|||
|
||||
mix:
|
||||
script:
|
||||
- mix credo || true
|
||||
- mix credo
|
||||
- mix dogma
|
||||
- mix coveralls
|
||||
|
|
|
@ -34,4 +34,4 @@ config :guardian, Guardian.DB,
|
|||
repo: Eventos.Repo,
|
||||
schema_name: "guardian_tokens", # default
|
||||
token_types: ["refresh_token"], # store all token types if not set
|
||||
sweep_interval: 60 # default: 60 minutes
|
||||
sweep_interval: 60 # default: 60 minutes
|
||||
|
|
17
config/dogma.exs
Normal file
17
config/dogma.exs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use Mix.Config
|
||||
alias Dogma.Rule
|
||||
|
||||
config :dogma,
|
||||
|
||||
# Select a set of rules as a base
|
||||
rule_set: Dogma.RuleSet.All,
|
||||
|
||||
# Pick paths not to lint
|
||||
exclude: [
|
||||
~r(\Alib/vendor/),
|
||||
],
|
||||
|
||||
# Override an existing rule configuration
|
||||
override: [
|
||||
%Rule.LineLength{ enabled: false },
|
||||
]
|
|
@ -1,9 +1,9 @@
|
|||
defmodule Eventos do
|
||||
@moduledoc """
|
||||
Eventos keeps the contexts that define your domain
|
||||
and business logic.
|
||||
Eventos is a decentralized and federated Meetup-like using [ActivityPub](http://activitypub.rocks/).
|
||||
|
||||
Contexts are also responsible for managing your data, regardless
|
||||
if it comes from the database, an external API or others.
|
||||
It consists of an API server build with [Elixir](http://elixir-lang.github.io/) and the [Phoenix Framework](https://hexdocs.pm/phoenix).
|
||||
|
||||
Eventos relies on `Guardian` for auth and `Geo`/Postgis for geographical informations.
|
||||
"""
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Accounts.Account do
|
||||
@moduledoc """
|
||||
Represents an account (local and remote users)
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Accounts.{Account, User}
|
||||
|
|
|
@ -5,7 +5,6 @@ defmodule Eventos.Accounts do
|
|||
|
||||
import Ecto.Query, warn: false
|
||||
alias Eventos.Repo
|
||||
import Logger
|
||||
|
||||
alias Eventos.Accounts.Account
|
||||
|
||||
|
@ -37,12 +36,12 @@ defmodule Eventos.Accounts do
|
|||
|
||||
"""
|
||||
def get_account!(id) do
|
||||
account = Repo.get!(Account, id)
|
||||
Repo.get!(Account, id)
|
||||
end
|
||||
|
||||
def get_account_with_everything!(id) do
|
||||
account = Repo.get!(Account, id)
|
||||
|> Repo.preload :organized_events
|
||||
Repo.preload(account, :organized_events)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -126,8 +125,8 @@ defmodule Eventos.Accounts do
|
|||
end
|
||||
|
||||
def list_users_with_accounts do
|
||||
Repo.all(User)
|
||||
|> Repo.preload :account
|
||||
users = Repo.all(User)
|
||||
Repo.preload(users, :account)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -147,8 +146,8 @@ defmodule Eventos.Accounts do
|
|||
def get_user!(id), do: Repo.get!(User, id)
|
||||
|
||||
def get_user_with_account!(id) do
|
||||
Repo.get!(User, id)
|
||||
|> Repo.preload :account
|
||||
user = Repo.get!(User, id)
|
||||
Repo.preload(user, :account)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -156,7 +155,7 @@ defmodule Eventos.Accounts do
|
|||
"""
|
||||
def find_by_email(email) do
|
||||
user = Repo.get_by(User, email: email)
|
||||
|> Repo.preload :account
|
||||
Repo.preload(user, :account)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -199,23 +198,13 @@ defmodule Eventos.Accounts do
|
|||
account_with_user = Ecto.Changeset.put_assoc(account, :user, user)
|
||||
|
||||
try do
|
||||
coucou = Eventos.Repo.insert!(account_with_user)
|
||||
Eventos.Repo.insert!(account_with_user)
|
||||
user = find_by_email(email)
|
||||
{:ok, user}
|
||||
rescue
|
||||
e in Ecto.InvalidChangesetError ->
|
||||
Logger.debug(inspect e)
|
||||
{:error, e.changeset.changes.user.errors}
|
||||
end
|
||||
|
||||
# with {:ok, %Account{} = account} <- create_account(%{username: username, suspended: false, domain: nil, private_key: privkey, public_key: pubkey, uri: "h", url: "h"}) do
|
||||
# case create_user(%{email: email, password: password, account: account}) do
|
||||
# {:ok, %User{} = user } ->
|
||||
# {:ok, user}
|
||||
# {:error, %Ecto.Changeset{} = changeset} ->
|
||||
# {:error, changeset}
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Accounts.User do
|
||||
@moduledoc """
|
||||
Represents a local user
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Accounts.{Account, User}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Application do
|
||||
@moduledoc """
|
||||
The Eventos application
|
||||
"""
|
||||
use Application
|
||||
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Category do
|
||||
@moduledoc """
|
||||
Represents a category for events
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.Category
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Event.TitleSlug do
|
||||
@moduledoc """
|
||||
Generates a slug for an event title
|
||||
"""
|
||||
alias Eventos.Events.Event
|
||||
import Ecto.Query
|
||||
alias Eventos.Repo
|
||||
|
@ -17,25 +20,16 @@ defmodule Eventos.Events.Event.TitleSlug do
|
|||
nil -> slug
|
||||
_event ->
|
||||
slug
|
||||
|> increment_slug
|
||||
|> Eventos.Slug.increment_slug()
|
||||
|> build_unique_slug(changeset)
|
||||
end
|
||||
end
|
||||
|
||||
defp increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Eventos.Events.Event do
|
||||
@moduledoc """
|
||||
Represents an event
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Event, Participant, Request, Tag, Session, Track}
|
||||
|
@ -72,4 +66,4 @@ defmodule Eventos.Events.Event do
|
|||
|> TitleSlug.maybe_generate_slug()
|
||||
|> TitleSlug.unique_constraint()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,6 @@ defmodule Eventos.Events do
|
|||
alias Eventos.Repo
|
||||
|
||||
alias Eventos.Events.Event
|
||||
alias Eventos.Accounts.Account
|
||||
|
||||
@doc """
|
||||
Returns the list of events.
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Participant do
|
||||
@moduledoc """
|
||||
Represents a participant, an account participating to an event
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Participant, Event}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Request do
|
||||
@moduledoc """
|
||||
Represents an account request to join an event
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Request, Event}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Session do
|
||||
@moduledoc """
|
||||
Represents a session for an event (such as a talk at a conference)
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Session, Event, Track}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Tag.TitleSlug do
|
||||
@moduledoc """
|
||||
Generates slugs for tags
|
||||
"""
|
||||
alias Eventos.Events.Tag
|
||||
import Ecto.Query
|
||||
alias Eventos.Repo
|
||||
|
@ -17,25 +20,16 @@ defmodule Eventos.Events.Tag.TitleSlug do
|
|||
nil -> slug
|
||||
_story ->
|
||||
slug
|
||||
|> increment_slug
|
||||
|> Eventos.Slug.increment_slug()
|
||||
|> build_unique_slug(changeset)
|
||||
end
|
||||
end
|
||||
|
||||
defp increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Eventos.Events.Tag do
|
||||
@moduledoc """
|
||||
Represents a tag for events
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.Tag
|
||||
|
@ -56,4 +50,4 @@ defmodule Eventos.Events.Tag do
|
|||
|> TitleSlug.maybe_generate_slug()
|
||||
|> TitleSlug.unique_constraint()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Events.Track do
|
||||
@moduledoc """
|
||||
Represents a track for an event (such as a theme) having multiple sessions
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Track, Event, Session}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Groups.Group.TitleSlug do
|
||||
@moduledoc """
|
||||
Slug generation for groups
|
||||
"""
|
||||
alias Eventos.Groups.Group
|
||||
import Ecto.Query
|
||||
alias Eventos.Repo
|
||||
|
@ -17,25 +20,16 @@ defmodule Eventos.Groups.Group.TitleSlug do
|
|||
nil -> slug
|
||||
_story ->
|
||||
slug
|
||||
|> increment_slug
|
||||
|> Eventos.Slug.increment_slug()
|
||||
|> build_unique_slug(changeset)
|
||||
end
|
||||
end
|
||||
|
||||
defp increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Eventos.Groups.Group do
|
||||
@moduledoc """
|
||||
Represents a group
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Groups.{Group, Member, Request}
|
||||
|
@ -63,4 +57,4 @@ defmodule Eventos.Groups.Group do
|
|||
|> TitleSlug.maybe_generate_slug()
|
||||
|> TitleSlug.unique_constraint()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Groups.Member do
|
||||
@moduledoc """
|
||||
Represents the membership of an account to a group
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Groups.{Member, Group}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Groups.Request do
|
||||
@moduledoc """
|
||||
Represents a group request, when an user wants to be member of a group
|
||||
"""
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Groups.Request
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
Postgrex.Types.define(Eventos.PostgresTypes,
|
||||
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
|
||||
json: Poison)
|
||||
json: Poison)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Repo do
|
||||
@moduledoc """
|
||||
Eventos Repo
|
||||
"""
|
||||
use Ecto.Repo, otp_app: :eventos
|
||||
|
||||
@doc """
|
||||
|
|
16
lib/eventos/slug.ex
Normal file
16
lib/eventos/slug.ex
Normal file
|
@ -0,0 +1,16 @@
|
|||
defmodule Eventos.Slug do
|
||||
@moduledoc """
|
||||
Common functions for slug generation
|
||||
"""
|
||||
def increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +1,11 @@
|
|||
defmodule EventosWeb.AuthErrorHandler do
|
||||
@moduledoc """
|
||||
In case we have an auth error
|
||||
"""
|
||||
import Plug.Conn
|
||||
|
||||
def auth_error(conn, {type, _reason}, _opts) do
|
||||
body = Poison.encode!(%{message: to_string(type)})
|
||||
send_resp(conn, 401, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.AuthPipeline do
|
||||
@moduledoc """
|
||||
Handles the app sessions
|
||||
"""
|
||||
|
||||
use Guardian.Plug.Pipeline, otp_app: :eventos,
|
||||
module: EventosWeb.Guardian,
|
||||
|
@ -8,4 +11,4 @@ defmodule EventosWeb.AuthPipeline do
|
|||
plug Guardian.Plug.EnsureAuthenticated
|
||||
plug Guardian.Plug.LoadResource, ensure: true
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
defmodule EventosWeb.UserSocket do
|
||||
@moduledoc """
|
||||
Channel for User
|
||||
"""
|
||||
use Phoenix.Socket
|
||||
|
||||
## Channels
|
||||
# Channels
|
||||
# channel "room:*", EventosWeb.RoomChannel
|
||||
|
||||
## Transports
|
||||
# Transports
|
||||
transport :websocket, Phoenix.Transports.WebSocket
|
||||
# transport :longpoll, Phoenix.Transports.LongPoll
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
defmodule EventosWeb.AccountController do
|
||||
@moduledoc """
|
||||
Controller for Accounts
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.Account
|
||||
import Logger
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.CategoryController do
|
||||
@moduledoc """
|
||||
Controller for Categories
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.EventController do
|
||||
@moduledoc """
|
||||
Controller for Events
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.GroupController do
|
||||
@moduledoc """
|
||||
Controller for Groups
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Groups
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.PageController do
|
||||
@moduledoc """
|
||||
Controller to load our webapp
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
plug :put_layout, false
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.SessionController do
|
||||
@moduledoc """
|
||||
Controller for (event) Sessions
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.TagController do
|
||||
@moduledoc """
|
||||
Controller for Tags
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.TrackController do
|
||||
@moduledoc """
|
||||
Controller for Tracks
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
defmodule EventosWeb.UserController do
|
||||
@moduledoc """
|
||||
Controller for Users
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
import Logger
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.User
|
||||
|
@ -16,11 +18,10 @@ defmodule EventosWeb.UserController do
|
|||
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
|
||||
case Accounts.register(%{email: email, password: password, username: username}) do
|
||||
{:ok, %User{} = user} ->
|
||||
Logger.debug(inspect user)
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> render "show_with_token.json", %{token: token, user: user}
|
||||
|> render("show_with_token.json", %{token: token, user: user})
|
||||
{:error, error} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|
@ -30,12 +31,14 @@ defmodule EventosWeb.UserController do
|
|||
|
||||
def show_current_account(conn, _params) do
|
||||
user = Guardian.Plug.current_resource(conn)
|
||||
|> Repo.preload :account
|
||||
user
|
||||
|> Repo.preload(:account)
|
||||
render(conn, "show_simple.json", user: user)
|
||||
end
|
||||
|
||||
defp handle_changeset_errors(errors) do
|
||||
Enum.map(errors, fn {field, detail} ->
|
||||
errors
|
||||
|> Enum.map(fn {field, detail} ->
|
||||
"#{field} " <> render_detail(detail)
|
||||
end)
|
||||
|> Enum.join
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
defmodule EventosWeb.UserSessionController do
|
||||
@moduledoc """
|
||||
Controller for user sessions
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
alias Eventos.Accounts.User
|
||||
alias Eventos.Accounts
|
||||
import Logger
|
||||
|
||||
def sign_in(conn, %{"email" => email, "password" => password}) do
|
||||
case Accounts.find_by_email(email) do
|
||||
|
@ -22,7 +24,7 @@ defmodule EventosWeb.UserSessionController do
|
|||
|
||||
def sign_out(conn, _params) do
|
||||
conn
|
||||
|> Guardian.Plug.sign_out()
|
||||
|> EventosWeb.Guardian.Plug.sign_out()
|
||||
|> send_resp(204, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.Endpoint do
|
||||
@moduledoc """
|
||||
Endpoint for Eventos app
|
||||
"""
|
||||
use Phoenix.Endpoint, otp_app: :eventos
|
||||
|
||||
socket "/socket", EventosWeb.UserSocket
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
defmodule EventosWeb.Guardian do
|
||||
@moduledoc """
|
||||
Handles the JWT tokens encoding and decoding
|
||||
"""
|
||||
use Guardian, otp_app: :eventos, permissions: %{
|
||||
superuser: [:moderate, :super],
|
||||
user: [:base]
|
||||
}
|
||||
|
||||
import Logger
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.{Account, User}
|
||||
alias Eventos.Accounts.User
|
||||
|
||||
def subject_for_token(user = %User{}, _claims) do
|
||||
def subject_for_token(%User{} = user, _claims) do
|
||||
{:ok, "User:" <> to_string(user.id)}
|
||||
end
|
||||
|
||||
|
@ -19,8 +20,6 @@ defmodule EventosWeb.Guardian do
|
|||
|
||||
def resource_from_claims(%{"sub" => "User:" <> uid_str}) do
|
||||
try do
|
||||
Logger.debug("Inspecting resource token")
|
||||
Logger.debug(inspect uid_str)
|
||||
case Integer.parse(uid_str) do
|
||||
{uid, ""} ->
|
||||
{:ok, Accounts.get_user_with_account!(uid)}
|
||||
|
@ -32,9 +31,7 @@ defmodule EventosWeb.Guardian do
|
|||
end
|
||||
end
|
||||
|
||||
def resource_from_claims(claims) do
|
||||
Logger.debug("Check bad resource")
|
||||
Logger.debug(inspect claims)
|
||||
def resource_from_claims(_) do
|
||||
{:error, :reason_for_error}
|
||||
end
|
||||
|
||||
|
@ -45,7 +42,6 @@ defmodule EventosWeb.Guardian do
|
|||
end
|
||||
|
||||
def on_verify(claims, token, _options) do
|
||||
Logger.debug(inspect claims)
|
||||
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
|
||||
{:ok, claims}
|
||||
end
|
||||
|
@ -62,4 +58,4 @@ defmodule EventosWeb.Guardian do
|
|||
# |> encode_permissions_into_claims!(Keyword.get(opts, :permissions))
|
||||
# {:ok, claims}
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.Router do
|
||||
@moduledoc """
|
||||
Router for eventos app
|
||||
"""
|
||||
use EventosWeb, :router
|
||||
|
||||
pipeline :api do
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.AccountView do
|
||||
@moduledoc """
|
||||
View for Accounts
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.AccountView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.CategoryView do
|
||||
@moduledoc """
|
||||
View for Categories
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.CategoryView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.ChangesetView do
|
||||
@moduledoc """
|
||||
View for changesets in case of errors
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.ErrorView do
|
||||
@moduledoc """
|
||||
View for errors
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
def render("404.html", _assigns) do
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.EventView do
|
||||
@moduledoc """
|
||||
View for Events
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.EventView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.GroupView do
|
||||
@moduledoc """
|
||||
View for Groups
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.GroupView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.MemberView do
|
||||
@moduledoc """
|
||||
View for Members
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.MemberView
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
defmodule EventosWeb.PageView do
|
||||
@moduledoc """
|
||||
View for our webapp
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.ParticipantView do
|
||||
@moduledoc """
|
||||
View for Participants
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.ParticipantView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.RequestView do
|
||||
@moduledoc """
|
||||
View for event request
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.RequestView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.SessionView do
|
||||
@moduledoc """
|
||||
View for event Sessions
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.SessionView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.TagView do
|
||||
@moduledoc """
|
||||
View for Tags
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TagView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.TrackView do
|
||||
@moduledoc """
|
||||
View for Tracks
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TrackView
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.UserSessionView do
|
||||
@moduledoc """
|
||||
View for user Sessions
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
def render("token.json", %{token: token, user: user}) do
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule EventosWeb.UserView do
|
||||
@moduledoc """
|
||||
View for Users
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.UserView
|
||||
alias EventosWeb.AccountView
|
||||
|
|
8
mix.exs
8
mix.exs
|
@ -12,7 +12,11 @@ defmodule Eventos.Mixfile do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test]
|
||||
preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
name: "Eventos",
|
||||
source_url: "https://framagit.org/tcit/eventos",
|
||||
homepage_url: "https://framagit.org/tcit/eventos",
|
||||
docs: [main: "Eventos"]
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -58,6 +62,8 @@ defmodule Eventos.Mixfile do
|
|||
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
|
||||
{:excoveralls, "~> 0.8", only: :test},
|
||||
{:dogma, "~> 0.1", only: :dev},
|
||||
{:icalendar, "~> 0.6"},
|
||||
{:ex_doc, "~> 0.16", only: :dev, runtime: false}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
3
mix.lock
3
mix.lock
|
@ -13,9 +13,11 @@
|
|||
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"},
|
||||
"dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [], [], "hexpm"},
|
||||
"ecto": {:hex, :ecto, "2.2.7", "2074106ff4a5cd9cb2b54b12ca087c4b659ddb3f6b50be4562883c1d763fb031", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"ecto_autoslug_field": {:hex, :ecto_autoslug_field, "0.4.0", "f07db9ac545c7489b49ae77d0675a4a1635af821d3d4c95b8399edfa8f779deb", [], [{:ecto, ">= 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:slugger, ">= 0.2.0", [hex: :slugger, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], [], "hexpm"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"ex_machina": {:hex, :ex_machina, "2.1.0", "4874dc9c78e7cf2d429f24dc3c4005674d4e4da6a08be961ffccc08fb528e28b", [], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.8.0", "99d2691d3edf8612f128be3f9869c4d44b91c67cec92186ce49470ae7a7404cf", [], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
@ -26,6 +28,7 @@
|
|||
"guardian": {:hex, :guardian, "1.0.1", "db0fbaf571c3b874785818b7272eaf5f1ed97a2f9b1f8bc5dc8b0fb8f8f7bb06", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}, {:uuid, ">= 1.1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"guardian_db": {:hex, :guardian_db, "1.1.0", "45ab94206cce38f7443dc27de6dc52966ccbdeff65ca1b1f11a6d8f3daceb556", [], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:guardian, "~> 1.0", [hex: :guardian, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"hackney": {:hex, :hackney, "1.10.1", "c38d0ca52ea80254936a32c45bb7eb414e7a96a521b4ce76d00a69753b157f21", [], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"icalendar": {:hex, :icalendar, "0.6.0", "0e30054b234752fa1ec3e2b928101f8c98f70067766590360d7790b41faab315", [], [{:timex, "~> 3.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"jose": {:hex, :jose, "1.8.4", "7946d1e5c03a76ac9ef42a6e6a20001d35987afd68c2107bcd8f01a84e75aa73", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [], [], "hexpm"},
|
||||
|
|
|
@ -36,7 +36,7 @@ defmodule Eventos.AccountsTest do
|
|||
assert account.domain == "some domain"
|
||||
assert account.private_key == "some private_key"
|
||||
assert account.public_key == "some public_key"
|
||||
assert account.suspended == true
|
||||
assert account.suspended
|
||||
assert account.uri == "some uri"
|
||||
assert account.url == "some url"
|
||||
assert account.username == "some username"
|
||||
|
@ -55,7 +55,7 @@ defmodule Eventos.AccountsTest do
|
|||
assert account.domain == "some updated domain"
|
||||
assert account.private_key == "some updated private_key"
|
||||
assert account.public_key == "some updated public_key"
|
||||
assert account.suspended == false
|
||||
refute account.suspended
|
||||
assert account.uri == "some updated uri"
|
||||
assert account.url == "some updated url"
|
||||
assert account.username == "some updated username"
|
||||
|
|
|
@ -9,11 +9,11 @@ defmodule Eventos.EventsTest do
|
|||
@account_valid_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", private_key: "some private_key", public_key: "some public_key", suspended: true, uri: "some uri", url: "some url", username: "some username"}
|
||||
@event_valid_attrs %{begins_on: "2010-04-17 14:00:00.000000Z", description: "some description", ends_on: "2010-04-17 14:00:00.000000Z", title: "some title"}
|
||||
|
||||
def account_fixture(attrs \\ %{}) do
|
||||
def account_fixture do
|
||||
insert(:account)
|
||||
end
|
||||
|
||||
def event_fixture(attrs \\ %{}) do
|
||||
def event_fixture do
|
||||
insert(:event, organizer: account_fixture())
|
||||
end
|
||||
|
||||
|
@ -274,7 +274,7 @@ defmodule Eventos.EventsTest do
|
|||
event = event_fixture()
|
||||
account = account_fixture()
|
||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
||||
|> Map.put(:account_id, account.id)
|
||||
valid_attrs = Map.put(valid_attrs, :account_id, account.id)
|
||||
{:ok, participant} =
|
||||
attrs
|
||||
|> Enum.into(valid_attrs)
|
||||
|
@ -297,7 +297,7 @@ defmodule Eventos.EventsTest do
|
|||
account = account_fixture()
|
||||
event = event_fixture()
|
||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
||||
|> Map.put(:account_id, account.id)
|
||||
valid_attrs = Map.put(valid_attrs, :account_id, account.id)
|
||||
assert {:ok, %Participant{} = participant} = Events.create_participant(valid_attrs)
|
||||
assert participant.role == 42
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ defmodule Eventos.GroupsTest do
|
|||
test "create_group/1 with valid data creates a group" do
|
||||
assert {:ok, %Group{} = group} = Groups.create_group(@valid_attrs)
|
||||
assert group.description == "some description"
|
||||
assert group.suspended == true
|
||||
assert group.suspended
|
||||
assert group.title == "some title"
|
||||
assert group.uri == "some uri"
|
||||
assert group.url == "some url"
|
||||
|
@ -47,7 +47,7 @@ defmodule Eventos.GroupsTest do
|
|||
assert {:ok, group} = Groups.update_group(group, @update_attrs)
|
||||
assert %Group{} = group
|
||||
assert group.description == "some updated description"
|
||||
assert group.suspended == false
|
||||
refute group.suspended
|
||||
assert group.title == "some updated title"
|
||||
assert group.uri == "some updated uri"
|
||||
assert group.url == "some updated url"
|
||||
|
|
|
@ -6,8 +6,6 @@ defmodule EventosWeb.AccountControllerTest do
|
|||
alias Eventos.Accounts
|
||||
|
||||
@create_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", private_key: "some private_key", public_key: "some public_key", suspended: true, uri: "some uri", url: "some url", username: "some username"}
|
||||
@update_attrs %{description: "some updated description", display_name: "some updated display_name", domain: "some updated domain", private_key: "some updated private_key", public_key: "some updated public_key", suspended: false, uri: "some updated uri", url: "some updated url", username: "some updated username"}
|
||||
@invalid_attrs %{description: nil, display_name: nil, domain: nil, private_key: nil, public_key: nil, suspended: nil, uri: nil, url: nil, username: nil}
|
||||
|
||||
def fixture(:account) do
|
||||
{:ok, account} = Accounts.create_account(@create_attrs)
|
||||
|
|
|
@ -7,7 +7,7 @@ defmodule EventosWeb.UserControllerTest do
|
|||
alias Eventos.Accounts.User
|
||||
|
||||
@create_attrs %{email: "foo@bar.tld", password: "some password_hash", username: "some username"}
|
||||
@update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"}
|
||||
# @update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"}
|
||||
@invalid_attrs %{email: "not an email", password: nil, username: nil}
|
||||
|
||||
def fixture(:user) do
|
||||
|
@ -33,6 +33,7 @@ defmodule EventosWeb.UserControllerTest do
|
|||
test "renders user when data is valid", %{conn: conn} do
|
||||
conn = post conn, user_path(conn, :create), @create_attrs
|
||||
assert %{"user" => %{"id" => id}} = json_response(conn, 201)
|
||||
assert id > 0
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Eventos.Factory do
|
||||
@moduledoc """
|
||||
Factory for fixtures with ExMachina
|
||||
"""
|
||||
# with Ecto
|
||||
use ExMachina.Ecto, repo: Eventos.Repo
|
||||
|
||||
|
@ -12,7 +15,7 @@ defmodule Eventos.Factory do
|
|||
end
|
||||
|
||||
def account_factory do
|
||||
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
|
||||
{:ok, {_, pubkey}} = RsaEx.generate_keypair("4096")
|
||||
%Eventos.Accounts.Account{
|
||||
username: sequence("Thomas"),
|
||||
domain: nil,
|
||||
|
@ -47,4 +50,4 @@ defmodule Eventos.Factory do
|
|||
event: build(:event)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,4 +3,3 @@
|
|||
ExUnit.start()
|
||||
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, :manual)
|
||||
|
||||
|
|
Loading…
Reference in a new issue