diff --git a/wildlifecompliance/components/users/api.py b/wildlifecompliance/components/users/api.py index 4c0ee7760..f187c90e6 100644 --- a/wildlifecompliance/components/users/api.py +++ b/wildlifecompliance/components/users/api.py @@ -10,7 +10,7 @@ #from rest_framework.decorators import detail_route, list_route from rest_framework.response import Response from rest_framework.renderers import JSONRenderer -from ledger.accounts.models import EmailUser, Address, Profile, EmailIdentity, EmailUserAction +from ledger.accounts.models import EmailUser, Address, Profile, EmailIdentity, EmailUserAction, PrivateDocument from django.contrib.auth.models import Permission, ContentType from datetime import datetime from django_countries import countries @@ -575,7 +575,14 @@ def upload_id(self, request, *args, **kwargs): with transaction.atomic(): private_doc = instance.identification2 private_doc.file_group = 1 - private_doc.extension = "".join(pathlib.Path(request.data.dict()['identification2'].name).suffixes) + private_doc.name = pathlib.Path(request.data.dict()['identification2'].name).name + private_doc.extension = pathlib.Path( + request.data.dict()['identification2'].name + ).suffix if (len( + pathlib.Path( + request.data.dict()['identification2'].name + ).suffix) <= PrivateDocument._meta.get_field('extension').max_length + ) else "" private_doc.save() instance.save() instance.log_user_action( diff --git a/wildlifecompliance/components/users/serializers.py b/wildlifecompliance/components/users/serializers.py index 938e8a30b..049544c64 100644 --- a/wildlifecompliance/components/users/serializers.py +++ b/wildlifecompliance/components/users/serializers.py @@ -370,6 +370,7 @@ class FirstTimeUserSerializer(UserSerializer): has_complete_first_time = serializers.SerializerMethodField(read_only=True) prefer_compliance_management = serializers.SerializerMethodField(read_only=True) is_compliance_management_approved_external_user = serializers.SerializerMethodField(read_only=True) + sso_setting_url = serializers.SerializerMethodField(read_only=True) class Meta: model = EmailUser @@ -397,6 +398,7 @@ class Meta: 'has_complete_first_time', 'prefer_compliance_management', 'is_compliance_management_approved_external_user', + 'sso_setting_url', ) def get_has_complete_first_time(self, obj): @@ -423,6 +425,8 @@ def get_prefer_compliance_management(self, obj): def get_is_compliance_management_approved_external_user(self, obj): return is_compliance_management_approved_external_user(self.context.get('request')) + def get_sso_setting_url(self, obj): + return settings.SSO_SETTING_URL class DTUserSerializer(serializers.ModelSerializer): @@ -481,6 +485,7 @@ class MyUserDetailsSerializer(serializers.ModelSerializer): legal_dob = serializers.SerializerMethodField(read_only=True) is_payment_officer = serializers.SerializerMethodField(read_only=True) has_complete_first_time = serializers.SerializerMethodField(read_only=True) + sso_setting_url = serializers.SerializerMethodField(read_only=True) class Meta: model = EmailUser @@ -512,6 +517,7 @@ class Meta: 'has_complete_first_time', 'is_compliance_management_user', 'is_compliance_management_approved_external_user', + 'sso_setting_url', ) def get_has_complete_first_time(self, obj): @@ -592,7 +598,9 @@ def get_prefer_compliance_management(self, obj): def get_is_reception(self, obj): return is_reception(self.context.get('request')) - + + def get_sso_setting_url(self, obj): + return settings.SSO_SETTING_URL class ComplianceUserDetailsSerializer(serializers.ModelSerializer): residential_address = UserAddressSerializer() diff --git a/wildlifecompliance/frontend/wildlifecompliance/src/components/user/manage_my_user_details.vue b/wildlifecompliance/frontend/wildlifecompliance/src/components/user/manage_my_user_details.vue index 03635e6f9..320509cfc 100644 --- a/wildlifecompliance/frontend/wildlifecompliance/src/components/user/manage_my_user_details.vue +++ b/wildlifecompliance/frontend/wildlifecompliance/src/components/user/manage_my_user_details.vue @@ -32,7 +32,7 @@
- To update your account name please click here: + To update your account name please click here:
diff --git a/wildlifecompliance/management/commands/update_identification_document_fields.py b/wildlifecompliance/management/commands/update_identification_document_fields.py new file mode 100644 index 000000000..d62ffcca6 --- /dev/null +++ b/wildlifecompliance/management/commands/update_identification_document_fields.py @@ -0,0 +1,36 @@ +from django.core.management.base import BaseCommand +from django.db.models import Q + +import logging +import pathlib + +from ledger.accounts.models import PrivateDocument + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = 'Updates all Identification document records to have all required fields populated.' + + def handle(self, *args, **options): + try: + logger.info('Running command {}'.format(__name__)) + + private_docs = PrivateDocument.objects.filter(Q(name=None)|Q(name="")|Q(extension=None)|Q(file_group=None)) + + for i in private_docs: + i.name = pathlib.Path(i.upload.name).name + i.extension = pathlib.Path(i.upload.name + ).suffix if (len( + pathlib.Path( + i.upload.name + ).suffix) <= PrivateDocument._meta.get_field('extension').max_length + ) else "" + i.file_group = 1 + i.save(update_fields=["name","extension","file_group"]) + + logger.info('Command {} finished'.format(__name__)) + + except Exception as e: + logger.error('Error command {0} : {1}'.format( + __name__, e)) diff --git a/wildlifecompliance/settings.py b/wildlifecompliance/settings.py index 3f4704d65..7c4b6729a 100644 --- a/wildlifecompliance/settings.py +++ b/wildlifecompliance/settings.py @@ -23,6 +23,8 @@ LEDGER_UI_URL=env('LEDGER_UI_URL','') +SSO_SETTING_URL=env('SSO_SETTING_URL','') + if SHOW_DEBUG_TOOLBAR: # def get_ip(): # import subprocess diff --git a/wildlifecompliance/templates/wildlifecompliance/user_profile.html b/wildlifecompliance/templates/wildlifecompliance/user_profile.html index 70cb4944b..ee4eb351a 100644 --- a/wildlifecompliance/templates/wildlifecompliance/user_profile.html +++ b/wildlifecompliance/templates/wildlifecompliance/user_profile.html @@ -39,7 +39,7 @@

Personal Details Provide your personal details
- To update your account name please click here: + To update your account name please click here: