Detect unwriteable file permissions earlier

This commit is contained in:
Philip Sargent
2022-03-05 17:05:15 +00:00
parent 32377f4e6c
commit d7fd6b00ae
6 changed files with 29 additions and 19 deletions

View File

@@ -142,7 +142,7 @@ def expowebpage(request, expowebpath, path):
if m:
editable = False
else:
editable = True
editable = os.access(Path(expowebpath / path), os.W_OK) # are file permissions writeable?
has_menu = False
menumatch = re.match(r'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
@@ -253,7 +253,7 @@ def getmimetype(path):
@ensure_csrf_cookie
def editexpopage(request, path):
'''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:
# if a cave not a webpage at all.
@@ -310,7 +310,8 @@ def editexpopage(request, path):
cwd = filepath.parent
filename = filepath.name
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:
with open(filepath, "w") as f:
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
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)
# This produces return code = 1 if it commits OK, but if the repo still needs to be pushed to origin/expoweb
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 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':
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})
except subprocess.SubprocessError: