def make_model(self, scope, hashkey, **kwargs): from app import db for arg in self.required_fields: if arg not in kwargs: raise InvalidArgumentsException() parent = kwargs.pop("parent", None) if "settings" in kwargs: try: kwargs["settings"] = json.loads(kwargs["settings"]) except Exception: pass context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) model = manager.create_resource(**kwargs) # If the resource specifies its parent, then automatically setup the link. if parent: parent_model = self.get_resource(parent) if parent_model: parent_model.related.append(model) db.session.commit() return model
def make_model(self, scope, hashkey, **kwargs): from app import db for arg in self.required_fields: if arg not in kwargs: raise InvalidArgumentsException() parent = kwargs.pop('parent', None) if 'settings' in kwargs: try: kwargs['settings'] = json.loads(kwargs['settings']) except Exception: pass context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) model = manager.create_resource(**kwargs) # If the resource specifies its parent, then automatically setup the link. if parent: parent_model = self.get_resource(parent) if parent_model: parent_model.related.append(model) db.session.commit() return model
def get(self, scope, hashkey): from app import db context, mod = get_context_for_scope(scope, hashkey) resource_data = db.session.query(ResourceData).filter(getattr(ResourceData, scope) == mod).all() resources = [] for r in resource_data: data = self.convert(scope, hashkey, r) url = api_url_for("resource_views", ResourceDetail, resource_hashkey=data['hashkey'], scope=scope, hashkey=hashkey) data['url'] = url resources.append(data) return resources
def delete(self, scope, hashkey, resource_hashkey): from app import db parent = request.args.get('parent', None) context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) manager.delete_resource(resource_hashkey) if parent: parent_model = self.get_resource(parent) if parent_model: parent_model.related.remove() db.session.commit() return {}
def post(self, scope, hashkey): data = get_data() positions = data.pop("positions", None) if positions is None: return {}, 400 context, mod = get_context_for_scope(scope, hashkey) row = 0 for (i, pos) in enumerate(positions): manager = ResourceManager(context) manager.update_model(pos["hashkey"], dict(layout=pos["layout"])) row += self.get_resource(pos["hashkey"]).layout.sizeX return {}, 200
def post(self, scope, hashkey): data = get_data() positions = data.pop('positions', None) if positions is None: return {}, 400 context, mod = get_context_for_scope(scope, hashkey) row = 0 for (i, pos) in enumerate(positions): manager = ResourceManager(context) manager.update_model(pos['hashkey'], dict(layout=pos['layout'])) row += self.get_resource(pos['hashkey']).layout.sizeX return {}, 200
def delete(self, scope, hashkey, resource_hashkey): from app import db parent = request.args.get("parent", None) context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) manager.delete_resource(resource_hashkey) if parent: parent_model = self.get_resource(parent) if parent_model: parent_model.related.remove() db.session.commit() return {}
def get(self, scope, hashkey, plugin_hashkey): from core.plugins.loader import plugins context, mod = get_context_for_scope(scope, hashkey) views = plugins[plugin_hashkey].views context.plugin = plugins[plugin_hashkey] manager = ViewManager(context) user_views = [] for v in views: data = manager.get_meta(v.hashkey) data['url'] = self.get_url(scope, hashkey, plugin_hashkey, v.hashkey) user_views.append(data) return user_views
def convert(self, scope, hashkey, resource, find_related=False): if resource.user is not None: owner_key = resource.user.hashkey res_scope = "user" elif resource.group is not None: owner_key = resource.group.hashkey res_scope = "group" else: raise InvalidScopeException() permissions = [] for p in resource.permissions: if p.user is not None: key = p.user.hashkey elif p.group is not None: key = p.group.hashkey else: key = None permissions.append(dict( public=p.public, hashkey=key, scope=p.scope )) layout = dict( row=resource.layout.row, col=resource.layout.col, sizeX=resource.layout.sizeX, sizeY=resource.layout.sizeY ) vals = dict( hashkey=resource.hashkey, name=resource.name, type=resource.type, settings=resource.settings, owner_scope=res_scope, owner_hashkey=owner_key, views=[v.hashkey for v in resource.views], permissions=permissions, current_view=resource.current_view, parents=[r.hashkey for r in resource.parents], layout=layout ) if find_related: related = [] context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) for r in resource.related: if manager.check_permissions(r, "view"): related.append(r) vals['related'] = [self.convert(scope, hashkey, r, find_related=find_related) for r in related] return vals
def get(self, scope, hashkey): from app import db context, mod = get_context_for_scope(scope, hashkey) resource_data = db.session.query(ResourceData).filter(getattr(ResourceData, scope) == mod).all() resources = [] for r in resource_data: data = self.convert(scope, hashkey, r) url = api_url_for( "resource_views", ResourceDetail, resource_hashkey=data["hashkey"], scope=scope, hashkey=hashkey ) data["url"] = url resources.append(data) return resources
def get(self, scope, hashkey): from core.plugins.loader import plugins context, model = get_context_for_scope(scope, hashkey) installed_plugins = model.plugins installed_keys = [p.hashkey for p in installed_plugins] plugin_schema = [] for p in plugins: plugin = plugins[p] plugin_scheme = self.convert(plugin, scope, hashkey) plugin_scheme['installed'] = (plugin.hashkey in installed_keys) plugin_schema.append(plugin_scheme) return plugin_schema
def get(self, scope, hashkey): context, mod = get_context_for_scope(scope, hashkey) auth = mod.authorizations current_auth = {} for a in auth: current_auth[a.name] = auth all_logins = login_urls auth_schema = [] for l in all_logins: auth_scheme = dict(url=all_logins[l], name=l, active=(l in current_auth)) auth_schema.append(auth_scheme) return auth_schema
def get(self, scope, hashkey): context, mod = get_context_for_scope(scope, hashkey) auth = mod.authorizations current_auth = {} for a in auth: current_auth[a.name] = auth all_logins = login_urls auth_schema = [] for l in all_logins: auth_scheme = dict( url=all_logins[l], name=l, active=(l in current_auth) ) auth_schema.append(auth_scheme) return auth_schema
def convert(self, scope, hashkey, resource, find_related=False): if resource.user is not None: owner_key = resource.user.hashkey res_scope = "user" elif resource.group is not None: owner_key = resource.group.hashkey res_scope = "group" else: raise InvalidScopeException() permissions = [] for p in resource.permissions: if p.user is not None: key = p.user.hashkey elif p.group is not None: key = p.group.hashkey else: key = None permissions.append(dict(public=p.public, hashkey=key, scope=p.scope)) layout = dict( row=resource.layout.row, col=resource.layout.col, sizeX=resource.layout.sizeX, sizeY=resource.layout.sizeY ) vals = dict( hashkey=resource.hashkey, name=resource.name, type=resource.type, settings=resource.settings, owner_scope=res_scope, owner_hashkey=owner_key, views=[v.hashkey for v in resource.views], permissions=permissions, current_view=resource.current_view, parents=[r.hashkey for r in resource.parents], layout=layout, ) if find_related: related = [] context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) for r in resource.related: if manager.check_permissions(r, "view"): related.append(r) vals["related"] = [self.convert(scope, hashkey, r, find_related=find_related) for r in related] return vals
def get(self, scope, hashkey): from core.plugins.loader import plugins context, mod = get_context_for_scope(scope, hashkey) user_views = [] scope_installed = [p.hashkey for p in mod.plugins] for key in plugins: p = plugins[key] views = p.views for v in views: context.plugin = p manager = ViewManager(context) data = manager.get_meta(v.hashkey) data['url'] = self.get_url(scope, hashkey, p.hashkey, v.hashkey) data['installed'] = False data['plugin'] = p.hashkey if p.hashkey in scope_installed: data['installed'] = True user_views.append(data) return user_views
def get(self, scope, hashkey, resource_hashkey): context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) model, model_settings = manager.get_resource(resource_hashkey) return self.convert(scope, hashkey, model, find_related=True)
def get_manager(self, scope, hashkey, view_hashkey): plugin = self.get_plugin(view_hashkey) context, mod = get_context_for_scope(scope, hashkey) context.plugin = PluginProxy(hashkey=plugin.hashkey, name="") manager = PluginManager(context) return manager
def patch(self, scope, hashkey, resource_hashkey): settings = get_data() context, mod = get_context_for_scope(scope, hashkey) manager = ResourceManager(context) model = manager.update_resource(resource_hashkey, settings) return self.convert(scope, hashkey, model)
def get_runner(self, scope, hashkey): context, mod = get_context_for_scope(scope, hashkey) runner = PluginActionRunner(context) return runner