def post(self): if 'file' not in request.files: return {'No File Sent'}, 404 file = request.files['file'] if file.filename == '': return {'No File Selected'}, 404 if file: body = request.form.to_dict() file_ext = None scan = None if 'fileExt' in body: file_ext = body['fileExt'] del body['fileExt'] if 'scan' in body: scan = True del body['scan'] form = Storage(**body) form.save(file=file, fileExt=file_ext, scan=scan) send_email_async(get_user_email(), 'notification', get_user_name(), notif=f"Your document {form.fileName} has been successfully uploaded and ready to " f"be used.Please check E-Daftar portal for further updates.") return {'id': str(form.id)}, 200 else: return {'Error: Invalid Document'}, 405
def reject(self, id, message=None): application = Application.objects( Q(id=id) & Q(assignedId=get_jwt_identity()['_id']['$oid'])).get() if message is not None: application.update(message=message) application.update(status=-1) user = User.objects(Q(id=application.creatorId)).get() send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"You have successfully rejected {application.name} created by {user.first_name}." ) send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"{get_user_name()} has unfortunately rejected your application due to the following " f"reason: '{message}'. Please check E-Daftar portal for more updates." ) return 'Success', 200
def delete(self, doc_id): s = Storage.objects(Q(id=doc_id) & Q(creator=get_jwt_identity()['_id']['$oid'])).get() file_name = s.fileName s.delete() send_email_async(get_user_email(), 'notification', get_user_name(), notif=f"Your document {file_name} has been deleted successfully.") return 'Success', 200
def post(self): body = request.get_json() user = User(**body) user.save() user.add_ca() send_email_async(user.email, 'signup', user.first_name, pin=user.verification_pin) return {'id': str(user.id)}, 200
def post(self): body = request.get_json() workflow = Workflow(**body).save() send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"Workflow {workflow.name} has been successfully created and ready to be used. Please " f"check E-Daftar portal for more updates.") return {'id': str(workflow.id)}, 200
def post(self): body = request.get_json() application_template = ApplicationTemplate(**body).save() send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"Your Application Template {application_template.name} has been successfully uploaded " f"and ready to be used by the users.Please check E-Daftar portal for more " f"updates.") return {'id': str(application_template.id)}, 200
def sign(self, id): application = Application.objects( Q(id=id) & Q(assignedId=get_jwt_identity()['_id']['$oid'])).get() if application.to_hash() != application.hash: return 'Data Tampered', 403 current_stage = int(application.stage) private_key = User.objects( Q(id=get_jwt_identity()['_id']['$oid'])).get().private_key signatures = application.signatures signatures[current_stage] = Ecdsa.sign( json.dumps(application.to_hash()), PrivateKey.fromPem(private_key)).toBase64() application.update(signatures=signatures) if application.stage == application.stages - 1: application.update(stage=current_stage + 1) application.update(status=1) else: workflow = Workflow.objects(id=application.workflowId).get() new_auth_id = workflow.stages[current_stage + 1]['authId'] new_auth_name = workflow.stages[current_stage + 1]['authName'] application.update(assignedId=new_auth_id) application.update(assignedName=new_auth_name) application.update(stage=current_stage + 1) user = User.objects(Q(id=application.creatorId)).get() send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"You have successfully signed {application.name} created by {user.first_name} with " f"your digital signatures") send_email_async( user.email, 'notification', user.first_name, notif= f"{get_user_name()} has successfully signed your {application.name}. Please check " f"E-Daftar portal for more updates.") return signatures[current_stage], 200
def post(self): body = request.get_json() application = Application(**body).save() send_email_async( get_user_email(), 'notification', get_user_name(), notif= f"Your Application has been successfully received for {application.name} and " f"awaiting signatures from the authorities, Please check E-Daftar portal for more " f"updates.") auth = User.objects.get(id=application.assignedId) send_email_async( auth.email, 'notification', auth.first_name, notif= f"User {get_user_name()} has applied for {application.name} and is awaiting for your " f"signatures, Please review it from the E-Daftar portal.") return {'id': str(application.id)}, 200