예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 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
예제 #4
0
 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 {}
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
    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 {}
예제 #8
0
    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
예제 #9
0
 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
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
    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
예제 #14
0
 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
예제 #15
0
    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
예제 #16
0
 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)
예제 #17
0
 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
예제 #18
0
 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)
예제 #19
0
 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)
예제 #20
0
 def get_runner(self, scope, hashkey):
     context, mod = get_context_for_scope(scope, hashkey)
     runner = PluginActionRunner(context)
     return runner
예제 #21
0
 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)