From 209371820da47d7ccbfcf899dc9707d5fa118ca9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 9 Aug 2019 23:49:44 +0100 Subject: [PATCH] Don't show delete icon if deletions are not allowed --- daemon.py | 20 +++++++++++++++----- webinterface.py | 38 +++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/daemon.py b/daemon.py index a540cd82..3a04439b 100644 --- a/daemon.py +++ b/daemon.py @@ -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')) diff --git a/webinterface.py b/webinterface.py index 37e4cdf3..8d4ed060 100644 --- a/webinterface.py +++ b/webinterface.py @@ -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, \ '' \ '' deleteStr='' - if '/users/'+nickname+'/' in postJsonObject['object']['id']: - deleteStr= \ - '' \ - '' + if allowDeletion: + if '/users/'+nickname+'/' in postJsonObject['object']['id']: + deleteStr= \ + '' \ + '' 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+='
Page down
' 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='' 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