Exemplo n.º 1
0
    def test_call_with_not_creatable_appstructs_data(self, resource_meta,
                                                     registry, mock_sheet):
        meta = resource_meta._replace(iresource=IResource,
                                      basic_sheets=(ISheetY,))
        register_sheet(None, mock_sheet, registry, ISheetY)
        mock_sheet.meta = sheet_meta._replace(creatable=False)
        appstructs = {ISheetY.__identifier__: {'count': 0}}

        self.make_one(meta)(appstructs=appstructs)

        assert not mock_sheet.set.called
Exemplo n.º 2
0
    def test_call_with_not_creatable_appstructs_data(self, resource_meta,
                                                     registry, mock_sheet):
        meta = resource_meta._replace(iresource=IResource,
                                      basic_sheets=(ISheetY, ))
        register_sheet(None, mock_sheet, registry, ISheetY)
        mock_sheet.meta = sheet_meta._replace(creatable=False)
        appstructs = {ISheetY.__identifier__: {'count': 0}}

        self.make_one(meta)(appstructs=appstructs)

        assert not mock_sheet.set.called
Exemplo n.º 3
0
def mock_sheet() -> Mock:
    """Mock :class:`adhocracy_core.sheets.GenericResourceSheet`."""
    from adhocracy_core.sheets import sheet_meta
    from adhocracy_core.interfaces import ISheet
    # Better would be spec=GenericResourceSheet for the mock object;
    # however this fails if the object is deepcopied.
    sheet = Mock()
    sheet.meta = sheet_meta._replace(isheet=ISheet, schema_class=MappingSchema)
    sheet.schema = MappingSchema()
    sheet.get.return_value = {}
    return sheet
Exemplo n.º 4
0
def mock_sheet() -> Mock:
    """Mock :class:`adhocracy_core.sheets.GenericResourceSheet`."""
    from adhocracy_core.sheets import sheet_meta
    from adhocracy_core.interfaces import ISheet
    # Better would be spec=GenericResourceSheet for the mock object;
    # however this fails if the object is deepcopied.
    sheet = Mock()
    sheet.meta = sheet_meta._replace(isheet=ISheet,
                                     schema_class=colander.MappingSchema)
    sheet.schema = colander.MappingSchema()
    sheet.get.return_value = {}
    return sheet
Exemplo n.º 5
0
    mapping = request.registry.getMultiAdapter((context, request),
                                               IEmbedCodeConfig)
    code = render('adhocracy_core:templates/embed_code.html.mako', mapping)
    return code


class EmbedSchema(MappingSchema):
    """Embed sheet data structure.

    `embed_code`: html code to embed the `context` resource in web pages.
    `external_url`: canonical URL that embeds the `context` resource.
    """

    embed_code = Text(readonly=True,
                      default=deferred_default_embed_code,
                      )
    external_url = URL()


embed_meta = sheet_meta._replace(isheet=IEmbed,
                                 schema_class=EmbedSchema,
                                 )


def includeme(config):
    """Register sheets and embed code config adapter."""
    add_sheet_to_registry(embed_meta, config.registry)
    config.registry.registerAdapter(embed_code_config_adapter,
                                    (IResource, IRequest),
                                    IEmbedCodeConfig)
Exemplo n.º 6
0
    source_isheet = ITags
    source_isheet_field = 'FIRST'
    target_isheet = IVersionable


class TagsLastReference(SheetToSheet):
    """Tags sheet last reference."""

    source_isheet = ITags
    source_isheet_field = 'LAST'
    target_isheet = IVersionable


class TagsSchema(colander.MappingSchema):
    """Tags sheet data structure."""

    LAST = Reference(reftype=TagsLastReference)
    FIRST = Reference(reftype=TagsFirstReference)


tags_meta = sheet_meta._replace(isheet=ITags,
                                schema_class=TagsSchema,
                                editable=False,
                                creatable=False,
                                )


def includeme(config):
    """Register tags sheet."""
    add_sheet_to_registry(tags_meta, config.registry)
Exemplo n.º 7
0
    Ask the validator registered for *object* whether *rate* is valid.
    In this way, `IRateable` subclasses can modify the range of allowed
    ratings by registering their own `IRateValidator` adapter.
    """
    def validator(node, value):
        rate_validator = registry.getAdapter(value['object'], IRateValidator)
        if not rate_validator.validate(value['rate']):
            err = colander.Invalid(node, msg='')
            err['rate'] = rate_validator.helpful_error_message()
            raise err
    return validator


rate_meta = sheet_meta._replace(isheet=IRate,
                                schema_class=RateSchema,
                                sheet_class=AttributeResourceSheet,
                                create_mandatory=True)


class CanRateSchema(colander.MappingSchema):
    """CanRate sheet data structure."""


can_rate_meta = sheet_meta._replace(isheet=ICanRate,
                                    schema_class=CanRateSchema)


class RateableSchema(colander.MappingSchema):
    """Commentable sheet data structure.

    `post_pool`: Pool to post new :class:`adhocracy_sample.resource.IRate`.
Exemplo n.º 8
0
class IProposal(ISheet):
    """Marker interface for the BPlan proposal sheet."""


class ProposalSchema(colander.MappingSchema):
    """Data structure for plan stellungsname information."""

    name = SingleLine(missing=colander.required)
    street_number = SingleLine(missing=colander.required)
    postal_code_city = SingleLine(missing=colander.required)
    email = SingleLine(validator=colander.Email())
    statement = Text(missing=colander.required,
                     validator=colander.Length(max=17500))


proposal_meta = sheet_meta._replace(isheet=IProposal,
                                    schema_class=ProposalSchema)


class IWorkflowAssignment(workflow.IWorkflowAssignment):
    """Marker interface for the bplan workflow assignment sheet."""


deprecated('IWorkflowAssignment',
           'Backward compatible code use IWorkflowAssignment instead')


class IPrivateWorkflowAssignment(workflow.IWorkflowAssignment):
    """Marker interface for the bplan private workflow assignment sheet."""


deprecated('IPrivateWorkflowAssignment',
Exemplo n.º 9
0
    source_isheet = IDocument
    source_isheet_field = 'elements'
    target_isheet = ISection


class DocumentSchema(MappingSchema):
    """Document sheet data structure.

    `elements`: structural subelements like sections
    """

    elements = UniqueReferences(reftype=DocumentElementsReference)


document_meta = sheet_meta._replace(
    isheet=IDocument,
    schema_class=DocumentSchema,
)


class ParagraphSchema(MappingSchema):
    """Paragraph Section sheet data structure.

    `content`:  Text
    `documents`: Documents referencing this paragraph
    """

    text = Text()
    documents = UniqueReferences(reftype=DocumentElementsReference,
                                 readonly=True,
                                 backref=True)
Exemplo n.º 10
0
    source_isheet = IPool
    source_isheet_field = 'elements'
    target_isheet = ISheet


class PoolSchema(MappingSchema):
    """Pool sheet data structure.

    `elements`: children of this resource (object hierarchy).
    """

    elements = UniqueReferences(
        reftype=PoolElementsReference,
        readonly=True,
    )


pool_meta = sheet_meta._replace(
    isheet=IPool,
    schema_class=PoolSchema,
    sheet_class=PoolSheet,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register adapter."""
    add_sheet_to_registry(pool_meta, config.registry)
Exemplo n.º 11
0
    def _get_schema_for_cstruct(self, request, params: dict):
        workflow = self.registry.content.get_workflow(self.context)
        schema = self.schema.bind(context=self.context,
                                  registry=self.registry,
                                  workflow=workflow,
                                  request=request)
        return schema

    def _store_data(self, appstruct: dict):
        if 'workflow_state' in appstruct:
            self._set_state(appstruct['workflow_state'])
            del appstruct['workflow_state']
        super()._store_data(appstruct)

    def _set_state(self, name: str):
        """Do transition to state `name`, don`t check user permissions."""
        workflow = self.get()['workflow']
        request = get_current_request() or DummyRequest()  # ease testing
        workflow.transition_to_state(self.context, request, to_state=name)


workflow_meta = sheet_meta._replace(isheet=IWorkflowAssignment,
                                    schema_class=WorkflowAssignmentSchema,
                                    sheet_class=WorkflowAssignmentSheet,
                                    permission_edit='do_transition')


def includeme(config):
    """Add sheet."""
    add_sheet_to_registry(workflow_meta, config.registry)
Exemplo n.º 12
0
from adhocracy_core.sheets import sheet_meta


class IHasAssetPool(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for resources that have an asset pool."""


class HasAssetPoolSchema(colander.MappingSchema):
    """Data structure pointing to an asset pool."""

    asset_pool = PostPool(iresource_or_service_name='assets')


has_asset_pool_meta = sheet_meta._replace(
    isheet=IHasAssetPool,
    schema_class=HasAssetPoolSchema,
    editable=False,
    creatable=False,
)


class IAssetMetadata(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for asset metadata."""


class AssetReference(SheetToSheet):
    """Reference to an asset."""

    target_isheet = IAssetMetadata


class AssetMetadataSchema(colander.MappingSchema):
Exemplo n.º 13
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import MappingSchema


ANONYMIZE_PERMISSION = 'manage_anonymized'


class IAllowAddAnonymized(ISheet):
    """Marker interface for the allow_add_anonymized sheet."""


class AllowAddAnonymizedSchema(MappingSchema):
    """AllowAddAnonymized sheet data structure."""


allow_add_anonymized_meta = sheet_meta._replace(
    isheet=IAllowAddAnonymized,
    schema_class=AllowAddAnonymizedSchema,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register sheet and permission."""
    add_sheet_to_registry(allow_add_anonymized_meta, config.registry)
    # register free standing permission to validate permission names
    config.add_permission(ANONYMIZE_PERMISSION)
Exemplo n.º 14
0
    return get_choices_by_interface(IFollowable, context, request)


class NotificationSchema(MappingSchema):
    """Notification sheet data structure.

    `follow_resources`: Follow activities these resources are involved in.
    """

    follow_resources = UniqueReferences(reftype=NotificationFollowReference,
                                        choices_getter=get_follow_choices)
    email_notification_enabled = Boolean(default=True, missing=drop)


notification_meta = sheet_meta._replace(isheet=INotification,
                                        schema_class=NotificationSchema,
                                        permission_edit='edit_notification',
                                        )


followable_meta = sheet_meta._replace(isheet=IFollowable,
                                      editable=False,
                                      creatable=False,
                                      )


def includeme(config):
    """Register sheet."""
    add_sheet_to_registry(notification_meta, config.registry)
    add_sheet_to_registry(followable_meta, config.registry)
Exemplo n.º 15
0
    """Reference from the activity to its target."""

    source_isheet = IActivity
    source_isheet_field = 'target'
    target_isheet = ISheet


class ActivitySchema(MappingSchema):
    """Activity entry."""

    subject = Reference(reftype=SubjectReference)
    type = SingleLine(validator=OneOf(
        [activity_type.value for activity_type in ActivityType]))
    object = Reference(reftype=ObjectReference)
    target = Reference(reftype=TargetReference)
    name = SingleLine()
    published = DateTime()


activity_meta = sheet_meta._replace(
    isheet=IActivity,
    schema_class=ActivitySchema,
    editable=False,
    creatable=True,
)


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(activity_meta, config.registry)
Exemplo n.º 16
0
    source_isheet = ITag
    source_isheet_field = 'elements'
    target_isheet = IVersionable


class TagSchema(colander.MappingSchema):
    """Tag sheet data structure.

    `elements`: Resources with this Tag
    """

    elements = UniqueReferences(reftype=TagElementsReference)


tag_meta = sheet_meta._replace(
    isheet=ITag,
    schema_class=TagSchema,
)


class ITags(ISheet):
    """Marker interface for the tag sheet."""


class TagsElementsReference(SheetToSheet):
    """Tags sheet elements reference."""

    source_isheet = ITags
    source_isheet_field = 'elements'
    target_isheet = ITag

Exemplo n.º 17
0
    source_isheet_field = 'FIRST'
    target_isheet = IVersionable


class TagsLastReference(SheetToSheet):
    """Tags sheet last reference."""

    source_isheet = ITags
    source_isheet_field = 'LAST'
    target_isheet = IVersionable


class TagsSchema(MappingSchema):
    """Tags sheet data structure."""

    LAST = Reference(reftype=TagsLastReference)
    FIRST = Reference(reftype=TagsFirstReference)


tags_meta = sheet_meta._replace(
    isheet=ITags,
    schema_class=TagsSchema,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register tags sheet."""
    add_sheet_to_registry(tags_meta, config.registry)
Exemplo n.º 18
0

class IHeardFrom(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for heard from fields."""


class TitleSchema(colander.MappingSchema):
    """Data structure for the proposal title."""

    title = SingleLine(validator=colander.Length(min=1, max=100))


deprecated('TitleSchema', 'moved to adhocracy_core.sheets.title')


title_meta = sheet_meta._replace(isheet=ITitle,
                                 schema_class=TitleSchema)


class UserInfoSchema(colander.MappingSchema):
    """Data structure for information about the proposal submitter."""

    personal_name = SingleLine(missing=colander.required)
    family_name = SingleLine()
    country = ISOCountryCode()


userinfo_meta = sheet_meta._replace(isheet=IUserInfo,
                                    schema_class=UserInfoSchema)


class OrganizationInfoReference(SheetToSheet):
Exemplo n.º 19
0
    source_isheet_field = 'groups'
    target_isheet = IGroup


class GroupSchema(colander.MappingSchema):
    """Group sheet data structure."""

    users = UniqueReferences(readonly=True,
                             backref=True,
                             reftype=PermissionsGroupsReference)
    roles = Roles()


group_meta = sheet_meta._replace(
    isheet=IGroup,
    schema_class=GroupSchema,
    sheet_class=AttributeResourceSheet,
)


@colander.deferred
def deferred_validate_user_name(node: colander.SchemaNode, kw: dict)\
        -> callable:
    """Return validator to check that the user login `name` is unique or None.

    :param kw: dictionary with 'request' key and
               :class:`pyramid.request.Request` object.
               If this is not available the validator is None.
    :raise: colander.Invalid: if name is not unique.
    """
    request = kw.get('request', None)
Exemplo n.º 20
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import ISheetReferenceAutoUpdateMarker
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import Text


class IDescription(ISheet, ISheetReferenceAutoUpdateMarker):

    """Market interface for the description sheet."""


class DescriptionSchema(colander.MappingSchema):

    """Description sheet data structure.

    `description`: a description
    """

    description = Text()


description_meta = sheet_meta._replace(isheet=IDescription,
                                       schema_class=DescriptionSchema,
                                       )


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(description_meta, config.registry)
Exemplo n.º 21
0
    `administrative_level`: administrative division level
    `administrative_division`: administrative division name
    `part_of`: surrounding geographical object
    """

    type = SingleLine(default='MultiPolygon', readonly=True)
    coordinates = MultiPolygon()

    administrative_division = AdministrativeDivisionName()
    part_of = Reference(reftype=PartOfReference)


multipolygon_meta = sheet_meta._replace(
    isheet=IMultiPolygon,
    schema_class=MultiPolygonSchema,
    editable=False,
    create_mandatory=True,
)


class ILocationReference(ISheet):
    """Marker interface for the location reference sheet."""


class LocationReference(SheetToSheet):
    """Reference to a geographical object."""

    source_isheet = ILocationReference
    source_isheet_field = 'location'
    target_isheet = IMultiPolygon
Exemplo n.º 22
0
        if elements:
            err = colander.Invalid(node)
            err['object'] = 'Another rate by the same user already exists'
            raise err

    def _query_registered_object_validator(self, node, value, request):
        registry = request.registry
        rate_validator = registry.getAdapter(value['object'], IRateValidator)
        if not rate_validator.validate(value['rate']):
            err = colander.Invalid(node)
            err['rate'] = rate_validator.helpful_error_message()
            raise err


rate_meta = sheet_meta._replace(isheet=IRate,
                                schema_class=RateSchema,
                                sheet_class=AttributeResourceSheet,
                                create_mandatory=True)


class CanRateSchema(colander.MappingSchema):
    """CanRate sheet data structure."""


can_rate_meta = sheet_meta._replace(isheet=ICanRate,
                                    schema_class=CanRateSchema)


class RateableSchema(colander.MappingSchema):
    """Commentable sheet data structure.

    `post_pool`: Pool to post new :class:`adhocracy_sample.resource.IRate`.
Exemplo n.º 23
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import PostPool


class IHasLogbookPool(ISheet):

    """Marker interface for resources that have a logbook pool."""


class HasLogbookPoolSchema(colander.MappingSchema):

    """Data structure pointing to a logbook pool."""

    logbook_pool = PostPool(iresource_or_service_name='logbook')


has_logbook_pool_meta = sheet_meta._replace(
    isheet=IHasLogbookPool,
    schema_class=HasLogbookPoolSchema,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register sheets, adapters and index views."""
    add_sheet_to_registry(has_logbook_pool_meta, config.registry)
Exemplo n.º 24
0
    """Pool sheet elements reference."""

    source_isheet = IPool
    source_isheet_field = 'elements'
    target_isheet = ISheet


class PoolSchema(colander.MappingSchema):
    """Pool sheet data structure.

    `elements`: children of this resource (object hierarchy).
    """

    elements = UniqueReferences(reftype=PoolElementsReference,
                                readonly=True,
                                )


pool_meta = sheet_meta._replace(
    isheet=IPool,
    schema_class=PoolSchema,
    sheet_class=PoolSheet,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register adapter."""
    add_sheet_to_registry(pool_meta, config.registry)
Exemplo n.º 25
0
    source_isheet_field = 'refers_to'
    target_isheet = ICommentable


class CommentSchema(MappingSchema):
    """Comment sheet data structure.

    `content`:  Text
    """

    refers_to = Reference(reftype=CommentRefersToReference)
    content = Text()
    # TODO add post_pool validator


comment_meta = sheet_meta._replace(isheet=IComment,
                                   schema_class=CommentSchema)


@deferred
def deferred_default_comment_count(node: MappingSchema, kw: dict) -> str:
    """Return comment_count of the current `context` resource."""
    context = kw['context']
    catalogs = find_service(context, 'catalogs')
    return catalogs.get_index_value(context, 'comments')


class CommentableSchema(MappingSchema):
    """Commentable sheet data structure.

    `post_pool`: Pool to post new :class:`adhocracy_sample.resource.IComment`.
    """
Exemplo n.º 26
0
    source_isheet = IDocument
    source_isheet_field = 'elements'
    target_isheet = ISection


class DocumentSchema(colander.MappingSchema):
    """Document sheet data structure.

    `elements`: structural subelements like sections
    """

    elements = UniqueReferences(reftype=DocumentElementsReference)


document_meta = sheet_meta._replace(isheet=IDocument,
                                    schema_class=DocumentSchema,
                                    )


class ParagraphSchema(colander.MappingSchema):
    """Paragraph Section sheet data structure.

    `content`:  Text
    `documents`: Documents referencing this paragraph
    """

    text = Text()
    documents = UniqueReferences(reftype=DocumentElementsReference,
                                 readonly=True,
                                 backref=True)
Exemplo n.º 27
0
    """ Versionable sheet data structure.

    Set/get predecessor (`follows`) and get successor (`followed_by`) versions
    of this resource.
    """

    follows = UniqueReferences(reftype=VersionableFollowsReference,
                               validator=deferred_validate_follows)
    followed_by = UniqueReferences(readonly=True,
                                   backref=True,
                                   reftype=VersionableFollowsReference)


versionable_meta = sheet_meta._replace(
    isheet=IVersionable,
    schema_class=VersionableSchema,
)


class IForkableVersionable(IVersionable):

    """Maker interface for resources that support forking.

    This means that the multiple heads are allowed (the LAST tag can point
    to two or more versions).
    """


forkable_versionable_meta = versionable_meta._replace(
    isheet=IForkableVersionable,
)
Exemplo n.º 28
0
import magic  # noqa


class IHasAssetPool(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for resources that have an asset pool."""


class HasAssetPoolSchema(MappingSchema):
    """Data structure pointing to an asset pool."""

    asset_pool = PostPool(iresource_or_service_name='assets')


has_asset_pool_meta = sheet_meta._replace(
    isheet=IHasAssetPool,
    schema_class=HasAssetPoolSchema,
    editable=False,
    creatable=False,
)


class IAssetMetadata(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for asset metadata."""


class AssetReference(SheetToSheet):
    """Reference to an asset."""

    target_isheet = IAssetMetadata


class AssetMetadataSchema(MappingSchema):
Exemplo n.º 29
0
                                               IEmbedCodeConfig)
    code = render('adhocracy_core:templates/embed_code.html.mako', mapping)
    return code


class EmbedSchema(MappingSchema):
    """Embed sheet data structure.

    `embed_code`: html code to embed the `context` resource in web pages.
    `external_url`: canonical URL that embeds the `context` resource.
    """

    embed_code = Text(
        default=deferred_default_embed_code,
        widget=TextAreaWidget(rows=10),
    )
    external_url = URL()


embed_meta = sheet_meta._replace(
    isheet=IEmbed,
    schema_class=EmbedSchema,
)


def includeme(config):
    """Register sheets and embed code config adapter."""
    add_sheet_to_registry(embed_meta, config.registry)
    config.registry.registerAdapter(embed_code_config_adapter,
                                    (IResource, IRequest), IEmbedCodeConfig)
Exemplo n.º 30
0
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import MappingSchema
from adhocracy_core.schema import Text


class IDescription(ISheet, ISheetReferenceAutoUpdateMarker):
    """Market interface for the description sheet."""


class DescriptionSchema(MappingSchema):
    """Description sheet data structure.

    `short_description`: teaser text for listings, html description etc.
    `description`: a full description
    """

    short_description = Text()
    description = Text()


description_meta = sheet_meta._replace(
    isheet=IDescription,
    schema_class=DescriptionSchema,
)


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(description_meta, config.registry)
Exemplo n.º 31
0
class IProposal(ISheet):
    """Marker interface for the BPlan proposal sheet."""


class ProposalSchema(MappingSchema):
    """Data structure for plan stellungsname information."""

    name = SingleLine(missing=required)
    street_number = SingleLine(missing=required)
    postal_code_city = SingleLine(missing=required)
    email = Email()
    statement = Text(missing=required,
                     validator=Length(max=17500))


proposal_meta = sheet_meta._replace(isheet=IProposal,
                                    schema_class=ProposalSchema)


class IWorkflowAssignment(workflow.IWorkflowAssignment):
    """Marker interface for the bplan workflow assignment sheet."""


deprecated('IWorkflowAssignment',
           'Backward compatible code use IWorkflowAssignment instead')


class IPrivateWorkflowAssignment(workflow.IWorkflowAssignment):
    """Marker interface for the bplan private workflow assignment sheet."""


deprecated('IPrivateWorkflowAssignment',
Exemplo n.º 32
0
               deferred_validate_linear_history_no_fork(node, kw),
               )


class VersionableSchema(MappingSchema):
    """Versionable sheet data structure.

    Set/get predecessor (`follows`) versions of this resource.
    """

    follows = UniqueReferences(reftype=VersionableFollowsReference,
                               validator=deferred_validate_follows)


versionable_meta = sheet_meta._replace(
    isheet=IVersionable,
    schema_class=VersionableSchema,
)


class IForkableVersionable(IVersionable):
    """Maker interface for resources that support forking.

    This means that the multiple heads are allowed (the LAST tag can point
    to two or more versions).
    """


forkable_versionable_meta = versionable_meta._replace(
    isheet=IForkableVersionable,
)
Exemplo n.º 33
0
            del appstruct['workflow_state']
        super()._store_data(appstruct)

    def _get_data_appstruct(self) -> dict:
        """Get data appstruct."""
        appstruct = super()._get_data_appstruct()
        workflow = self.registry.content.get_workflow(self.context)
        if workflow:
            appstruct['workflow'] = workflow
            appstruct['workflow_state'] = workflow.state_of(self.context)
        return appstruct

    def _do_transition_to(self, name: str):
        """Do transition to state `name`, don`t check user permissions."""
        workflow = self.get()['workflow']
        request = self.request or DummyRequest()  # ease testing
        workflow.transition_to_state(self.context, request, to_state=name)


workflow_meta = sheet_meta._replace(
    isheet=IWorkflowAssignment,
    schema_class=WorkflowAssignmentSchema,
    sheet_class=WorkflowAssignmentSheet,
    permission_edit='do_transition'
)


def includeme(config):
    """Add sheet."""
    add_sheet_to_registry(workflow_meta, config.registry)
Exemplo n.º 34
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import ISheetReferenceAutoUpdateMarker
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import SingleLine


class ITitle(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for the title sheet."""


class TitleSchema(colander.MappingSchema):
    """Title sheet data structure.

    `title`: a human readable title
    """

    title = SingleLine(validator=colander.Length(min=3, max=100))


title_meta = sheet_meta._replace(
    isheet=ITitle,
    schema_class=TitleSchema,
)


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(title_meta, config.registry)
Exemplo n.º 35
0
from adhocracy_core.schema import AdhocracySequenceNode
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta


class IUserInfo(ISheet):
    """Marker interface for information about the proposal submitter."""


class UserInfoSchema(colander.MappingSchema):
    """Information about the proposal submitter."""

    first_name = SingleLine(missing=colander.required)
    last_name = SingleLine(missing=colander.required)

userinfo_meta = sheet_meta._replace(isheet=IUserInfo,
                                    schema_class=UserInfoSchema)


class IOrganizationInfo(ISheet):
    """Marker interface for organizational information."""


class OrganizationStatusEnum(AdhocracySchemaNode):
    """Enum of organizational statuses."""

    schema_type = colander.String
    default = 'other'
    missing = colander.required
    validator = colander.OneOf(['registered_nonprofit',
                                'planned_nonprofit',
                                'support_needed',
Exemplo n.º 36
0
def sheet_meta() -> SheetMetadata:
    """ Return basic sheet metadata."""
    from adhocracy_core.sheets import sheet_meta
    from adhocracy_core.interfaces import ISheet
    return sheet_meta._replace(isheet=ISheet,
                               schema_class=colander.MappingSchema)
Exemplo n.º 37
0
"""Logbook sheet."""
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import MappingSchema
from adhocracy_core.schema import PostPool


class IHasLogbookPool(ISheet):
    """Marker interface for resources that have a logbook pool."""


class HasLogbookPoolSchema(MappingSchema):
    """Data structure pointing to a logbook pool."""

    logbook_pool = PostPool(iresource_or_service_name='logbook')


has_logbook_pool_meta = sheet_meta._replace(
    isheet=IHasLogbookPool,
    schema_class=HasLogbookPoolSchema,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register sheets, adapters and index views."""
    add_sheet_to_registry(has_logbook_pool_meta, config.registry)
Exemplo n.º 38
0
    """Marker interface for the BPlan proposal sheet."""


class ProposalSchema(colander.MappingSchema):

    """Data structure for plan stellungsname information."""

    name = SingleLine(missing=colander.required)
    street_number = SingleLine(missing=colander.required)
    postal_code_city = SingleLine(missing=colander.required)
    email = SingleLine(validator=colander.Email())
    statement = Text(missing=colander.required,
                     validator=colander.Length(max=17500))


proposal_meta = sheet_meta._replace(isheet=IProposal,
                                    schema_class=ProposalSchema)


class IWorkflowAssignment(workflow.IWorkflowAssignment):

    """Marker interface for the bplan workflow assignment sheet."""


deprecated('IWorkflowAssignment',
           'Backward compatible code use IWorkflowAssignment instead')


class IPrivateWorkflowAssignment(workflow.IWorkflowAssignment):

    """Marker interface for the bplan private workflow assignment sheet."""
Exemplo n.º 39
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import Name


class IName(ISheet):
    """Market interface for the name sheet."""


class NameSchema(colander.MappingSchema):
    """Name sheet data structure.

    `name`: a human readable resource Identifier
    """

    name = Name()


name_meta = sheet_meta._replace(isheet=IName,
                                schema_class=NameSchema,
                                editable=False,
                                create_mandatory=True,
                                )


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(name_meta, config.registry)
Exemplo n.º 40
0
    source_isheet_field = 'refers_to'
    target_isheet = ICommentable


class CommentSchema(colander.MappingSchema):
    """Comment sheet data structure.

    `content`:  Text
    """

    refers_to = Reference(reftype=CommentRefersToReference)
    content = Text()
    # TODO add post_pool validator


comment_meta = sheet_meta._replace(isheet=IComment,
                                   schema_class=CommentSchema)


class CommentableSchema(colander.MappingSchema):
    """Commentable sheet data structure.

    `comments`: list of comments (not stored)
    `post_pool`: Pool to post new :class:`adhocracy_sample.resource.IComment`.
    """

    comments = UniqueReferences(readonly=True,
                                backref=True,
                                reftype=CommentRefersToReference)
    post_pool = PostPool(iresource_or_service_name='comments')

Exemplo n.º 41
0
            break
    return groups


class BadgeSchema(colander.MappingSchema):

    """Badge sheet data structure."""

    groups = UniqueReferences(reftype=BadgeGroupReference,
                              readonly=True,
                              default=deferred_groups_default,
                              )


badge_meta = sheet_meta._replace(isheet=IBadge,
                                 schema_class=BadgeSchema,
                                 )


class HasBadgesPoolSchema(colander.MappingSchema):

    """Data structure pointing to a badges post pool."""

    badges_pool = PostPool(iresource_or_service_name='badges')


has_badges_pool_meta = sheet_meta._replace(
    isheet=IHasBadgesPool,
    schema_class=HasBadgesPoolSchema,
    editable=False,
    creatable=False,
Exemplo n.º 42
0
class IProposal(ISheet):
    """Marker interface for the Kiezkassen proposal sheet."""


class ProposalSchema(MappingSchema):
    """Data structure for organizational information."""

    # TODO: check exact length restrictions

    budget = CurrencyAmount(missing=required,
                            validator=Range(min=0, max=50000))
    creator_participate = Boolean()
    location_text = SingleLine(validator=Length(max=100))


proposal_meta = sheet_meta._replace(isheet=IProposal,
                                    schema_class=ProposalSchema)


class IWorkflowAssignment(workflow.IWorkflowAssignment):
    """Marker interface for the kiezkassen workflow assignment sheet."""


deprecated('IWorkflowAssignment',
           'Backward compatible code use IWorkflowAssignment instead')


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(proposal_meta, config.registry)
Exemplo n.º 43
0
            break
    return groups


class BadgeSchema(MappingSchema):
    """Badge sheet data structure."""

    groups = UniqueReferences(
        reftype=BadgeGroupReference,
        readonly=True,
        default=deferred_groups_default,
    )


badge_meta = sheet_meta._replace(
    isheet=IBadge,
    schema_class=BadgeSchema,
)


class HasBadgesPoolSchema(MappingSchema):
    """Data structure pointing to a badges post pool."""

    badges_pool = PostPool(iresource_or_service_name='badges')


has_badges_pool_meta = sheet_meta._replace(
    isheet=IHasBadgesPool,
    schema_class=HasBadgesPoolSchema,
    editable=False,
    creatable=False,
)
Exemplo n.º 44
0
    source_isheet_field = 'groups'
    target_isheet = IGroup


class GroupSchema(colander.MappingSchema):
    """Group sheet data structure."""

    users = UniqueReferences(readonly=True,
                             backref=True,
                             reftype=PermissionsGroupsReference)
    roles = Roles()


group_meta = sheet_meta._replace(
    isheet=IGroup,
    schema_class=GroupSchema,
    sheet_class=AttributeResourceSheet,
)


@colander.deferred
def deferred_validate_user_name(node: colander.SchemaNode, kw: dict)\
        -> callable:
    """Return validator to check that the user login `name` is unique or None.

    :param kw: dictionary with 'request' key and
               :class:`pyramid.request.Request` object.
               If this is not available the validator is None.
    :raise: colander.Invalid: if name is not unique.
    """
    request = kw.get('request', None)
Exemplo n.º 45
0
import colander

from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import ISheetReferenceAutoUpdateMarker
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import SingleLine


class ITitle(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for the title sheet."""


class TitleSchema(colander.MappingSchema):
    """Title sheet data structure.

    `title`: a human readable title
    """

    title = SingleLine(validator=colander.Length(min=3, max=100))


title_meta = sheet_meta._replace(isheet=ITitle,
                                 schema_class=TitleSchema,
                                 )


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(title_meta, config.registry)
Exemplo n.º 46
0

class NotificationSchema(MappingSchema):
    """Notification sheet data structure.

    `follow_resources`: Follow activities these resources are involved in.
    """

    follow_resources = UniqueReferences(reftype=NotificationFollowReference,
                                        choices_getter=get_follow_choices)
    email_notification_enabled = Boolean(default=True, missing=drop)


notification_meta = sheet_meta._replace(
    isheet=INotification,
    schema_class=NotificationSchema,
    permission_edit='edit_notification',
)

followable_meta = sheet_meta._replace(
    isheet=IFollowable,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register sheet."""
    add_sheet_to_registry(notification_meta, config.registry)
    add_sheet_to_registry(followable_meta, config.registry)
Exemplo n.º 47
0
def sheet_meta() -> SheetMetadata:
    """Return basic sheet metadata."""
    from adhocracy_core.sheets import sheet_meta
    from adhocracy_core.interfaces import ISheet
    return sheet_meta._replace(isheet=ISheet,
                               schema_class=colander.MappingSchema)
Exemplo n.º 48
0
    """Marker interface for the Kiezkassen proposal sheet."""


class ProposalSchema(colander.MappingSchema):

    """Data structure for organizational information."""

    # TODO: check exact length restrictions

    budget = CurrencyAmount(missing=colander.required,
                            validator=colander.Range(min=0, max=50000))
    creator_participate = Boolean()
    location_text = SingleLine(validator=colander.Length(max=100))
    address = Text()

proposal_meta = sheet_meta._replace(isheet=IProposal,
                                    schema_class=ProposalSchema)


class IWorkflowAssignment(workflow.IWorkflowAssignment):

    """Marker interface for the kiezkassen workflow assignment sheet."""


deprecated('IWorkflowAssignment',
           'Backward compatible code use IWorkflowAssignment instead')


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(proposal_meta, config.registry)
Exemplo n.º 49
0
class UserBasicSchema(MappingSchema):
    """Basic user sheet data structure.

    This sheet must only store public information, as everyone can see it.

    `name`: visible name
    """

    name = SingleLine(missing=required,
                      validator=deferred_validate_user_name)


userbasic_meta = sheet_meta._replace(
    isheet=IUserBasic,
    schema_class=UserBasicSchema,
    sheet_class=AttributeResourceSheet,
    permission_create='create_user',
)


class IUserExtended(ISheet):
    """Marker interface for the extended user sheet."""


@deferred
def deferred_validate_user_email(node: SchemaNode, kw: dict) -> callable:
    """Return validator to check that the `email` is unique and valid or None.

    :param kw: dictionary with 'request' key and
               :class:`pyramid.request.Request` object
               If this is not available the validator is None.
Exemplo n.º 50
0
    target_isheet = IPolarizable


class PolarizationSchema(colander.MappingSchema):

    """Polarizable sheet data structure.

    `position`: the position in the debate, 'pro' or 'contra'.
    """

    subject = Reference(reftype=PolarizationSubjectReference)
    object = Reference(reftype=PolarizationObjectReference)
    position = Position()

polarization_meta = sheet_meta._replace(isheet=IPolarization,
                                        schema_class=PolarizationSchema,
                                        create_mandatory=True)


class CanPolarizeSchema(colander.MappingSchema):

    """CanPolarize sheet data structure."""

    polarization = Reference(reftype=PolarizationSubjectReference,
                             backref=True,
                             readonly=True,)

can_polarize_meta = sheet_meta._replace(isheet=ICanPolarize,
                                        schema_class=CanPolarizeSchema)

Exemplo n.º 51
0
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import MappingSchema
from adhocracy_core.schema import Name


class IName(ISheet):
    """Market interface for the name sheet."""


class NameSchema(MappingSchema):
    """Name sheet data structure.

    `name`: a human readable resource Identifier
    """

    name = Name()


name_meta = sheet_meta._replace(isheet=IName,
                                schema_class=NameSchema,
                                editable=False,
                                create_mandatory=True,
                                )


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(name_meta, config.registry)
Exemplo n.º 52
0
    `administrative_level`: administrative division level
    `administrative_division`: administrative division name
    `part_of`: surrounding geographical object
    """

    type = SingleLine(default='MultiPolygon', readonly=True)
    coordinates = MultiPolygon()

    administrative_division = AdministrativeDivisionName()
    part_of = Reference(reftype=PartOfReference)


multipolygon_meta = sheet_meta._replace(isheet=IMultiPolygon,
                                        schema_class=MultiPolygonSchema,
                                        editable=False,
                                        create_mandatory=True,
                                        )


class ILocationReference(ISheet):
    """Marker interface for the location reference sheet."""


class LocationReference(SheetToSheet):
    """Reference to a geographical object."""

    source_isheet = ILocationReference
    source_isheet_field = 'location'
    target_isheet = IMultiPolygon
Exemplo n.º 53
0
    """Sheet to set/get local roles."""
    def _get_data_appstruct(self):
        roles = get_local_roles(self.context)
        roles_list = [{
            'principal': x,
            'roles': list(y)
        } for x, y in roles.items()]
        return {'local_roles': roles_list}

    def _store_data(self, appstruct):
        roles_list = appstruct.get('local_roles', [])
        if not roles_list:
            return
        roles = {x['principal']: set(x['roles']) for x in roles_list}
        set_local_roles(self.context, roles, self.registry)


local_roles_meta = sheet_meta._replace(
    isheet=ILocalRoles,
    schema_class=LocalRolesSchema,
    sheet_class=LocalRolesSheet,
    creatable=False,
    permission_edit='manage_sheet_local_roles',
    permission_view='manage_sheet_local_roles',
)


def includeme(config):
    """Register sheets."""
    add_sheet_to_registry(local_roles_meta, config.registry)
Exemplo n.º 54
0
    """

    creator = Reference(reftype=MetadataCreatorsReference, readonly=True)
    creation_date = DateTime(missing=colander.drop, readonly=True)
    item_creation_date = DateTime(missing=colander.drop, readonly=True)
    modified_by = Reference(reftype=MetadataModifiedByReference, readonly=True)
    modification_date = DateTime(missing=colander.drop, readonly=True)
    deleted = Boolean()
    hidden = Boolean(validator=deferred_validate_hidden)


metadata_meta = sheet_meta._replace(
    isheet=IMetadata,
    schema_class=MetadataSchema,
    sheet_class=AttributeResourceSheet,
    editable=True,
    creatable=True,
    readable=True,
    permission_edit='delete',
)


def view_blocked_by_metadata(resource: IResource, registry: Registry,
                             block_reason: str) -> dict:
    """
    Return a dict with an explanation why viewing this resource is not allowed.

    If the resource provides metadata, the date of the
    last change and its author are added to the result.
    """
    result = {'reason': block_reason}
Exemplo n.º 55
0
"""Sheet to allow adding children annonymized."""
from adhocracy_core.interfaces import ISheet
from adhocracy_core.sheets import add_sheet_to_registry
from adhocracy_core.sheets import sheet_meta
from adhocracy_core.schema import MappingSchema

ANONYMIZE_PERMISSION = 'manage_anonymized'


class IAllowAddAnonymized(ISheet):
    """Marker interface for the allow_add_anonymized sheet."""


class AllowAddAnonymizedSchema(MappingSchema):
    """AllowAddAnonymized sheet data structure."""


allow_add_anonymized_meta = sheet_meta._replace(
    isheet=IAllowAddAnonymized,
    schema_class=AllowAddAnonymizedSchema,
    editable=False,
    creatable=False,
)


def includeme(config):
    """Register sheet and permission."""
    add_sheet_to_registry(allow_add_anonymized_meta, config.registry)
    # register free standing permission to validate permission names
    config.add_permission(ANONYMIZE_PERMISSION)