From 04c3a5f9709e3aac0ee8e7e09355d6a0214c6bd8 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Mon, 30 Oct 2023 18:49:10 +0100 Subject: [PATCH 1/7] Add ValueConflictValidator and check for conflicts when storing values --- rdmo/projects/serializers/v1/__init__.py | 7 ++-- .../projects/js/project_questions/services.js | 11 +++++- ...ect_questions_form_group_autocomplete.html | 2 ++ ...project_questions_form_group_checkbox.html | 3 ++ .../project_questions_form_group_date.html | 2 ++ .../project_questions_form_group_file.html | 2 ++ .../project_questions_form_group_radio.html | 2 ++ .../project_questions_form_group_range.html | 2 ++ .../project_questions_form_group_select.html | 2 ++ .../project_questions_form_group_text.html | 2 ++ ...project_questions_form_group_textarea.html | 2 ++ .../project_questions_form_group_yesno.html | 2 ++ .../projects/project_questions_overview.html | 3 ++ .../project_questions_save_error.html | 2 +- .../project_questions_value_errors.html | 21 ++++++++++++ rdmo/projects/validators.py | 34 +++++++++++++++++-- 16 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 rdmo/projects/templates/projects/project_questions_value_errors.html diff --git a/rdmo/projects/serializers/v1/__init__.py b/rdmo/projects/serializers/v1/__init__.py index 7e65e7cb9f..a5ec382b30 100644 --- a/rdmo/projects/serializers/v1/__init__.py +++ b/rdmo/projects/serializers/v1/__init__.py @@ -8,7 +8,7 @@ from rdmo.services.validators import ProviderValidator from ...models import Integration, IntegrationOption, Invite, Issue, IssueResource, Membership, Project, Snapshot, Value -from ...validators import ValueValidator +from ...validators import ValueConflictValidator, ValueQuotaValidator class UserSerializer(serializers.ModelSerializer): @@ -259,7 +259,10 @@ class Meta: 'unit', 'external_id' ) - validators = (ValueValidator(), ) + validators = ( + ValueConflictValidator(), + ValueQuotaValidator() + ) class MembershipSerializer(serializers.ModelSerializer): diff --git a/rdmo/projects/static/projects/js/project_questions/services.js b/rdmo/projects/static/projects/js/project_questions/services.js index efa8e4ea9d..77fabffcc4 100644 --- a/rdmo/projects/static/projects/js/project_questions/services.js +++ b/rdmo/projects/static/projects/js/project_questions/services.js @@ -706,6 +706,9 @@ angular.module('project_questions') }; service.storeValue = function(value, question, set_prefix, set_index, collection_index) { + // reset value errors + value.errors = [] + if (angular.isDefined(value.removed) && value.removed) { // remove additional_input from unselected checkboxes value.additional_input = {}; @@ -826,10 +829,16 @@ angular.module('project_questions') }, function (response) { if (response.status == 500) { service.error = response; + } else if (response.status == 400) { + service.error = true; + value.errors = Object.keys(response.data); + } else if (response.status == 404) { + service.error = true; + value.errors = ['not_found'] } }) } -}; + }; service.storeValues = function() { var promises = []; diff --git a/rdmo/projects/templates/projects/project_questions_form_group_autocomplete.html b/rdmo/projects/templates/projects/project_questions_form_group_autocomplete.html index e35e795114..2996f3a321 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_autocomplete.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_autocomplete.html @@ -44,6 +44,8 @@ + + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_checkbox.html b/rdmo/projects/templates/projects/project_questions_form_group_checkbox.html index 48ed47be19..bb344cd818 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_checkbox.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_checkbox.html @@ -24,6 +24,9 @@ ng-disabled="service.project.read_only" ng-change="service.changed(service.values[question.attribute][valueset.set_prefix][valueset.set_index][$index])" /> +
+ {% include 'projects/project_questions_value_errors.html' %} +
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_date.html b/rdmo/projects/templates/projects/project_questions_form_group_date.html index 8994983bd5..36e60cf423 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_date.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_date.html @@ -24,6 +24,8 @@ ng-change="service.changed(value, true)" ng-class="{'default-value': service.isDefaultValue(question, value)}"/> + + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_file.html b/rdmo/projects/templates/projects/project_questions_form_group_file.html index 4ddf98dc31..ee0db7fad5 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_file.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_file.html @@ -33,6 +33,8 @@
+ + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_radio.html b/rdmo/projects/templates/projects/project_questions_form_group_radio.html index d1e8f462f6..29e498e8c7 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_radio.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_radio.html @@ -43,6 +43,8 @@
+ + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_range.html b/rdmo/projects/templates/projects/project_questions_form_group_range.html index 384f413d59..39fb0552d5 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_range.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_range.html @@ -31,6 +31,8 @@ ng-class="{'default-value': service.isDefaultValue(question, value)}"/>
+ + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_select.html b/rdmo/projects/templates/projects/project_questions_form_group_select.html index d672b98981..4589371cb0 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_select.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_select.html @@ -28,6 +28,8 @@
+ + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_text.html b/rdmo/projects/templates/projects/project_questions_form_group_text.html index d9284bdf56..e3fad422ec 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_text.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_text.html @@ -21,6 +21,8 @@ ng-disabled="service.project.read_only" ng-change="service.changed(value)" ng-class="{'default-value': service.isDefaultValue(question, value)}"> + + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_textarea.html b/rdmo/projects/templates/projects/project_questions_form_group_textarea.html index 756e21c96e..26baee92a1 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_textarea.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_textarea.html @@ -23,6 +23,8 @@ ng-class="{'default-value': service.isDefaultValue(question, value)}"> + + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_form_group_yesno.html b/rdmo/projects/templates/projects/project_questions_form_group_yesno.html index c06ce86618..31dda7fb79 100644 --- a/rdmo/projects/templates/projects/project_questions_form_group_yesno.html +++ b/rdmo/projects/templates/projects/project_questions_form_group_yesno.html @@ -41,6 +41,8 @@
+ + {% include 'projects/project_questions_value_errors.html' %}
diff --git a/rdmo/projects/templates/projects/project_questions_overview.html b/rdmo/projects/templates/projects/project_questions_overview.html index 1ee6ea347b..6058e465a5 100644 --- a/rdmo/projects/templates/projects/project_questions_overview.html +++ b/rdmo/projects/templates/projects/project_questions_overview.html @@ -10,6 +10,9 @@