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
|
# secrets files as long as you replace their contents by environment
|
||||||
# variables.
|
# variables.
|
||||||
/config/*.secret.exs
|
/config/*.secret.exs
|
||||||
|
|
||||||
|
/doc
|
@ -29,5 +29,6 @@ before_script:
|
|||||||
|
|
||||||
mix:
|
mix:
|
||||||
script:
|
script:
|
||||||
- mix credo || true
|
- mix credo
|
||||||
|
- mix dogma
|
||||||
- mix coveralls
|
- mix coveralls
|
||||||
|
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
|
defmodule Eventos do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Eventos keeps the contexts that define your domain
|
Eventos is a decentralized and federated Meetup-like using [ActivityPub](http://activitypub.rocks/).
|
||||||
and business logic.
|
|
||||||
|
|
||||||
Contexts are also responsible for managing your data, regardless
|
It consists of an API server build with [Elixir](http://elixir-lang.github.io/) and the [Phoenix Framework](https://hexdocs.pm/phoenix).
|
||||||
if it comes from the database, an external API or others.
|
|
||||||
|
Eventos relies on `Guardian` for auth and `Geo`/Postgis for geographical informations.
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Accounts.Account do
|
defmodule Eventos.Accounts.Account do
|
||||||
|
@moduledoc """
|
||||||
|
Represents an account (local and remote users)
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Accounts.{Account, User}
|
alias Eventos.Accounts.{Account, User}
|
||||||
|
@ -5,7 +5,6 @@ defmodule Eventos.Accounts do
|
|||||||
|
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
alias Eventos.Repo
|
alias Eventos.Repo
|
||||||
import Logger
|
|
||||||
|
|
||||||
alias Eventos.Accounts.Account
|
alias Eventos.Accounts.Account
|
||||||
|
|
||||||
@ -37,12 +36,12 @@ defmodule Eventos.Accounts do
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
def get_account!(id) do
|
def get_account!(id) do
|
||||||
account = Repo.get!(Account, id)
|
Repo.get!(Account, id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_account_with_everything!(id) do
|
def get_account_with_everything!(id) do
|
||||||
account = Repo.get!(Account, id)
|
account = Repo.get!(Account, id)
|
||||||
|> Repo.preload :organized_events
|
Repo.preload(account, :organized_events)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -126,8 +125,8 @@ defmodule Eventos.Accounts do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def list_users_with_accounts do
|
def list_users_with_accounts do
|
||||||
Repo.all(User)
|
users = Repo.all(User)
|
||||||
|> Repo.preload :account
|
Repo.preload(users, :account)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -147,8 +146,8 @@ defmodule Eventos.Accounts do
|
|||||||
def get_user!(id), do: Repo.get!(User, id)
|
def get_user!(id), do: Repo.get!(User, id)
|
||||||
|
|
||||||
def get_user_with_account!(id) do
|
def get_user_with_account!(id) do
|
||||||
Repo.get!(User, id)
|
user = Repo.get!(User, id)
|
||||||
|> Repo.preload :account
|
Repo.preload(user, :account)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -156,7 +155,7 @@ defmodule Eventos.Accounts do
|
|||||||
"""
|
"""
|
||||||
def find_by_email(email) do
|
def find_by_email(email) do
|
||||||
user = Repo.get_by(User, email: email)
|
user = Repo.get_by(User, email: email)
|
||||||
|> Repo.preload :account
|
Repo.preload(user, :account)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -199,23 +198,13 @@ defmodule Eventos.Accounts do
|
|||||||
account_with_user = Ecto.Changeset.put_assoc(account, :user, user)
|
account_with_user = Ecto.Changeset.put_assoc(account, :user, user)
|
||||||
|
|
||||||
try do
|
try do
|
||||||
coucou = Eventos.Repo.insert!(account_with_user)
|
Eventos.Repo.insert!(account_with_user)
|
||||||
user = find_by_email(email)
|
user = find_by_email(email)
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
rescue
|
rescue
|
||||||
e in Ecto.InvalidChangesetError ->
|
e in Ecto.InvalidChangesetError ->
|
||||||
Logger.debug(inspect e)
|
|
||||||
{:error, e.changeset.changes.user.errors}
|
{:error, e.changeset.changes.user.errors}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Accounts.User do
|
defmodule Eventos.Accounts.User do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a local user
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Accounts.{Account, User}
|
alias Eventos.Accounts.{Account, User}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Application do
|
defmodule Eventos.Application do
|
||||||
|
@moduledoc """
|
||||||
|
The Eventos application
|
||||||
|
"""
|
||||||
use Application
|
use Application
|
||||||
|
|
||||||
# See https://hexdocs.pm/elixir/Application.html
|
# See https://hexdocs.pm/elixir/Application.html
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Category do
|
defmodule Eventos.Events.Category do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a category for events
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.Category
|
alias Eventos.Events.Category
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Event.TitleSlug do
|
defmodule Eventos.Events.Event.TitleSlug do
|
||||||
|
@moduledoc """
|
||||||
|
Generates a slug for an event title
|
||||||
|
"""
|
||||||
alias Eventos.Events.Event
|
alias Eventos.Events.Event
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Eventos.Repo
|
alias Eventos.Repo
|
||||||
@ -17,25 +20,16 @@ defmodule Eventos.Events.Event.TitleSlug do
|
|||||||
nil -> slug
|
nil -> slug
|
||||||
_event ->
|
_event ->
|
||||||
slug
|
slug
|
||||||
|> increment_slug
|
|> Eventos.Slug.increment_slug()
|
||||||
|> build_unique_slug(changeset)
|
|> build_unique_slug(changeset)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
defmodule Eventos.Events.Event do
|
defmodule Eventos.Events.Event do
|
||||||
|
@moduledoc """
|
||||||
|
Represents an event
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.{Event, Participant, Request, Tag, Session, Track}
|
alias Eventos.Events.{Event, Participant, Request, Tag, Session, Track}
|
||||||
|
@ -7,7 +7,6 @@ defmodule Eventos.Events do
|
|||||||
alias Eventos.Repo
|
alias Eventos.Repo
|
||||||
|
|
||||||
alias Eventos.Events.Event
|
alias Eventos.Events.Event
|
||||||
alias Eventos.Accounts.Account
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of events.
|
Returns the list of events.
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Participant do
|
defmodule Eventos.Events.Participant do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a participant, an account participating to an event
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.{Participant, Event}
|
alias Eventos.Events.{Participant, Event}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Request do
|
defmodule Eventos.Events.Request do
|
||||||
|
@moduledoc """
|
||||||
|
Represents an account request to join an event
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.{Request, Event}
|
alias Eventos.Events.{Request, Event}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Session do
|
defmodule Eventos.Events.Session do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a session for an event (such as a talk at a conference)
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.{Session, Event, Track}
|
alias Eventos.Events.{Session, Event, Track}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Tag.TitleSlug do
|
defmodule Eventos.Events.Tag.TitleSlug do
|
||||||
|
@moduledoc """
|
||||||
|
Generates slugs for tags
|
||||||
|
"""
|
||||||
alias Eventos.Events.Tag
|
alias Eventos.Events.Tag
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Eventos.Repo
|
alias Eventos.Repo
|
||||||
@ -17,25 +20,16 @@ defmodule Eventos.Events.Tag.TitleSlug do
|
|||||||
nil -> slug
|
nil -> slug
|
||||||
_story ->
|
_story ->
|
||||||
slug
|
slug
|
||||||
|> increment_slug
|
|> Eventos.Slug.increment_slug()
|
||||||
|> build_unique_slug(changeset)
|
|> build_unique_slug(changeset)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
defmodule Eventos.Events.Tag do
|
defmodule Eventos.Events.Tag do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a tag for events
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.Tag
|
alias Eventos.Events.Tag
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Events.Track do
|
defmodule Eventos.Events.Track do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a track for an event (such as a theme) having multiple sessions
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Events.{Track, Event, Session}
|
alias Eventos.Events.{Track, Event, Session}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Groups.Group.TitleSlug do
|
defmodule Eventos.Groups.Group.TitleSlug do
|
||||||
|
@moduledoc """
|
||||||
|
Slug generation for groups
|
||||||
|
"""
|
||||||
alias Eventos.Groups.Group
|
alias Eventos.Groups.Group
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Eventos.Repo
|
alias Eventos.Repo
|
||||||
@ -17,25 +20,16 @@ defmodule Eventos.Groups.Group.TitleSlug do
|
|||||||
nil -> slug
|
nil -> slug
|
||||||
_story ->
|
_story ->
|
||||||
slug
|
slug
|
||||||
|> increment_slug
|
|> Eventos.Slug.increment_slug()
|
||||||
|> build_unique_slug(changeset)
|
|> build_unique_slug(changeset)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
defmodule Eventos.Groups.Group do
|
defmodule Eventos.Groups.Group do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a group
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Groups.{Group, Member, Request}
|
alias Eventos.Groups.{Group, Member, Request}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Groups.Member do
|
defmodule Eventos.Groups.Member do
|
||||||
|
@moduledoc """
|
||||||
|
Represents the membership of an account to a group
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Groups.{Member, Group}
|
alias Eventos.Groups.{Member, Group}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Groups.Request do
|
defmodule Eventos.Groups.Request do
|
||||||
|
@moduledoc """
|
||||||
|
Represents a group request, when an user wants to be member of a group
|
||||||
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Eventos.Groups.Request
|
alias Eventos.Groups.Request
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Repo do
|
defmodule Eventos.Repo do
|
||||||
|
@moduledoc """
|
||||||
|
Eventos Repo
|
||||||
|
"""
|
||||||
use Ecto.Repo, otp_app: :eventos
|
use Ecto.Repo, otp_app: :eventos
|
||||||
|
|
||||||
@doc """
|
@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,4 +1,7 @@
|
|||||||
defmodule EventosWeb.AuthErrorHandler do
|
defmodule EventosWeb.AuthErrorHandler do
|
||||||
|
@moduledoc """
|
||||||
|
In case we have an auth error
|
||||||
|
"""
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|
||||||
def auth_error(conn, {type, _reason}, _opts) do
|
def auth_error(conn, {type, _reason}, _opts) do
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.AuthPipeline do
|
defmodule EventosWeb.AuthPipeline do
|
||||||
|
@moduledoc """
|
||||||
|
Handles the app sessions
|
||||||
|
"""
|
||||||
|
|
||||||
use Guardian.Plug.Pipeline, otp_app: :eventos,
|
use Guardian.Plug.Pipeline, otp_app: :eventos,
|
||||||
module: EventosWeb.Guardian,
|
module: EventosWeb.Guardian,
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
defmodule EventosWeb.UserSocket do
|
defmodule EventosWeb.UserSocket do
|
||||||
|
@moduledoc """
|
||||||
|
Channel for User
|
||||||
|
"""
|
||||||
use Phoenix.Socket
|
use Phoenix.Socket
|
||||||
|
|
||||||
## Channels
|
# Channels
|
||||||
# channel "room:*", EventosWeb.RoomChannel
|
# channel "room:*", EventosWeb.RoomChannel
|
||||||
|
|
||||||
## Transports
|
# Transports
|
||||||
transport :websocket, Phoenix.Transports.WebSocket
|
transport :websocket, Phoenix.Transports.WebSocket
|
||||||
# transport :longpoll, Phoenix.Transports.LongPoll
|
# transport :longpoll, Phoenix.Transports.LongPoll
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
defmodule EventosWeb.AccountController do
|
defmodule EventosWeb.AccountController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Accounts
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Accounts
|
alias Eventos.Accounts
|
||||||
alias Eventos.Accounts.Account
|
alias Eventos.Accounts.Account
|
||||||
import Logger
|
|
||||||
|
|
||||||
action_fallback EventosWeb.FallbackController
|
action_fallback EventosWeb.FallbackController
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.CategoryController do
|
defmodule EventosWeb.CategoryController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Categories
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Events
|
alias Eventos.Events
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.EventController do
|
defmodule EventosWeb.EventController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Events
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Events
|
alias Eventos.Events
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.GroupController do
|
defmodule EventosWeb.GroupController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Groups
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Groups
|
alias Eventos.Groups
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.PageController do
|
defmodule EventosWeb.PageController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller to load our webapp
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
plug :put_layout, false
|
plug :put_layout, false
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.SessionController do
|
defmodule EventosWeb.SessionController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for (event) Sessions
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Events
|
alias Eventos.Events
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.TagController do
|
defmodule EventosWeb.TagController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Tags
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Events
|
alias Eventos.Events
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.TrackController do
|
defmodule EventosWeb.TrackController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Tracks
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Events
|
alias Eventos.Events
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
defmodule EventosWeb.UserController do
|
defmodule EventosWeb.UserController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for Users
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
import Logger
|
|
||||||
|
|
||||||
alias Eventos.Accounts
|
alias Eventos.Accounts
|
||||||
alias Eventos.Accounts.User
|
alias Eventos.Accounts.User
|
||||||
@ -16,11 +18,10 @@ defmodule EventosWeb.UserController do
|
|||||||
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
|
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
|
||||||
case Accounts.register(%{email: email, password: password, username: username}) do
|
case Accounts.register(%{email: email, password: password, username: username}) do
|
||||||
{:ok, %User{} = user} ->
|
{:ok, %User{} = user} ->
|
||||||
Logger.debug(inspect user)
|
|
||||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||||
conn
|
conn
|
||||||
|> put_status(:created)
|
|> put_status(:created)
|
||||||
|> render "show_with_token.json", %{token: token, user: user}
|
|> render("show_with_token.json", %{token: token, user: user})
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
@ -30,12 +31,14 @@ defmodule EventosWeb.UserController do
|
|||||||
|
|
||||||
def show_current_account(conn, _params) do
|
def show_current_account(conn, _params) do
|
||||||
user = Guardian.Plug.current_resource(conn)
|
user = Guardian.Plug.current_resource(conn)
|
||||||
|> Repo.preload :account
|
user
|
||||||
|
|> Repo.preload(:account)
|
||||||
render(conn, "show_simple.json", user: user)
|
render(conn, "show_simple.json", user: user)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp handle_changeset_errors(errors) do
|
defp handle_changeset_errors(errors) do
|
||||||
Enum.map(errors, fn {field, detail} ->
|
errors
|
||||||
|
|> Enum.map(fn {field, detail} ->
|
||||||
"#{field} " <> render_detail(detail)
|
"#{field} " <> render_detail(detail)
|
||||||
end)
|
end)
|
||||||
|> Enum.join
|
|> Enum.join
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
defmodule EventosWeb.UserSessionController do
|
defmodule EventosWeb.UserSessionController do
|
||||||
|
@moduledoc """
|
||||||
|
Controller for user sessions
|
||||||
|
"""
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
alias Eventos.Accounts.User
|
alias Eventos.Accounts.User
|
||||||
alias Eventos.Accounts
|
alias Eventos.Accounts
|
||||||
import Logger
|
|
||||||
|
|
||||||
def sign_in(conn, %{"email" => email, "password" => password}) do
|
def sign_in(conn, %{"email" => email, "password" => password}) do
|
||||||
case Accounts.find_by_email(email) do
|
case Accounts.find_by_email(email) do
|
||||||
@ -22,7 +24,7 @@ defmodule EventosWeb.UserSessionController do
|
|||||||
|
|
||||||
def sign_out(conn, _params) do
|
def sign_out(conn, _params) do
|
||||||
conn
|
conn
|
||||||
|> Guardian.Plug.sign_out()
|
|> EventosWeb.Guardian.Plug.sign_out()
|
||||||
|> send_resp(204, "")
|
|> send_resp(204, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.Endpoint do
|
defmodule EventosWeb.Endpoint do
|
||||||
|
@moduledoc """
|
||||||
|
Endpoint for Eventos app
|
||||||
|
"""
|
||||||
use Phoenix.Endpoint, otp_app: :eventos
|
use Phoenix.Endpoint, otp_app: :eventos
|
||||||
|
|
||||||
socket "/socket", EventosWeb.UserSocket
|
socket "/socket", EventosWeb.UserSocket
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
defmodule EventosWeb.Guardian do
|
defmodule EventosWeb.Guardian do
|
||||||
|
@moduledoc """
|
||||||
|
Handles the JWT tokens encoding and decoding
|
||||||
|
"""
|
||||||
use Guardian, otp_app: :eventos, permissions: %{
|
use Guardian, otp_app: :eventos, permissions: %{
|
||||||
superuser: [:moderate, :super],
|
superuser: [:moderate, :super],
|
||||||
user: [:base]
|
user: [:base]
|
||||||
}
|
}
|
||||||
|
|
||||||
import Logger
|
|
||||||
|
|
||||||
alias Eventos.Accounts
|
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)}
|
{:ok, "User:" <> to_string(user.id)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,8 +20,6 @@ defmodule EventosWeb.Guardian do
|
|||||||
|
|
||||||
def resource_from_claims(%{"sub" => "User:" <> uid_str}) do
|
def resource_from_claims(%{"sub" => "User:" <> uid_str}) do
|
||||||
try do
|
try do
|
||||||
Logger.debug("Inspecting resource token")
|
|
||||||
Logger.debug(inspect uid_str)
|
|
||||||
case Integer.parse(uid_str) do
|
case Integer.parse(uid_str) do
|
||||||
{uid, ""} ->
|
{uid, ""} ->
|
||||||
{:ok, Accounts.get_user_with_account!(uid)}
|
{:ok, Accounts.get_user_with_account!(uid)}
|
||||||
@ -32,9 +31,7 @@ defmodule EventosWeb.Guardian do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_from_claims(claims) do
|
def resource_from_claims(_) do
|
||||||
Logger.debug("Check bad resource")
|
|
||||||
Logger.debug(inspect claims)
|
|
||||||
{:error, :reason_for_error}
|
{:error, :reason_for_error}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,7 +42,6 @@ defmodule EventosWeb.Guardian do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_verify(claims, token, _options) do
|
def on_verify(claims, token, _options) do
|
||||||
Logger.debug(inspect claims)
|
|
||||||
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
|
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
|
||||||
{:ok, claims}
|
{:ok, claims}
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.Router do
|
defmodule EventosWeb.Router do
|
||||||
|
@moduledoc """
|
||||||
|
Router for eventos app
|
||||||
|
"""
|
||||||
use EventosWeb, :router
|
use EventosWeb, :router
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.AccountView do
|
defmodule EventosWeb.AccountView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Accounts
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.AccountView
|
alias EventosWeb.AccountView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.CategoryView do
|
defmodule EventosWeb.CategoryView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Categories
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.CategoryView
|
alias EventosWeb.CategoryView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.ChangesetView do
|
defmodule EventosWeb.ChangesetView do
|
||||||
|
@moduledoc """
|
||||||
|
View for changesets in case of errors
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.ErrorView do
|
defmodule EventosWeb.ErrorView do
|
||||||
|
@moduledoc """
|
||||||
|
View for errors
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
|
|
||||||
def render("404.html", _assigns) do
|
def render("404.html", _assigns) do
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.EventView do
|
defmodule EventosWeb.EventView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Events
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.EventView
|
alias EventosWeb.EventView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.GroupView do
|
defmodule EventosWeb.GroupView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Groups
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.GroupView
|
alias EventosWeb.GroupView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.MemberView do
|
defmodule EventosWeb.MemberView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Members
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.MemberView
|
alias EventosWeb.MemberView
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
defmodule EventosWeb.PageView do
|
defmodule EventosWeb.PageView do
|
||||||
|
@moduledoc """
|
||||||
|
View for our webapp
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.ParticipantView do
|
defmodule EventosWeb.ParticipantView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Participants
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.ParticipantView
|
alias EventosWeb.ParticipantView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.RequestView do
|
defmodule EventosWeb.RequestView do
|
||||||
|
@moduledoc """
|
||||||
|
View for event request
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.RequestView
|
alias EventosWeb.RequestView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.SessionView do
|
defmodule EventosWeb.SessionView do
|
||||||
|
@moduledoc """
|
||||||
|
View for event Sessions
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.SessionView
|
alias EventosWeb.SessionView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.TagView do
|
defmodule EventosWeb.TagView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Tags
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.TagView
|
alias EventosWeb.TagView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.TrackView do
|
defmodule EventosWeb.TrackView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Tracks
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.TrackView
|
alias EventosWeb.TrackView
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.UserSessionView do
|
defmodule EventosWeb.UserSessionView do
|
||||||
|
@moduledoc """
|
||||||
|
View for user Sessions
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
|
|
||||||
def render("token.json", %{token: token, user: user}) do
|
def render("token.json", %{token: token, user: user}) do
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule EventosWeb.UserView do
|
defmodule EventosWeb.UserView do
|
||||||
|
@moduledoc """
|
||||||
|
View for Users
|
||||||
|
"""
|
||||||
use EventosWeb, :view
|
use EventosWeb, :view
|
||||||
alias EventosWeb.UserView
|
alias EventosWeb.UserView
|
||||||
alias EventosWeb.AccountView
|
alias EventosWeb.AccountView
|
||||||
|
8
mix.exs
8
mix.exs
@ -12,7 +12,11 @@ defmodule Eventos.Mixfile do
|
|||||||
aliases: aliases(),
|
aliases: aliases(),
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
test_coverage: [tool: ExCoveralls],
|
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
|
end
|
||||||
|
|
||||||
@ -58,6 +62,8 @@ defmodule Eventos.Mixfile do
|
|||||||
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
|
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
|
||||||
{:excoveralls, "~> 0.8", only: :test},
|
{:excoveralls, "~> 0.8", only: :test},
|
||||||
{:dogma, "~> 0.1", only: :dev},
|
{:dogma, "~> 0.1", only: :dev},
|
||||||
|
{:icalendar, "~> 0.6"},
|
||||||
|
{:ex_doc, "~> 0.16", only: :dev, runtime: false}
|
||||||
]
|
]
|
||||||
end
|
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"},
|
"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"},
|
"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"},
|
"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": {: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"},
|
"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"},
|
"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"},
|
"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"},
|
"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"},
|
"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": {: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"},
|
"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"},
|
"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"},
|
"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"},
|
"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"},
|
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [], [], "hexpm"},
|
||||||
|
@ -36,7 +36,7 @@ defmodule Eventos.AccountsTest do
|
|||||||
assert account.domain == "some domain"
|
assert account.domain == "some domain"
|
||||||
assert account.private_key == "some private_key"
|
assert account.private_key == "some private_key"
|
||||||
assert account.public_key == "some public_key"
|
assert account.public_key == "some public_key"
|
||||||
assert account.suspended == true
|
assert account.suspended
|
||||||
assert account.uri == "some uri"
|
assert account.uri == "some uri"
|
||||||
assert account.url == "some url"
|
assert account.url == "some url"
|
||||||
assert account.username == "some username"
|
assert account.username == "some username"
|
||||||
@ -55,7 +55,7 @@ defmodule Eventos.AccountsTest do
|
|||||||
assert account.domain == "some updated domain"
|
assert account.domain == "some updated domain"
|
||||||
assert account.private_key == "some updated private_key"
|
assert account.private_key == "some updated private_key"
|
||||||
assert account.public_key == "some updated public_key"
|
assert account.public_key == "some updated public_key"
|
||||||
assert account.suspended == false
|
refute account.suspended
|
||||||
assert account.uri == "some updated uri"
|
assert account.uri == "some updated uri"
|
||||||
assert account.url == "some updated url"
|
assert account.url == "some updated url"
|
||||||
assert account.username == "some updated username"
|
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"}
|
@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"}
|
@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)
|
insert(:account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def event_fixture(attrs \\ %{}) do
|
def event_fixture do
|
||||||
insert(:event, organizer: account_fixture())
|
insert(:event, organizer: account_fixture())
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ defmodule Eventos.EventsTest do
|
|||||||
event = event_fixture()
|
event = event_fixture()
|
||||||
account = account_fixture()
|
account = account_fixture()
|
||||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
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} =
|
{:ok, participant} =
|
||||||
attrs
|
attrs
|
||||||
|> Enum.into(valid_attrs)
|
|> Enum.into(valid_attrs)
|
||||||
@ -297,7 +297,7 @@ defmodule Eventos.EventsTest do
|
|||||||
account = account_fixture()
|
account = account_fixture()
|
||||||
event = event_fixture()
|
event = event_fixture()
|
||||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
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 {:ok, %Participant{} = participant} = Events.create_participant(valid_attrs)
|
||||||
assert participant.role == 42
|
assert participant.role == 42
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ defmodule Eventos.GroupsTest do
|
|||||||
test "create_group/1 with valid data creates a group" do
|
test "create_group/1 with valid data creates a group" do
|
||||||
assert {:ok, %Group{} = group} = Groups.create_group(@valid_attrs)
|
assert {:ok, %Group{} = group} = Groups.create_group(@valid_attrs)
|
||||||
assert group.description == "some description"
|
assert group.description == "some description"
|
||||||
assert group.suspended == true
|
assert group.suspended
|
||||||
assert group.title == "some title"
|
assert group.title == "some title"
|
||||||
assert group.uri == "some uri"
|
assert group.uri == "some uri"
|
||||||
assert group.url == "some url"
|
assert group.url == "some url"
|
||||||
@ -47,7 +47,7 @@ defmodule Eventos.GroupsTest do
|
|||||||
assert {:ok, group} = Groups.update_group(group, @update_attrs)
|
assert {:ok, group} = Groups.update_group(group, @update_attrs)
|
||||||
assert %Group{} = group
|
assert %Group{} = group
|
||||||
assert group.description == "some updated description"
|
assert group.description == "some updated description"
|
||||||
assert group.suspended == false
|
refute group.suspended
|
||||||
assert group.title == "some updated title"
|
assert group.title == "some updated title"
|
||||||
assert group.uri == "some updated uri"
|
assert group.uri == "some updated uri"
|
||||||
assert group.url == "some updated url"
|
assert group.url == "some updated url"
|
||||||
|
@ -6,8 +6,6 @@ defmodule EventosWeb.AccountControllerTest do
|
|||||||
alias Eventos.Accounts
|
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"}
|
@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
|
def fixture(:account) do
|
||||||
{:ok, account} = Accounts.create_account(@create_attrs)
|
{:ok, account} = Accounts.create_account(@create_attrs)
|
||||||
|
@ -7,7 +7,7 @@ defmodule EventosWeb.UserControllerTest do
|
|||||||
alias Eventos.Accounts.User
|
alias Eventos.Accounts.User
|
||||||
|
|
||||||
@create_attrs %{email: "foo@bar.tld", password: "some password_hash", username: "some username"}
|
@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}
|
@invalid_attrs %{email: "not an email", password: nil, username: nil}
|
||||||
|
|
||||||
def fixture(:user) do
|
def fixture(:user) do
|
||||||
@ -33,6 +33,7 @@ defmodule EventosWeb.UserControllerTest do
|
|||||||
test "renders user when data is valid", %{conn: conn} do
|
test "renders user when data is valid", %{conn: conn} do
|
||||||
conn = post conn, user_path(conn, :create), @create_attrs
|
conn = post conn, user_path(conn, :create), @create_attrs
|
||||||
assert %{"user" => %{"id" => id}} = json_response(conn, 201)
|
assert %{"user" => %{"id" => id}} = json_response(conn, 201)
|
||||||
|
assert id > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders errors when data is invalid", %{conn: conn} do
|
test "renders errors when data is invalid", %{conn: conn} do
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
defmodule Eventos.Factory do
|
defmodule Eventos.Factory do
|
||||||
|
@moduledoc """
|
||||||
|
Factory for fixtures with ExMachina
|
||||||
|
"""
|
||||||
# with Ecto
|
# with Ecto
|
||||||
use ExMachina.Ecto, repo: Eventos.Repo
|
use ExMachina.Ecto, repo: Eventos.Repo
|
||||||
|
|
||||||
@ -12,7 +15,7 @@ defmodule Eventos.Factory do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def account_factory do
|
def account_factory do
|
||||||
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
|
{:ok, {_, pubkey}} = RsaEx.generate_keypair("4096")
|
||||||
%Eventos.Accounts.Account{
|
%Eventos.Accounts.Account{
|
||||||
username: sequence("Thomas"),
|
username: sequence("Thomas"),
|
||||||
domain: nil,
|
domain: nil,
|
||||||
|
@ -3,4 +3,3 @@
|
|||||||
ExUnit.start()
|
ExUnit.start()
|
||||||
|
|
||||||
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, :manual)
|
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, :manual)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user