From 10e859dcded6829f489399361966f0ea37efcce1 Mon Sep 17 00:00:00 2001 From: Gabriel Kaufmann Date: Wed, 24 Feb 2021 10:41:41 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9ELicenseserver/health=5Fview/cron.py?= =?UTF-8?q?=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Licenseserver/health_view/cron.py | 74 ++++++++++++++++--------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/Licenseserver/health_view/cron.py b/Licenseserver/health_view/cron.py index 5674f49..113973a 100644 --- a/Licenseserver/health_view/cron.py +++ b/Licenseserver/health_view/cron.py @@ -1,51 +1,53 @@ from health_view.models import * -from health_view.views import check_expiration_date -from datetime import datetime +import health_view.views from health_view.crypto_functions import * import requests import json -#needs logindata from admin account form Contentserver -loginname_restapi = '' -passwort_restapi = '' +loginname_restapi = 'gabi' +passwort_restapi = 'Lolo7138' def check_exp_date(): licenses = License.objects.all() - date_now = datetime.now() + print("did it") for lic in licenses: - if check_expiration_date(lic): + if health_view.views.check_expiration_date(lic): continue - licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id) - folderparts = lic.folder_parts.all().values_list() - parts_to_delete = list() - for part in folderparts: - delete = True - for license in licenses_same_owner: - if not check_expiration_date(license): - continue - for check_part in license.folder_parts.all().values_list(): - if check_part == part: - delete = False - if delete is True: - parts_to_delete.append(part[2]) - if not parts_to_delete: - lic.delete() - continue - new_total_key = make_encrypted_key_content_server() - post_content = { - 'patient': lic.patient.username, - 'justified': lic.justified.username, - 'new_total_key': new_total_key, - 'old_total_key': lic.patient.folderinfo.content_key, - 'folder_parts': parts_to_delete, - } - lic.patient.folderinfo.content_key = new_total_key - lic.patient.folderinfo.save() + filter_license_and_delete(lic) + + +def filter_license_and_delete(lic): + print(lic.justified) + licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id) + folderparts = lic.folder_parts.all().values_list() + parts_to_delete = list() + for part in folderparts: + delete = True + for license in licenses_same_owner: + if not health_view.views.check_expiration_date(license): + continue + for check_part in license.folder_parts.all().values_list(): + if check_part == part: + delete = False + if delete is True: + parts_to_delete.append(part[2]) + if not parts_to_delete: lic.delete() - request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi)) - - + return + new_total_key = make_encrypted_key_content_server() + post_content = { + 'patient': lic.patient.username, + 'justified': lic.justified.username, + 'new_total_key': new_total_key, + 'old_total_key': lic.patient.folderinfo.content_key, + 'folder_parts': parts_to_delete, + } + lic.patient.folderinfo.content_key = new_total_key + lic.patient.folderinfo.save() + lic.delete() + request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi)) + return