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 suspendAccount
from person import unsuspendAccount
from person import removeAccount
from posts import outboxMessageCreateWrap
from posts import savePostToBox
from posts import sendToFollowers
@ -2109,7 +2110,8 @@ class PubServer(BaseHTTPRequestHandler):
moderationText=None
moderationButton=None
for moderationStr in moderationParams.split('&'):
if moderationStr=='moderationAction':
print('moderationStr: '+moderationStr)
if moderationStr.startswith('moderationAction'):
if '=' in moderationStr:
moderationText=moderationStr.split('=')[1].strip()
moderationText=moderationText.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip()
@ -2124,6 +2126,9 @@ class PubServer(BaseHTTPRequestHandler):
elif moderationStr.startswith('submitRemove'):
moderationButton='remove'
if moderationButton and moderationText:
if self.server.debug:
print('moderationButton: '+moderationButton)
print('moderationText: '+moderationText)
nickname=moderationText
if nickname.startswith('http') or \
nickname.startswith('dat'):
@ -2131,9 +2136,27 @@ class PubServer(BaseHTTPRequestHandler):
if '@' in nickname:
nickname=nickname.split('@')[0]
if moderationButton=='suspend':
print('**************** suspend')
suspendAccount(self.server.baseDir,nickname,self.server.salts)
if moderationButton=='unsuspend':
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.server.POSTbusy=False
return

View File

@ -27,6 +27,7 @@ from roles import setRole
from media import removeMetaData
from utils import validNickname
from utils import noOfAccounts
from auth import createPassword
from config import setConfigParam
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:
"""Removes an account
"""
"""
# Don't remove the admin
adminNickname=getConfigParam(baseDir,'admin')
if nickname==adminNickname:

View File

@ -1046,8 +1046,7 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
moderationButtonStr=''
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)