Show More
@@ -38,7 +38,9 b' from sqlalchemy.sql.expression import tr' | |||||
38 | from sqlalchemy.util import OrderedSet |
|
38 | from sqlalchemy.util import OrderedSet | |
39 | from webhelpers.pylonslib.secure_form import authentication_token |
|
39 | from webhelpers.pylonslib.secure_form import authentication_token | |
40 |
|
40 | |||
41 |
from rhodecode.authentication import |
|
41 | from rhodecode.authentication import ( | |
|
42 | legacy_plugin_prefix, _import_legacy_plugin) | |||
|
43 | from rhodecode.authentication.base import loadplugin | |||
42 | from rhodecode.config.routing import ADMIN_PREFIX |
|
44 | from rhodecode.config.routing import ADMIN_PREFIX | |
43 | from rhodecode.lib.auth import HasRepoGroupPermissionAny, HasPermissionAny |
|
45 | from rhodecode.lib.auth import HasRepoGroupPermissionAny, HasPermissionAny | |
44 | from rhodecode.lib.utils import repo_name_slug, make_db_config |
|
46 | from rhodecode.lib.utils import repo_name_slug, make_db_config | |
@@ -985,30 +987,71 b' def ValidAuthPlugins():' | |||||
985 | 'import_duplicate': _( |
|
987 | 'import_duplicate': _( | |
986 | u'Plugins %(loaded)s and %(next_to_load)s ' |
|
988 | u'Plugins %(loaded)s and %(next_to_load)s ' | |
987 | u'both export the same name'), |
|
989 | u'both export the same name'), | |
|
990 | 'missing_includeme': _( | |||
|
991 | u'The plugin "%(plugin_id)s" is missing an includeme ' | |||
|
992 | u'function.'), | |||
|
993 | 'import_error': _( | |||
|
994 | u'Can not load plugin "%(plugin_id)s"'), | |||
|
995 | 'no_plugin': _( | |||
|
996 | u'No plugin available with ID "%(plugin_id)s"'), | |||
988 | } |
|
997 | } | |
989 |
|
998 | |||
990 | def _to_python(self, value, state): |
|
999 | def _to_python(self, value, state): | |
991 | # filter empty values |
|
1000 | # filter empty values | |
992 | return filter(lambda s: s not in [None, ''], value) |
|
1001 | return filter(lambda s: s not in [None, ''], value) | |
993 |
|
1002 | |||
994 |
def validate_ |
|
1003 | def _validate_legacy_plugin_id(self, plugin_id, value, state): | |
995 | from rhodecode.authentication.base import loadplugin |
|
1004 | """ | |
996 | module_list = value |
|
1005 | Validates that the plugin import works. It also checks that the | |
997 | unique_names = {} |
|
1006 | plugin has an includeme attribute. | |
|
1007 | """ | |||
998 | try: |
|
1008 | try: | |
999 | for module in module_list: |
|
1009 | plugin = _import_legacy_plugin(plugin_id) | |
1000 | if module.startswith(legacy_plugin_prefix): |
|
1010 | except Exception as e: | |
1001 |
|
|
1011 | log.exception( | |
1002 | plugin = loadplugin(module) |
|
1012 | 'Exception during import of auth legacy plugin "{}"' | |
1003 |
|
|
1013 | .format(plugin_id)) | |
1004 | if plugin_name in unique_names: |
|
1014 | msg = M(self, 'import_error', plugin_id=plugin_id) | |
|
1015 | raise formencode.Invalid(msg, value, state) | |||
|
1016 | ||||
|
1017 | if not hasattr(plugin, 'includeme'): | |||
|
1018 | msg = M(self, 'missing_includeme', plugin_id=plugin_id) | |||
|
1019 | raise formencode.Invalid(msg, value, state) | |||
|
1020 | ||||
|
1021 | return plugin | |||
|
1022 | ||||
|
1023 | def _validate_plugin_id(self, plugin_id, value, state): | |||
|
1024 | """ | |||
|
1025 | Plugins are already imported during app start up. Therefore this | |||
|
1026 | validation only retrieves the plugin from the plugin registry and | |||
|
1027 | if it returns something not None everything is OK. | |||
|
1028 | """ | |||
|
1029 | plugin = loadplugin(plugin_id) | |||
|
1030 | ||||
|
1031 | if plugin is None: | |||
|
1032 | msg = M(self, 'no_plugin', plugin_id=plugin_id) | |||
|
1033 | raise formencode.Invalid(msg, value, state) | |||
|
1034 | ||||
|
1035 | return plugin | |||
|
1036 | ||||
|
1037 | def validate_python(self, value, state): | |||
|
1038 | unique_names = {} | |||
|
1039 | for plugin_id in value: | |||
|
1040 | ||||
|
1041 | # Validate legacy or normal plugin. | |||
|
1042 | if plugin_id.startswith(legacy_plugin_prefix): | |||
|
1043 | plugin = self._validate_legacy_plugin_id( | |||
|
1044 | plugin_id, value, state) | |||
|
1045 | else: | |||
|
1046 | plugin = self._validate_plugin_id(plugin_id, value, state) | |||
|
1047 | ||||
|
1048 | # Only allow unique plugin names. | |||
|
1049 | if plugin.name in unique_names: | |||
1005 |
|
|
1050 | msg = M(self, 'import_duplicate', state, | |
1006 |
|
|
1051 | loaded=unique_names[plugin.name], | |
1007 |
|
|
1052 | next_to_load=plugin) | |
1008 |
|
|
1053 | raise formencode.Invalid(msg, value, state) | |
1009 |
|
|
1054 | unique_names[plugin.name] = plugin | |
1010 | except (KeyError, AttributeError, TypeError) as e: |
|
|||
1011 | raise formencode.Invalid(str(e), value, state) |
|
|||
1012 |
|
1055 | |||
1013 | return _validator |
|
1056 | return _validator | |
1014 |
|
1057 |
General Comments 0
You need to be logged in to leave comments.
Login now