From 22f31f03569dc0b3457b50ffd87db99fafdcb6c2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 10 Oct 2020 17:10:32 +0100 Subject: [PATCH] More checks that admin user is defined --- person.py | 6 ++++++ posts.py | 10 ++++++++-- utils.py | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/person.py b/person.py index e0ee43e7a..61a307f10 100644 --- a/person.py +++ b/person.py @@ -789,6 +789,8 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None: """ # Don't suspend the admin adminNickname = getConfigParam(baseDir, 'admin') + if not adminNickname: + return if nickname == adminNickname: return @@ -843,6 +845,8 @@ def canRemovePost(baseDir: str, nickname: str, # is the post by the admin? adminNickname = getConfigParam(baseDir, 'admin') + if not adminNickname: + return False if domainFull + '/users/' + adminNickname + '/' in postId: return False @@ -899,6 +903,8 @@ def removeAccount(baseDir: str, nickname: str, """ # Don't remove the admin adminNickname = getConfigParam(baseDir, 'admin') + if not adminNickname: + return False if nickname == adminNickname: return False diff --git a/posts.py b/posts.py index f63c8a2d9..37215b620 100644 --- a/posts.py +++ b/posts.py @@ -74,14 +74,20 @@ def isModerator(baseDir: str, nickname: str) -> bool: moderatorsFile = baseDir + '/accounts/moderators.txt' if not os.path.isfile(moderatorsFile): - if getConfigParam(baseDir, 'admin') == nickname: + adminName = getConfigParam(baseDir, 'admin') + if not adminName: + return False + if adminName == nickname: return True return False with open(moderatorsFile, "r") as f: lines = f.readlines() if len(lines) == 0: - if getConfigParam(baseDir, 'admin') == nickname: + adminName = getConfigParam(baseDir, 'admin') + if not adminName: + return False + if adminName == nickname: return True for moderator in lines: moderator = moderator.strip('\n').strip('\r') diff --git a/utils.py b/utils.py index 68f207f85..da689e60f 100644 --- a/utils.py +++ b/utils.py @@ -58,6 +58,8 @@ def isSuspended(baseDir: str, nickname: str) -> bool: """Returns true if the given nickname is suspended """ adminNickname = getConfigParam(baseDir, 'admin') + if not adminNickname: + return False if nickname == adminNickname: return False