You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2022/05/10 21:30:45 UTC
[airavata-django-portal] 03/04: AIRAVATA-3565 Support for optional extended user profile fields
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch AIRAVATA-3562
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit 49ebb76c7ccaaf23e38bd57e803381bb56d608be
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue May 10 16:47:21 2022 -0400
AIRAVATA-3565 Support for optional extended user profile fields
---
.../js/models/ExtendedUserProfileField.js | 1 +
.../ExtendedUserProfileMultiChoiceFieldEditor.vue | 9 ++++++---
.../ExtendedUserProfileSingleChoiceFieldEditor.vue | 9 ++++++---
.../js/components/ExtendedUserProfileTextFieldEditor.vue | 7 +++++--
.../ExtendedUserProfileUserAgreementFieldEditor.vue | 15 ++++++++++++---
5 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/ExtendedUserProfileField.js b/django_airavata/apps/api/static/django_airavata_api/js/models/ExtendedUserProfileField.js
index 8b719db1..2eec7ac8 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/models/ExtendedUserProfileField.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/ExtendedUserProfileField.js
@@ -30,6 +30,7 @@ const FIELDS = [
type: ExtendedUserProfileFieldChoice,
},
"other",
+ "required",
];
export default class ExtendedUserProfileField extends BaseModel {
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileMultiChoiceFieldEditor.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileMultiChoiceFieldEditor.vue
index 8edc55b6..ff02eea7 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileMultiChoiceFieldEditor.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileMultiChoiceFieldEditor.vue
@@ -32,7 +32,7 @@
<script>
import { mapGetters, mapMutations } from "vuex";
import { validationMixin } from "vuelidate";
-import { required } from "vuelidate/lib/validators";
+import { requiredIf } from "vuelidate/lib/validators";
import { errors } from "django-airavata-common-ui";
import ExtendedUserProfileFieldEditor from "./ExtendedUserProfileFieldEditor.vue";
const OTHER_OPTION = new Object(); // sentinel value
@@ -101,16 +101,19 @@ export default {
valid() {
return !this.$v.$invalid;
},
+ required() {
+ return this.extendedUserProfileField.required;
+ },
},
validations() {
const validations = {
value: {
- required,
+ required: requiredIf("required"),
},
other: {},
};
if (this.showOther) {
- validations.other = { required };
+ validations.other = { required: requiredIf("required") };
}
return validations;
},
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileSingleChoiceFieldEditor.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileSingleChoiceFieldEditor.vue
index 0324b753..40872081 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileSingleChoiceFieldEditor.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileSingleChoiceFieldEditor.vue
@@ -36,7 +36,7 @@
<script>
import { mapGetters, mapMutations } from "vuex";
import { validationMixin } from "vuelidate";
-import { required } from "vuelidate/lib/validators";
+import { requiredIf } from "vuelidate/lib/validators";
import { errors } from "django-airavata-common-ui";
import ExtendedUserProfileFieldEditor from "./ExtendedUserProfileFieldEditor.vue";
const OTHER_OPTION = new Object(); // sentinel value
@@ -106,6 +106,9 @@ export default {
valid() {
return !this.$v.$invalid;
},
+ required() {
+ return this.extendedUserProfileField.required;
+ },
},
validations() {
const validations = {
@@ -113,9 +116,9 @@ export default {
other: {},
};
if (this.showOther) {
- validations.other = { required };
+ validations.other = { required: requiredIf("required") };
} else {
- validations.value = { required };
+ validations.value = { required: requiredIf("required") };
}
return validations;
},
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileTextFieldEditor.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileTextFieldEditor.vue
index 284ac65d..37b451d7 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileTextFieldEditor.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileTextFieldEditor.vue
@@ -10,7 +10,7 @@
<script>
import { mapGetters, mapMutations } from "vuex";
import { validationMixin } from "vuelidate";
-import { required } from "vuelidate/lib/validators";
+import { requiredIf } from "vuelidate/lib/validators";
import { errors } from "django-airavata-common-ui";
import ExtendedUserProfileFieldEditor from "./ExtendedUserProfileFieldEditor.vue";
export default {
@@ -31,11 +31,14 @@ export default {
valid() {
return !this.$v.$invalid;
},
+ required() {
+ return this.extendedUserProfileField.required;
+ },
},
validations() {
return {
value: {
- required,
+ required: requiredIf("required"),
},
};
},
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileUserAgreementFieldEditor.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileUserAgreementFieldEditor.vue
index 9d1c6ffa..487d6b09 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileUserAgreementFieldEditor.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/components/ExtendedUserProfileUserAgreementFieldEditor.vue
@@ -20,8 +20,6 @@ import { validationMixin } from "vuelidate";
import { errors } from "django-airavata-common-ui";
import ExtendedUserProfileFieldEditor from "./ExtendedUserProfileFieldEditor.vue";
-const mustBeTrue = (value) => value === true;
-
export default {
mixins: [validationMixin],
components: { ExtendedUserProfileFieldEditor },
@@ -43,17 +41,28 @@ export default {
valid() {
return !this.$v.$invalid;
},
+ required() {
+ return this.extendedUserProfileField.required;
+ },
},
validations() {
const validations = {
value: {
- mustBeTrue,
+ mustBeTrue: this.mustBeTrue,
},
};
return validations;
},
methods: {
...mapMutations("extendedUserProfile", ["setUserAgreementValue"]),
+ mustBeTrue(value) {
+ if (this.required) {
+ return value === true;
+ } else {
+ // If not required, always valid
+ return true;
+ }
+ },
validateState: errors.vuelidateHelpers.validateState,
validateStateErrorOnly: errors.vuelidateHelpers.validateStateErrorOnly,
},