Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
glibersat committed Feb 13, 2025
2 parents 68cce19 + ac2a7f3 commit 01827e3
Show file tree
Hide file tree
Showing 21 changed files with 6,074 additions and 206 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ jobs:
# Maps tcp port 5432 on service container to the host
- 5432:5432

strategy:
matrix:
python-version: ['3.11']

steps:
- name: Check out repository code
uses: actions/[email protected]

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5.1.0
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version-file: "pyproject.toml"

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -62,6 +58,12 @@ jobs:
sudo apt-get update
sudo apt-get install python3-gdal pandoc
- name: Install uv and python
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Compile JS
working-directory: ./recoco/frontend
run: |
Expand All @@ -70,10 +72,8 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r requirements.txt
pip install -r requirements-dev.txt
uv sync --no-dev
uv sync --only-dev
- name: Configure
run: |
Expand All @@ -90,4 +90,4 @@ jobs:
DJANGO_DB_PORT: 5432
DJANGO_DB_ENGINE: django.db.backends.postgresql
run: |
pytest --create-db
uv run pytest --create-db
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ repos:
hooks:
- id: django-upgrade
args: [--target-version, "5.0"]

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.30
hooks:
- id: uv-lock
- id: uv-export
117 changes: 117 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
[project]
name = "recoco"
version = "6.2.2"
description = "Recommandations Collaboratives"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"beautifulsoup4==4.12.3",
"celery==5.4.0",
"django>4,<5.0",
"django-activity-stream",
"django-admin-csvexport==2.2",
"django-allauth[openid,socialaccount]==0.63.6",
"django-autoslug==1.9.9",
"django-celery-results==2.5.1",
"django-clone==5.3.3",
"django-compressor==4.4",
"django-cookie-consent",
"django-crispy-forms==2.0",
"django-dbtemplates",
"django-filter>=24.3",
"django-gravatar2>=1.4.5",
"django-guardian==2.4.0",
"django-hijack==3.4.5",
"django-json-widget==2.0.1",
"django-leaflet>=0.31.0",
"django-magicauth",
"django-markdownx==4.0.7",
"django-multisite",
"django-notifications-hq",
"django-ordered-model==3.7.4",
"django-otp==1.3.0",
"django-phonenumber-field[phonenumbers]==6.3.0",
"django-recaptcha==3.0.0",
"django-reversion==5.0.2",
"django-reversion-compare==0.17.0",
"django-sass-processor==1.4",
"django-sesame[ua]==3.2.2",
"django-tagging",
"django-taggit==5.0.1",
"django-vite==3.0.3",
"django-waffle==4.1.0",
"django-watson==1.6.3",
"django-webhook",
"djangorestframework==3.15.2",
"djangorestframework-simplejwt>=5.4.0",
"djangorestframework-xml>=2.0.0",
"drf-spectacular[sidecar]>=0.28.0",
"dynamic-django-forms>=0.1.11",
"ipython>=8.32.0",
"libsass>=0.23.0",
"lxml[html-clean]>=5.3.1",
"markdown-link-attr-modifier==0.2.1",
"metabase-api==3.4",
"multimethod==1.7",
"mwclient==0.11.0",
"pandoc==2.4",
"psycopg[binary]>3",
"redis==5.0.4",
"requests-html==0.10.0",
"rest-framework-generic-relations>=2.2.0",
"sentry-sdk>=2.20.0",
"setuptools==70.2.0",
"sib-api-v3-sdk>=7.6.0",
"wagtail==6.2.2",
]

[tool.djlint]
# ignore = "W013"
extension = "html"
Expand Down Expand Up @@ -91,3 +158,53 @@ section-order = [

[tool.ruff.lint.flake8-bandit]
check-typed-exception = true

[tool.uv.sources]
django-magicauth = { git = "https://github.com/glibersat/django-magicauth", rev = "55eab0b91c95012944933b342748540b2c1b31bf" }
django-notifications-hq = { git = "https://github.com/glibersat/django-notifications.git", rev = "feature/sites-framework" }
django-activity-stream = { git = "https://github.com/glibersat/django-activity-stream.git", rev = "django4" }
django-multisite = { git = "https://github.com/protoroto/django-multisite.git", rev = "feature/add-django4-support" }
django-dbtemplates = { git = "https://github.com/jazzband/django-dbtemplates.git", rev = "master" }
django-cookie-consent = { git = "https://github.com/jazzband/django-cookie-consent", rev = "master" }
django-tagging = { git = "https://github.com/nextories/django-tagging.git", rev = "bug/usage_for_model_with_filters_none" }
django-webhook = { git = "https://github.com/etchegom/django-webhook.git", rev = "recoco" }

[dependency-groups]
dev = [
"black>=25.1.0",
"coverage==7.4.1",
"django-coverage-plugin>=3.1.0",
"django-debug-toolbar==4.3.0",
"django-extensions==3.2.1",
"fabric==3.2.2",
"freezegun>=1.5.1",
"graphviz==0.20.1",
"ipykernel==6.20.1",
"ipython>=8.32.0",
"jupyter==1.0.0",
"jupytext==1.16.1",
"model-bakery==1.17.0",
"notebook==6.4.12",
"pre-commit==3.6.0",
"pylint>=3.3.4",
"pylint-django>=2.6.1",
"pytest==8.0.1",
"pytest-cov==4.1.0",
"pytest-django==4.8.0",
"pytest-icdiff==0.9",
"pytest-mock==3.12.0",
"pytest-subtests==0.11.0",
"pytest-sugar==1.0.0",
"pytest-xdist==3.5.0",
"python-dotenv>=1.0.1",
"pytz>=2025.1",
"requests-mock==1.12.1",
"responses==0.25.3",
"rich>=13.9.4",
"semgrep==1.61.1",
"sphinx-autodoc-annotation>=1.0.post1",
"sphinx-js>=4.0.0",
"sphinx-toolbox>=3.8.2",
"sphinxcontrib-django>=2.5",
"sphinxcontrib-django-urls>=0.3",
]
1 change: 1 addition & 0 deletions recoco/apps/crm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ def project_site_handover(request, project_id):
is_origin=False,
status="DRAFT",
)

onboarding_utils.notify_new_project(
site=site, project=project, owner=project.owner
)
Expand Down
6 changes: 2 additions & 4 deletions recoco/apps/geomatics/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class RegionViewSet(viewsets.ReadOnlyModelViewSet):
"""

def get_queryset(self):
return (
models.Region.objects.all().order_by("name").prefetch_related("departments")
)
return models.Region.objects.prefetch_related("departments").order_by("name")

serializer_class = RegionSerializer

Expand All @@ -51,7 +49,7 @@ class CommuneViewSet(viewsets.ReadOnlyModelViewSet):
"""

def get_queryset(self):
return models.Commune.objects.all().order_by("name")
return models.Commune.objects.select_related("department").order_by("name")

serializer_class = CommuneSerializer
filter_backends = [DjangoFilterBackend]
Expand Down
10 changes: 4 additions & 6 deletions recoco/apps/home/management/commands/update_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@
from recoco.apps.projects.models import Project, ProjectSwitchtender
from recoco.apps.projects.utils import (
assign_advisor,
assign_collaborator,
assign_collaborator_permissions,
assign_observer,
)
from recoco.utils import get_group_for_site


def assign_user_permissions_by_projects():
"""Per project permission for user"""
"""Per project permission for user."""
for project in Project.objects.all():
print("Updating perms for project:", project.name)
for site in project.sites.all():
print("\t* Updating permissions for collaborators...")
with settings.SITE_ID.override(site.id):
for membership in project.projectmember_set.all():
assign_collaborator(
membership.member, project, is_owner=membership.is_owner
)
assign_collaborator_permissions(membership.member, project)

print("\t* Updating permissions for advisors/observers...")
print(f"\t== On site {site} ==")
Expand Down Expand Up @@ -63,7 +61,7 @@ def assign_user_permissions_by_projects():


def assign_group_permissions_by_sites():
"""Per site permissions for Group"""
"""Per site permissions for Group."""
for site in Site.objects.all():
print("site:", site)
with settings.SITE_ID.override(site.id):
Expand Down
4 changes: 2 additions & 2 deletions recoco/apps/onboarding/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def password_message_group(errors=None):
# TODO: add a phone number validation, pattern / mask
phone = forms.CharField(
max_length=16,
label="Téléphone *",
label="Numéro de téléphone *",
initial="",
help_text="Format attendu: 0102030405",
help_text="Votre numéro de téléphone ne sera jamais diffusé en dehors du site. Il permet aux administrateurs ou aux partenaires de votre dossier de vous joindre plus facilement. Format attendu: 0102030405.",
required=True,
)
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox(api_params={"hl": "fr"}))
Expand Down
2 changes: 1 addition & 1 deletion recoco/apps/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def origin(self):

def moderated(self):
"""Filter out sites where this project is not yet validated"""
return self.exclude(status="DRAFT")
return self.exclude(status__in=["DRAFT", "REJECTED"])

def to_moderate(self):
"""List only sites where this project needs moderation"""
Expand Down
16 changes: 13 additions & 3 deletions recoco/apps/projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@


@transaction.atomic
def assign_collaborator(user, project, is_owner=False):
"""Make someone becomes a project collaborator and assign permissions"""
def assign_collaborator_permissions(user, project):
"""
Assign permissions to project collaborator.
If the project is still in draft (not accepted by moderators)
"""
permissions = models.COLLABORATOR_DRAFT_PERMISSIONS
if project.project_sites.origin().status != "DRAFT":
if project.project_sites.current().status != "DRAFT":
permissions += models.COLLABORATOR_PERMISSIONS

for perm in permissions:
Expand All @@ -39,6 +42,13 @@ def assign_collaborator(user, project, is_owner=False):
print(f"Unable to find permission <{perm}>, aborting.")
raise e


@transaction.atomic
def assign_collaborator(user, project, is_owner=False):
"""Make someone becomes a project collaborator and assign permissions"""

assign_collaborator_permissions(user, project)

# if we already have an owner, don't allow her to be replaced
if is_owner:
if (
Expand Down
6 changes: 6 additions & 0 deletions recoco/apps/projects/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from ..utils import (
assign_advisor,
assign_collaborator,
assign_collaborator_permissions,
assign_observer,
can_administrate_project,
is_advisor_for_project,
Expand Down Expand Up @@ -159,6 +160,11 @@ def project_moderation_accept(request, project_pk):
# Invite her to fill in a new form
# Send an email to the project owner

# We assign permissions to use their project on this website in
# case of multiplication
for membership in project.projectmember_set.all():
assign_collaborator_permissions(membership.member, project)

params = {
"project": digests.make_project_digest(project, owner),
"site": digests.make_site_digest(
Expand Down
2 changes: 1 addition & 1 deletion recoco/apps/projects/views/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def fetch_the_site_project_statuses_for_user(site, user):
"""
project_statuses = models.UserProjectStatus.objects.filter(
user=user, project__deleted=None, project__sites=site
)
).exclude(project__project_sites__status__in=["DRAFT", "REJECTED"])

# create missing user project status
create_missing_user_project_statuses(site, user, project_statuses)
Expand Down
20 changes: 8 additions & 12 deletions recoco/apps/survey/templates/survey/question_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h3>{{ question.text }}</h3>
</div>
</form>
</div>
<div class="col col-lg-5">
<div class="col col-lg-5" x-data="{ showMore: false }">
{% if question.why %}
<div id="section-why" class="fr-mb-6w">
<svg class="d-inline-block bi fr-mr-1v"
Expand All @@ -191,18 +191,16 @@ <h3>{{ question.text }}</h3>
&nbsp;
<h5 class="d-inline-block">Pourquoi c'est important</h5>
<p class="text-secondary">
<div id="excerpt-why d-iline">{{ question.why_rendered|safe|truncatechars_html:150 }}</div>
<div x-show="!showMore">{{ question.why_rendered|safe|truncatechars_html:150 }}</div>
{% if question.why_rendered|safe|truncatechars_html:151|length > 150 %}
<span id="more-why d-none">{{ question.why_rendered|safe }}</span>
<a href="javascript:void(0);"
onclick="textFoldToggle('why')"
id="foldBtn-why">[Lire tout]</a>
<span x-show="showMore">{{ question.why_rendered|safe }}</span>
<button @click="showMore = true" x-show="!showMore">[Lire tout]</button>
{% endif %}
</p>
</div>
{% endif %}
{% if question.how %}
<div id="section-how">
<div id="section-how" x-data="{ showMore: false }">
<svg class="d-inline-block bi fr-mr-1v"
width="18"
height="18"
Expand All @@ -212,12 +210,10 @@ <h5 class="d-inline-block">Pourquoi c'est important</h5>
&nbsp;
<h5 class="d-inline-block">Où chercher l'information</h5>
<p class="text-secondary">
<div id="excerpt-how">{{ question.how_rendered|safe|truncatechars_html:500 }}</div>
<div x-show="!showMore">{{ question.how_rendered|safe|truncatechars_html:500 }}</div>
{% if question.how_rendered|safe|truncatechars_html:501|length > 500 %}
<span id="more-how d-none">{{ question.how_rendered|safe }}</span>
<a href="javascript:void(0);"
onclick="textFoldToggle('how')"
id="foldBtn-how">[Lire tout]</a>
<span x-show="showMore">{{ question.how_rendered|safe }}</span>
<button @click="showMore = true" x-show="!showMore">[Lire tout]</button>
{% endif %}
</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion recoco/apps/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ def trigged_by(self):

triggers = {}
for tag in self.condition_tags:
triggers[tag] = TaggedItem.objects.get_by_model(survey_models.Choice, tag)
triggers[tag] = TaggedItem.objects.get_by_model(
survey_models.Choice.objects.prefetch_related(
"question__question_set"
).select_related("question"),
tag,
)

return triggers

Expand Down
Loading

0 comments on commit 01827e3

Please sign in to comment.