From 03c234eac95b3283b0ec91d94ec3e2f0916be707 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 13 Feb 2021 11:37:02 +0000 Subject: [PATCH] Featured writers --- daemon.py | 39 ++++++++++++++++++++++++++++++++++++++- outbox.py | 19 +++++++++++-------- translations/ar.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/en.json | 3 ++- translations/es.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/hi.json | 3 ++- translations/it.json | 3 ++- translations/ja.json | 3 ++- translations/oc.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/zh.json | 3 ++- utils.py | 10 ++++++++++ webapp_person_options.py | 22 +++++++++++++++++++++- 19 files changed, 110 insertions(+), 25 deletions(-) diff --git a/daemon.py b/daemon.py index 62d3fbe7d..d4e9dd30c 100644 --- a/daemon.py +++ b/daemon.py @@ -1964,6 +1964,42 @@ class PubServer(BaseHTTPRequestHandler): self.server.POSTbusy = False return + # person options screen, permission to post to featured articles + # See htmlPersonOptions + if '&submitPostToFeatures=' in optionsConfirmParams: + adminNickname = getConfigParam(self.server.baseDir, 'admin') + if (chooserNickname != optionsNickname and + (chooserNickname == adminNickname or + (isModerator(self.server.baseDir, chooserNickname) and + not isModerator(self.server.baseDir, optionsNickname)))): + postsToFeatures = None + if 'postsToFeatures=' in optionsConfirmParams: + postsToFeatures = \ + optionsConfirmParams.split('postsToFeatures=')[1] + if '&' in postsToFeatures: + postsToFeatures = postsToFeatures.split('&')[0] + accountDir = self.server.baseDir + '/accounts/' + \ + optionsNickname + '@' + optionsDomain + featuresBlockedFilename = accountDir + '/.nofeatures' + if postsToFeatures == 'on': + if os.path.isfile(featuresBlockedFilename): + os.remove(featuresBlockedFilename) + refreshNewswire(self.server.baseDir) + else: + if os.path.isdir(accountDir): + noFeaturesFile = open(featuresBlockedFilename, "w+") + if noFeaturesFile: + noFeaturesFile.write('\n') + noFeaturesFile.close() + refreshNewswire(self.server.baseDir) + usersPathStr = \ + usersPath + '/' + self.server.defaultTimeline + \ + '?page=' + str(pageNumber) + self._redirect_headers(usersPathStr, cookie, + callingDomain) + self.server.POSTbusy = False + return + # person options screen, permission to post to newswire # See htmlPersonOptions if '&submitModNewsPosts=' in optionsConfirmParams: @@ -5472,7 +5508,8 @@ class PubServer(BaseHTTPRequestHandler): backToPath, lockedAccount, movedTo, alsoKnownAs, - self.server.textModeBanner).encode('utf-8') + self.server.textModeBanner, + self.server.newsInstance).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, callingDomain) diff --git a/outbox.py b/outbox.py index e50000386..2c3fda855 100644 --- a/outbox.py +++ b/outbox.py @@ -18,6 +18,7 @@ from utils import getFullDomain from utils import removeIdEnding from utils import getDomainFromActor from utils import dangerousMarkup +from utils import isFeaturedWriter from blocking import isBlockedDomain from blocking import outboxBlock from blocking import outboxUndoBlock @@ -211,14 +212,16 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str, # save all instance blogs to the news actor if postToNickname != 'news' and outboxName == 'tlblogs': if '/' in savedFilename: - savedPostId = savedFilename.split('/')[-1] - blogsDir = baseDir + '/accounts/news@' + domain + '/tlblogs' - if not os.path.isdir(blogsDir): - os.mkdir(blogsDir) - copyfile(savedFilename, blogsDir + '/' + savedPostId) - inboxUpdateIndex('tlblogs', baseDir, - 'news@' + domain, - savedFilename, debug) + if isFeaturedWriter(baseDir, postToNickname, domain): + savedPostId = savedFilename.split('/')[-1] + blogsDir = \ + baseDir + '/accounts/news@' + domain + '/tlblogs' + if not os.path.isdir(blogsDir): + os.mkdir(blogsDir) + copyfile(savedFilename, blogsDir + '/' + savedPostId) + inboxUpdateIndex('tlblogs', baseDir, + 'news@' + domain, + savedFilename, debug) # clear the citations file if it exists citationsFilename = \ diff --git a/translations/ar.json b/translations/ar.json index b3a408074..605d5b98b 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -367,5 +367,6 @@ "Skip to timeline": "تخطي إلى الجدول الزمني", "Skip to Newswire": "انتقل إلى Newswire", "Skip to Links": "تخطي إلى روابط الويب", - "Publish a blog article": "نشر مقال بلوق" + "Publish a blog article": "نشر مقال بلوق", + "Featured writer": "كاتب متميز" } diff --git a/translations/ca.json b/translations/ca.json index 232ee4300..3c8846bbf 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -367,5 +367,6 @@ "Skip to timeline": "Ves a la cronologia", "Skip to Newswire": "Vés a Newswire", "Skip to Links": "Vés als enllaços web", - "Publish a blog article": "Publicar un article del bloc" + "Publish a blog article": "Publicar un article del bloc", + "Featured writer": "Escriptor destacat" } diff --git a/translations/cy.json b/translations/cy.json index 55b4b95e1..6e45de39d 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -367,5 +367,6 @@ "Skip to timeline": "Neidio i'r llinell amser", "Skip to Newswire": "Neidio i Newswire", "Skip to Links": "Neidio i Dolenni Gwe", - "Publish a blog article": "Cyhoeddi erthygl blog" + "Publish a blog article": "Cyhoeddi erthygl blog", + "Featured writer": "Awdur dan sylw" } diff --git a/translations/de.json b/translations/de.json index 140712ebd..c15cb492f 100644 --- a/translations/de.json +++ b/translations/de.json @@ -367,5 +367,6 @@ "Skip to timeline": "Zur Zeitleiste springen", "Skip to Newswire": "Springe zu Newswire", "Skip to Links": "Springe zu Weblinks", - "Publish a blog article": "Veröffentlichen Sie einen Blog-Artikel" + "Publish a blog article": "Veröffentlichen Sie einen Blog-Artikel", + "Featured writer": "Ausgewählter Schriftsteller" } diff --git a/translations/en.json b/translations/en.json index 77da14052..3fbbfdd34 100644 --- a/translations/en.json +++ b/translations/en.json @@ -367,5 +367,6 @@ "Skip to timeline": "Skip to timeline", "Skip to Newswire": "Skip to Newswire", "Skip to Links": "Skip to Links", - "Publish a blog article": "Publish a blog article" + "Publish a blog article": "Publish a blog article", + "Featured writer": "Featured writer" } diff --git a/translations/es.json b/translations/es.json index cf09d1446..3566d06b0 100644 --- a/translations/es.json +++ b/translations/es.json @@ -367,5 +367,6 @@ "Skip to timeline": "Saltar a la línea de tiempo", "Skip to Newswire": "Saltar a Newswire", "Skip to Links": "Saltar a enlaces web", - "Publish a blog article": "Publica un artículo de blog" + "Publish a blog article": "Publica un artículo de blog", + "Featured writer": "Escritora destacada" } diff --git a/translations/fr.json b/translations/fr.json index ac51b24fa..78c7ff547 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -367,5 +367,6 @@ "Skip to timeline": "Passer à la chronologie", "Skip to Newswire": "Passer à Newswire", "Skip to Links": "Passer aux liens Web", - "Publish a blog article": "Publier un article de blog" + "Publish a blog article": "Publier un article de blog", + "Featured writer": "Écrivain en vedette" } diff --git a/translations/ga.json b/translations/ga.json index 5cff4c525..75f87780c 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -367,5 +367,6 @@ "Skip to timeline": "Scipeáil chuig an amlíne", "Skip to Newswire": "Scipeáil chuig Newswire", "Skip to Links": "Scipeáil chuig Naisc Ghréasáin", - "Publish a blog article": "Foilsigh alt blagála" + "Publish a blog article": "Foilsigh alt blagála", + "Featured writer": "Scríbhneoir mór le rá" } diff --git a/translations/hi.json b/translations/hi.json index a83d8d5a9..acf417f88 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -367,5 +367,6 @@ "Skip to timeline": "टाइमलाइन पर जाएं", "Skip to Newswire": "Newswire पर जाएं", "Skip to Links": "वेब लिंक पर जाएं", - "Publish a blog article": "एक ब्लॉग लेख प्रकाशित करें" + "Publish a blog article": "एक ब्लॉग लेख प्रकाशित करें", + "Featured writer": "फीचर्ड लेखक" } diff --git a/translations/it.json b/translations/it.json index e7082ff98..f2bc1e1ed 100644 --- a/translations/it.json +++ b/translations/it.json @@ -367,5 +367,6 @@ "Skip to timeline": "Passa alla sequenza temporale", "Skip to Newswire": "Passa a Newswire", "Skip to Links": "Passa a collegamenti Web", - "Publish a blog article": "Pubblica un articolo sul blog" + "Publish a blog article": "Pubblica un articolo sul blog", + "Featured writer": "Scrittore in primo piano" } diff --git a/translations/ja.json b/translations/ja.json index 38d6685a4..9f1275544 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -367,5 +367,6 @@ "Skip to timeline": "タイムラインにスキップ", "Skip to Newswire": "Newswireにスキップ", "Skip to Links": "Webリンクにスキップ", - "Publish a blog article": "ブログ記事を公開する" + "Publish a blog article": "ブログ記事を公開する", + "Featured writer": "注目の作家" } diff --git a/translations/oc.json b/translations/oc.json index 7cd70a858..c9e3717a0 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -363,5 +363,6 @@ "Skip to timeline": "Skip to timeline", "Skip to Newswire": "Skip to Newswire", "Skip to Links": "Skip to Links", - "Publish a blog article": "Publish a blog article" + "Publish a blog article": "Publish a blog article", + "Featured writer": "Featured writer" } diff --git a/translations/pt.json b/translations/pt.json index 2abe336bf..b2a29ca2d 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -367,5 +367,6 @@ "Skip to timeline": "Pular para a linha do tempo", "Skip to Newswire": "Pular para Newswire", "Skip to Links": "Pular para links da web", - "Publish a blog article": "Publique um artigo de blog" + "Publish a blog article": "Publique um artigo de blog", + "Featured writer": "Escritor em destaque" } diff --git a/translations/ru.json b/translations/ru.json index b75628208..618c5cbf0 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -367,5 +367,6 @@ "Skip to timeline": "Перейти к временной шкале", "Skip to Newswire": "Перейти к ленте новостей", "Skip to Links": "Перейти к веб-ссылкам", - "Publish a blog article": "Опубликовать статью в блоге" + "Publish a blog article": "Опубликовать статью в блоге", + "Featured writer": "Избранный писатель" } diff --git a/translations/zh.json b/translations/zh.json index ea0dcce39..e7fab5755 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -367,5 +367,6 @@ "Skip to timeline": "跳到时间线", "Skip to Newswire": "跳到新闻专线", "Skip to Links": "跳到网页链接", - "Publish a blog article": "发布博客文章" + "Publish a blog article": "发布博客文章", + "Featured writer": "特色作家" } diff --git a/utils.py b/utils.py index d36fb5447..f1247e898 100644 --- a/utils.py +++ b/utils.py @@ -26,6 +26,16 @@ invalidCharacters = ( ) +def isFeaturedWriter(baseDir: str, nickname: str, domain: str) -> bool: + """Is the given account a featured writer, appearing in the features + timeline on news instances? + """ + featuresBlockedFilename = \ + baseDir + '/accounts/' + \ + nickname + '@' + domain + '/.nofeatures' + return not os.path.isfile(featuresBlockedFilename) + + def refreshNewswire(baseDir: str): """Causes the newswire to be updates after a change to user accounts """ diff --git a/webapp_person_options.py b/webapp_person_options.py index dc2be6fea..75dd21045 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -17,6 +17,7 @@ from utils import isDormant from utils import removeHtml from utils import getDomainFromActor from utils import getNicknameFromActor +from utils import isFeaturedWriter from blocking import isBlocked from follow import isFollowerOfPerson from follow import isFollowingActor @@ -51,7 +52,8 @@ def htmlPersonOptions(defaultTimeline: str, lockedAccount: bool, movedTo: str, alsoKnownAs: [], - textModeBanner: str) -> str: + textModeBanner: str, + newsInstance: bool) -> str: """Show options for a person: view/follow/block/report """ optionsDomain, optionsPort = getDomainFromActor(optionsActor) @@ -287,6 +289,24 @@ def htmlPersonOptions(defaultTimeline: str, checkboxStr = checkboxStr.replace(' checked>', '>') optionsStr += checkboxStr + # checkbox for permission to post to featured articles + if newsInstance and optionsDomainFull == domainFull: + adminNickname = getConfigParam(baseDir, 'admin') + if (nickname == adminNickname or + (isModerator(baseDir, nickname) and + not isModerator(baseDir, optionsNickname))): + checkboxStr = \ + ' ' + \ + translate['Featured writer'] + \ + '\n
\n' + if not isFeaturedWriter(baseDir, optionsNickname, + optionsDomain): + checkboxStr = checkboxStr.replace(' checked>', '>') + optionsStr += checkboxStr + optionsStr += optionsLinkStr backPath = '/' if nickname: