Skip to content

Commit

Permalink
Configura prefixo do ambiente em título e emails
Browse files Browse the repository at this point in the history
O prefixo será inserido apenas nos ambientes de desenvolvimento e
homologação, facilitando testar funcionalidades. Ele será inserido no
título das páginas e também no assunto dos emails.
  • Loading branch information
turicas committed Sep 8, 2024
1 parent b9ff381 commit e5861dd
Show file tree
Hide file tree
Showing 32 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_serialize_api_info(self):
data = response.json()

assert 200 == response.status_code
assert "Brasil.io API" == data["title"]
assert "[dev] Brasil.IO API" == data["title"]
assert "v1" == data["version"]
assert reverse("v1:dataset-list") == data["datasets_url"]
assert data["description"]
3 changes: 2 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence

from django.conf import settings
from django.shortcuts import get_object_or_404
from django.urls import reverse
from rest_framework import viewsets
Expand Down Expand Up @@ -124,7 +125,7 @@ class ApiRootView(APIView):
@check_api_version_redirect
def get(self, request):
data = {
"title": "Brasil.io API",
"title": f"{settings.EMAIL_SUBJECT_PREFIX}Brasil.IO API",
"version": self.request.version,
"description": api_description,
"datasets_url": reverse("v1:dataset-list"),
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"name": "web colabore check",
"description": "Check /colabore",
"path": "/colabore",
"content": "Colabore - Brasil.IO"
"content": "Colabore - "
},
{
"type": "startup",
"name": "web datasets check",
"description": "Check /datasets",
"path": "/datasets",
"content": "Lista de datasets - Brasil.IO"
"content": "Lista de datasets - "
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}

{% block title %}Exemplo de uso de Chaves API - Brasil.IO{% endblock %}
{% block title %}Exemplo de uso de Chaves API - {{ block.super }}{% endblock %}

{% block content %}
<div class="section">
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[Brasil.IO] Ative sua conta
{{ EMAIL_SUBJECT_PREFIX }}[Brasil.IO] Ative sua conta
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Atualização de senha para o Brasil.IO
{{ EMAIL_SUBJECT_PREFIX }}[Brasil.IO] Troca de senha
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}

{% block title %}Gerenciamento de Chaves API - Brasil.IO{% endblock %}
{% block title %}Gerenciamento de Chaves API - {{ block.super }}{% endblock %}

{% block content %}
<div class="section">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}

{% block title %}Gerar nova Chave de API - Brasil.IO{% endblock %}
{% block title %}Gerar nova Chave de API - {{ block.super }}{% endblock %}

{% block content %}
<div class="section">
Expand Down
8 changes: 8 additions & 0 deletions core/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings


def template_settings(request):
return {
"ENV_TYPE": settings.ENV_TYPE,
"EMAIL_SUBJECT_PREFIX": settings.EMAIL_SUBJECT_PREFIX,
}
2 changes: 1 addition & 1 deletion core/templates/core/collaborate.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Colabore - Brasil.IO{% endblock %}
{% block title %}Colabore - {{ block.super }}{% endblock %}
{% block content %}
<div class="section">
<h4>Colabore</h4>
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/contact.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Contato - Brasil.IO{% endblock %}
{% block title %}Contato - {{ block.super }}{% endblock %}
{% block content %}

<h4>Contato</h4>
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/contributors.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}Contribuidores - Brasil.IO{% endblock %}
{% block title %}Contribuidores - {{ block.super }}{% endblock %}
{% block content %}
<div class="section">
<h4>Contribuidores</h4>
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/dataset-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load l10n %}
{% load markdown %}
{% load utils %}
{% block title %}{{ dataset.name }} - Datasets - Brasil.IO{% endblock %}
{% block title %}{{ dataset.name }} - Datasets - {{ block.super }}{% endblock %}
{% block content %}{% localize off %}
<div class="section">
<div id="dataset-detail">
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/dataset-list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Lista de datasets - Brasil.IO{% endblock %}
{% block title %}Lista de datasets - {{ block.super }}{% endblock %}

{% block content %}
<div class="section">
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/dataset-suggestion.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Sugira um dataset - Brasil.IO{% endblock %}
{% block title %}Sugira um dataset - {{ block.super }}{% endblock %}
{% block content %}
<iframe
src="https://docs.google.com/forms/d/e/1FAIpQLSebnx76uRb8Ua9GpKtfpNKmCzdaH99PMwl3XnZdxpiit-J24w/viewform?embedded=true"
Expand Down
2 changes: 1 addition & 1 deletion core/templates/core/home.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}Home - Brasil.IO{% endblock %}
{% block title %}Home - {{ block.super }}{% endblock %}
{% block top %}
<div class="top-container indigo darken-1">
<div class="container">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/manifesto.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Manifesto - Brasil.IO{% endblock %}
{% block title %}Manifesto - {{ block.super }}{% endblock %}
{% block content %}
<div class="section">
<h4>Manifesto</h4>
Expand Down Expand Up @@ -147,4 +147,4 @@ <h5>Aplicações</h5>
</p>

</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion core/templates/specials/company-groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}
{% load utils %}

{% block title %}Grupos Empresariais - Brasil.IO{% endblock %}
{% block title %}Grupos Empresariais - {{ block.super }}{% endblock %}

{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion core/templates/specials/document-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}
{% load utils %}

{% block title %}{{ obj.name }} - {% if is_person %}Pessoa Física{% elif is_company %}Pessoa Jurídica{% endif %} - Brasil.IO{% endblock %}
{% block title %}{{ obj.name }} - {% if is_person %}Pessoa Física{% elif is_company %}Pessoa Jurídica{% endif %} - {{ block.super }}{% endblock %}

{% block head %}
{{ block.super }}
Expand Down
2 changes: 1 addition & 1 deletion core/templates/specials/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Especiais - Brasil.IO{% endblock %}
{% block title %}Especiais - {{ block.super }}{% endblock %}
{% block content %}

<h3>Aplicações Especiais</h3>
Expand Down
2 changes: 1 addition & 1 deletion core/templates/specials/registry.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block title %}Registro Nacional - Busca - Brasil.IO{% endblock %}
{% block title %}Registro Nacional - Busca - {{ block.super }}{% endblock %}
{% block content %}

{% include 'core/contas-gratuitas.html' %}
Expand Down
2 changes: 1 addition & 1 deletion core/templates/specials/trace-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}
{% load utils %}

{% block title %}Traçador de Caminhos - Brasil.IO{% endblock %}
{% block title %}Traçador de Caminhos - {{ block.super }}{% endblock %}

{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def contact(request):
if form.is_valid():
data = form.cleaned_data
email = EmailMessage(
subject=f"Contato no Brasil.IO: {data['name']}",
subject=f"{settings.EMAIL_SUBJECT_PREFIX}Contato no Brasil.IO: {data['name']}",
body=data["message"],
from_email=f'{data["name"]} (via Brasil.IO) <{settings.DEFAULT_FROM_EMAIL}>',
to=[settings.DEFAULT_FROM_EMAIL],
Expand Down
4 changes: 2 additions & 2 deletions covid19/templates/covid19/bulletins.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load l10n %}
{% load static %}
{% block title %}Covid19 Boletins Diários - Brasil.IO{% endblock %}
{% block title %}Covid19 Boletins Diários - {{ block.super }}{% endblock %}
{% load thumbnail %}

{% block head %}
Expand Down Expand Up @@ -76,4 +76,4 @@ <h2 class="monthYearBulletins">{{ month.list.0.date|date:"F" }} {{ month.list.0.
});
});
</script>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions covid19/templates/covid19/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load l10n %}
{% load static %}
{% block title %}Covid19 por Município - Brasil.IO{% endblock %}
{% block title %}Covid19 por Município - {{ block.super }}{% endblock %}

{% block head %}
{{ block.super }}
Expand Down Expand Up @@ -270,4 +270,4 @@ <h1 style="padding-top:15px">
});
});
</script>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion covid19/templates/covid19/state_status.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load l10n %}
{% load static %}
{% block title %}Covid19 Status de Importação {{ state.name }}- Brasil.IO{% endblock %}
{% block title %}Covid19 Status de Importação {{ state.name }}- {{ block.super }}{% endblock %}

{% block head %}
{{ block.super }}
Expand Down
4 changes: 2 additions & 2 deletions covid19/templates/covid19/status.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load l10n %}
{% load static %}
{% block title %}Covid19 Status de Importação - Brasil.IO{% endblock %}
{% block title %}Covid19 Status de Importação - {{ block.super }}{% endblock %}

{% block head %}
{{ block.super }}
Expand Down Expand Up @@ -91,4 +91,4 @@ <h1> ESPECIAL COVID-19 - Status de Importação </h1>

</script>

{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion covid19/templates/covid19/volunteers.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}Voluntários COVID-19 - Brasil.IO{% endblock %}
{% block title %}Voluntários COVID-19 - {{ block.super }}{% endblock %}
{% block content %}
<div class="section">
<h4>Voluntários COVID-19</h4>
Expand Down
1 change: 1 addition & 0 deletions docker/env/web
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DEBUG_SQL="True"
DEV_BUILD="True"
DJANGO_SETTINGS_MODULE=project.settings
DEFAULT_FROM_EMAIL="root@localhost"
ENV_TYPE="development"
EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST="mail"
EMAIL_HOST_PASSWORD=""
Expand Down
2 changes: 2 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export DATA_DIR="/data"
export DEBUG="false"
export DEV_BUILD="false"
export DB_NAME="pg_${APP_NAME}"
export ENV_TYPE="production"
export REDIS_NAME="redis_${APP_NAME}"
export STORAGE_PATH="/var/lib/dokku/data/storage/$APP_NAME"
export SESSION_COOKIE_DOMAIN=".brasil.io"
Expand Down Expand Up @@ -168,6 +169,7 @@ dokku config:set --no-restart $APP_NAME CSRF_TRUSTED_ORIGINS="$CSRF_TRUSTED_ORIG
dokku config:set --no-restart $APP_NAME DATA_DIR="$DATA_DIR"
dokku config:set --no-restart $APP_NAME DATA_URL="$DATA_URL"
dokku config:set --no-restart $APP_NAME DEBUG="$DEBUG"
dokku config:set --no-restart $APP_NAME ENV_TYPE="$ENV_TYPE"
dokku config:set --no-restart $APP_NAME DEFAULT_FROM_EMAIL="$DEFAULT_FROM_EMAIL"
dokku config:set --no-restart $APP_NAME DEV_BUILD="$DEV_BUILD"
dokku config:set --no-restart $APP_NAME EMAIL_BACKEND="$EMAIL_BACKEND"
Expand Down
6 changes: 5 additions & 1 deletion project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import dj_database_url
import sentry_sdk
from decouple import Csv, config
from decouple import Choices, Csv, config
from django.urls import reverse_lazy
from django.utils.log import DEFAULT_LOGGING
from sentry_sdk.integrations.django import DjangoIntegration
Expand All @@ -27,6 +27,7 @@

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config("DEBUG", cast=bool, default=False)
ENV_TYPE = config("ENV_TYPE", cast=Choices(["development", "staging", "production"], cast=str))

# Hostname
ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv())
Expand Down Expand Up @@ -111,6 +112,7 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"core.context_processors.template_settings",
"covid19.context_processors.is_covid19_contributor",
],
},
Expand Down Expand Up @@ -264,6 +266,8 @@
EMAIL_PORT = config("EMAIL_PORT", cast=int, default=587)
EMAIL_USE_TLS = config("EMAIL_USE_TLS", cast=bool, default=True)
DEFAULT_FROM_EMAIL = config("DEFAULT_FROM_EMAIL", default="[email protected]")
env_type_abbrev = {"development": "dev", "staging": "stg", "production": "prd"}[ENV_TYPE]
EMAIL_SUBJECT_PREFIX = f"[{env_type_abbrev}] " if ENV_TYPE != "production" else ""


# Auth conf
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="{% static 'img/favicon.ico' %}">
<title>{% block title %}Brasil.IO{% endblock %}</title>
<title>{% block title %}{{ EMAIL_SUBJECT_PREFIX }}Brasil.IO{% endblock %}</title>

{% block script %}
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-117698282-1"></script>
Expand Down

0 comments on commit e5861dd

Please sign in to comment.