diff --git a/daemon.py b/daemon.py index a313f35a..4430903b 100644 --- a/daemon.py +++ b/daemon.py @@ -105,6 +105,7 @@ from blocking import isBlockedDomain from blocking import getDomainBlocklist from roles import setRole from roles import clearModeratorStatus +from roles import clearEditorStatus from blog import htmlBlogPageRSS2 from blog import htmlBlogPageRSS3 from blog import htmlBlogView @@ -3558,6 +3559,66 @@ class PubServer(BaseHTTPRequestHandler): 'instance', '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 if fields.get('removeScheduledPosts'): if fields['removeScheduledPosts'] == 'on': diff --git a/roles.py b/roles.py index 9cfa1cc7..fe60b2ab 100644 --- a/roles.py +++ b/roles.py @@ -37,6 +37,26 @@ def clearModeratorStatus(baseDir: str) -> None: 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: """Adds a moderator nickname to the file """ diff --git a/translations/ar.json b/translations/ar.json index 17e22a97..ca37a994 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -306,5 +306,7 @@ "This is a news instance": "هذا مثال أخبار", "News": "أخبار", "Read more...": "اقرأ أكثر...", - "Edit News Post": "تحرير منشور الأخبار" + "Edit News Post": "تحرير منشور الأخبار", + "A list of editor nicknames. One per line.": "قائمة بأسماء المحرر. واحد في كل سطر.", + "Site Editors": "محررو الموقع" } diff --git a/translations/ca.json b/translations/ca.json index df1bbe56..78a90aff 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -306,5 +306,7 @@ "This is a news instance": "Aquesta és una instància de notícies", "News": "Notícies", "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" } diff --git a/translations/cy.json b/translations/cy.json index aad0ef7a..a68b2456 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -306,5 +306,7 @@ "This is a news instance": "Dyma enghraifft newyddion", "News": "Newyddion", "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" } diff --git a/translations/de.json b/translations/de.json index 2c0812fc..06bdd7e9 100644 --- a/translations/de.json +++ b/translations/de.json @@ -306,5 +306,7 @@ "This is a news instance": "Dies ist eine Nachrichteninstanz", "News": "Nachrichten", "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" } diff --git a/translations/en.json b/translations/en.json index 7f101427..9a10f674 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" + "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" } diff --git a/translations/es.json b/translations/es.json index 6cf7431d..6970b49b 100644 --- a/translations/es.json +++ b/translations/es.json @@ -306,5 +306,7 @@ "This is a news instance": "Esta es una instancia de noticias", "News": "Noticias", "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" } diff --git a/translations/fr.json b/translations/fr.json index 755de43b..65d77012 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -306,5 +306,7 @@ "This is a news instance": "Ceci est une instance d'actualité", "News": "Nouvelles", "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" } diff --git a/translations/ga.json b/translations/ga.json index caf8cac0..d97ad267 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -306,5 +306,7 @@ "This is a news instance": "Is sampla nuachta é seo", "News": "Nuacht", "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" } diff --git a/translations/hi.json b/translations/hi.json index 6299d424..f1ed564b 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -306,5 +306,7 @@ "This is a news instance": "यह एक समाचार का उदाहरण है", "News": "समाचार", "Read more...": "अधिक पढ़ें...", - "Edit News Post": "समाचार पोस्ट संपादित करें" + "Edit News Post": "समाचार पोस्ट संपादित करें", + "A list of editor nicknames. One per line.": "संपादक उपनामों की एक सूची। प्रति पंक्ति एक।", + "Site Editors": "साइट संपादकों" } diff --git a/translations/it.json b/translations/it.json index 9997606a..d01e1fd4 100644 --- a/translations/it.json +++ b/translations/it.json @@ -306,5 +306,7 @@ "This is a news instance": "Questa è un'istanza di notizie", "News": "Notizia", "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" } diff --git a/translations/ja.json b/translations/ja.json index dbb9dc8b..1867a618 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -306,5 +306,7 @@ "This is a news instance": "これはニュースインスタンスです", "News": "ニュース", "Read more...": "続きを読む...", - "Edit News Post": "ニュース投稿を編集する" + "Edit News Post": "ニュース投稿を編集する", + "A list of editor nicknames. One per line.": "編集者のニックネームのリスト。 1行に1つ。", + "Site Editors": "サイト編集者" } diff --git a/translations/oc.json b/translations/oc.json index 8fad854d..5f54ec75 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -302,5 +302,7 @@ "This is a news instance": "This is a news instance", "News": "News", "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" } diff --git a/translations/pt.json b/translations/pt.json index d93322cb..78832177 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -306,5 +306,7 @@ "This is a news instance": "Esta é uma instância de notícias", "News": "Notícia", "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" } diff --git a/translations/ru.json b/translations/ru.json index fc26f829..798d51b1 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -306,5 +306,7 @@ "This is a news instance": "Это новостной экземпляр", "News": "Новости", "Read more...": "Подробнее...", - "Edit News Post": "Редактировать новость" + "Edit News Post": "Редактировать новость", + "A list of editor nicknames. One per line.": "Список ников редакторов. По одному на строку.", + "Site Editors": "Редакторы сайта" } diff --git a/translations/zh.json b/translations/zh.json index cf8c0300..ffd2dd28 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -306,5 +306,7 @@ "This is a news instance": "这是一个新闻实例", "News": "新闻", "Read more...": "阅读更多...", - "Edit News Post": "编辑新闻帖子" + "Edit News Post": "编辑新闻帖子", + "A list of editor nicknames. One per line.": "编辑者昵称列表。 每行一个。", + "Site Editors": "网站编辑" } diff --git a/webinterface.py b/webinterface.py index fe9fd789..28002df9 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1698,6 +1698,20 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str, '..." style="height:200px">' + moderators + '' moderatorsStr += '' + editors = '' + editorsFile = baseDir + '/accounts/editors.txt' + if os.path.isfile(editorsFile): + with open(editorsFile, "r") as f: + editors = f.read() + editorsStr = '