From c89e8cea90aa0493cbdecce5c4f9a8bd5dce2c17 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 25 Jun 2025 23:39:41 +0300 Subject: remaining shared-use machine cookie tyimeouts set --- core/utils.py | 5 ++--- core/views/caves.py | 4 ++-- core/views/editor_helpers.py | 2 +- core/views/expo.py | 6 +++--- core/views/survex.py | 2 +- core/views/uploads.py | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/utils.py b/core/utils.py index 116e517..3dd1089 100644 --- a/core/utils.py +++ b/core/utils.py @@ -80,7 +80,7 @@ except: # Opening of file for writing is going to fail currently, so decide it doesn't matter for now pass -def get_cookie_max_age(request=None): +def get_cookie_max_age(request): """This is where we detect whether the machine the user is using is a shared-use device or a personal device. If it is shared-use, then we set a much shorter cookie timout period. """ @@ -314,8 +314,7 @@ def get_git_string(user): def shared_use_machine(request): """Looks for a cookie which only exists on shared use machines """ - print(f" - shared use cookie check {request}") - + if not request: # temporary while rolling out implementation to all calling functions return False diff --git a/core/views/caves.py b/core/views/caves.py index b6a9127..856c2cd 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -547,7 +547,7 @@ def edit_cave(request, path="", slug=None): edit_response = HttpResponseRedirect("/" + cave.url) else: edit_response = HttpResponseRedirect(reverse("newentrance", args = [cave.url_parent(), cave.slug()])) - edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # cookie expires after get_cookie_max_age() seconds + edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds try: cave_file = cave.file_output() @@ -777,7 +777,7 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): try: write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}", editor) edit_response = HttpResponseRedirect("/" + cave.url) - edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # cookie expires after get_cookie_max_age() seconds + edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds return edit_response except Exception as e: efilepath, econtent, eencoding = entrance_file diff --git a/core/views/editor_helpers.py b/core/views/editor_helpers.py index 28cd936..cfa0fca 100644 --- a/core/views/editor_helpers.py +++ b/core/views/editor_helpers.py @@ -410,7 +410,7 @@ def new_image_form(request, path): ) save_original_in_expofiles(f, year, form.cleaned_data["photographer"], host, image_rel_path, referer) j_response = JsonResponse({"html": html_snippet}) - j_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # does NOT work updating who_are_you cookie - because it is JsonResponse not HttpResponse. + j_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # does NOT work updating who_are_you cookie - because it is JsonResponse not HttpResponse. return j_response else: # print(f"new_image_form(): not POST ") diff --git a/core/views/expo.py b/core/views/expo.py index 723f772..a77ecf6 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -493,8 +493,8 @@ def editexpopage(request, path): if not filefound or result != html: # Check if content changed at all edit_response = HttpResponseRedirect(reverse("expopage", args=[path])) # Redirect after POST - edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # cookie expires after get_cookie_max_age() seconds - print(f"Cookie set: {editor} for {get_cookie_max_age()/(3600)} hour(s)") + edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds + print(f"Cookie set: {editor} for {get_cookie_max_age(request)/(3600)} hour(s)") try: change_message = pageform.cleaned_data["change_message"] write_and_commit([(filepath, result, "utf-8")], f"{change_message} - online edit of {path}", editor) @@ -610,7 +610,7 @@ def edittxtpage(request, path, filepath): savepath = "/" + path print(f"redirect {savepath}") response = redirect(savepath) # Redirect after POST - response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # cookie expires after get_cookie_max_age() seconds + response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds return response else: diff --git a/core/views/survex.py b/core/views/survex.py index 230d98f..075c426 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -441,7 +441,7 @@ def svx(request, survex_file): else: edit_response = render(request, "svxfile.html", vmap) - edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age() seconds + edit_response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds print(f"Cookie reset: {editor} for another {get_cookie_max_age(request)/3600} hour(s)") return edit_response diff --git a/core/views/uploads.py b/core/views/uploads.py index 9e07978..b956480 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -755,5 +755,5 @@ def dwgupload(request, folder=None, gitdisable="no"): "who_are_you": editor, }, ) - response.set_cookie('editor_id', editor, max_age=get_cookie_max_age()) # cookie expires after get_cookie_max_age() seconds + response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds return response -- cgit v1.2.3