Assigning site editors

main
Bob Mottram 2020-10-11 20:42:21 +01:00
parent f2913b47ed
commit 7b616a4c70
18 changed files with 140 additions and 15 deletions

View File

@ -105,6 +105,7 @@ from blocking import isBlockedDomain
from blocking import getDomainBlocklist from blocking import getDomainBlocklist
from roles import setRole from roles import setRole
from roles import clearModeratorStatus from roles import clearModeratorStatus
from roles import clearEditorStatus
from blog import htmlBlogPageRSS2 from blog import htmlBlogPageRSS2
from blog import htmlBlogPageRSS3 from blog import htmlBlogPageRSS3
from blog import htmlBlogView from blog import htmlBlogView
@ -3558,6 +3559,66 @@ class PubServer(BaseHTTPRequestHandler):
'instance', 'instance',
'moderator') 'moderator')
# change site editors list
if fields.get('editors'):
adminNickname = \
getConfigParam(baseDir, 'admin')
if adminNickname:
if path.startswith('/users/' +
adminNickname + '/'):
editorsFile = \
baseDir + \
'/accounts/editors.txt'
clearEditorStatus(baseDir)
if ',' in fields['editors']:
# if the list was given as comma separated
edFile = open(editorsFile, "w+")
eds = fields['editors'].split(',')
for edNick in eds:
edNick = edNick.strip()
edDir = baseDir + \
'/accounts/' + edNick + \
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
edFile.close()
eds = fields['editors'].split(',')
for edNick in eds:
edNick = edNick.strip()
edDir = baseDir + \
'/accounts/' + edNick + \
'@' + domain
if os.path.isdir(edDir):
setRole(baseDir,
edNick, domain,
'instance', 'editor')
else:
# nicknames on separate lines
edFile = open(editorsFile, "w+")
eds = fields['editors'].split('\n')
for edNick in eds:
edNick = edNick.strip()
edDir = \
baseDir + \
'/accounts/' + edNick + \
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
edFile.close()
eds = fields['editors'].split('\n')
for edNick in eds:
edNick = edNick.strip()
edDir = \
baseDir + \
'/accounts/' + \
edNick + '@' + \
domain
if os.path.isdir(edDir):
setRole(baseDir,
edNick, domain,
'instance',
'editor')
# remove scheduled posts # remove scheduled posts
if fields.get('removeScheduledPosts'): if fields.get('removeScheduledPosts'):
if fields['removeScheduledPosts'] == 'on': if fields['removeScheduledPosts'] == 'on':

View File

@ -37,6 +37,26 @@ def clearModeratorStatus(baseDir: str) -> None:
saveJson(actorJson, filename) saveJson(actorJson, filename)
def clearEditorStatus(baseDir: str) -> None:
"""Removes editor status from all accounts
This could be slow if there are many users, but only happens
rarely when editors are appointed or removed
"""
directory = os.fsencode(baseDir + '/accounts/')
for f in os.scandir(directory):
f = f.name
filename = os.fsdecode(f)
if filename.endswith(".json") and '@' in filename:
filename = os.path.join(baseDir + '/accounts/', filename)
if '"editor"' in open(filename).read():
actorJson = loadJson(filename)
if actorJson:
if actorJson['roles'].get('instance'):
if 'editor' in actorJson['roles']['instance']:
actorJson['roles']['instance'].remove('editor')
saveJson(actorJson, filename)
def addModerator(baseDir: str, nickname: str, domain: str) -> None: def addModerator(baseDir: str, nickname: str, domain: str) -> None:
"""Adds a moderator nickname to the file """Adds a moderator nickname to the file
""" """

View File

@ -306,5 +306,7 @@
"This is a news instance": "هذا مثال أخبار", "This is a news instance": "هذا مثال أخبار",
"News": "أخبار", "News": "أخبار",
"Read more...": "اقرأ أكثر...", "Read more...": "اقرأ أكثر...",
"Edit News Post": "تحرير منشور الأخبار" "Edit News Post": "تحرير منشور الأخبار",
"A list of editor nicknames. One per line.": "قائمة بأسماء المحرر. واحد في كل سطر.",
"Site Editors": "محررو الموقع"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Aquesta és una instància de notícies", "This is a news instance": "Aquesta és una instància de notícies",
"News": "Notícies", "News": "Notícies",
"Read more...": "Llegeix més...", "Read more...": "Llegeix més...",
"Edit News Post": "Edita la publicació de notícies" "Edit News Post": "Edita la publicació de notícies",
"A list of editor nicknames. One per line.": "Una llista de sobrenoms de l'editor. Un per línia.",
"Site Editors": "Editors de llocs"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Dyma enghraifft newyddion", "This is a news instance": "Dyma enghraifft newyddion",
"News": "Newyddion", "News": "Newyddion",
"Read more...": "Darllen mwy...", "Read more...": "Darllen mwy...",
"Edit News Post": "Golygu News News" "Edit News Post": "Golygu News News",
"A list of editor nicknames. One per line.": "Rhestr o lysenwau golygydd. Un i bob llinell.",
"Site Editors": "Golygyddion Safle"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Dies ist eine Nachrichteninstanz", "This is a news instance": "Dies ist eine Nachrichteninstanz",
"News": "Nachrichten", "News": "Nachrichten",
"Read more...": "Weiterlesen...", "Read more...": "Weiterlesen...",
"Edit News Post": "Nachrichtenbeitrag bearbeiten" "Edit News Post": "Nachrichtenbeitrag bearbeiten",
"A list of editor nicknames. One per line.": "Eine Liste der Editor-Spitznamen. Eine pro Zeile.",
"Site Editors": "Site-Editoren"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "This is a news instance", "This is a news instance": "This is a news instance",
"News": "News", "News": "News",
"Read more...": "Read more...", "Read more...": "Read more...",
"Edit News Post": "Edit News Post" "Edit News Post": "Edit News Post",
"A list of editor nicknames. One per line.": "A list of editor nicknames. One per line.",
"Site Editors": "Site Editors"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Esta es una instancia de noticias", "This is a news instance": "Esta es una instancia de noticias",
"News": "Noticias", "News": "Noticias",
"Read more...": "Lee mas...", "Read more...": "Lee mas...",
"Edit News Post": "Editar publicación de noticias" "Edit News Post": "Editar publicación de noticias",
"A list of editor nicknames. One per line.": "Una lista de apodos de los editores. Uno por línea.",
"Site Editors": "Editores del sitio"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Ceci est une instance d'actualité", "This is a news instance": "Ceci est une instance d'actualité",
"News": "Nouvelles", "News": "Nouvelles",
"Read more...": "Lire la suite...", "Read more...": "Lire la suite...",
"Edit News Post": "Modifier l'article d'actualité" "Edit News Post": "Modifier l'article d'actualité",
"A list of editor nicknames. One per line.": "Une liste de surnoms d'éditeur. Un par ligne.",
"Site Editors": "Éditeurs du site"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Is sampla nuachta é seo", "This is a news instance": "Is sampla nuachta é seo",
"News": "Nuacht", "News": "Nuacht",
"Read more...": "Leigh Nios mo...", "Read more...": "Leigh Nios mo...",
"Edit News Post": "Cuir News Post in eagar" "Edit News Post": "Cuir News Post in eagar",
"A list of editor nicknames. One per line.": "Liosta leasainmneacha eagarthóra. Ceann in aghaidh na líne.",
"Site Editors": "Eagarthóirí Suímh"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "यह एक समाचार का उदाहरण है", "This is a news instance": "यह एक समाचार का उदाहरण है",
"News": "समाचार", "News": "समाचार",
"Read more...": "अधिक पढ़ें...", "Read more...": "अधिक पढ़ें...",
"Edit News Post": "समाचार पोस्ट संपादित करें" "Edit News Post": "समाचार पोस्ट संपादित करें",
"A list of editor nicknames. One per line.": "संपादक उपनामों की एक सूची। प्रति पंक्ति एक।",
"Site Editors": "साइट संपादकों"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Questa è un'istanza di notizie", "This is a news instance": "Questa è un'istanza di notizie",
"News": "Notizia", "News": "Notizia",
"Read more...": "Leggi di più...", "Read more...": "Leggi di più...",
"Edit News Post": "Modifica post di notizie" "Edit News Post": "Modifica post di notizie",
"A list of editor nicknames. One per line.": "Un elenco di soprannomi dell'editor. Uno per riga.",
"Site Editors": "Editori del sito"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "これはニュースインスタンスです", "This is a news instance": "これはニュースインスタンスです",
"News": "ニュース", "News": "ニュース",
"Read more...": "続きを読む...", "Read more...": "続きを読む...",
"Edit News Post": "ニュース投稿を編集する" "Edit News Post": "ニュース投稿を編集する",
"A list of editor nicknames. One per line.": "編集者のニックネームのリスト。 1行に1つ。",
"Site Editors": "サイト編集者"
} }

View File

@ -302,5 +302,7 @@
"This is a news instance": "This is a news instance", "This is a news instance": "This is a news instance",
"News": "News", "News": "News",
"Read more...": "Read more...", "Read more...": "Read more...",
"Edit News Post": "Edit News Post" "Edit News Post": "Edit News Post",
"A list of editor nicknames. One per line.": "A list of editor nicknames. One per line.",
"Site Editors": "Site Editors"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Esta é uma instância de notícias", "This is a news instance": "Esta é uma instância de notícias",
"News": "Notícia", "News": "Notícia",
"Read more...": "Consulte Mais informação...", "Read more...": "Consulte Mais informação...",
"Edit News Post": "Editar Postagem de Notícias" "Edit News Post": "Editar Postagem de Notícias",
"A list of editor nicknames. One per line.": "Uma lista de apelidos de editores. Um por linha.",
"Site Editors": "Editores do site"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "Это новостной экземпляр", "This is a news instance": "Это новостной экземпляр",
"News": "Новости", "News": "Новости",
"Read more...": "Подробнее...", "Read more...": "Подробнее...",
"Edit News Post": "Редактировать новость" "Edit News Post": "Редактировать новость",
"A list of editor nicknames. One per line.": "Список ников редакторов. По одному на строку.",
"Site Editors": "Редакторы сайта"
} }

View File

@ -306,5 +306,7 @@
"This is a news instance": "这是一个新闻实例", "This is a news instance": "这是一个新闻实例",
"News": "新闻", "News": "新闻",
"Read more...": "阅读更多...", "Read more...": "阅读更多...",
"Edit News Post": "编辑新闻帖子" "Edit News Post": "编辑新闻帖子",
"A list of editor nicknames. One per line.": "编辑者昵称列表。 每行一个。",
"Site Editors": "网站编辑"
} }

View File

@ -1698,6 +1698,20 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
'..." style="height:200px">' + moderators + '</textarea>' '..." style="height:200px">' + moderators + '</textarea>'
moderatorsStr += '</div>' moderatorsStr += '</div>'
editors = ''
editorsFile = baseDir + '/accounts/editors.txt'
if os.path.isfile(editorsFile):
with open(editorsFile, "r") as f:
editors = f.read()
editorsStr = '<div class="container">'
editorsStr += ' <b>' + translate['Site Editors'] + '</b><br>'
editorsStr += ' ' + \
translate['A list of editor nicknames. One per line.']
editorsStr += \
' <textarea id="message" name="editors" placeholder="" ' + \
'style="height:200px">' + editors + '</textarea>'
editorsStr += '</div>'
themes = getThemesList() themes = getThemesList()
themesDropdown = '<div class="container">' themesDropdown = '<div class="container">'
themesDropdown += ' <b>' + translate['Theme'] + '</b><br>' themesDropdown += ' <b>' + translate['Theme'] + '</b><br>'