Don't show delete icon if deletions are not allowed

master
Bob Mottram 2019-08-09 23:49:44 +01:00
parent 1e08a9143a
commit 209371820d
2 changed files with 36 additions and 22 deletions

View File

@ -450,6 +450,9 @@ class PubServer(BaseHTTPRequestHandler):
self.path.endswith('/shares'): self.path.endswith('/shares'):
divertToLoginScreen=False divertToLoginScreen=False
if divertToLoginScreen and not authorized: if divertToLoginScreen and not authorized:
if self.server.debug:
print('DEBUG: divertToLoginScreen='+str(divertToLoginScreen))
print('DEBUG: authorized='+str(authorized))
self.send_response(303) self.send_response(303)
self.send_header('Location', '/login') self.send_header('Location', '/login')
self.end_headers() self.end_headers()
@ -863,7 +866,10 @@ class PubServer(BaseHTTPRequestHandler):
# delete a post from the web interface icon # delete a post from the web interface icon
if authorized and self.server.allowDeletion and '?delete=' in self.path: if authorized and self.server.allowDeletion and '?delete=' in self.path:
deleteUrl=self.path.split('?delete=')[1] deleteUrl=self.path.split('?delete=')[1]
actor=self.path.split('?delete=')[0] actor=self.server.httpPrefix+'://'+self.server.domainFull+self.path.split('?delete=')[0]
if self.server.debug:
print('DEBUG: deleteUrl='+deleteUrl)
print('DEBUG: actor='+actor)
if actor not in deleteUrl: if actor not in deleteUrl:
# You can only delete your own posts # You can only delete your own posts
self.server.GETbusy=False self.server.GETbusy=False
@ -877,10 +883,12 @@ class PubServer(BaseHTTPRequestHandler):
deleteJson= { deleteJson= {
'actor': actor, 'actor': actor,
'object': deleteUrl, 'object': deleteUrl,
'to': ['https://www.w3.org/ns/activitystreams#Public'], 'to': ['https://www.w3.org/ns/activitystreams#Public',actor],
'cc': [actor+'/followers'], 'cc': [actor+'/followers'],
'type': 'Delete' 'type': 'Delete'
} }
if self.server.debug:
pprint(deleteJson)
self._postToOutbox(deleteJson) self._postToOutbox(deleteJson)
self.server.GETbusy=False self.server.GETbusy=False
self._redirect_headers(actor+'/inbox',cookie) self._redirect_headers(actor+'/inbox',cookie)
@ -1186,7 +1194,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \ nickname, \
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
inboxFeed).encode('utf-8')) inboxFeed, \
self.server.allowDeletion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(inboxFeed).encode('utf-8')) self.wfile.write(json.dumps(inboxFeed).encode('utf-8'))
@ -1242,7 +1251,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \ nickname, \
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
outboxFeed).encode('utf-8')) outboxFeed, \
self.server.allowDeletion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(outboxFeed).encode('utf-8')) self.wfile.write(json.dumps(outboxFeed).encode('utf-8'))

View File

@ -396,7 +396,7 @@ def htmlProfilePosts(baseDir: str,httpPrefix: str, \
if item['type']=='Create' or item['type']=='Announce': if item['type']=='Create' or item['type']=='Announce':
profileStr+= \ profileStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False) nickname,domain,port,item,None,True,False,False)
return profileStr return profileStr
def htmlProfileFollowing(baseDir: str,httpPrefix: str, \ def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
@ -653,7 +653,7 @@ def individualPostAsHtml(baseDir: str, \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
postJsonObject: {}, \ postJsonObject: {}, \
avatarUrl: str, showAvatarDropdown: bool, avatarUrl: str, showAvatarDropdown: bool,
showIcons=False) -> str: allowDeletion: bool,showIcons=False) -> str:
""" Shows a single post as html """ Shows a single post as html
""" """
titleStr='' titleStr=''
@ -799,10 +799,11 @@ def individualPostAsHtml(baseDir: str, \
'<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="'+likeTitle+'">' \ '<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="'+likeTitle+'">' \
'<img src="/icons/'+likeIcon+'"/></a>' '<img src="/icons/'+likeIcon+'"/></a>'
deleteStr='' deleteStr=''
if '/users/'+nickname+'/' in postJsonObject['object']['id']: if allowDeletion:
deleteStr= \ if '/users/'+nickname+'/' in postJsonObject['object']['id']:
'<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \ deleteStr= \
'<img src="/icons/delete.png"/></a>' '<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \
'<img src="/icons/delete.png"/></a>'
if showIcons: if showIcons:
replyToLink=postJsonObject['object']['id'] replyToLink=postJsonObject['object']['id']
@ -848,7 +849,7 @@ def individualPostAsHtml(baseDir: str, \
def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
wfRequest: {},personCache: {}, \ wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,timelineJson: {}, \ nickname: str,domain: str,port: int,timelineJson: {}, \
boxName: str) -> str: boxName: str,allowDeletion: bool) -> str:
"""Show the timeline as html """Show the timeline as html
""" """
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile: with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
@ -898,7 +899,8 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
if item['type']=='Create' or item['type']=='Announce': if item['type']=='Create' or item['type']=='Announce':
itemCtr+=1 itemCtr+=1
tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,showIndividualPostIcons) nickname,domain,port,item,None,True, \
allowDeletion,showIndividualPostIcons)
if itemCtr>=itemsPerPage: if itemCtr>=itemsPerPage:
tlStr+='<center><a href="'+actor+'/'+boxName+'?page='+str(pageNumber+1)+'"><img class="pageicon" src="/icons/pagedown.png" title="Page down" alt="Page down"></a></center>' tlStr+='<center><a href="'+actor+'/'+boxName+'?page='+str(pageNumber+1)+'"><img class="pageicon" src="/icons/pagedown.png" title="Page down" alt="Page down"></a></center>'
tlStr+=htmlFooter() tlStr+=htmlFooter()
@ -906,19 +908,21 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
def htmlInbox(pageNumber: int,itemsPerPage: int, \ def htmlInbox(pageNumber: int,itemsPerPage: int, \
session,baseDir: str,wfRequest: {},personCache: {}, \ session,baseDir: str,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,inboxJson: {}) -> str: nickname: str,domain: str,port: int,inboxJson: {}, \
allowDeletion: bool) -> str:
"""Show the inbox as html """Show the inbox as html
""" """
return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \ return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \
nickname,domain,port,inboxJson,'inbox') nickname,domain,port,inboxJson,'inbox',allowDeletion)
def htmlOutbox(pageNumber: int,itemsPerPage: int, \ def htmlOutbox(pageNumber: int,itemsPerPage: int, \
session,baseDir: str,wfRequest: {},personCache: {}, \ session,baseDir: str,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,outboxJson: {}) -> str: nickname: str,domain: str,port: int,outboxJson: {}, \
allowDeletion: bool) -> str:
"""Show the Outbox as html """Show the Outbox as html
""" """
return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \ return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \
nickname,domain,port,outboxJson,'outbox') nickname,domain,port,outboxJson,'outbox',allowDeletion)
def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,authorized: bool, \ nickname: str,domain: str,port: int,authorized: bool, \
@ -928,7 +932,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
postStr='<script>'+contentWarningScript()+'</script>' postStr='<script>'+contentWarningScript()+'</script>'
postStr+= \ postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject,None,True,False) nickname,domain,port,postJsonObject,None,True,False,False)
messageId=postJsonObject['id'].replace('/activity','') messageId=postJsonObject['id'].replace('/activity','')
# show the previous posts # show the previous posts
@ -941,7 +945,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
postStr= \ postStr= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject, \ nickname,domain,port,postJsonObject, \
None,True,False)+postStr None,True,False,False)+postStr
# show the following posts # show the following posts
postFilename=locatePost(baseDir,nickname,domain,messageId) postFilename=locatePost(baseDir,nickname,domain,messageId)
@ -956,7 +960,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
for item in repliesJson['orderedItems']: for item in repliesJson['orderedItems']:
postStr+= \ postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False) nickname,domain,port,item,None,True,False,False)
return htmlHeader()+postStr+htmlFooter() return htmlHeader()+postStr+htmlFooter()
def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
@ -967,7 +971,7 @@ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
if repliesJson.get('orderedItems'): if repliesJson.get('orderedItems'):
for item in repliesJson['orderedItems']: for item in repliesJson['orderedItems']:
repliesStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ repliesStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False) nickname,domain,port,item,None,True,False,False)
return htmlHeader()+repliesStr+htmlFooter() return htmlHeader()+repliesStr+htmlFooter()
@ -1239,7 +1243,7 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
individualPostAsHtml(baseDir, \ individualPostAsHtml(baseDir, \
session,wfRequest,personCache, \ session,wfRequest,personCache, \
nickname,domain,port, \ nickname,domain,port, \
item,avatarUrl,False,False) item,avatarUrl,False,False,False)
i+=1 i+=1
if i>=20: if i>=20:
break break