From 1aee89b425acb94cbc01432fb9338809602408a4 Mon Sep 17 00:00:00 2001 From: muahahahh Date: Sun, 3 Jan 2021 23:44:16 +0100 Subject: [PATCH] added links --- db.sqlite3 | Bin 176128 -> 176128 bytes hr_module/__pycache__/views.cpython-38.pyc | Bin 7461 -> 7964 bytes hr_module/static/js/csrf_token.js | 2 +- .../js/hr_module_change_employee_data.js | 1 + .../static/js/hr_module_create_schedule.js | 1 + .../static/js/hr_module_show_schedule.js | 2 + hr_module/templates/hr_module_base.html | 3 +- hr_module/views.py | 47 ++++++++++++++---- 8 files changed, 43 insertions(+), 13 deletions(-) diff --git a/db.sqlite3 b/db.sqlite3 index 87485472dc36c218784fd04cd946baa19cc00f54..801844be4a7f4811c366233cfdbfb080e6d1acd9 100644 GIT binary patch delta 278 zcmZp8z}4`8Yl1Z6p@}lijE6QRuc@uPt#|dSHQ*0|B-?J8~;cC-_r#aFfQ7@ zVF9Bfzbp$gCnGb6U}9lroczkvRE7MctkmQZ1r3;lW^}buazr zT4riaN->Zbt>l}SmzbVfq>z@An64CCTN|sz3scHexa%?<$Q C4=(~h>=T?Nx2qZZ4#0}=(;G&{RSlVxAzWM*}|K{Hr ze|hAyS2O3+X-mW3sYlMP!g}VD*s85&$i1eXa0N82qg6EuHT@Q_wi-hfM?Q~Ljk|HG z--D_du?ZTx0bS@oHPO`-l4`OWIKc; zZ)iMIv)JdLbrYbqv%Ig9SOd_g)-^9^FX20}lDMc{(tQ1*=Ce+W#v_B-_B8LKCdNKZ zykja`*^XX|F}bDXPjA&yTe72StN&llz|@XOwHi@r1>R2+lz6ZPMJ*~Y&?V|U&`t8e zPI3V{+Vn|bx#?*1y@h0jaiY|{*Fa0n!2H{7PUyw-V&r*QOl>_ zmd3fW#W_jbMzbDVcilWl(h6PXmm4mdQeSGWovSRlm73=-Zf}(R@}kSOFVxG6GVU@K zu+pd>IOR&k4MQhjj+*qc^SU&hke9hDNwXY=$36@gJ@Ejf5tbL+QokQ?r`+O8uFt)S zilX_P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L&8`BI;39e4aZ!5}7OLyo9(Se#ymsq z`Te>4Ct$APx;OV9KJ!2&+4slpK^n8L%ZRrkSu=%E_&_Wa7N8-*!Xq=vToD(>*Ive* zkvT?t0po5bSoe4<=sLMbp)|19(dPYMY!ZXxxo1`J`}nN+9-1dbsW=6$m@l4#FU8H` zG*EG`xCR%Mh%u2V<#OMuWuc*kP9!FeK~JTx zi2CFc;G$YSzJn5^!CC*`q}fABF>)1=MLdV_5e(rVZX#|WJj9`!FsHnYB%|xMZz4ybV&eiBD2RoE7 - + {% endblock %} \ No newline at end of file diff --git a/hr_module/views.py b/hr_module/views.py index 51b451e..22f0848 100644 --- a/hr_module/views.py +++ b/hr_module/views.py @@ -22,20 +22,45 @@ def change_employee_data(request): return render(request, template_name) def change_employee_data_api(request): - if request.method == 'POST': - body = json.loads(request.body) - username = body['username'] + if request.user.is_authenticated: + session_user = User.objects.select_related('employee').get(username=request.user.username) + session_user_username = session_user.username + session_user_manager_flag = session_user.employee.manager_flag - empl = User.objects.select_related('employee').get(username=username) + body = json.loads(request.body) + username = body['username'] - record_employee = empl.employee.__dict__ - record_user = empl.__dict__ - response_dict = dict(record_user, **record_employee) - for i in ['_state', 'password']: - response_dict.pop(i) - print(response_dict) - return JsonResponse(response_dict, safe=False) + if request.user.is_superuser: + try: + empl = User.objects.select_related('employee').get(username=username) + except Exception as e: + print(e) + empl = None + elif session_user_manager_flag == True: + try: + print('checking manager flag') + empl = User.objects.select_related('employee').get(username=username) + if empl.employee.manager_username != session_user_username: + empl = None + except Exception as e: + print(e) + empl = None + else: + empl = None + + if empl is None: + return JsonResponse({'error': 'no_access_or_no_username'}) + + record_employee = empl.employee.__dict__ + record_user = empl.__dict__ + response_dict = dict(record_user, **record_employee) + for i in ['_state', 'password']: + response_dict.pop(i) + print(response_dict) + return JsonResponse(response_dict, safe=False) + else: + return JsonResponse({'error': 'not_authenticated'}) def create_employees(request):