Show shared item remove button for admin and moderators

merge-requests/30/head
Bob Mottram 2021-07-28 21:12:27 +01:00
parent 1b2c4cb3e5
commit b5fc769af3
2 changed files with 24 additions and 7 deletions

View File

@ -156,13 +156,14 @@ def _htmlSearchResultSharePage(actor: str, domainFull: str,
return sharedItemsForm return sharedItemsForm
def _htmlSharesResult(sharesJson: {}, pageNumber: int, resultsPerPage: int, def _htmlSharesResult(baseDir: str,
sharesJson: {}, pageNumber: int, resultsPerPage: int,
searchStrLowerList: [], currPage: int, ctr: int, searchStrLowerList: [], currPage: int, ctr: int,
callingDomain: str, httpPrefix: str, domainFull: str, callingDomain: str, httpPrefix: str, domainFull: str,
contactNickname: str, actor: str, contactNickname: str, actor: str,
resultsExist: bool, searchStrLower: str, resultsExist: bool, searchStrLower: str,
translate: {}) -> (bool, int, int, str): translate: {}) -> (bool, int, int, str):
""" """Result for shared items search
""" """
sharedItemsForm = '' sharedItemsForm = ''
if currPage > pageNumber: if currPage > pageNumber:
@ -173,7 +174,7 @@ def _htmlSharesResult(sharesJson: {}, pageNumber: int, resultsPerPage: int,
if currPage == pageNumber: if currPage == pageNumber:
# show individual search result # show individual search result
sharedItemsForm += \ sharedItemsForm += \
htmlSearchResultShare(sharedItem, translate, htmlSearchResultShare(baseDir, sharedItem, translate,
httpPrefix, domainFull, httpPrefix, domainFull,
contactNickname, contactNickname,
name, actor) name, actor)
@ -247,7 +248,7 @@ def htmlSearchSharedItems(cssCache: {}, translate: {},
continue continue
(resultsExist, currPage, ctr, (resultsExist, currPage, ctr,
resultStr) = _htmlSharesResult(sharesJson, pageNumber, resultStr) = _htmlSharesResult(baseDir, sharesJson, pageNumber,
resultsPerPage, resultsPerPage,
searchStrLowerList, searchStrLowerList,
currPage, ctr, currPage, ctr,
@ -280,7 +281,8 @@ def htmlSearchSharedItems(cssCache: {}, translate: {},
continue continue
(resultsExist, currPage, ctr, (resultsExist, currPage, ctr,
resultStr) = _htmlSharesResult(sharesJson, pageNumber, resultStr) = _htmlSharesResult(baseDir, sharesJson,
pageNumber,
resultsPerPage, resultsPerPage,
searchStrLowerList, searchStrLowerList,
currPage, ctr, currPage, ctr,

View File

@ -24,6 +24,7 @@ from cache import storePersonInCache
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
from person import getPersonAvatarUrl from person import getPersonAvatarUrl
from posts import isModerator
def getBrokenLinkSubstitute() -> str: def getBrokenLinkSubstitute() -> str:
@ -1253,7 +1254,7 @@ def editTextArea(label: str, name: str, value: str = "",
return text return text
def htmlSearchResultShare(sharedItem: {}, translate: {}, def htmlSearchResultShare(baseDir: str, sharedItem: {}, translate: {},
httpPrefix: str, domainFull: str, httpPrefix: str, domainFull: str,
contactNickname: str, name: str, contactNickname: str, name: str,
actor: str) -> str: actor: str) -> str:
@ -1298,7 +1299,21 @@ def htmlSearchResultShare(sharedItem: {}, translate: {},
'<p><a href="' + actor + '?replydm=sharedesc:' + \ '<p><a href="' + actor + '?replydm=sharedesc:' + \
sharedItem['displayName'] + '?mention=' + contactActor + \ sharedItem['displayName'] + '?mention=' + contactActor + \
'"><button class="button">' + translate['Contact'] + '</button></a>\n' '"><button class="button">' + translate['Contact'] + '</button></a>\n'
# should the remove button be shown?
showRemoveButton = False
nickname = getNicknameFromActor(actor)
if actor.endswith('/users/' + contactNickname): if actor.endswith('/users/' + contactNickname):
showRemoveButton = True
elif isModerator(baseDir, nickname):
showRemoveButton = True
else:
adminNickname = getConfigParam(baseDir, 'admin')
if adminNickname:
if actor.endswith('/users/' + adminNickname):
showRemoveButton = True
if showRemoveButton:
sharedItemsForm += \ sharedItemsForm += \
' <a href="' + actor + '?rmshare=' + \ ' <a href="' + actor + '?rmshare=' + \
name + '"><button class="button">' + \ name + '"><button class="button">' + \
@ -1370,7 +1385,7 @@ def htmlShowShare(baseDir: str, domain: str, nickname: str,
'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n' + \ 'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n' + \
'</header><br>\n' '</header><br>\n'
shareStr += \ shareStr += \
htmlSearchResultShare(sharedItem, translate, httpPrefix, htmlSearchResultShare(baseDir, sharedItem, translate, httpPrefix,
domainFull, contactNickname, itemID, domainFull, contactNickname, itemID,
actor) actor)