Make the site block check usable from plugins and core modules
Fixes https://github.com/HelloZeroNet/ZeroNet/issues/1888
This commit is contained in:
parent
6c8849139f
commit
1144964062
3 changed files with 13 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
|||
**Other:**
|
||||
|
||||
* Implemented the log level overriding for separate modules for easier debugging.
|
||||
* Make the site block check implemented in `ContentFilter` usable from plugins and core modules via `SiteManager.isAddressBlocked()`.
|
||||
|
||||
## Plugins
|
||||
|
||||
|
|
|
@ -24,6 +24,14 @@ class SiteManagerPlugin(object):
|
|||
super(SiteManagerPlugin, self).load(*args, **kwargs)
|
||||
filter_storage = ContentFilterStorage(site_manager=self)
|
||||
|
||||
def isAddressBlocked(self, address):
|
||||
# FIXME: code duplication of isSiteblocked(address) or isSiteblocked(address_hashed)
|
||||
# in several places here and below
|
||||
address_hashed = filter_storage.getSiteAddressHashed(address)
|
||||
if filter_storage.isSiteblocked(address) or filter_storage.isSiteblocked(address_hashed):
|
||||
return True
|
||||
return super(SiteManagerPlugin, self).isAddressBlocked(address)
|
||||
|
||||
def add(self, address, *args, **kwargs):
|
||||
should_ignore_block = kwargs.get("ignore_block") or kwargs.get("settings")
|
||||
if should_ignore_block:
|
||||
|
|
|
@ -155,6 +155,10 @@ class SiteManager(object):
|
|||
def resolveDomainCached(self, domain):
|
||||
return self.resolveDomain(domain)
|
||||
|
||||
# Checks if the address is blocked. To be implemented in content filter plugins.
|
||||
def isAddressBlocked(self, address):
|
||||
return False
|
||||
|
||||
# Return: Site object or None if not found
|
||||
def get(self, address):
|
||||
if self.isDomainCached(address):
|
||||
|
|
Loading…
Reference in a new issue