Restrict blocked site addition when using mergerSiteAdd
This commit is contained in:
parent
b21b885aa9
commit
43c366d2fb
3 changed files with 18 additions and 2 deletions
|
@ -25,6 +25,13 @@ class SiteManagerPlugin(object):
|
|||
super(SiteManagerPlugin, self).load(*args, **kwargs)
|
||||
filter_storage = ContentFilterStorage(site_manager=self)
|
||||
|
||||
def add(self, address, *args, **kwargs):
|
||||
if filter_storage.isSiteblocked(address):
|
||||
details = filter_storage.getSiteblockDetails(address)
|
||||
raise Exception("Site blocked: %s" % html.escape(details.get("reason", "unknown reason")))
|
||||
else:
|
||||
return super(SiteManagerPlugin, self).add(address, *args, **kwargs)
|
||||
|
||||
|
||||
@PluginManager.registerTo("UiWebsocket")
|
||||
class UiWebsocketPlugin(object):
|
||||
|
|
|
@ -120,6 +120,12 @@ class ContentFilterStorage(object):
|
|||
else:
|
||||
return False
|
||||
|
||||
def getSiteblockDetails(self, address):
|
||||
details = self.file_content["siteblocks"].get(address)
|
||||
if not details:
|
||||
details = self.include_filters["siteblocks"].get(address)
|
||||
return details
|
||||
|
||||
# Search and remove or readd files of an user
|
||||
def changeDbs(self, auth_address, action):
|
||||
self.log.debug("Mute action %s on user %s" % (action, auth_address))
|
||||
|
|
|
@ -79,8 +79,11 @@ class UiWebsocketPlugin(object):
|
|||
def cbMergerSiteAdd(self, to, addresses):
|
||||
added = 0
|
||||
for address in addresses:
|
||||
added += 1
|
||||
site_manager.need(address)
|
||||
try:
|
||||
site_manager.need(address)
|
||||
added += 1
|
||||
except Exception as err:
|
||||
self.cmd("notification", ["error", _["Adding <b>%s</b> failed: %s"] % (address, err)])
|
||||
if added:
|
||||
self.cmd("notification", ["done", _["Added <b>%s</b> new site"] % added, 5000])
|
||||
RateLimit.called(self.site.address + "-MergerSiteAdd")
|
||||
|
|
Loading…
Reference in a new issue