2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 15:21:52 +00:00

not found now does 404 & moved login

This commit is contained in:
Philip Sargent 2021-05-03 20:35:35 +01:00
parent 254b465755
commit 9b9f6720e0
8 changed files with 37 additions and 35 deletions

View File

@ -75,7 +75,7 @@ class PageTests(TestCase):
def test_expoweb_dir_no_index(self):
response = self.client.get('/handbook/troggle')
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 404)
ph = r'Page not found handbook/troggle/index.html'
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
@ -116,7 +116,7 @@ class PageTests(TestCase):
def test_expoweb_notfound(self):
response = self.client.get('/handbook/zyxxypqrqx.html')
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 404)
ph = r'<h1>Page not found'
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
@ -367,7 +367,7 @@ class PageTests(TestCase):
def test_page_photos_not_ok(self):
# Flat file tests.
response = self.client.get('/photos/2018/PhilipSargent/corin.jpeg')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 404)
content = response.content.decode()
ph = r'<title>Page not found 2018/PhilipSargent/corin.jpeg</title>'
phmatch = re.search(ph, content)

View File

@ -156,11 +156,11 @@ class FixturePageTests(TestCase):
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_fix_cave_bare_url115(self):
'''Expect to get Page Not Found and status 200'''
'''Expect to get Page Not Found and status 404'''
ph = self.ph
ph = 'Probably a mistake.'
response = self.client.get('/1623/115')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 404)
content = response.content.decode()
phmatch = re.search(ph, content)
@ -168,11 +168,11 @@ class FixturePageTests(TestCase):
def test_fix_cave_slug115(self):
'''Expect to get Page Not Found and status 200'''
'''Expect to get Page Not Found and status 404'''
ph = self.ph
ph = 'Probably a mistake.'
response = self.client.get('/1623-115')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 404)
content = response.content.decode()
phmatch = re.search(ph, content)

View File

@ -1,8 +1,27 @@
from builtins import str
from django.conf import settings
from django.shortcuts import render
from django.http import Http404, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth import forms as auth_forms
from django.contrib.auth.decorators import login_required
"""This enforces the login requirement for non-public pages using
the decorator mechanism.
https://www.fullstackpython.com/django-contrib-auth-decorators-login-required-examples.html
"""
class login_required_if_public(object):
def __init__(self, f):
if settings.PUBLIC_SITE:
self.f = login_required(f)
else:
self.f = f
def __call__(self, *args, **kwargs):
return self.f(*args, **kwargs)
# This is copied from CUYC.cuy.website.view.auth
# If we want to do the whole online-email thing, we would also need to copy across the code in these

View File

@ -20,7 +20,7 @@ from troggle.core.models.troggle import Expedition, DataIssue
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, EntranceForm, EntranceLetterForm
#from troggle.core.forms import VersionControlCommentForm
from .login import login_required_if_public
from .auth import login_required_if_public
'''Manages the complex procedures to assemble a cave description out of the compnoents
Manages the use of cavern to parse survex files to produce 3d and pos files

View File

@ -14,7 +14,7 @@ from django.contrib import admin
import django.forms as forms
from .login import login_required_if_public
from .auth import login_required_if_public
from troggle.core.models.caves import Cave
import troggle.core.views.caves
import troggle.settings as settings
@ -121,7 +121,7 @@ def expowebpage(request, expowebpath, path):
'''Adds menus and serves an HTML page
'''
if not Path(expowebpath / path).is_file():
return render(request, 'pagenotfound.html', {'path': path})
return render(request, 'pagenotfound.html', {'path': path}, status="404")
with open(os.path.normpath(expowebpath / path), "r") as o:
html = o.read()
@ -164,9 +164,9 @@ def mediapage(request, subpath=None, doc_root=None):
try:
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(subpath))
except IOError:
return render(request, 'pagenotfound.html', {'path': subpath})
return render(request, 'pagenotfound.html', {'path': subpath}, status="404")
else:
return render(request, 'pagenotfound.html', {'path': subpath})
return render(request, 'pagenotfound.html', {'path': subpath}, status="404")
@ -196,7 +196,7 @@ def expopage(request, path):
if (expowebpath / path / p).is_file():
# This needs to reset the path to the new subdirectory
return HttpResponseRedirect('/'+str(Path(path) / p))
return render(request, 'pagenotfound.html', {'path': Path(path) / "index.html"})
return render(request, 'pagenotfound.html', {'path': Path(path) / "index.html"}, status="404")
if path.endswith("/"):
# we already know it is not a directory.
@ -210,7 +210,7 @@ def expopage(request, path):
try:
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(path))
except IOError:
return render(request, 'pagenotfound.html', {'path': path})
return render(request, 'pagenotfound.html', {'path': path}, status="404")
@ -310,7 +310,7 @@ def editexpopage(request, path):
git = settings.GIT
with open(filepath, "w") as f:
f.write(result)
print(f'WROTE {cwd}---{filename} ')
#print(f'WROTE {cwd}---{filename} ')
subprocess.call([git, "add", filename], cwd=cwd)
subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)

View File

@ -16,7 +16,7 @@ from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.utils import TROG
from troggle.core.models.caves import LogbookEntry, PersonTrip
from troggle.core.models.survex import SurvexBlock
from .login import login_required_if_public
from .auth import login_required_if_public
from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup

View File

@ -1,17 +0,0 @@
from django.contrib.auth.decorators import login_required
from django.conf import settings
"""This enforces the login requirement for non-public pages using
the decorator mechanism.
https://www.fullstackpython.com/django-contrib-auth-decorators-login-required-examples.html
"""
class login_required_if_public(object):
def __init__(self, f):
if settings.PUBLIC_SITE:
self.f = login_required(f)
else:
self.f = f
def __call__(self, *args, **kwargs):
return self.f(*args, **kwargs)

View File

@ -16,7 +16,7 @@ from troggle.parsers.imports import import_logbooks, import_QMs, import_drawings
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
from .login import login_required_if_public
from .auth import login_required_if_public
'''Utility functions and code to serve the control panel and individual user's
progress and task list (deprecated as we do not have individual user login).