Commit 584d7f9b authored by James Laver's avatar James Laver

Merge branch 'chore/misc-dev' into 'develop'

Miscellaneous dev improvements

See merge request !18
parents 45aea987 16d94902
Pipeline #66031351 passed with stages
in 8 minutes and 39 seconds
......@@ -36,6 +36,7 @@ make dev
#### Other useful makefile tasks
- `make dev-build` - rebuild the dev docker image
- `make dev-rebuild` - `dev-build`, but without caches
- `make dev-db` - rebuild the development database
- `make dev-test-db` - rebuild the test database
- `make dev-test` - run the tests
......
.PHONY: help dev-build dev-deps dev-db dev-test-db dev-test dev-setup dev
.PHONY: help dev-exports dev-build dev-deps dev-db dev-test-db dev-test dev-setup dev
APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'`
APP_VSN ?= `grep 'version:' mix.exs | cut -d '"' -f2`
......@@ -64,32 +64,49 @@ push_stable: ## Tag stable, latest and version tags to the last build and push
@echo docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
@docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
dev-exports:
awk '{print "export " $$0}' config/docker.dev.env
dev-build:
docker-compose -f docker-compose.dev.yml build web
docker-compose -p moodlenet_dev -f docker-compose.dev.yml build web
dev-rebuild:
docker-compose -p moodlenet_dev -f docker-compose.dev.yml build --no-cache web
dev-deps:
docker-compose -f docker-compose.dev.yml run web mix local.hex --force
docker-compose -f docker-compose.dev.yml run web mix local.rebar --force
docker-compose -f docker-compose.dev.yml run web mix deps.get
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix local.hex --force
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix local.rebar --force
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix deps.get
dev-db-up:
docker-compose -p moodlenet_dev -f docker-compose.dev.yml up db
dev-db:
docker-compose -f docker-compose.dev.yml run web mix ecto.reset
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix ecto.reset
dev-test-db:
docker-compose -f docker-compose.dev.yml -e MIX_ENV=test run web mix ecto.reset
docker-compose -p moodlenet_dev -f docker-compose.dev.yml -e MIX_ENV=test run web mix ecto.reset
dev-test:
docker-compose -f docker-compose.dev.yml run web mix test
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix test
dev-setup: dev-deps dev-db
dev:
docker-compose -f docker-compose.dev.yml run --service-ports web
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run --service-ports web
manual-deps:
mix local.hex --force
mix local.rebar --force
mix deps.get
manual-db:
mix ecto.reset
run: ## Run the app in Docker
docker run\
--env-file config/docker.env \
--expose 4000 -p 4000:4000 \
--link postgres \
--link db \
--rm -it moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
......@@ -4,6 +4,7 @@ DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_NAME=moodle_net_dev
POSTGRES_DB=moodle_net_dev
PORT=4000
LANG=en_US.UTF-8
REPLACE_OS_VARS=true
......
......@@ -5,6 +5,7 @@
defmodule MoodleNet.Accounts.User do
use Ecto.Schema
alias Ecto.Changeset
schema "accounts_users" do
field(:email, :string)
......@@ -20,39 +21,39 @@ defmodule MoodleNet.Accounts.User do
actor_id = ActivityPub.Entity.local_id(actor)
%__MODULE__{}
|> Ecto.Changeset.cast(attrs, [:email])
|> Ecto.Changeset.validate_format(:email, ~r/.+\@.+\..+/)
# |> Ecto.Changeset.put_assoc(:primary_actor, actor)
|> Ecto.Changeset.change(actor: actor, actor_id: actor_id)
|> Ecto.Changeset.validate_required([:actor_id, :email])
|> Ecto.Changeset.unique_constraint(:email)
|> Changeset.cast(attrs, [:email])
|> Changeset.validate_format(:email, ~r/.+\@.+\..+/)
# |> Changeset.put_assoc(:primary_actor, actor)
|> Changeset.change(actor: actor, actor_id: actor_id)
|> Changeset.validate_required([:actor_id, :email])
|> Changeset.unique_constraint(:email)
|> lower_case_email()
|> whitelist_email()
end
defp lower_case_email(%Ecto.Changeset{valid?: false} = ch), do: ch
defp lower_case_email(%Changeset{valid?: false} = ch), do: ch
defp lower_case_email(%Ecto.Changeset{} = ch) do
{_, email} = Ecto.Changeset.fetch_field(ch, :email)
Ecto.Changeset.change(ch, email: String.downcase(email))
defp lower_case_email(%Changeset{} = ch) do
{_, email} = Changeset.fetch_field(ch, :email)
Changeset.change(ch, email: String.downcase(email))
end
defp whitelist_email(%Ecto.Changeset{valid?: false} = ch), do: ch
defp whitelist_email(%Changeset{valid?: false} = ch), do: ch
defp whitelist_email(%Ecto.Changeset{} = ch) do
{_, email} = Ecto.Changeset.fetch_field(ch, :email)
defp whitelist_email(%Changeset{} = ch) do
{_, email} = Changeset.fetch_field(ch, :email)
if MoodleNet.Accounts.is_email_in_whitelist?(email) do
ch
else
Ecto.Changeset.add_error(ch, :email, "You cannot register with this email address",
Changeset.add_error(ch, :email, "You cannot register with this email address",
validation: "inclusion"
)
end
end
def confirm_email_changeset(%__MODULE__{} = user) do
Ecto.Changeset.change(user, confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second))
Changeset.change(user, confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second))
end
def name(%__MODULE__{} = user) do
......
......@@ -5,7 +5,7 @@ defmodule MoodleNet.Mixfile do
def project do
[
app: :moodle_net,
version: "0.9.4-dev.2", # current MoodleNet Server version
version: "0.9.4-dev.3", # current MoodleNet Server version
elixir: "~> 1.7", # required version of Elixir
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
......@@ -26,7 +26,9 @@ defmodule MoodleNet.Mixfile do
# Configuration for the OTP application.
# Type `mix help compile.app` for more information.
def application do
[mod: {MoodleNet.Application, []}, extra_applications: [:logger, :runtime_tools, :comeonin]]
[mod: {MoodleNet.Application, []},
extra_applications: [:logger, :runtime_tools, :comeonin]
]
end
# Specifies which paths to compile per environment.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment