def get_context_for_scope(scope, hashkey): context = ExecutionContext() if scope == "user": mod = lookup_user(hashkey) context.user = mod elif scope == "group": mod = lookup_group(hashkey) context.group = mod else: raise InvalidScopeException() return context, mod
def setup_task(self, task_cls): manager = self.get_manager_from_context() plugin = self.lookup_plugin(self.plugin.hashkey) context = ExecutionContext(user=self.user, plugin=plugin, group=self.group) auth_manager = AuthorizationManager(context) return task_cls(context=context, manager=manager, auth_manager=auth_manager)
def run_actions(self, plugin_hashkey, action_name, **kwargs): plugin_cls = self.get_plugin(plugin_hashkey) manager = self.get_manager_from_hashkey(plugin_hashkey) context = ExecutionContext(plugin=self.lookup_plugin(plugin_hashkey), user=self.user) plugin = plugin_cls(context, manager) func = getattr(plugin, action_name) return func(**kwargs)
def test_get_settings(self): context = ExecutionContext(user=self.plugin_info['1']['user'], plugin=self.plugin_info['1']['plugin']) manager = PluginManager(context) # Should return the response from the view. response = manager.get_settings( self.plugin_info['1']['plugin'].hashkey) self.assertTrue(isinstance(response, dict))
def base_convert(self, plugin): context = ExecutionContext(plugin=plugin) data = dict( name=plugin.name, description=plugin.description, permissions=AuthorizationManager(context).get_permissions(), hashkey=plugin.hashkey ) return data
def test_get_route(self): context = ExecutionContext(user=self.plugin_info['1']['user'], plugin=self.plugin_info['1']['plugin']) login_user(self.plugin_info['1']['user']) manager = PluginManager(context) response = manager.call_route_handler( self.plugin_info['1']['views']['test'].hashkey, "get", {}, None) logout_user() self.assertEqual(response.status_code, 200)
def put(self, hashkey): from app import db mod = self.get_group_by_key(hashkey) context = ExecutionContext(user=current_user) perm_manager = GroupPermissions(context) perm = perm_manager.check_perms(mod, "update") data = get_data() if perm: mod.description = data.get('description', mod.description) db.session.commit() return self.convert_group(mod), 200
def test_add_remove(self): user = UserFactory() context = ExecutionContext(user=user, plugin=self.plugin_info['1']['plugin']) manager = PluginManager(context) # This should be 1 because we have just added a plugin for the user. plugin_key = self.plugin_info['1']['plugin'].hashkey manager.add(plugin_key) self.assertEqual(len(user.plugins), 1) manager.remove(plugin_key) self.assertEqual(len(user.plugins), 0)
def load_plugins(): plugins = {} from flask import current_app context = ExecutionContext() manager = DatabaseManager(context, session=db.session) view_manager = ViewManager(context, manager=manager) for plugin in PluginLoader(current_app.config['PLUGIN_PATH']): # Store plugins in a dictionary for later access. plugins[plugin.hashkey] = plugin # Register all plugins and create a DB entry as needed. manager.register_plugin(plugin) view_manager.register_views(plugin) db.session.commit() return plugins
def check_perms(self, obj, perm_type, resource_hashkey): from app import db from core.database.models import ResourceData authed = False if self.req_user is not None: authed = self.check_user_perms(obj, perm_type) elif self.req_group is not None: authed = self.check_group_perms(obj, perm_type) if not authed and resource_hashkey is not None: context = ExecutionContext(plugin=self.plugin, user=current_user) resource_permissions = ResourcePermissionsManager(context) resource = db.session.query(ResourceData).filter_by(hashkey=resource_hashkey).first() authed = resource_permissions.check_perms(resource, perm_type) return authed
def add_commands(): context = ExecutionContext() command_manager = CommandManager(context) return command_manager.get_plugin_command_manager(app)
def get_manager(plugin, session, user=None, group=None): from core.database.manager import DatabaseManager context = ExecutionContext(user=user, plugin=plugin, group=group) manager = DatabaseManager(context, session=session) return manager
def get_manager_group(self): group = Group.query.filter(Group.id == self.group_id).first() context = ExecutionContext(group=group, plugin=self.plugin) return TaskManager(context)
def get_manager_user(self): user = User.query.filter(User.id == self.user_id).first() context = ExecutionContext(user=user, plugin=self.plugin) return TaskManager(context)
def check_permissions(self, obj, perm_type): context = ExecutionContext(user=current_user) permissions = ResourcePermissionsManager(context) return permissions.check_perms(obj, perm_type)