Skip to content

Commit e19be64

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 e19be64

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-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

+7
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,12 @@ 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 and value:
100+
raise ValidationError(_('Updating views is not allowed.'))
101+
return value
102+
96103

97104
class ProjectCopySerializer(ProjectSerializer):
98105

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/tests/test_viewset_project.py

+14
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,20 @@ def test_update_parent(db, client, username, password, project_id):
429429
assert Project.objects.get(pk=project_id).parent == project.parent
430430

431431

432+
def test_update_project_views_not_allowed(db, client, settings):
433+
assert settings.PROJECT_VIEWS_SYNC
434+
client.login(username='owner', password='owner')
435+
436+
url = reverse(urlnames['detail'], args=[project_id])
437+
data = {
438+
'views': [1]
439+
}
440+
response = client.put(url, data, content_type='application/json')
441+
442+
assert response.status_code == 400
443+
assert 'Updating views is not allowed' in ' '.join(response.json()['views'])
444+
445+
432446
@pytest.mark.parametrize('username,password', users)
433447
@pytest.mark.parametrize('project_id', projects)
434448
def test_delete(db, client, username, password, project_id):

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)