Skip to content

Commit

Permalink
feat(project, update): prevent views or tasks update when sync is ena…
Browse files Browse the repository at this point in the history
…bled

Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Jan 24, 2025
1 parent 4dc9f04 commit 55905ba
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
4 changes: 3 additions & 1 deletion rdmo/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@
'PROJECT_IMPORTS_LIST',
'PROJECT_SEND_ISSUE',
'PROJECT_QUESTIONS_AUTOSAVE',
'NESTED_PROJECTS'
'NESTED_PROJECTS',
'PROJECT_VIEWS_SYNC',
'PROJECT_TASKS_SYNC'
]

SETTINGS_API = [
Expand Down
13 changes: 13 additions & 0 deletions rdmo/projects/serializers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.translation import gettext_lazy as _

from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from rdmo.questions.models import Catalog
from rdmo.services.validators import ProviderValidator
Expand Down Expand Up @@ -93,6 +94,18 @@ class Meta:
ProjectParentValidator()
]

def validate_views(self, value):
"""Block updates to views if syncing is enabled."""
if settings.PROJECT_VIEWS_SYNC:
raise ValidationError(_('Updating views is not allowed when PROJECT_VIEWS_SYNC is enabled.'))
return value

def validate_tasks(self, value):
"""Block updates to tasks if syncing is enabled."""
if settings.PROJECT_TASKS_SYNC:
raise ValidationError(_('Updating tasks is not allowed when PROJECT_TASKS_SYNC is enabled.'))
return value


class ProjectCopySerializer(ProjectSerializer):

Expand Down
4 changes: 2 additions & 2 deletions rdmo/projects/templates/projects/project_detail_issues.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>{% trans 'Tasks' %}</h2>
<th style="width: 15%">{% trans 'Time frame' %}</th>
<th style="width: 15%">{% trans 'Status' %}</th>
<th style="width: 10%" class="text-right">
{% if can_change_project %}
{% if can_change_project and not settings.PROJECT_TASKS_SYNC %}
<a href="{% url 'project_update_tasks' project.pk %}" title="{% trans 'Update project tasks.' %}">
<i class="fa fa-pencil"></i>
</a>
Expand Down Expand Up @@ -67,7 +67,7 @@ <h2>{% trans 'Tasks' %}</h2>

{% else %}

{% if can_change_project %}
{% if can_change_project and not settings.PROJECT_TASKS_SYNC %}
<p class="project-update">
<a href="{% url 'project_update_tasks' project.pk %}" title="{% trans 'Update project tasks.' %}">
<i class="fa fa-pencil"></i>
Expand Down
4 changes: 2 additions & 2 deletions rdmo/projects/templates/projects/project_detail_views.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2>{% trans 'Views' %}</h2>
<th style="width: 20%">{% trans 'View' %}</th>
<th style="width: 60%">{% trans 'Description' %}</th>
<th style="width: 20%" class="text-right">
{% if can_change_project %}
{% if can_change_project and not settings.PROJECT_VIEWS_SYNC %}
<a href="{% url 'project_update_views' project.pk %}" title="{% trans 'Update project views' %}">
<i class="fa fa-pencil"></i>
</a>
Expand All @@ -45,7 +45,7 @@ <h2>{% trans 'Views' %}</h2>

{% else %}

{% if can_change_project %}
{% if can_change_project and not settings.PROJECT_VIEWS_SYNC %}
<p class="project-update">
<a href="{% url 'project_update_views' project.pk %}" title="{% trans 'Update project views' %}">
<i class="fa fa-pencil"></i>
Expand Down
13 changes: 11 additions & 2 deletions rdmo/projects/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ def get_context_data(self, **kwargs):
context['catalogs'] = Catalog.objects.filter_current_site() \
.filter_group(self.request.user) \
.filter_availability(self.request.user)
context['tasks_available'] = Task.objects.filter_current_site() \

if settings.PROJECT_TASKS_SYNC:
# tasks should be synced, the user can not change them
context['tasks_available'] = project.tasks.exists()
else:
context['tasks_available'] = Task.objects.filter_current_site() \
.filter_catalog(self.object.catalog) \
.filter_group(self.request.user) \
.filter_availability(self.request.user).exists()
context['views_available'] = View.objects.filter_current_site() \
if settings.PROJECT_VIEWS_SYNC:
# views should be synced, the user can not change them
context['views_available'] = project.views.exists()
else:
context['views_available'] = View.objects.filter_current_site() \
.filter_catalog(self.object.catalog) \
.filter_group(self.request.user) \
.filter_availability(self.request.user).exists()
Expand Down

0 comments on commit 55905ba

Please sign in to comment.