Basic moderation functions

master
Bob Mottram 2019-08-13 14:58:48 +01:00
parent 727c8ca6fc
commit 4a80c94cbe
3 changed files with 27 additions and 4 deletions

View File

@ -29,6 +29,7 @@ from person import createSharedInbox
from person import isSuspended from person import isSuspended
from person import suspendAccount from person import suspendAccount
from person import unsuspendAccount from person import unsuspendAccount
from person import removeAccount
from posts import outboxMessageCreateWrap from posts import outboxMessageCreateWrap
from posts import savePostToBox from posts import savePostToBox
from posts import sendToFollowers from posts import sendToFollowers
@ -2109,7 +2110,8 @@ class PubServer(BaseHTTPRequestHandler):
moderationText=None moderationText=None
moderationButton=None moderationButton=None
for moderationStr in moderationParams.split('&'): for moderationStr in moderationParams.split('&'):
if moderationStr=='moderationAction': print('moderationStr: '+moderationStr)
if moderationStr.startswith('moderationAction'):
if '=' in moderationStr: if '=' in moderationStr:
moderationText=moderationStr.split('=')[1].strip() moderationText=moderationStr.split('=')[1].strip()
moderationText=moderationText.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip() moderationText=moderationText.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip()
@ -2124,6 +2126,9 @@ class PubServer(BaseHTTPRequestHandler):
elif moderationStr.startswith('submitRemove'): elif moderationStr.startswith('submitRemove'):
moderationButton='remove' moderationButton='remove'
if moderationButton and moderationText: if moderationButton and moderationText:
if self.server.debug:
print('moderationButton: '+moderationButton)
print('moderationText: '+moderationText)
nickname=moderationText nickname=moderationText
if nickname.startswith('http') or \ if nickname.startswith('http') or \
nickname.startswith('dat'): nickname.startswith('dat'):
@ -2131,9 +2136,27 @@ class PubServer(BaseHTTPRequestHandler):
if '@' in nickname: if '@' in nickname:
nickname=nickname.split('@')[0] nickname=nickname.split('@')[0]
if moderationButton=='suspend': if moderationButton=='suspend':
print('**************** suspend')
suspendAccount(self.server.baseDir,nickname,self.server.salts) suspendAccount(self.server.baseDir,nickname,self.server.salts)
if moderationButton=='unsuspend': if moderationButton=='unsuspend':
unsuspendAccount(self.server.baseDir,nickname) unsuspendAccount(self.server.baseDir,nickname)
if moderationButton=='remove':
if '/statuses/' not in moderationText:
removeAccount(self.server.baseDir, \
nickname, \
self.server.domain, \
self.server.port)
else:
postFilename= \
locatePost(self.server.baseDir, \
nickname,self.server.domain, \
moderationText)
if postFilename:
deletePost(self.server.baseDir, \
self.server.httpPrefix, \
nickname,self.server.omain, \
postFilename, \
self.server.debug)
self._redirect_headers(actorStr+'/moderation',cookie) self._redirect_headers(actorStr+'/moderation',cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return

View File

@ -27,6 +27,7 @@ from roles import setRole
from media import removeMetaData from media import removeMetaData
from utils import validNickname from utils import validNickname
from utils import noOfAccounts from utils import noOfAccounts
from auth import createPassword
from config import setConfigParam from config import setConfigParam
from config import getConfigParam from config import getConfigParam
@ -564,7 +565,7 @@ def removeTagsForNickname(baseDir: str,nickname: str,domain: str,port: int) -> N
def removeAccount(baseDir: str,nickname: str,domain: str,port: int) -> bool: def removeAccount(baseDir: str,nickname: str,domain: str,port: int) -> bool:
"""Removes an account """Removes an account
""" """
# Don't remove the admin # Don't remove the admin
adminNickname=getConfigParam(baseDir,'admin') adminNickname=getConfigParam(baseDir,'admin')
if nickname==adminNickname: if nickname==adminNickname:

View File

@ -1046,8 +1046,7 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
moderationButtonStr='' moderationButtonStr=''
if moderator: if moderator:
if noOfModerationPosts(baseDir)>0: moderationButtonStr='<a href="'+actor+'/moderation"><button class="'+moderationButton+'"><span>Moderate </span></button></a>'
moderationButtonStr='<a href="'+actor+'/moderation"><button class="'+moderationButton+'"><span>Moderate </span></button></a>'
tlStr=htmlHeader(profileStyle) tlStr=htmlHeader(profileStyle)