From 2f336bc33f9ac0f8d0301c63f67c84f5018e8cfd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 26 Aug 2019 10:13:26 +0100 Subject: [PATCH] Screen for confirming removal of shared item --- daemon.py | 15 ++++++++++++++ webinterface.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index ac48983d..a85f5b26 100644 --- a/daemon.py +++ b/daemon.py @@ -76,6 +76,7 @@ from roles import setRole from roles import clearModeratorStatus from skills import outboxSkills from availability import outboxAvailability +from webinterface import htmlRemoveSharedItem from webinterface import htmlInboxDMs from webinterface import htmlUnblockConfirm from webinterface import htmlPersonOptions @@ -979,6 +980,20 @@ class PubServer(BaseHTTPRequestHandler): self._redirect_headers(actor+'/inbox',cookie) return + # remove a shared item + if htmlGET and '?rmshare=' in self.path: + shareName=self.path.split('?rmshare=')[1] + actor=self.server.httpPrefix+'://'+self.server.domainFull+self.path.split('?rmshare=')[0] + msg=htmlRemoveSharedItem(self.server.baseDir,actor,shareName).encode() + if not msg: + self._redirect_headers(actor+'/inbox',cookie) + self.server.GETbusy=False + return + self._set_headers('text/html',len(msg),cookie) + self.wfile.write(msg) + self.server.GETbusy=False + return + # delete a post from the web interface icon if htmlGET and '?delete=' in self.path: deleteUrl=self.path.split('?delete=')[1] diff --git a/webinterface.py b/webinterface.py index 533509d3..c0ff1f7b 100644 --- a/webinterface.py +++ b/webinterface.py @@ -149,8 +149,10 @@ def htmlSearchSharedItems(baseDir: str,searchStr: str, \ sharedItemsForm+='Category: '+sharedItem['category']+' ' sharedItemsForm+='Location: '+sharedItem['location']+'

' contactActor=httpPrefix+'://'+domainFull+'/users/'+contactNickname - sharedItemsForm+='

Contact' - sharedItemsForm+='' + sharedItemsForm+='

' + if actor.endswith('/users/'+contactNickname): + sharedItemsForm+=' ' + sharedItemsForm+='

' if not resultsExist and currPage>1: # previous page link, needs to be a POST sharedItemsForm+= \ @@ -1583,6 +1585,52 @@ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \ return htmlHeader()+repliesStr+htmlFooter() +def htmlRemoveSharedItem(baseDir: str,actor: str,shareName: str) -> str: + """Shows a screen asking to confirm the removal of a shared item + """ + nickname=getNicknameFromActor(actor) + domain,port=getDomainFromActor(actor) + sharesFile=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json' + if not os.path.isfile(sharesFile): + return None + sharesJson=None + with open(sharesFile, 'r') as fp: + sharesJson=commentjson.load(fp) + if not sharesJson: + return None + if not sharesJson.get(shareName): + return None + sharedItemDisplayName=sharesJson[shareName]['displayName'] + sharedItemImageUrl=None + if sharesJson[shareName].get('imageUrl'): + sharedItemImageUrl=sharesJson[shareName]['imageUrl'] + + if os.path.isfile(baseDir+'/img/shares-background.png'): + if not os.path.isfile(baseDir+'/accounts/shares-background.png'): + copyfile(baseDir+'/img/shares-background.png',baseDir+'/accounts/shares-background.png') + + with open(baseDir+'/epicyon-follow.css', 'r') as cssFile: + profileStyle = cssFile.read() + sharesStr=htmlHeader(profileStyle) + sharesStr+='
' + sharesStr+='
' + sharesStr+='
' + if sharedItemImageUrl: + sharesStr+=' ' + sharesStr+='

Remove '+sharedItemDisplayName+' ?

' + sharesStr+= \ + '
' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + '
' + sharesStr+='
' + sharesStr+='
' + sharesStr+='
' + sharesStr+=htmlFooter() + return sharesStr + def htmlFollowConfirm(baseDir: str,originPathStr: str,followActor: str,followProfileUrl: str) -> str: """Asks to confirm a follow """