示例#1
0
def validate_root_versions(node: SchemaNode,  value: list):
    """Validate root versions."""
    for root_version in value:
        if not IItemVersion.providedBy(root_version):
            msg = 'This resource is not a valid ' \
                  'root version: {}'.format(resource_path(root_version))
            raise Invalid(node, msg=msg)
示例#2
0
def validate_root_versions(node: SchemaNode, value: list):  # pragma: no cover
    """Validate root versions."""
    for root_version in value:
        if not IItemVersion.providedBy(root_version):
            msg = 'This resource is not a valid ' \
                  'root version: {}'.format(resource_path(root_version))
            raise Invalid(node, msg=msg)
示例#3
0
def _is_first_version(change: ChangelogMetadata, registry) -> bool:
    is_version = IItemVersion.providedBy(change.resource)
    if is_version:
        follows = registry.content.get_sheet_field(change.resource,
                                                   IVersionable,
                                                   'follows')
        return follows == []
    else:
        return False
示例#4
0
def download_external_picture_for_created(event: IResourceCreatedAndAdded):
    """Download external_picture_url for new resources."""
    if IItemVersion.providedBy(event.object):
        return  # download_external_picture_for_version takes care for it
    registry = event.registry
    new_url = registry.content.get_sheet_field(event.object,
                                               IImageReference,
                                               'external_picture_url')
    _download_picture_url(event.object, '', new_url, registry)
示例#5
0
 def _only_version_zero_exists(self, context: object,
                               meta: ResourceMetadata) -> bool:
     only_first_version = False
     is_item_version = meta.iresource.isOrExtends(IItemVersion)
     has_item_parent = IItem.providedBy(context)
     if has_item_parent and is_item_version:
         children = context.values()
         versions = [x for x in children if IItemVersion.providedBy(x)]
         only_first_version = len(versions) == 1
     return only_first_version
示例#6
0
 def _only_version_zero_exists(self, context: object, meta:
                               ResourceMetadata) -> bool:
     only_first_version = False
     is_item_version = meta.iresource.isOrExtends(IItemVersion)
     has_item_parent = IItem.providedBy(context)
     if has_item_parent and is_item_version:
         children = context.values()
         versions = [x for x in children if IItemVersion.providedBy(x)]
         only_first_version = len(versions) == 1
     return only_first_version
示例#7
0
    def test_create(self, context, registry, creator):
        from adhocracy_core.sheets.metadata import IMetadata
        from adhocracy_core.sheets.tags import ITags
        item = self.make_one(context, registry, creator=creator)

        version0 = item['VERSION_0000000']
        assert IItemVersion.providedBy(version0)
        tags_sheet = registry.content.get_sheet(item, ITags)
        first = tags_sheet.get()['FIRST']
        last = tags_sheet.get()['LAST']
        assert first == version0
        assert last == version0
        meta_sheet = registry.content.get_sheet(version0, IMetadata)
        assert creator == meta_sheet.get()['creator']
示例#8
0
    def test_create(self, context, registry, creator):
        from adhocracy_core.sheets.metadata import IMetadata
        from adhocracy_core.sheets.tags import ITags
        item = self.make_one(context, registry, creator=creator)

        version0 = item['VERSION_0000000']
        assert IItemVersion.providedBy(version0)
        tags_sheet = registry.content.get_sheet(item, ITags)
        first = tags_sheet.get()['FIRST']
        last = tags_sheet.get()['LAST']
        assert first == version0
        assert last == version0
        meta_sheet = registry.content.get_sheet(version0, IMetadata)
        assert creator == meta_sheet.get()['creator']
示例#9
0
def validate_post_root_versions(context, request: Request):
    """Check and transform the 'root_version' paths to resources."""
    # TODO: make this a colander validator and move to schema.py
    # use the catalog to find IItemversions
    root_versions = request.validated.get("root_versions", [])
    valid_root_versions = []
    for root in root_versions:
        if not IItemVersion.providedBy(root):
            error = "This resource is not a valid " "root version: {}".format(request.resource_url(root))
            request.errors.append(error_entry("body", "root_versions", error))
            continue
        valid_root_versions.append(root)

    request.validated["root_versions"] = valid_root_versions
示例#10
0
def validate_post_root_versions(context, request: Request):
    """Check and transform the 'root_version' paths to resources."""
    # TODO: make this a colander validator and move to schema.py
    root_versions = request.validated.get('root_versions', [])
    valid_root_versions = []
    for root in root_versions:
        if not IItemVersion.providedBy(root):
            error = 'This resource is not a valid ' \
                    'root version: {}'.format(request.resource_url(root))
            request.errors.append(error_entry('body', 'root_versions', error))
            continue
        valid_root_versions.append(root)

    request.validated['root_versions'] = valid_root_versions
示例#11
0
def _get_entry_name(change: ChangelogMetadata) -> str:
    if change.created:
        if IItemVersion.providedBy(change.resource):
            return ActivityType.update
        else:
            return ActivityType.add
    elif change.visibility == VisibilityChange.concealed:
        return ActivityType.remove
    elif change.modified:
        if _is_workflow_state_change(change):
            return ActivityType.transition
        else:
            return ActivityType.update
    else:  # pragma: no cover
        raise ValueError('Invalid change state', change)
示例#12
0
def validate_post_root_versions(context, request: Request):
    """Check and transform the 'root_version' paths to resources."""
    # TODO: make this a colander validator and move to schema.py
    # use the catalog to find IItemversions
    root_versions = request.validated.get('root_versions', [])
    valid_root_versions = []
    for root in root_versions:
        if not IItemVersion.providedBy(root):
            error = 'This resource is not a valid ' \
                    'root version: {}'.format(request.resource_url(root))
            request.errors.append(error_entry('body', 'root_versions', error))
            continue
        valid_root_versions.append(root)

    request.validated['root_versions'] = valid_root_versions
示例#13
0
    def test_create(self, context, registry):
        from adhocracy_core.sheets.tags import ITag as ITagS

        item = self.make_one(context, registry)

        version0 = item['VERSION_0000000']
        assert IItemVersion.providedBy(version0)
        first_tag = item['FIRST']
        assert ITag.providedBy(first_tag)
        last_tag = item['LAST']
        assert ITag.providedBy(last_tag)
        first_targets = context.__graph__.get_references_for_isheet(first_tag, ITagS)['elements']
        assert first_targets == [version0]
        last_targets = context.__graph__.get_references_for_isheet(last_tag, ITagS)['elements']
        assert last_targets == [version0]
示例#14
0
    def _get_metadata(self, resource: IResource, creator: IResource,
                      registry: Registry) -> dict:
        now = get_modification_date(registry)
        creator = creator if creator is not None else None
        metadata = {'creator': creator,
                    'creation_date': now,
                    'item_creation_date': now,
                    'modified_by': creator,
                    'modification_date': now,
                    }

        item = find_interface(resource, IItem)
        if IItemVersion.providedBy(resource) and item is not None:
            item_sheet = get_sheet(item, IMetadata, registry=registry)
            item_creation_date = item_sheet.get()['creation_date']
            metadata['item_creation_date'] = item_creation_date
        return metadata
示例#15
0
    def test_create(self, context, registry):
        from adhocracy_core.sheets.tags import ITag as ITagS

        item = self.make_one(context, registry)

        version0 = item['VERSION_0000000']
        assert IItemVersion.providedBy(version0)
        first_tag = item['FIRST']
        assert ITag.providedBy(first_tag)
        last_tag = item['LAST']
        assert ITag.providedBy(last_tag)
        first_targets = context.__graph__.get_references_for_isheet(
            first_tag, ITagS)['elements']
        assert first_targets == [version0]
        last_targets = context.__graph__.get_references_for_isheet(
            last_tag, ITagS)['elements']
        assert last_targets == [version0]
示例#16
0
def remove_tag_resources(root, registry):  # pragma: no cover
    """Remove all ITag resources, create ITags sheet references instead."""
    from adhocracy_core.sheets.tags import ITags
    from adhocracy_core.interfaces import IItem
    catalogs = find_service(root, 'catalogs')
    items = _search_for_interfaces(catalogs, IItem)
    items_with_tags = [x for x in items if 'FIRST' in x]
    count = len(items_with_tags)
    for index, item in enumerate(items_with_tags):
        logger.info('Migrate tag resource {0} of {1}'.format(index + 1, count))
        del item['FIRST']
        del item['LAST']
        version_names = [x[0] for x in item.items()
                         if IItemVersion.providedBy(x[1])]
        version_names.sort()  # older version names are lower then younger ones
        first_version = version_names[0]
        last_version = version_names[-1]
        tags_sheet = registry.content.get_sheet(item, ITags)
        tags_sheet.set({'LAST': item[last_version],
                        'FIRST': item[first_version]})
示例#17
0
def remove_tag_resources(root, registry):  # pragma: no cover
    """Remove all ITag resources, create ITags sheet references instead."""
    from adhocracy_core.sheets.tags import ITags
    from adhocracy_core.interfaces import IItem
    catalogs = find_service(root, 'catalogs')
    items = _search_for_interfaces(catalogs, IItem)
    items_with_tags = [x for x in items if 'FIRST' in x]
    count = len(items_with_tags)
    for index, item in enumerate(items_with_tags):
        logger.info('Migrate tag resource {0} of {1}'.format(index + 1, count))
        del item['FIRST']
        del item['LAST']
        version_names = [x[0] for x in item.items()
                         if IItemVersion.providedBy(x[1])]
        version_names.sort()  # older version names are lower then younger ones
        first_version = version_names[0]
        last_version = version_names[-1]
        tags_sheet = registry.content.get_sheet(item, ITags)
        tags_sheet.set({'LAST': item[last_version],
                        'FIRST': item[first_version]})
示例#18
0
 def test_create(self, config, context):
     version_0 = self.make_one(config, context)
     assert IItemVersion.providedBy(version_0)
示例#19
0
 def _dispatch_created_event(self, resource: IResource):
     if IItemVersion.providedBy(resource):
         self._notify_new_version(resource.__parent__, resource)
     else:
         self._notify_new_child(resource.__parent__, resource)
示例#20
0
 def test_create(self, registry, item):
     version_0 = self.make_one(registry, item)
     assert IItemVersion.providedBy(version_0)
示例#21
0
 def _get_first_version(self, item: IItem) -> IItemVersion:
     for child in item.values():
         if IItemVersion.providedBy(child):
             return child
示例#22
0
 def _creating_new_version(self) -> bool:
     iresource = self.request.validated['content_type']
     return IItemVersion.isEqualOrExtendedBy(iresource)
示例#23
0
 def _get_first_version(self, item: IItem) -> IItemVersion:
     for child in item.values():
         if IItemVersion.providedBy(child):
             return child
示例#24
0
 def test_create(self, registry, item):
     version_0 = self.make_one(registry, item)
     assert IItemVersion.providedBy(version_0)
 def test_create(self, config, context):
     version_0 = self.make_one(config, context)
     assert IItemVersion.providedBy(version_0)
示例#26
0
def _get_object(change: ChangelogMetadata) -> IResource:
    if IItemVersion.providedBy(change.resource):
        item = find_interface(change.resource, IItem)
        return item
    else:
        return change.resource
示例#27
0
 def _dispatch_created_event(self, resource: IResource):
     if IItemVersion.providedBy(resource):
         self._notify_new_version(resource.__parent__, resource)
     else:
         self._notify_new_child(resource.__parent__, resource)