Commit 3d321a4b authored by John Red Medrano's avatar John Red Medrano

Merge pull request #389 in RMS/api-main-service from RMSv2 to staging

* commit 'e88f6902':
  refactor upload
  refactor upload
  added new field attch_ref to allow upload same file name on attachment
  added serializer data to attachment
  forgot pass
parents fb45d664 e88f6902
...@@ -19,6 +19,7 @@ from django.conf import settings ...@@ -19,6 +19,7 @@ from django.conf import settings
from app.helper.email_service import sender from app.helper.email_service import sender
from app.applicationlayer.utils import main_threading from app.applicationlayer.utils import main_threading
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from datetime import timedelta
class Login(ObtainAuthToken): class Login(ObtainAuthToken):
...@@ -131,7 +132,7 @@ class ForgotPassword(APIView): ...@@ -131,7 +132,7 @@ class ForgotPassword(APIView):
REF = 'AUTH' REF = 'AUTH'
TOKEN = '' TOKEN = ''
TIMEOUT = 3600 # TIMEOUT = 3600
PASSCODE = 0 PASSCODE = 0
# Generate Random token for TOKEN # Generate Random token for TOKEN
...@@ -144,16 +145,20 @@ class ForgotPassword(APIView): ...@@ -144,16 +145,20 @@ class ForgotPassword(APIView):
rands.append(randrange(10)) rands.append(randrange(10))
rands.append(randrange(10)) rands.append(randrange(10))
PASSCODE = f"{rands[0]}{rands[1]}{rands[2]}{rands[3]}" PASSCODE = f"{rands[0]}{rands[1]}{rands[2]}{rands[3]}"
date_now = datetime.now()
timeout_at = date_now + timedelta(seconds=3600)
AuthToken( AuthToken(
ref=REF, ref=REF,
token=TOKEN, token=TOKEN,
passcode=PASSCODE, passcode=PASSCODE,
timeout=TIMEOUT,
is_active=True, is_active=True,
user=existingUser, user=existingUser,
created=date_now,
timeout_at=timeout_at
).save() ).save()
url = f"{settings.FRONT_END_URL}/forgot-password/reset"\ url = f"{settings.FRONT_END_URL}/forgot-password/reset"\
f"?token={TOKEN}" f"?token={TOKEN}"
......
...@@ -36,12 +36,15 @@ class ChangeRequestFormAttachmentsFileUploadSerializer( ...@@ -36,12 +36,15 @@ class ChangeRequestFormAttachmentsFileUploadSerializer(
class Meta: class Meta:
model = models.ChangeRequestFormAttachments model = models.ChangeRequestFormAttachments
fields = ( fields = (
'id',
'code',
'attachment_type', 'attachment_type',
'attachment_name', 'attachment_name',
'file_name', 'file_name',
'description', 'description',
'file_upload', 'file_upload',
'uploaded_by', 'uploaded_by',
'form_code' 'form_code',
'created'
) )
# read_only_fields = ['created', 'code'] read_only_fields = ['id,', 'created', 'code']
\ No newline at end of file \ No newline at end of file
...@@ -1294,11 +1294,18 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet): ...@@ -1294,11 +1294,18 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
id_number id_number
) )
self.queryset = models.ChangeRequestFormAttachments.objects.filter(
form_code=form_code
)
self.serializer_class = ChangeRequestFormAttachmentsFileUploadSerializer
serializer = self.get_serializer(self.queryset, many=True)
message = status_message_response( message = status_message_response(
200, 'success', 200, 'success',
'Attachments successfully updated!', 'Attachments successfully updated!',
'' serializer.data
) )
return Response(message, status=status.HTTP_200_OK) return Response(message, status=status.HTTP_200_OK)
......
...@@ -85,7 +85,7 @@ urlpatterns = [ ...@@ -85,7 +85,7 @@ urlpatterns = [
path('form-user-list/', UserListForm.as_view(), name="User List"), path('form-user-list/', UserListForm.as_view(), name="User List"),
path('template-user-list/', UserListTemplate.as_view(), name="User List"), path('template-user-list/', UserListTemplate.as_view(), name="User List"),
# filter endpoints under Allowed Companies table # filter endpoints under Allowed Companies table
# path('reminder/', reminder.ReminderTriggerAPIView.as_view()), path('reminder/', reminder.ReminderTriggerAPIView.as_view()),
# path('cancelled/', cancel.CancelTriggerAPIView.as_view()), # path('cancelled/', cancel.CancelTriggerAPIView.as_view()),
] ]
......
...@@ -40,15 +40,20 @@ class MasterAttachmentViewSet(viewsets.ModelViewSet): ...@@ -40,15 +40,20 @@ class MasterAttachmentViewSet(viewsets.ModelViewSet):
@transaction.atomic @transaction.atomic
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
attachments = [] attachments = []
for instance in self.request.data.getlist('url'): for key in request.data.keys():
for instance in self.request.data.getlist(key):
body = {}
data = MasterAttachment.objects.create(url=instance) body = {}
data = MasterAttachment.objects.create(
file_name = str(data.url).split('/') url=instance,
body['id'] = data.id attch_ref=key
body['file_name'] = instance.name )
attachments.append(body)
file_name = str(data.url).split('/')
body['id'] = data.id
body['file_name'] = instance.name
body['attch_ref'] = key
attachments.append(body)
return Response( return Response(
{"results": attachments}, {"results": attachments},
......
# Generated by Django 2.2 on 2019-10-15 17:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('entities', '0018_canceltrigger_overduetrigger_remindertrigger'),
]
operations = [
migrations.RemoveField(
model_name='authtoken',
name='timeout',
),
migrations.AddField(
model_name='authtoken',
name='created',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='authtoken',
name='timeout_at',
field=models.DateTimeField(blank=True, null=True),
),
]
# Generated by Django 2.2 on 2019-10-15 18:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('entities', '0019_auto_20191015_1721'),
]
operations = [
migrations.AddField(
model_name='masterattachment',
name='attch_ref',
field=models.TextField(default=1),
preserve_default=False,
),
]
...@@ -7,6 +7,7 @@ from django.dispatch import receiver ...@@ -7,6 +7,7 @@ from django.dispatch import receiver
from datetime import datetime from datetime import datetime
from . import enums from . import enums
from django.utils.text import slugify from django.utils.text import slugify
from datetime import timedelta
# ********************* AUTH TABLES ********************* # ********************* AUTH TABLES *********************
...@@ -326,11 +327,12 @@ class AuthToken(models.Model): ...@@ -326,11 +327,12 @@ class AuthToken(models.Model):
ref = models.CharField(max_length=255) ref = models.CharField(max_length=255)
token = models.TextField() token = models.TextField()
passcode = models.CharField(max_length=255) passcode = models.CharField(max_length=255)
timeout = models.IntegerField()
is_active = models.BooleanField(default=False) is_active = models.BooleanField(default=False)
user = models.ForeignKey(User, to_field='code', user = models.ForeignKey(User, to_field='code',
related_name='auth_access_token', related_name='auth_access_token',
on_delete=models.PROTECT) on_delete=models.PROTECT)
created = models.DateTimeField(blank=True, null=True)
timeout_at = models.DateTimeField(blank=True, null=True)
class Meta: class Meta:
db_table = 'auth_access_token' db_table = 'auth_access_token'
...@@ -446,6 +448,7 @@ class MasterAttachment(models.Model): ...@@ -446,6 +448,7 @@ class MasterAttachment(models.Model):
upload_to='uploads/', upload_to='uploads/',
blank=True, blank=True,
null=True) null=True)
attch_ref = models.TextField()
class Meta: class Meta:
db_table = 'master_attachments' db_table = 'master_attachments'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment