Example #1
0
def _upgrade_tags(call: APICall, tags: Sequence, system_tags: Sequence):
    if tags is not None and not system_tags:
        service_name = call.endpoint_name.partition(".")[0]
        entity = service_name[:-1] if service_name.endswith(
            "s") else service_name
        return partition_tags(entity, tags)

    return tags, system_tags
Example #2
0
def upgrade_tags(entity: str, document: dict):
    """
    If only 'tags' is present in the fields then extract
    the system tags from it to a separate field 'system_tags'
    """
    tags = document.get("tags")
    if tags is not None and not document.get("system_tags"):
        user_tags, system_tags = partition_tags(entity, tags)
        document["tags"] = user_tags
        document["system_tags"] = system_tags
Example #3
0
    def testPartition(self):
        tags, system_tags = partition_tags("project", ["test"])
        self.assertTagsEqual(tags, ["test"])
        self.assertTagsEqual(system_tags, [])

        tags, system_tags = partition_tags("project", ["test", "archived"])
        self.assertTagsEqual(tags, ["test"])
        self.assertTagsEqual(system_tags, ["archived"])

        tags, system_tags = partition_tags("project", ["test", "archived"],
                                           ["custom"])
        self.assertTagsEqual(tags, ["test"])
        self.assertTagsEqual(system_tags, ["archived", "custom"])

        tags, system_tags = partition_tags(
            "task", ["test", "development", "annotator20", "Annotation"])
        self.assertTagsEqual(tags, ["test"])
        self.assertTagsEqual(system_tags,
                             ["development", "annotator20", "Annotation"])
Example #4
0
def migrate_backend(db: Database):
    for name in ("project", "task", "model"):
        collection: Collection = db[name]
        for doc in collection.find(projection=["tags", "system_tags"]):
            tags = doc.get("tags")
            if tags is not None:
                user_tags, system_tags = partition_tags(
                    name, tags, doc.get("system_tags", []))
                collection.update_one(
                    {"_id": doc["_id"]},
                    {"$set": {
                        "system_tags": system_tags,
                        "tags": user_tags
                    }})