Skip to content

Commit 55905ba

Browse files
committed
feat(project, update): prevent views or tasks update when sync is enabled
Signed-off-by: David Wallace <[email protected]>
1 parent 4dc9f04 commit 55905ba

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Diff for: rdmo/core/settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@
209209
'PROJECT_IMPORTS_LIST',
210210
'PROJECT_SEND_ISSUE',
211211
'PROJECT_QUESTIONS_AUTOSAVE',
212-
'NESTED_PROJECTS'
212+
'NESTED_PROJECTS',
213+
'PROJECT_VIEWS_SYNC',
214+
'PROJECT_TASKS_SYNC'
213215
]
214216

215217
SETTINGS_API = [

Diff for: rdmo/projects/serializers/v1/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.utils.translation import gettext_lazy as _
55

66
from rest_framework import serializers
7+
from rest_framework.exceptions import ValidationError
78

89
from rdmo.questions.models import Catalog
910
from rdmo.services.validators import ProviderValidator
@@ -93,6 +94,18 @@ class Meta:
9394
ProjectParentValidator()
9495
]
9596

97+
def validate_views(self, value):
98+
"""Block updates to views if syncing is enabled."""
99+
if settings.PROJECT_VIEWS_SYNC:
100+
raise ValidationError(_('Updating views is not allowed when PROJECT_VIEWS_SYNC is enabled.'))
101+
return value
102+
103+
def validate_tasks(self, value):
104+
"""Block updates to tasks if syncing is enabled."""
105+
if settings.PROJECT_TASKS_SYNC:
106+
raise ValidationError(_('Updating tasks is not allowed when PROJECT_TASKS_SYNC is enabled.'))
107+
return value
108+
96109

97110
class ProjectCopySerializer(ProjectSerializer):
98111

Diff for: rdmo/projects/templates/projects/project_detail_issues.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h2>{% trans 'Tasks' %}</h2>
2121
<th style="width: 15%">{% trans 'Time frame' %}</th>
2222
<th style="width: 15%">{% trans 'Status' %}</th>
2323
<th style="width: 10%" class="text-right">
24-
{% if can_change_project %}
24+
{% if can_change_project and not settings.PROJECT_TASKS_SYNC %}
2525
<a href="{% url 'project_update_tasks' project.pk %}" title="{% trans 'Update project tasks.' %}">
2626
<i class="fa fa-pencil"></i>
2727
</a>
@@ -67,7 +67,7 @@ <h2>{% trans 'Tasks' %}</h2>
6767

6868
{% else %}
6969

70-
{% if can_change_project %}
70+
{% if can_change_project and not settings.PROJECT_TASKS_SYNC %}
7171
<p class="project-update">
7272
<a href="{% url 'project_update_tasks' project.pk %}" title="{% trans 'Update project tasks.' %}">
7373
<i class="fa fa-pencil"></i>

Diff for: rdmo/projects/templates/projects/project_detail_views.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h2>{% trans 'Views' %}</h2>
1919
<th style="width: 20%">{% trans 'View' %}</th>
2020
<th style="width: 60%">{% trans 'Description' %}</th>
2121
<th style="width: 20%" class="text-right">
22-
{% if can_change_project %}
22+
{% if can_change_project and not settings.PROJECT_VIEWS_SYNC %}
2323
<a href="{% url 'project_update_views' project.pk %}" title="{% trans 'Update project views' %}">
2424
<i class="fa fa-pencil"></i>
2525
</a>
@@ -45,7 +45,7 @@ <h2>{% trans 'Views' %}</h2>
4545

4646
{% else %}
4747

48-
{% if can_change_project %}
48+
{% if can_change_project and not settings.PROJECT_VIEWS_SYNC %}
4949
<p class="project-update">
5050
<a href="{% url 'project_update_views' project.pk %}" title="{% trans 'Update project views' %}">
5151
<i class="fa fa-pencil"></i>

Diff for: rdmo/projects/views/project.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ def get_context_data(self, **kwargs):
6464
context['catalogs'] = Catalog.objects.filter_current_site() \
6565
.filter_group(self.request.user) \
6666
.filter_availability(self.request.user)
67-
context['tasks_available'] = Task.objects.filter_current_site() \
67+
68+
if settings.PROJECT_TASKS_SYNC:
69+
# tasks should be synced, the user can not change them
70+
context['tasks_available'] = project.tasks.exists()
71+
else:
72+
context['tasks_available'] = Task.objects.filter_current_site() \
6873
.filter_catalog(self.object.catalog) \
6974
.filter_group(self.request.user) \
7075
.filter_availability(self.request.user).exists()
71-
context['views_available'] = View.objects.filter_current_site() \
76+
if settings.PROJECT_VIEWS_SYNC:
77+
# views should be synced, the user can not change them
78+
context['views_available'] = project.views.exists()
79+
else:
80+
context['views_available'] = View.objects.filter_current_site() \
7281
.filter_catalog(self.object.catalog) \
7382
.filter_group(self.request.user) \
7483
.filter_availability(self.request.user).exists()

0 commit comments

Comments
 (0)