Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1669] Added MockPublisherAuth to handle the authorisation, using the…
… appropriate functions when trying to test publisher profiles
- Loading branch information
Showing
6 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from ckan.new_authz import is_authorized | ||
from ckan.logic import NotAuthorized | ||
|
||
class MockPublisherAuth(object): | ||
""" | ||
MockPublisherAuth | ||
""" | ||
|
||
def __init__(self): | ||
self.functions = {} | ||
self._load() | ||
|
||
def _load(self): | ||
for auth_module_name in ['get', 'create', 'update','delete']: | ||
module_path = 'ckan.logic.auth.publisher.%s' % (auth_module_name,) | ||
try: | ||
module = __import__(module_path) | ||
except ImportError,e: | ||
log.debug('No auth module for action "%s"' % auth_module_name) | ||
continue | ||
|
||
for part in module_path.split('.')[1:]: | ||
module = getattr(module, part) | ||
|
||
for key, v in module.__dict__.items(): | ||
if not key.startswith('_'): | ||
self.functions[key] = v | ||
|
||
|
||
def check_access(self,action, context, data_dict): | ||
logic_authorization = self.functions[action](context, data_dict) | ||
if not logic_authorization['success']: | ||
msg = logic_authorization.get('msg','') | ||
raise NotAuthorized(msg) |