mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-29 13:21:54 +00:00
Detect unwriteable file permissions earlier
This commit is contained in:
parent
32377f4e6c
commit
d7fd6b00ae
@ -42,7 +42,8 @@ def writetrogglefile(filepath, filecontent):
|
|||||||
'''Set permissions to rw-rw-r-- and commit the new saved file to git
|
'''Set permissions to rw-rw-r-- and commit the new saved file to git
|
||||||
Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly
|
Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly
|
||||||
'''
|
'''
|
||||||
# see also core/views/expo.py editexpopage()
|
# GIT see also core/views/expo.py editexpopage()
|
||||||
|
# GIT see also core/views/uploads.py dwgupload()
|
||||||
filepath = Path(filepath)
|
filepath = Path(filepath)
|
||||||
cwd = filepath.parent
|
cwd = filepath.parent
|
||||||
filename = filepath.name
|
filename = filepath.name
|
||||||
@ -56,7 +57,7 @@ def writetrogglefile(filepath, filecontent):
|
|||||||
#os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
#os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
||||||
# should replace .call with .run and capture_output=True
|
# should replace .call with .run and capture_output=True
|
||||||
call([git, "add", filename], cwd=cwd)
|
call([git, "add", filename], cwd=cwd)
|
||||||
call([git, "commit", "-m", 'Troggle online cave or entrance edit'], cwd=cwd)
|
call([git, "commit", "-m", f'Troggle online: cave or entrance edit -{filename}'], cwd=cwd)
|
||||||
|
|
||||||
|
|
||||||
class Area(TroggleModel):
|
class Area(TroggleModel):
|
||||||
|
@ -142,7 +142,7 @@ def expowebpage(request, expowebpath, path):
|
|||||||
if m:
|
if m:
|
||||||
editable = False
|
editable = False
|
||||||
else:
|
else:
|
||||||
editable = True
|
editable = os.access(Path(expowebpath / path), os.W_OK) # are file permissions writeable?
|
||||||
|
|
||||||
has_menu = False
|
has_menu = False
|
||||||
menumatch = re.match(r'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
|
menumatch = re.match(r'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
|
||||||
@ -253,7 +253,7 @@ def getmimetype(path):
|
|||||||
@ensure_csrf_cookie
|
@ensure_csrf_cookie
|
||||||
def editexpopage(request, path):
|
def editexpopage(request, path):
|
||||||
'''Manages the 'Edit this Page' capability for expo handbook and other html pages.
|
'''Manages the 'Edit this Page' capability for expo handbook and other html pages.
|
||||||
Relies on javascript to provide the in-browser editing environment.
|
Relies on HTML5 or javascript to provide the in-browser editing environment.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
# if a cave not a webpage at all.
|
# if a cave not a webpage at all.
|
||||||
@ -310,7 +310,8 @@ def editexpopage(request, path):
|
|||||||
cwd = filepath.parent
|
cwd = filepath.parent
|
||||||
filename = filepath.name
|
filename = filepath.name
|
||||||
git = settings.GIT
|
git = settings.GIT
|
||||||
# see also core/models/cave.py writetrogglefile()
|
# GIT see also core/models/cave.py writetrogglefile()
|
||||||
|
# GIT see also core/views/uploads.py dwgupload()
|
||||||
try:
|
try:
|
||||||
with open(filepath, "w") as f:
|
with open(filepath, "w") as f:
|
||||||
print(f'WRITING{cwd}---{filename} ')
|
print(f'WRITING{cwd}---{filename} ')
|
||||||
@ -328,11 +329,11 @@ def editexpopage(request, path):
|
|||||||
message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata
|
message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata
|
||||||
return render(request,'errors/generic.html', {'message': message})
|
return render(request,'errors/generic.html', {'message': message})
|
||||||
|
|
||||||
cp_commit = subprocess.run([git, "commit", "-m", 'Edit this page'], cwd=cwd, capture_output=True, text=True)
|
cp_commit = subprocess.run([git, "commit", "-m", f'Troggle online: Edit this page - {filename}'], cwd=cwd, capture_output=True, text=True)
|
||||||
# This produces return code = 1 if it commits OK, but if the repo still needs to be pushed to origin/expoweb
|
# This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb
|
||||||
if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean':
|
if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean':
|
||||||
msgdata = 'Ask a nerd to fix this.\n\n' + cp_commit.stderr + '\n\n' + cp_commit.stdout + '\n\nreturn code: ' + str(cp_commit.returncode)
|
msgdata = 'Ask a nerd to fix this.\n\n' + cp_commit.stderr + '\n\n' + cp_commit.stdout + '\n\nreturn code: ' + str(cp_commit.returncode)
|
||||||
message = f'Eror code with git on server for this file {filename}. Edits saved, added to git but NOT committed.\n\n' + msgdata
|
message = f'Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n' + msgdata
|
||||||
return render(request,'errors/generic.html', {'message': message})
|
return render(request,'errors/generic.html', {'message': message})
|
||||||
|
|
||||||
except subprocess.SubprocessError:
|
except subprocess.SubprocessError:
|
||||||
|
@ -144,6 +144,9 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
|||||||
|
|
||||||
actual_saved = []
|
actual_saved = []
|
||||||
refused = []
|
refused = []
|
||||||
|
|
||||||
|
# GIT see also core/views/expo.py editexpopage()
|
||||||
|
# GIT see also core/models/cave.py writetrogglefile()
|
||||||
if gitdisable != 'yes': # set in url 'dwguploadnogit/'
|
if gitdisable != 'yes': # set in url 'dwguploadnogit/'
|
||||||
git = settings.GIT
|
git = settings.GIT
|
||||||
else:
|
else:
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
{{ body|safe }}
|
{{ body|safe }}
|
||||||
{% if homepage %}
|
{% if homepage %}
|
||||||
{% if editable %}
|
{% if editable %}
|
||||||
<a href="{% url "editexpopage" path %}">Edit</a>
|
<a href="{% url "editexpopage" path %}">Edit</a>
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
{% if not has_menu %}
|
|
||||||
{% include "menu.html" %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% else %}
|
||||||
|
{% if not has_menu %}
|
||||||
|
{% include "menu.html" %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
<li><form name=P method=get action="/search" target="_top">
|
<li><form name=P method=get action="/search" target="_top">
|
||||||
<input id="omega-autofocus" type=search name=P size=8 autofocus>
|
<input id="omega-autofocus" type=search name=P size=8 autofocus>
|
||||||
<input type=submit value="Search"></li>
|
<input type=submit value="Search"></li>
|
||||||
{% if editable %}<li><a href="{% url "editexpopage" path %}" class="editlink"><strong>Edit this page</strong></a></li>{% endif %}
|
{% if editable %}<li><a href="{% url "editexpopage" path %}" class="editlink"><strong>Edit this page</strong></a></li>
|
||||||
|
{% else %}<a href="/handbook/computing/hbmanual1.html#auto">This page not editable</a></li>{% endif %}
|
||||||
{% if cave_editable %}<li><a href="{% url "edit_cave" cave.slug %}" class="editlink"><strong>Edit this cave</strong></a></li>{% endif %}
|
{% if cave_editable %}<li><a href="{% url "edit_cave" cave.slug %}" class="editlink"><strong>Edit this cave</strong></a></li>{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
8
urls.py
8
urls.py
@ -71,6 +71,9 @@ else:
|
|||||||
# accounts/reset/<uidb64>/<token>/ [name='password_reset_confirm']
|
# accounts/reset/<uidb64>/<token>/ [name='password_reset_confirm']
|
||||||
# accounts/reset/done/ [name='password_reset_complete']
|
# accounts/reset/done/ [name='password_reset_complete']
|
||||||
|
|
||||||
|
# BUT many of these are set up by opinionated Django even if 'django.contrib.auth.urls' is NOT included.
|
||||||
|
# Some overlap with 'admin.site.urls' needs to be investigated.
|
||||||
|
|
||||||
trogglepatterns = [
|
trogglepatterns = [
|
||||||
path('expofiles/', include(expofilesurls)), # intercepted by Apache, if it is running.
|
path('expofiles/', include(expofilesurls)), # intercepted by Apache, if it is running.
|
||||||
path('expofiles', include(expofilesurls)), # curious interaction with the include() here, not just a slash problem.
|
path('expofiles', include(expofilesurls)), # curious interaction with the include() here, not just a slash problem.
|
||||||
@ -171,7 +174,7 @@ trogglepatterns = [
|
|||||||
re_path(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDX]?)?$', caves.qm, name="qm"),
|
re_path(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDX]?)?$', caves.qm, name="qm"),
|
||||||
|
|
||||||
# Prospecting Guide document
|
# Prospecting Guide document
|
||||||
re_path(r'^prospecting_guide/$', prospecting),
|
re_path(r'^prospecting_guide/$', prospecting), # disabled. Bad links, incompatible image package use and very, very out of date.
|
||||||
|
|
||||||
# This next set are all intercepted by Apache, if it is running.
|
# This next set are all intercepted by Apache, if it is running.
|
||||||
re_path(r'^photos/(?P<subpath>.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries
|
re_path(r'^photos/(?P<subpath>.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries
|
||||||
@ -203,7 +206,8 @@ urlpatterns = [
|
|||||||
# Alias /robots.txt /home/expo/troggle/media/robots.txt # does not exist!
|
# Alias /robots.txt /home/expo/troggle/media/robots.txt # does not exist!
|
||||||
# Alias /favicon.ico /home/expo/troggle/media/favicon.ico # comes from /expoweb/* when running runserver
|
# Alias /favicon.ico /home/expo/troggle/media/favicon.ico # comes from /expoweb/* when running runserver
|
||||||
# Alias /javascript /home/expo/troggle/media/jslib # empty
|
# Alias /javascript /home/expo/troggle/media/jslib # empty
|
||||||
# Alias /search ? # teh text search thinggy
|
# Alias /search ? # the Xapian text search thinggy
|
||||||
|
# Alias /kanboard ? # the Kanban Trello-clone thinggy
|
||||||
|
|
||||||
# Copy of old standard apache configurations:
|
# Copy of old standard apache configurations:
|
||||||
# Alias /expofiles /home/expo/expofiles
|
# Alias /expofiles /home/expo/expofiles
|
||||||
|
Loading…
Reference in New Issue
Block a user