diff --git a/.env.template b/.env.template
new file mode 100644
index 00000000..e49bfb2b
--- /dev/null
+++ b/.env.template
@@ -0,0 +1,25 @@
+# Database settings
+POSTGRES_USER=mobilizon
+POSTGRES_PASSWORD=changethis
+POSTGRES_DB=mobilizon
+POSTGRES_PORT=5432
+
+# Instance configuration
+MOBILIZON_INSTANCE_REGISTRATIONS_OPEN=false
+MOBILIZON_INSTANCE_NAME=My Mobilizon Instance
+MOBILIZON_INSTANCE_HOST=mobilizon.lan
+MOBILIZON_INSTANCE_PORT=4000
+
+MOBILIZON_INSTANCE_SECRET_KEY_BASE=changethis
+MOBILIZON_INSTANCE_SECRET_KEY=changethis
+
+MOBILIZON_INSTANCE_EMAIL=noreply@mobilizon.lan
+MOBILIZON_REPLY_EMAIL=contact@mobilizon.lan
+
+# Email settings
+MOBILIZON_SMTP_SERVER=localhost
+MOBILIZON_SMTP_PORT=25
+MOBILIZON_SMTP_HOSTNAME=localhost
+MOBILIZON_SMTP_USERNAME=noreply@mobilizon.lan
+MOBILIZON_SMTP_PASSWORD=password
+MOBILIZON_SMTP_SSL=false
diff --git a/.gitignore b/.gitignore
index fb8ad471..b4b15332 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,4 @@ release/
docker/production/.env
test-junit-report.xml
js/junit.xml
+.env
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 28f6f444..91d8d1c8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -201,7 +201,7 @@ pages:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$CI_REGISTRY_AUTH\",\"email\":\"$CI_REGISTRY_EMAIL\"}}}" > /kaniko/.docker/config.json
script:
- - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $DOCKER_IMAGE_NAME --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP
+ - /kaniko/executor --cache=true --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $DOCKER_IMAGE_NAME --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP
build-docker-master:
<<: *docker
diff --git a/Dockerfile b/Dockerfile
index 01cde686..0c80b83d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
-FROM bitwalker/alpine-elixir:latest
+FROM elixir:alpine
-RUN apk add --no-cache inotify-tools postgresql-client yarn file make gcc libc-dev argon2 imagemagick cmake build-base libwebp-tools bash ncurses
+RUN apk add --no-cache inotify-tools postgresql-client yarn file make gcc libc-dev argon2 imagemagick cmake build-base libwebp-tools bash ncurses git
RUN mix local.hex --force && mix local.rebar --force
diff --git a/config/dev.exs b/config/dev.exs
index 23e63beb..660e6dd5 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -1,21 +1,15 @@
import Config
-# For development, we disable any cache and enable
-# debugging and code reloading.
-#
-# The watchers configuration can be used to run external
-# watchers to your application. For example, we use it
-# with brunch.io to recompile .js and .css sources.
config :mobilizon, Mobilizon.Web.Endpoint,
http: [
- ip: {127, 0, 0, 1},
- port: 4000
+ port: String.to_integer(System.get_env("MOBILIZON_INSTANCE_HOST_PORT", "4000"))
],
url: [
host: System.get_env("MOBILIZON_INSTANCE_HOST", "mobilizon.local"),
- port: 80,
+ port: String.to_integer(System.get_env("MOBILIZON_INSTANCE_HOST_PORT", "80")),
scheme: "http"
],
+ secret_key_base: System.get_env("MOBILIZON_INSTANCE_SECRET_KEY_BASE", "changethis"),
debug_errors: true,
code_reloader: true,
check_origin: false,
@@ -91,6 +85,9 @@ config :mobilizon, :instance,
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") == "true",
groups: true
+config :mobilizon, Mobilizon.Web.Auth.Guardian,
+ secret_key: System.get_env("MOBILIZON_INSTANCE_SECRET_KEY", "changethis")
+
# config :mobilizon, :activitypub, sign_object_fetches: false
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "uploads"
diff --git a/config/docker.exs b/config/docker.exs
index 50252737..dec3d28e 100644
--- a/config/docker.exs
+++ b/config/docker.exs
@@ -2,7 +2,7 @@
import Config
-listen_ip = System.get_env("MOBILIZON_INSTANCE_LISTEN_IP", "::")
+listen_ip = System.get_env("MOBILIZON_INSTANCE_LISTEN_IP", "127.0.0.1")
listen_ip =
case listen_ip |> to_charlist() |> :inet.parse_address() do
diff --git a/docker-compose.yml b/docker-compose.yml
index 8726415b..9b75aad9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,13 +1,14 @@
-version: "3"
-
+version: "3.2"
services:
postgres:
container_name: mobilizon_db
restart: unless-stopped
- image: postgis/postgis:13-3.0
+ image: postgis/postgis
environment:
- POSTGRES_PASSWORD: postgres
- POSTGRES_DB: mobilizon_dev
+ - POSTGRES_USER
+ - POSTGRES_PASSWORD
+ - POSTGRES_DB
+ - POSTGRES_PORT
volumes:
- pgdata:/var/lib/postgresql/data
api:
@@ -17,29 +18,24 @@ services:
volumes:
- ".:/app"
ports:
- - "4000:4000"
+ - 4000:4000
depends_on:
- postgres
environment:
MIX_ENV: "dev"
DOCKER: "true"
MOBILIZON_INSTANCE_NAME: My Mobilizon Instance
- MOBILIZON_INSTANCE_HOST: mobilizon.me
+ MOBILIZON_INSTANCE_HOST: localhost
+ MOBILIZON_INSTANCE_HOST_PORT: 4000
+ MOBILIZON_INSTANCE_PORT: 4000
MOBILIZON_INSTANCE_EMAIL: noreply@mobilizon.me
MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "true"
- MOBILIZON_DATABASE_PASSWORD: postgres
- MOBILIZON_DATABASE_USERNAME: postgres
- MOBILIZON_DATABASE_DBNAME: mobilizon_dev
+ MOBILIZON_DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
+ MOBILIZON_DATABASE_USERNAME: ${POSTGRES_USER}
+ MOBILIZON_DATABASE_DBNAME: ${POSTGRES_DB}
MOBILIZON_DATABASE_HOST: postgres
- command: >
- sh -c "cd js &&
- yarn install &&
- cd ../ &&
- mix deps.get &&
- mix compile &&
- mix ecto.create &&
- mix ecto.migrate &&
- mix phx.server"
+ MOBILIZON_DATABASE_PORT: ${POSTGRES_PORT}
+ command: sh -c "mix phx.server"
volumes:
pgdata:
.:
diff --git a/lib/service/metadata/actor.ex b/lib/service/metadata/actor.ex
index 0e162251..e0fc59dc 100644
--- a/lib/service/metadata/actor.ex
+++ b/lib/service/metadata/actor.ex
@@ -23,11 +23,17 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
Tag.tag(:meta, property: "og:url", content: group.url),
Tag.tag(:meta, property: "og:description", content: group.summary),
Tag.tag(:meta, property: "og:type", content: "profile"),
- Tag.tag(:meta, property: "profile:username", content: group.preferred_username),
+ Tag.tag(:meta,
+ property: "profile:username",
+ content: Actor.preferred_username_and_domain(group)
+ ),
Tag.tag(:meta, property: "twitter:card", content: "summary")
]
|> maybe_add_avatar(group)
|> add_group_schema(group)
+ |> add_group_feeds(group)
+ |> add_canonical(group)
+ |> maybe_add_no_index(group)
end
def build_tags(%Actor{} = _actor, _locale), do: []
@@ -42,27 +48,59 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
end
end
+ @spec add_group_schema(list(Tag.t()), Actor.t()) :: list(Tag.t())
defp add_group_schema(tags, %Actor{} = group) do
tags ++
[
- ~s{} |> HTML.raw(),
+ ~s{} |> HTML.raw()
+ ]
+ end
+
+ @spec add_group_feeds(list(Tag.t()), Actor.t()) :: list(Tag.t())
+ defp add_group_feeds(tags, %Actor{} = group) do
+ tags ++
+ [
Tag.tag(:link,
rel: "alternate",
type: "application/atom+xml",
title:
gettext("%{name}'s feed", name: group.name || group.preferred_username) |> HTML.raw(),
- href: Routes.feed_url(Endpoint, :actor, group.preferred_username, :atom)
+ href:
+ Routes.feed_url(Endpoint, :actor, Actor.preferred_username_and_domain(group), :atom)
),
Tag.tag(:link,
rel: "alternate",
type: "text/calendar",
title:
gettext("%{name}'s feed", name: group.name || group.preferred_username) |> HTML.raw(),
- href: Routes.feed_url(Endpoint, :actor, group.preferred_username, :ics)
+ href:
+ Routes.feed_url(
+ Endpoint,
+ :actor,
+ Actor.preferred_username_and_domain(group),
+ :ics
+ )
+ ),
+ Tag.tag(:link,
+ rel: "alternate",
+ type: "application/activity+json",
+ href: group.url
)
]
end
+ @spec add_canonical(list(Tag.t()), Actor.t()) :: list(Tag.t())
+ defp add_canonical(tags, %Actor{url: group_url}) do
+ tags ++ [Tag.tag(:link, rel: "canonical", href: group_url)]
+ end
+
+ @spec maybe_add_no_index(list(Tag.t()), Actor.t()) :: list(Tag.t())
+ defp maybe_add_no_index(tags, %Actor{domain: nil}), do: tags
+
+ defp maybe_add_no_index(tags, %Actor{}) do
+ tags ++ [Tag.tag(:meta, name: "robots", content: "noindex")]
+ end
+
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
defp json(%Actor{} = group) do
"group.json"
diff --git a/lib/web/upload/upload.ex b/lib/web/upload/upload.ex
index 9b7f1db9..5e19cec7 100644
--- a/lib/web/upload/upload.ex
+++ b/lib/web/upload/upload.ex
@@ -69,7 +69,10 @@ defmodule Mobilizon.Web.Upload do
opts = get_opts(opts)
with {:ok, upload} <- prepare_upload(upload, opts),
- upload = %__MODULE__{upload | path: upload.path || "#{upload.id}/#{upload.name}"},
+ %__MODULE__{} = upload <- %__MODULE__{
+ upload
+ | path: upload.path || "#{upload.id}/#{upload.name}"
+ },
{:ok, upload} <- Filter.filter(opts.filters, upload),
{:ok, url_spec} <- Uploader.put_file(opts.uploader, upload) do
{:ok,
diff --git a/test/service/metadata/metadata_test.exs b/test/service/metadata/metadata_test.exs
index d3455bc7..64f0e340 100644
--- a/test/service/metadata/metadata_test.exs
+++ b/test/service/metadata/metadata_test.exs
@@ -12,12 +12,13 @@ defmodule Mobilizon.Service.MetadataTest do
import Mobilizon.Factory
describe "build_tags/2 for an actor" do
+ # TODO : Refactor me with DOM assertions, like the event test below
test "that is a group gives tags" do
- %Actor{} = group = insert(:group, name: "My group")
+ %Actor{} = group = insert(:group, name: "My group", domain: "remote.domain")
assert group |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() ==
String.trim("""
-
+
""")
assert group
@@ -25,7 +26,7 @@ defmodule Mobilizon.Service.MetadataTest do
|> Metadata.build_tags()
|> Metadata.Utils.stringify_tags() ==
String.trim("""
-
+
""")
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index a450f11d..0c896ab9 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -273,8 +273,7 @@ defmodule Mobilizon.Factory do
%{
content_type: "image/jpeg",
name: "image.jpg",
- url: url,
- size: 13_227
+ url: url
} = data
%Mobilizon.Medias.File{