misc: import pre-commit configuration from authentic
gitea/authentic2-cut/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-10-19 10:46:55 +02:00
parent 62a963157b
commit eac6a4be92
19 changed files with 127 additions and 126 deletions

View File

@ -5,21 +5,31 @@ repos:
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
- id: double-quote-string-fixer - id: double-quote-string-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py39-plus']
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.13.0
hooks:
- id: django-upgrade
args: ['--target-version', '3.2']
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.3.0 rev: 23.1.0
hooks: hooks:
- id: black - id: black
args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110'] args: ['--target-version', 'py39', '--skip-string-normalization', '--line-length', '110']
- repo: https://github.com/PyCQA/isort - repo: https://github.com/PyCQA/isort
rev: 5.12.0 rev: 5.12.0
hooks: hooks:
- id: isort - id: isort
args: ['--profile', 'black', '--line-length', '110'] args: ['--profile', 'black', '--line-length', '110']
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/rtts/djhtml
rev: v2.20.0 rev: '3.0.5'
hooks: hooks:
- id: pyupgrade - id: djhtml
args: ['--keep-percent-format', '--py37-plus'] args: ['--tabwidth', '2']
- repo: https://git.entrouvert.org/pre-commit-debian.git - repo: https://git.entrouvert.org/pre-commit-debian.git
rev: v0.3 rev: v0.3
hooks: hooks:

View File

@ -14,5 +14,3 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
default_app_config = 'authentic2_cut.apps.AppConfig'

View File

@ -50,7 +50,7 @@ A2_CUT_PARTNERS = [
SESSION_ENGINE = 'django.contrib.sessions.backends.cache' SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
# 48h pour les mails de reset de mot de passe # 48h pour les mails de reset de mot de passe
PASSWORD_RESET_TIMEOUT_DAYS = 2 PASSWORD_RESET_TIMEOUT = 60 * 60 * 24 * 2
A2_EMAIL_CHANGE_TOKEN_LIFETIME = 3600 * 24 * 2 A2_EMAIL_CHANGE_TOKEN_LIFETIME = 3600 * 24 * 2
ACCOUNT_ACTIVATION_DAYS = 2 ACCOUNT_ACTIVATION_DAYS = 2

View File

@ -27,7 +27,6 @@ class Command(BaseCommand):
with atomic(): with atomic():
validation_request = ValidationRequest.objects.create(user=user, origin=oidc_client) validation_request = ValidationRequest.objects.create(user=user, origin=oidc_client)
for path in paths: for path in paths:
with open(path) as file_object: with open(path) as file_object:
filename = os.path.basename(path) filename = os.path.basename(path)
f = ContentFile(file_object.read(), name=filename) f = ContentFile(file_object.read(), name=filename)

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('authentic2_cut', '0001_initial'), ('authentic2_cut', '0001_initial'),
] ]

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('contenttypes', '0002_remove_content_type_name'), ('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('authentic2_cut', '0003_auto_20180423_1532'), ('authentic2_cut', '0003_auto_20180423_1532'),
] ]

View File

@ -6,7 +6,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('authentic2_cut', '0004_auto_20180801_1147'), ('authentic2_cut', '0004_auto_20180801_1147'),
] ]

View File

@ -4,7 +4,6 @@ from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('authentic2_cut', '0005_auto_20200515_1616'), ('authentic2_cut', '0005_auto_20200515_1616'),
] ]

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import django_tables2 as tables import django_tables2 as tables
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy as _
from . import models from . import models

View File

@ -1,12 +1,12 @@
{% extends "emails/body_base.html" %} {% extends "emails/body_base.html" %}
{% block content %} {% block content %}
<p>Bonjour,</p> <p>Bonjour,</p>
<p> <p>
Un agent vient de modifier votre compte de la manière suivante&nbsp;: Un agent vient de modifier votre compte de la manière suivante&nbsp;:
</p> </p>
<ul><li>{{ message }}</li></ul> <ul><li>{{ message }}</li></ul>
{% endblock %} {% endblock %}

View File

@ -5,13 +5,13 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<ul class="messages"> <ul class="messages">
<li class="info"> <li class="info">
<p>Vous devez demander à l'usager de présenter une pièce d'identité pour valider son compte ou <p>Vous devez demander à l'usager de présenter une pièce d'identité pour valider son compte ou
modifier des données cœur déjà validées.</p> modifier des données cœur déjà validées.</p>
<p>Si l'usager est mineur, son identité ne peut pas être validée. Pour l'accès au service, merci de se référer au protocole d'accès du partenaire</p> <p>Si l'usager est mineur, son identité ne peut pas être validée. Pour l'accès au service, merci de se référer au protocole d'accès du partenaire</p>
</li> </li>
</ul> </ul>
{{ block.super }} {{ block.super }}
{% endblock %} {% endblock %}

View File

@ -15,72 +15,72 @@
{% block content %} {% block content %}
<p>Validation demandée par {{ validation_request.origin }} le {{ validation_request.created }}, identifiant externe de la demande <em>{{ validation_request.external_id }}</em>.</p> <p>Validation demandée par {{ validation_request.origin }} le {{ validation_request.created }}, identifiant externe de la demande <em>{{ validation_request.external_id }}</em>.</p>
{% if validation_request.validated %} {% if validation_request.validated %}
{% with agent=validation_request.validated_by %} {% with agent=validation_request.validated_by %}
<p>Demande {{ validation_request.get_status_display }} le {{ validation_request.validated }} par <a href="{% url "a2-manager-user-detail" pk=agent.pk %}">{{ agent.get_full_name }}</a></p> <p>Demande {{ validation_request.get_status_display }} le {{ validation_request.validated }} par <a href="{% url "a2-manager-user-detail" pk=agent.pk %}">{{ agent.get_full_name }}</a></p>
{% endwith %} {% endwith %}
{% else %} {% else %}
{% if validation_request.taken_by != user and validation_request.is_taken %} {% if validation_request.taken_by != user and validation_request.is_taken %}
<p>Demande en cours de traitement par {{ validation_request.taken_by }} depuis le {{ validation_request.taken }}</p> <p>Demande en cours de traitement par {{ validation_request.taken_by }} depuis le {{ validation_request.taken }}</p>
{% endif %}
{% endif %} {% endif %}
{% endif %}
<script> <script>
$('body').on('click', 'a.popup-image', function (event) { $('body').on('click', 'a.popup-image', function (event) {
var target = event.target; var target = event.target;
var src = $(target).parent('a')[0].href; var src = $(target).parent('a')[0].href;
var vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); var vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); var vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var ratio_width = target.width / (vw - 100); var ratio_width = target.width / (vw - 100);
var ratio_height = target.height / (vh - 100); var ratio_height = target.height / (vh - 100);
var ratio = Math.max(ratio_width, ratio_height); var ratio = Math.max(ratio_width, ratio_height);
var new_width = target.width / ratio; var new_width = target.width / ratio;
var new_height = target.height / ratio; var new_height = target.height / ratio;
var $overlay = $('<img src="' + src +'"/>'); var $overlay = $('<img src="' + src +'"/>');
$overlay.css({ $overlay.css({
'position': 'fixed', 'position': 'fixed',
'height': '' + new_height + 'px', 'height': '' + new_height + 'px',
'width': '' + new_width + 'px', 'width': '' + new_width + 'px',
'top': 0, 'top': 0,
'left': 0, 'left': 0,
'padding-left': ((vw - new_width) / 2) + 'px', 'padding-left': ((vw - new_width) / 2) + 'px',
'padding-right': ((vw - new_width) / 2) + 'px', 'padding-right': ((vw - new_width) / 2) + 'px',
'padding-top': ((vh - new_height) / 2) + 'px', 'padding-top': ((vh - new_height) / 2) + 'px',
'padding-bottom': ((vh - new_height) / 2) + 'px', 'padding-bottom': ((vh - new_height) / 2) + 'px',
'z-index': 999, 'z-index': 999,
}) })
$overlay.appendTo($('body')); $overlay.appendTo($('body'));
$overlay.on('click', function () { $overlay.on('click', function () {
$overlay.remove(); $overlay.remove();
}); });
event.preventDefault(); event.preventDefault();
}) })
</script> </script>
<div id="attachments"> <div id="attachments">
<h4>Pièces jointes</h4> <h4>Pièces jointes</h4>
<p> <p>
{% for attachment in attachments %} {% for attachment in attachments %}
<a <a
{% if attachment.extension != 'pdf' %} {% if attachment.extension != 'pdf' %}
class="popup-image" class="popup-image"
{% endif %} {% endif %}
target="_blank" target="_blank"
href="{{ attachment.url }}"> href="{{ attachment.url }}">
<img <img
src="{{ attachment.thumbnail_image.src }}" src="{{ attachment.thumbnail_image.src }}"
title="Pièce jointe {{ forloop.counter }}" title="Pièce jointe {{ forloop.counter }}"
style="border: 1px solid black; padding: 1ex"/> style="border: 1px solid black; padding: 1ex"/>
</a> </a>
{% endfor %} {% endfor %}
</p> </p>
</div> </div>
<h4>Identité</h4> <h4>Identité</h4>
<div> <div>
{{ block.super }} {{ block.super }}
</div> </div>
{% endblock %} {% endblock %}
{% block beforeform %} {% block beforeform %}
@ -96,16 +96,16 @@ $('body').on('click', 'a.popup-image', function (event) {
{% endblock %} {% endblock %}
{% block buttons %} {% block buttons %}
{% if not validation_request.validated %} {% if not validation_request.validated %}
<div class="buttons"> <div class="buttons">
<button name="validate">Valider</button> <button name="validate">Valider</button>
</div> </div>
<h4>Refus</h4> <h4>Refus</h4>
{{ validation_form.as_p }} {{ validation_form.as_p }}
<div class="buttons"> <div class="buttons">
<button name="refuse">Refuser</button> <button name="refuse">Refuser</button>
<button style="float: right; margin-right: 30px" name="next">Suivant</button> <button style="float: right; margin-right: 30px" name="next">Suivant</button>
</div> </div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
{% block appbar %} {% block appbar %}
<h2>Validation d'identité <h2>Validation d'identité
</h2> </h2>
{% endblock %} {% endblock %}
{% block breadcrumb %} {% block breadcrumb %}
@ -16,9 +16,9 @@
<p> <p>
<h2>Filtres</h2> <h2>Filtres</h2>
{% if request.GET.all %} {% if request.GET.all %}
<a href="?">Uniquement les demandes reçues</a> <a href="?">Uniquement les demandes reçues</a>
{% else %} {% else %}
<a href="?all=1">Toutes les demandes</a> <a href="?all=1">Toutes les demandes</a>
{% endif %} {% endif %}
</p> </p>
<p> <p>
@ -30,7 +30,7 @@
{% block main %} {% block main %}
<style> <style>
#validation-request-table tbody .human_status { #validation-request-table tbody .human_status {
text-align: left; text-align: left;
} }
</style> </style>
{% with row_link=1 %} {% with row_link=1 %}

View File

@ -16,35 +16,35 @@
from authentic2.decorators import required from authentic2.decorators import required
from authentic2.manager.utils import manager_login_required from authentic2.manager.utils import manager_login_required
from django.conf.urls import url from django.urls import path, re_path
from . import api_views, views from . import api_views, views
urlpatterns = required( urlpatterns = required(
manager_login_required, manager_login_required,
[ [
url('^accounts/edit-core/$', views.edit_core, name='cut-edit-core'), path('accounts/edit-core/', views.edit_core, name='cut-edit-core'),
url('^accounts/edit-crown/$', views.edit_crown, name='cut-edit-crown'), path('accounts/edit-crown/', views.edit_crown, name='cut-edit-crown'),
url(r'^manage/users/(?P<pk>\d+)/$', views.manager_user_detail, name='a2-manager-user-detail'), path('manage/users/<int:pk>/', views.manager_user_detail, name='a2-manager-user-detail'),
url( re_path(
r'^manage/users/uuid:(?P<slug>[a-z0-9]+)/$', r'^manage/users/uuid:(?P<slug>[a-z0-9]+)/$',
views.manager_user_detail, views.manager_user_detail,
name='a2-manager-user-by-uuid-detail', name='a2-manager-user-by-uuid-detail',
), ),
url( path(
r'^manage/users/(?P<pk>\d+)/edit-core/$', 'manage/users/<int:pk>/edit-core/',
views.manager_user_edit_core, views.manager_user_edit_core,
name='cut-manager-user-edit-core', name='cut-manager-user-edit-core',
), ),
url('^manage/validation/$', views.validation_homepage, name='cut-manager-user-validation'), path('manage/validation/', views.validation_homepage, name='cut-manager-user-validation'),
url('^manage/validation/next/$', views.next_validation, name='cut-manager-user-next-validation'), path('manage/validation/next/', views.next_validation, name='cut-manager-user-next-validation'),
url(r'^manage/validation/(?P<pk>\d+)/$', views.validation, name='cut-manager-user-validation'), path('manage/validation/<int:pk>/', views.validation, name='cut-manager-user-validation'),
url( re_path(
r'^manage/validation/attachment/(?P<pk>\d*)/(?P<filename>.*)$', r'^manage/validation/attachment/(?P<pk>\d*)/(?P<filename>.*)$',
views.validation_attachment, views.validation_attachment,
name='cut-manager-user-validation-attachment', name='cut-manager-user-validation-attachment',
), ),
url( re_path(
r'^manage/validation/attachment-thumbnail/(?P<pk>\d*)/(?P<filename>.*)$', r'^manage/validation/attachment-thumbnail/(?P<pk>\d*)/(?P<filename>.*)$',
views.validation_attachment_thumbnail, views.validation_attachment_thumbnail,
name='cut-manager-user-validation-attachment-thumbnail', name='cut-manager-user-validation-attachment-thumbnail',
@ -53,6 +53,6 @@ urlpatterns = required(
) )
urlpatterns += [ urlpatterns += [
url('^cgu/$', views.cgu, name='cut-cgu'), path('cgu/', views.cgu, name='cut-cgu'),
url('^api/validate/$', api_views.validate, name='api-cut-validate'), path('api/validate/', api_views.validate, name='api-cut-validate'),
] ]

View File

@ -27,7 +27,7 @@ from django.core.exceptions import PermissionDenied
from django.db.transaction import atomic from django.db.transaction import atomic
from django.http import Http404, HttpResponse, HttpResponseRedirect from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from . import forms, models, tables, utils from . import forms, models, tables, utils

View File

@ -4,7 +4,7 @@ ALLOWED_HOSTS = ['localhost']
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql',
'NAME': 'authentic2-cut', 'NAME': 'authentic2-cut',
} }
} }

View File

@ -3,7 +3,7 @@ import uuid
import pytest import pytest
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.utils.encoding import force_text from django.utils.encoding import force_str
from utils import login from utils import login
from authentic2_cut import models from authentic2_cut import models
@ -60,7 +60,7 @@ def helper_test_validation_image(glc_app, john, image_file, extension):
'external_id': external_id, 'external_id': external_id,
'justificatifs': [ 'justificatifs': [
{ {
'b64_content': force_text(base64.b64encode(image_file)), 'b64_content': force_str(base64.b64encode(image_file)),
} }
], ],
}, },
@ -109,13 +109,13 @@ def test_many_attachments(app, admin, glc_app, john, png_file, jpeg_file, pdf_fi
'external_id': external_id, 'external_id': external_id,
'justificatifs': [ 'justificatifs': [
{ {
'b64_content': force_text(base64.b64encode(png_file)), 'b64_content': force_str(base64.b64encode(png_file)),
}, },
{ {
'b64_content': force_text(base64.b64encode(jpeg_file)), 'b64_content': force_str(base64.b64encode(jpeg_file)),
}, },
{ {
'b64_content': force_text(base64.b64encode(pdf_file)), 'b64_content': force_str(base64.b64encode(pdf_file)),
}, },
], ],
}, },