Blocking and upblocking from web interface dropdown

master
Bob Mottram 2019-08-02 15:36:03 +01:00
parent 0fb0f89462
commit e04db12604
2 changed files with 167 additions and 1 deletions

View File

@ -53,6 +53,8 @@ from like import outboxLike
from like import outboxUndoLike
from blocking import outboxBlock
from blocking import outboxUndoBlock
from blocking import addBlock
from blocking import removeBlock
from config import setConfigParam
from roles import outboxDelegate
from skills import outboxSkills
@ -624,6 +626,23 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False
return
# block a person from the web interface by selecting Block on the dropdown
if '/users/' in self.path:
if '?block=' in self.path:
blockStr=self.path.split('?block=')[1]
originPathStr=self.path.split('?block=')[0]
if ';' in blockStr:
blockActor=blockStr.split(';')[0]
blockProfileUrl=blockStr.split(';')[1]
# show the confirm block screen
self._set_headers('text/html',cookie)
self.wfile.write(htmlBlockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode())
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# search for a fediverse address from the web interface by selecting search icon
if '/users/' in self.path:
if self.path.endswith('/search'):
@ -650,6 +669,23 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False
return
# Unblock a person from the web interface by selecting Unblock on the dropdown
if '/users/' in self.path:
if '?unblock=' in self.path:
blockStr=self.path.split('?unblock=')[1]
originPathStr=self.path.split('?unblock=')[0]
if ';' in blockStr:
blockActor=blockStr.split(';')[0]
blockProfileUrl=blockStr.split(';')[1]
# show the confirm unblock screen
self._set_headers('text/html',cookie)
self.wfile.write(htmlUnblockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode())
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# announce/repeat from the web interface
if authorized and '?repeat=' in self.path:
repeatUrl=self.path.split('?repeat=')[1]
@ -1872,6 +1908,66 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False
return
# decision to unblock in the web interface is confirmed
if authorized and self.path.endswith('/unblockconfirm'):
originPathStr=self.path.split('/unblockconfirm')[0]
blockerNickname=getNicknameFromActor(originPathStr)
length = int(self.headers['Content-length'])
blockConfirmParams=self.rfile.read(length).decode('utf-8')
if '&submitYes=' in blockConfirmParams:
blockingActor=blockConfirmParams.replace('%3A',':').replace('%2F','/').split('actor=')[1]
if '&' in blockingActor:
blockingActor=blockingActor.split('&')[0]
blockingNickname=getNicknameFromActor(blockingActor)
blockingDomain,blockingPort=getDomainFromActor(blockingActor)
blockingDomainFull=blockingDomain
if blockingPort:
if blockingPort!=80 and blockingPort!=443:
blockingDomainFull=blockingDomain+':'+str(blockingPort)
if blockerNickname==blockingNickname and \
blockingDomain==self.server.domain and \
blockingPort==self.server.port:
if self.server.debug:
print('You cannot unblock yourself!')
else:
if self.server.debug:
print(blockerNickname+' stops blocking '+blockingActor)
removeBlock(self.server.baseDir,blockerNickname,self.server.domain, \
blockingNickname,blockingDomainFull)
self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False
return
# decision to block in the web interface is confirmed
if authorized and self.path.endswith('/blockconfirm'):
originPathStr=self.path.split('/blockconfirm')[0]
blockerNickname=getNicknameFromActor(originPathStr)
length = int(self.headers['Content-length'])
blockConfirmParams=self.rfile.read(length).decode('utf-8')
if '&submitYes=' in blockConfirmParams:
blockingActor=blockConfirmParams.replace('%3A',':').replace('%2F','/').split('actor=')[1]
if '&' in blockingActor:
blockingActor=blockingActor.split('&')[0]
blockingNickname=getNicknameFromActor(blockingActor)
blockingDomain,blockingPort=getDomainFromActor(blockingActor)
blockingDomainFull=blockingDomain
if blockingPort:
if blockingPort!=80 and blockingPort!=443:
blockingDomainFull=blockingDomain+':'+str(blockingPort)
if blockerNickname==blockingNickname and \
blockingDomain==self.server.domain and \
blockingPort==self.server.port:
if self.server.debug:
print('You cannot block yourself!')
else:
if self.server.debug:
print('Adding block by '+blockerNickname+' of '+blockingActor)
addBlock(self.server.baseDir,blockerNickname,self.server.domain, \
blockingNickname,blockingDomainFull)
self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False
return
postState=self._receiveNewPost(authorized,'newpost')
if postState!=0:
nickname=self.path.split('/users/')[1]

View File

@ -25,6 +25,7 @@ from session import getJson
from auth import createPassword
from like import likedByPerson
from announce import announcedByPerson
from blocking import isBlocked
def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str:
"""Shows the edit profile screen
@ -640,13 +641,22 @@ def individualPostAsHtml(baseDir: str, \
if isFollowingActor(baseDir,nickname,domain,postJsonObject['actor']):
followUnfollowStr='<a href="/users/'+nickname+'?unfollow='+postJsonObject['actor']+';'+avatarUrl+'">Unfollow</a>'
blockUnblockStr='<a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>'
# if blocking then show "Unblock" in the dropdown
actorDomainFull=actorDomain
if actorPort:
if actorPort!=80 and actorPort!=443:
actorDomainFull=actorDomain+':'+str(actorPort)
if isBlocked(baseDir,nickname,domain,actorNickname,actorDomainFull):
blockUnblockStr='<a href="/users/'+nickname+'?unblock='+postJsonObject['actor']+';'+avatarUrl+'">Unblock</a>'
avatarDropdown= \
' <div class="dropdown-timeline">' \
' <img src="'+avatarUrl+'" '+avatarPosition+'/>' \
' <div class="dropdown-timeline-content">' \
' <a href="'+postJsonObject['actor']+'">Visit</a>'+ \
followUnfollowStr+ \
' <a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>' \
blockUnblockStr+ \
' <a href="/users/'+nickname+'?report='+postJsonObject['actor']+';'+avatarUrl+'">Report</a>' \
' </div>' \
' </div>'
@ -857,6 +867,66 @@ def htmlUnfollowConfirm(baseDir: str,originPathStr: str,followActor: str,followP
followStr+=htmlFooter()
return followStr
def htmlBlockConfirm(baseDir: str,originPathStr: str,blockActor: str,blockProfileUrl: str) -> str:
"""Asks to confirm a block
"""
blockDomain,port=getDomainFromActor(blockActor)
if os.path.isfile(baseDir+'/img/block-background.png'):
if not os.path.isfile(baseDir+'/accounts/block-background.png'):
copyfile(baseDir+'/img/block-background.png',baseDir+'/accounts/block-background.png')
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
profileStyle = cssFile.read()
blockStr=htmlHeader(profileStyle)
blockStr+='<div class="block">'
blockStr+=' <div class="blockAvatar">'
blockStr+=' <center>'
blockStr+=' <a href="'+blockActor+'">'
blockStr+=' <img src="'+blockProfileUrl+'"/></a>'
blockStr+=' <p class="blockText">Block '+getNicknameFromActor(blockActor)+'@'+blockDomain+' ?</p>'
blockStr+= \
' <form method="POST" action="'+originPathStr+'/blockconfirm">' \
' <input type="hidden" name="actor" value="'+blockActor+'">' \
' <button type="submit" class="button" name="submitYes">Yes</button>' \
' <a href="'+originPathStr+'"><button class="button">No</button></a>' \
' </form>'
blockStr+='</center>'
blockStr+='</div>'
blockStr+='</div>'
blockStr+=htmlFooter()
return blockStr
def htmlUnblockConfirm(baseDir: str,originPathStr: str,blockActor: str,blockProfileUrl: str) -> str:
"""Asks to confirm unblocking an actor
"""
blockDomain,port=getDomainFromActor(blockActor)
if os.path.isfile(baseDir+'/img/block-background.png'):
if not os.path.isfile(baseDir+'/accounts/block-background.png'):
copyfile(baseDir+'/img/block-background.png',baseDir+'/accounts/block-background.png')
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
profileStyle = cssFile.read()
blockStr=htmlHeader(profileStyle)
blockStr+='<div class="block">'
blockStr+=' <div class="blockAvatar">'
blockStr+=' <center>'
blockStr+=' <a href="'+blockActor+'">'
blockStr+=' <img src="'+blockProfileUrl+'"/></a>'
blockStr+=' <p class="blockText">Stop blocking '+getNicknameFromActor(blockActor)+'@'+blockDomain+' ?</p>'
blockStr+= \
' <form method="POST" action="'+originPathStr+'/unblockconfirm">' \
' <input type="hidden" name="actor" value="'+blockActor+'">' \
' <button type="submit" class="button" name="submitYes">Yes</button>' \
' <a href="'+originPathStr+'"><button class="button">No</button></a>' \
' </form>'
blockStr+='</center>'
blockStr+='</div>'
blockStr+='</div>'
blockStr+=htmlFooter()
return blockStr
def htmlSearch(baseDir: str,path: str) -> str:
"""Search called from the timeline icon
"""