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'):
divertToLoginScreen=False
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_header('Location', '/login')
self.end_headers()
@ -863,7 +866,10 @@ class PubServer(BaseHTTPRequestHandler):
# delete a post from the web interface icon
if authorized and self.server.allowDeletion and '?delete=' in self.path:
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:
# You can only delete your own posts
self.server.GETbusy=False
@ -877,10 +883,12 @@ class PubServer(BaseHTTPRequestHandler):
deleteJson= {
'actor': actor,
'object': deleteUrl,
'to': ['https://www.w3.org/ns/activitystreams#Public'],
'to': ['https://www.w3.org/ns/activitystreams#Public',actor],
'cc': [actor+'/followers'],
'type': 'Delete'
}
if self.server.debug:
pprint(deleteJson)
self._postToOutbox(deleteJson)
self.server.GETbusy=False
self._redirect_headers(actor+'/inbox',cookie)
@ -1186,7 +1194,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \
self.server.domain, \
self.server.port, \
inboxFeed).encode('utf-8'))
inboxFeed, \
self.server.allowDeletion).encode('utf-8'))
else:
self._set_headers('application/json',None)
self.wfile.write(json.dumps(inboxFeed).encode('utf-8'))
@ -1242,7 +1251,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \
self.server.domain, \
self.server.port, \
outboxFeed).encode('utf-8'))
outboxFeed, \
self.server.allowDeletion).encode('utf-8'))
else:
self._set_headers('application/json',None)
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':
profileStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False)
nickname,domain,port,item,None,True,False,False)
return profileStr
def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
@ -653,7 +653,7 @@ def individualPostAsHtml(baseDir: str, \
nickname: str,domain: str,port: int, \
postJsonObject: {}, \
avatarUrl: str, showAvatarDropdown: bool,
showIcons=False) -> str:
allowDeletion: bool,showIcons=False) -> str:
""" Shows a single post as html
"""
titleStr=''
@ -799,10 +799,11 @@ def individualPostAsHtml(baseDir: str, \
'<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="'+likeTitle+'">' \
'<img src="/icons/'+likeIcon+'"/></a>'
deleteStr=''
if '/users/'+nickname+'/' in postJsonObject['object']['id']:
deleteStr= \
'<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \
'<img src="/icons/delete.png"/></a>'
if allowDeletion:
if '/users/'+nickname+'/' in postJsonObject['object']['id']:
deleteStr= \
'<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \
'<img src="/icons/delete.png"/></a>'
if showIcons:
replyToLink=postJsonObject['object']['id']
@ -848,7 +849,7 @@ def individualPostAsHtml(baseDir: str, \
def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,timelineJson: {}, \
boxName: str) -> str:
boxName: str,allowDeletion: bool) -> str:
"""Show the timeline as html
"""
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':
itemCtr+=1
tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,showIndividualPostIcons)
nickname,domain,port,item,None,True, \
allowDeletion,showIndividualPostIcons)
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+=htmlFooter()
@ -906,19 +908,21 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
def htmlInbox(pageNumber: int,itemsPerPage: int, \
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
"""
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, \
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
"""
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: {}, \
nickname: str,domain: str,port: int,authorized: bool, \
@ -928,7 +932,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
postStr='<script>'+contentWarningScript()+'</script>'
postStr+= \
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','')
# show the previous posts
@ -941,7 +945,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
postStr= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject, \
None,True,False)+postStr
None,True,False,False)+postStr
# show the following posts
postFilename=locatePost(baseDir,nickname,domain,messageId)
@ -956,7 +960,7 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
for item in repliesJson['orderedItems']:
postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False)
nickname,domain,port,item,None,True,False,False)
return htmlHeader()+postStr+htmlFooter()
def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
@ -967,7 +971,7 @@ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
if repliesJson.get('orderedItems'):
for item in repliesJson['orderedItems']:
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()
@ -1239,7 +1243,7 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
individualPostAsHtml(baseDir, \
session,wfRequest,personCache, \
nickname,domain,port, \
item,avatarUrl,False,False)
item,avatarUrl,False,False,False)
i+=1
if i>=20:
break