Skip to content

Commit

Permalink
Merge pull request #281 from awf-dbca/update-ident-script
Browse files Browse the repository at this point in the history
Update Identification and Auth2 link
  • Loading branch information
xzzy authored Aug 2, 2024
2 parents 4319c47 + cbfe555 commit c824fc5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
11 changes: 9 additions & 2 deletions wildlifecompliance/components/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion wildlifecompliance/components/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="form-group">
<label for="" class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<b>To update your account name please <a href='/sso/setting'>click here</a>:</b>
<b>To update your account name please <a :href="current_user.sso_setting_url">click here</a>:</b>
</div>
</div>
<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions wildlifecompliance/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 class="panel-title">Personal Details <small>Provide your personal details</s
<div class="form-group">
<label for="" class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<b>To update your account name please <a href='/sso/setting'>click here</a>:</b>
<b>To update your account name please <a href='{{sso_setting_url}}'>click here</a>:</b>
</div>
</div>
<div class="form-group">
Expand Down

0 comments on commit c824fc5

Please sign in to comment.