Exemple #1
0
    def api_list_bootstraptable_data(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"total":0, "rows": []})

        if request.data:
            data = json_.loads(request.data)
        else:
            data = {}

        LinciArtifact = get_model("linciartifact")
        l = LinciArtifact.all()

        sort = data.get("sort")
        order = data.get("order")
        limit = data.get("limit")
        offset = data.get("offset")
        if sort:
            sort_key = getattr(LinciArtifact.c,sort)
            if order:
                sort_key = getattr(sort_key,order)()
            l = l.order_by(sort_key)
        if limit:
            l = l.limit(limit)
        if offset:
            l = l.offset(offset)
        return json({"total":l.count(), "rows": [i.to_dict() for i in l]})
Exemple #2
0
    def api_list_bootstraptable_data(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"total": 0, "rows": []})

        if request.data:
            data = json_.loads(request.data)
        else:
            data = {}

        LinciArtifact = get_model("linciartifact")
        l = LinciArtifact.all()

        sort = data.get("sort")
        order = data.get("order")
        limit = data.get("limit")
        offset = data.get("offset")
        if sort:
            sort_key = getattr(LinciArtifact.c, sort)
            if order:
                sort_key = getattr(sort_key, order)()
            l = l.order_by(sort_key)
        if limit:
            l = l.limit(limit)
        if offset:
            l = l.offset(offset)
        return json({"total": l.count(), "rows": [i.to_dict() for i in l]})
Exemple #3
0
    def api_new(self):
        if not functions.linci_artifact_has_permission("linci_artifact_new"):
            return json({"success":False,"msg":"error: no permission"})
        asite = request.values.get("asite")
        aindex = request.values.get("aindex")
        if not asite:
            return json({"success":False,"msg":"error: parameter 'asite' needed"})
        asite = asite.upper()
        local_site = (asite == settings.LINCI.artifact_site)
        if local_site:
            if aindex:
                return json({"success":False,"msg":"error: local artifact creation don't accept aindex parameter"})
            else:
                aindex = self._get_new_index()
        else:
            if not aindex:
                return json({"success":False,"msg":"error: non-local artifact creation need aindex parameter"})
            try:
                aindex = int(aindex)
            except ValueError as e:
                return json({"success":False,"msg":"error: aindex not integer"})

        LinciArtifact = get_model("linciartifact")
        linciartifact = LinciArtifact(asite = asite,aindex = aindex)
        ret = linciartifact.save()
        if ret:
            return json({"success":True,"msg":"new artifact '%s-%s' OK"%(linciartifact.asite,linciartifact.aindex)})
        else:
            json({"success":False,"msg":"error: unknown error when create new artifact"})
Exemple #4
0
    def api_get(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"success":False,"msg":"error: have no permission"})
        item = self._get_artifact_item()
        if not item:
            return json({"success":False,"msg":"error: artifact not found"})

        d = item.to_dict()
        perm_update = functions.linci_artifact_has_permission("linci_artifact_update")
        d["aid"] = "%s-%s"%(d["asite"],d["aindex"])
        sid,sort_num,tclass = functions.get_linci_artifact_type(item.type)
        d["type_label"] = tclass.name
        d["action_fix"] = (not item.fixed) and item.ready and perm_update
        d["action_set_ready"] = (not item.ready) and perm_update

        return json({"success":True,"item":d})
Exemple #5
0
    def api_artifactfile_download(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({
                "success": False,
                "msg": "have no permission"
            },
                        status=403)

        not_found_response = json({
            "success": False,
            "msg": "not found"
        },
                                  status=404)

        id_ = request.values.get("id")
        if not id_:
            return not_found_response

        LinciArtifactFile = get_model("linciartifactfile")
        afile = LinciArtifactFile.get(int(id_))
        if not afile:
            return not_found_response

        real_filename = os.path.join(afile.artifact.get_artifact_dpath(),
                                     afile.store_path)
        filename = os.path.basename(afile.path)

        if not os.path.isfile(real_filename):
            return not_found_response

        return filedown(request.environ,
                        filename,
                        cache=False,
                        real_filename=real_filename,
                        action="download")
Exemple #6
0
    def api_new(self):
        if not functions.linci_artifact_has_permission("linci_artifact_new"):
            return json({"success": False, "msg": "error: no permission"})
        asite = request.values.get("asite", settings.LINCI.artifact_site)
        aindex = request.values.get("aindex")
        atype = request.values.get("atype", "default")
        if not asite:
            return json({
                "success": False,
                "msg": "error: parameter 'asite' needed"
            })
        asite = asite.upper()
        local_site = (asite == settings.LINCI.artifact_site)
        if local_site:
            if aindex:
                return json({
                    "success":
                    False,
                    "msg":
                    "error: local artifact creation don't accept aindex parameter"
                })
            else:
                aindex = self._get_new_index()
        else:
            if not aindex:
                return json({
                    "success":
                    False,
                    "msg":
                    "error: non-local artifact creation need aindex parameter"
                })
            try:
                aindex = int(aindex)
            except ValueError as e:
                return json({
                    "success": False,
                    "msg": "error: aindex not integer"
                })
        if not settings.LINCI_ARTIFACT_TYPE.get(atype):
            return json({
                "success": False,
                "msg": "error: bad artifact type %s" % (atype)
            })

        LinciArtifact = get_model("linciartifact")
        linciartifact = LinciArtifact(asite=asite, aindex=aindex, type=atype)
        ret = linciartifact.save()
        if ret:
            aid = '%s-%s' % (linciartifact.asite, linciartifact.aindex)
            return json({
                "success": True,
                "aid": aid,
                "msg": "new artifact '%s' OK" % (aid)
            })
        else:
            json({
                "success": False,
                "msg": "error: unknown error when create new artifact"
            })
Exemple #7
0
    def api_set_ready(self):
        if not functions.linci_artifact_has_permission("linci_artifact_update"):
            return json({"success":False,"msg":"error: have no permission"})

        item = self._get_artifact_item()
        item.ready = True
        item.save()

        return json({"success":True,"msg":"artifact set ready OK"})
Exemple #8
0
    def api_set_ready(self):
        if not functions.linci_artifact_has_permission("linci_artifact_update"):
            return json({"success":False,"msg":"error: have no permission"})

        item = self._get_artifact_item()
        item.ready = bool(request.values.get("ready","true").lower()=="true")
        item.save()

        return json({"success":True,"msg":"artifact set ready OK"})
Exemple #9
0
    def api_fix(self):
        if not functions.linci_artifact_has_permission(
                "linci_artifact_update"):
            return json({"success": False, "msg": "error: have no permission"})

        item = self._get_artifact_item()
        item.fixed = True
        item.save()

        return json({"success": True, "msg": "artifact fix OK"})
Exemple #10
0
    def api_set_ready(self):
        if not functions.linci_artifact_has_permission(
                "linci_artifact_update"):
            return json({"success": False, "msg": "error: have no permission"})

        item = self._get_artifact_item()
        item.ready = bool(
            request.values.get("ready", "true").lower() == "true")
        item.save()

        return json({"success": True, "msg": "artifact set ready OK"})
Exemple #11
0
    def api_get(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"success":False,"msg":"error: have no permission"})
        item = self._get_artifact_item()
        if not item:
            return json({"success":False,"msg":"error: artifact not found"})

        d = item.to_dict()
        perm_update = functions.linci_artifact_has_permission("linci_artifact_update")
        d["aid"] = "%s-%s"%(d["asite"],d["aindex"])
        tclass = functions.get_linci_artifact_scheme_class(item.type)
        d["type_label"] = tclass.name
        d["action_fix"] = (not item.fixed) and item.ready and perm_update
        d["action_set_ready"] = (not item.ready) and perm_update

        files = request.values.get("files","false")
        if files=="true":
            LinciArtifactFile = get_model("linciartifactfile")
            l = LinciArtifactFile.filter(LinciArtifactFile.c.artifact==item.id)
            d["files"] = [i.to_dict() for i in l]

        return json({"success":True,"item":d})
Exemple #12
0
    def api_get(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"success": False, "msg": "error: have no permission"})
        item = self._get_artifact_item()
        if not item:
            return json({"success": False, "msg": "error: artifact not found"})

        d = item.to_dict()
        perm_update = functions.linci_artifact_has_permission(
            "linci_artifact_update")
        d["aid"] = "%s-%s" % (d["asite"], d["aindex"])
        tclass = functions.get_linci_artifact_scheme_class(item.type)
        d["type_label"] = tclass.name
        d["action_fix"] = (not item.fixed) and item.ready and perm_update
        d["action_set_ready"] = (not item.ready) and perm_update

        files = request.values.get("files", "false")
        if files == "true":
            LinciArtifactFile = get_model("linciartifactfile")
            l = LinciArtifactFile.filter(
                LinciArtifactFile.c.artifact == item.id)
            d["files"] = [i.to_dict() for i in l]

        return json({"success": True, "item": d})
Exemple #13
0
    def api_artifactfile_list_bootstraptable_data(self):
        from uliweb.utils.common import convert_bytes

        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"total": 0, "rows": []})

        if request.data:
            data = json_.loads(request.data)
        else:
            data = {}

        LinciArtifactFile = get_model("linciartifactfile")
        l = LinciArtifactFile.all()

        sort = data.get("sort")
        order = data.get("order")
        limit = data.get("limit")
        offset = data.get("offset")
        item_id = data.get("item_id")

        if not item_id:
            return json({"total": 0, "rows": []})
        l = l.filter(LinciArtifactFile.c.artifact == item_id)
        if sort:
            if sort == "size_str":
                sort = "size"
            sort_key = getattr(LinciArtifactFile.c, sort)
            if order:
                sort_key = getattr(sort_key, order)()
            l = l.order_by(sort_key)
        if limit:
            l = l.limit(limit)
        if offset:
            l = l.offset(offset)

        def get_info(i):
            d = i.to_dict()
            d["size_str"] = convert_bytes(i.size)
            return d

        return json({"total": l.count(), "rows": [get_info(i) for i in l]})
Exemple #14
0
    def api_artifactfile_download(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"success":False,"msg":"have no permission"}, status=403)

        not_found_response = json({"success":False,"msg":"not found"}, status=404)

        id_ = request.values.get("id")
        if not id_:
            return not_found_response

        LinciArtifactFile = get_model("linciartifactfile")
        afile = LinciArtifactFile.get(int(id_))
        if not afile:
            return not_found_response

        real_filename = os.path.join(afile.artifact.get_artifact_dpath(),afile.store_path)
        filename = os.path.basename(afile.path)

        if not os.path.isfile(real_filename):
            return not_found_response

        return filedown(request.environ,filename,cache=False,real_filename=real_filename,action="download")
Exemple #15
0
    def api_artifactfile_list_bootstraptable_data(self):
        from uliweb.utils.common import convert_bytes

        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"total":0, "rows": []})

        if request.data:
            data = json_.loads(request.data)
        else:
            data = {}

        LinciArtifactFile = get_model("linciartifactfile")
        l = LinciArtifactFile.all()

        sort = data.get("sort")
        order = data.get("order")
        limit = data.get("limit")
        offset = data.get("offset")
        item_id = data.get("item_id")

        if not item_id:
            return json({"total":0, "rows": []})
        l = l.filter(LinciArtifactFile.c.artifact==item_id)
        if sort:
            if sort=="size_str":
                sort = "size"
            sort_key = getattr(LinciArtifactFile.c,sort)
            if order:
                sort_key = getattr(sort_key,order)()
            l = l.order_by(sort_key)
        if limit:
            l = l.limit(limit)
        if offset:
            l = l.offset(offset)
        def get_info(i):
            d = i.to_dict()
            d["size_str"] = convert_bytes(i.size)
            return d
        return json({"total":l.count(), "rows": [get_info(i) for i in l]})
Exemple #16
0
 def list(self):
     if not functions.linci_artifact_has_permission("linci_artifact_read"):
         errmsg = "no permission"
     else:
         errmsg = ""
     return {"errmsg":errmsg}
Exemple #17
0
 def list(self):
     if not functions.linci_artifact_has_permission("linci_artifact_read"):
         errmsg = "no permission"
     else:
         errmsg = ""
     return {"errmsg": errmsg}