Configurable default follower approval

main
Bob Mottram 2020-07-12 13:31:28 +01:00
parent f537c2f96f
commit 9bc6f1691e
4 changed files with 60 additions and 38 deletions

View File

@ -5842,7 +5842,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.httpPrefix,
self.server.domain,
self.server.port,
loginNickname, loginPassword):
loginNickname,
loginPassword,
self.server.manualFollowerApproval):
self.server.POSTbusy = False
if callingDomain.endswith('.onion') and \
self.server.onionDomain:
@ -8324,7 +8326,8 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
domainMaxPostsPerDay=8640, accountMaxPostsPerDay=864,
allowDeletion=False, debug=False, unitTest=False,
instanceOnlySkillsSearch=False, sendThreads=[],
useBlurHash=False) -> None:
useBlurHash=False,
manualFollowerApproval=True) -> None:
if len(domain) == 0:
domain = 'localhost'
if '.' not in domain:
@ -8356,6 +8359,7 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
httpd.blocklistUpdateInterval = 100
httpd.domainBlocklist = getDomainBlocklist(baseDir)
httpd.manualFollowerApproval = manualFollowerApproval
httpd.onionDomain = onionDomain
httpd.i2pDomain = i2pDomain
httpd.useBlurHash = useBlurHash

View File

@ -163,6 +163,9 @@ parser.add_argument('--json', dest='json', type=str, default=None,
help='Show the json for a given activitypub url')
parser.add_argument('-f', '--federate', nargs='+', dest='federationList',
help='Specify federation list separated by spaces')
parser.add_argument("--noapproval", type=str2bool, nargs='?',
const=True, default=False,
help="Allow followers without approval")
parser.add_argument("--mediainstance", type=str2bool, nargs='?',
const=True, default=False,
help="Media Instance - favor media over text")
@ -1265,7 +1268,7 @@ if args.addaccount:
print('Account is deactivated')
sys.exit()
createPerson(baseDir, nickname, domain, port, httpPrefix,
True, args.password.strip())
True, not args.noapproval, args.password.strip())
if os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain):
print('Account created for ' + nickname + '@' + domain)
else:
@ -1696,16 +1699,16 @@ if args.testdata:
str(maxRegistrations))
createPerson(baseDir, 'maxboardroom', domain, port, httpPrefix,
True, password)
True, False, password)
createPerson(baseDir, 'ultrapancake', domain, port, httpPrefix,
True, password)
True, False, password)
createPerson(baseDir, 'drokk', domain, port, httpPrefix,
True, password)
True, False, password)
createPerson(baseDir, 'sausagedog', domain, port, httpPrefix,
True, password)
True, False, password)
createPerson(baseDir, nickname, domain, port, httpPrefix,
True, 'likewhateveryouwantscoob')
True, False, 'likewhateveryouwantscoob')
setSkillLevel(baseDir, nickname, domain, 'testing', 60)
setSkillLevel(baseDir, nickname, domain, 'typing', 50)
setRole(baseDir, nickname, domain, 'instance', 'admin')
@ -1807,4 +1810,4 @@ runDaemon(args.blogsinstance, args.mediainstance,
args.accountMaxPostsPerDay,
args.allowdeletion, debug, False,
args.instanceOnlySkillsSearch, [],
args.blurhash)
args.blurhash, not args.noapproval)

View File

@ -165,6 +165,7 @@ def randomizeActorImages(personJson: {}) -> None:
def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
httpPrefix: str, saveToFile: bool,
manualFollowerApproval: bool,
password=None) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint
"""
@ -185,7 +186,7 @@ def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
personType = 'Person'
# Enable follower approval by default
approveFollowers = True
approveFollowers = manualFollowerApproval
personName = nickname
personId = httpPrefix + '://' + domain + '/users/' + nickname
inboxStr = personId + '/inbox'
@ -352,7 +353,8 @@ def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
def registerAccount(baseDir: str, httpPrefix: str, domain: str, port: int,
nickname: str, password: str) -> bool:
nickname: str, password: str,
manualFollowerApproval: bool) -> bool:
"""Registers a new account from the web interface
"""
if accountExists(baseDir, nickname, domain):
@ -367,6 +369,7 @@ def registerAccount(baseDir: str, httpPrefix: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPerson(baseDir, nickname,
domain, port,
httpPrefix, True,
manualFollowerApproval,
password)
if privateKeyPem:
return True
@ -382,7 +385,7 @@ def createGroup(baseDir: str, nickname: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPerson(baseDir, nickname,
domain, port,
httpPrefix, saveToFile,
password)
False, password)
newPerson['type'] = 'Group'
return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint
@ -407,6 +410,7 @@ def savePersonQrcode(baseDir: str,
def createPerson(baseDir: str, nickname: str, domain: str, port: int,
httpPrefix: str, saveToFile: bool,
manualFollowerApproval: bool,
password=None) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint
"""
@ -425,7 +429,9 @@ def createPerson(baseDir: str, nickname: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPersonBase(baseDir, nickname,
domain, port,
httpPrefix,
saveToFile, password)
saveToFile,
manualFollowerApproval,
password)
if noOfAccounts(baseDir) == 1:
# print(nickname+' becomes the instance admin and a moderator')
setRole(baseDir, nickname, domain, 'instance', 'admin')
@ -470,7 +476,7 @@ def createSharedInbox(baseDir: str, nickname: str, domain: str, port: int,
"""Generates the shared inbox
"""
return createPersonBase(baseDir, nickname, domain, port, httpPrefix,
True, None)
True, True, None)
def createCapabilitiesInbox(baseDir: str, nickname: str,
@ -479,7 +485,7 @@ def createCapabilitiesInbox(baseDir: str, nickname: str,
"""Generates the capabilities inbox to sign requests
"""
return createPersonBase(baseDir, nickname, domain, port,
httpPrefix, True, None)
httpPrefix, True, True, None)
def personUpgradeActor(baseDir: str, personJson: {},

View File

@ -101,7 +101,8 @@ def testHttpsigBase(withDigest):
port = 5576
password = 'SuperSecretPassword'
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, False, password)
createPerson(path, nickname, domain, port, httpPrefix,
False, False, password)
assert privateKeyPem
messageBodyJson = {
"a key": "a value",
@ -253,7 +254,8 @@ def createServerAlice(path: str, domain: str, port: int,
accountMaxPostsPerDay = 1000
allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password)
createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox')
assert setSkillLevel(path, nickname, domain, 'hacking', 90)
@ -289,7 +291,8 @@ def createServerAlice(path: str, domain: str, port: int,
noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies,
domainMaxPostsPerDay, accountMaxPostsPerDay,
allowDeletion, True, True, False, sendThreads, False)
allowDeletion, True, True, False, sendThreads, False,
False)
def createServerBob(path: str, domain: str, port: int,
@ -317,7 +320,8 @@ def createServerBob(path: str, domain: str, port: int,
accountMaxPostsPerDay = 1000
allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password)
createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox')
assert setRole(path, nickname, domain, 'bandname', 'bass player')
@ -352,7 +356,8 @@ def createServerBob(path: str, domain: str, port: int,
noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies,
domainMaxPostsPerDay, accountMaxPostsPerDay,
allowDeletion, True, True, False, sendThreads, False)
allowDeletion, True, True, False, sendThreads, False,
False)
def createServerEve(path: str, domain: str, port: int, federationList: [],
@ -375,7 +380,8 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
maxReplies = 64
allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password)
createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox')
global testServerEveRunning
@ -391,7 +397,7 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
httpPrefix, federationList, maxMentions, maxEmoji, False,
noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies, allowDeletion, True, True, False,
sendThreads, False)
sendThreads, False, False)
def testPostMessageBetweenServers():
@ -840,15 +846,15 @@ def testFollowersOfPerson():
os.mkdir(baseDir)
os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'maxboardroom', domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'ultrapancake', domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'drokk', domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'sausagedog', domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
clearFollows(baseDir, nickname, domain)
followPerson(baseDir, nickname, domain, 'maxboardroom', domain,
@ -889,15 +895,16 @@ def testNoOfFollowersOnDomain():
shutil.rmtree(baseDir)
os.mkdir(baseDir)
os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password)
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
createPerson(baseDir, 'maxboardroom', otherdomain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'ultrapancake', otherdomain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'drokk', otherdomain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
createPerson(baseDir, 'sausagedog', otherdomain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
followPerson(baseDir, 'drokk', otherdomain, nickname, domain,
federationList, False)
@ -949,7 +956,8 @@ def testGroupFollowers():
shutil.rmtree(baseDir)
os.mkdir(baseDir)
os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password)
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
clearFollowers(baseDir, nickname, domain)
followerOfPerson(baseDir, nickname, domain, 'badger', 'wild.domain',
@ -992,7 +1000,8 @@ def testFollows():
shutil.rmtree(baseDir)
os.mkdir(baseDir)
os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password)
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
clearFollows(baseDir, nickname, domain)
followPerson(baseDir, nickname, domain, 'badger', 'wild.com',
@ -1072,7 +1081,7 @@ def testCreatePerson():
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
assert os.path.isfile(baseDir + '/accounts/passwords')
deleteAllPosts(baseDir, nickname, domain, 'inbox')
deleteAllPosts(baseDir, nickname, domain, 'outbox')
@ -1106,10 +1115,10 @@ def testDelegateRoles():
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password)
httpPrefix, True, False, password)
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nicknameDelegated, domain, port,
httpPrefix, True, 'insecure')
httpPrefix, True, False, 'insecure')
httpPrefix = 'http'
project = 'artechoke'
@ -1702,7 +1711,7 @@ def testAddEmoji():
os.chdir(baseDir)
privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port,
httpPrefix, True, 'password')
httpPrefix, True, False, 'password')
contentModified = \
addHtmlTags(baseDir, httpPrefix,
nickname, domain, content,