Exemple #1
0
def beginDrafting(context, event):
    """When we enter the edit screen, set up the target key and draft cookie
    path. If there is exactly one draft for the given user id and target key,
    consider that to be the current draft. Also mark the request with
    IDrafting if applicable.
    """

    storage = queryUtility(IDraftStorage)
    if storage is None or not storage.enabled:
        return

    request = getattr(context, 'REQUEST', None)
    if request is None:
        return

    current = ICurrentDraftManagement(request)

    # Update target key regardless - we could have a stale cookie
    current.targetKey = getObjectKey(context)

    if current.draftName is None:
        drafts = storage.getDrafts(current.userId, current.targetKey)
        if len(drafts) == 1:
            current.draftName = tuple(drafts.keys())[0]

    # Save the path now so that we can use it again later, even on URLs
    # (e.g. in AJAX dialogues) that are below this path.
    current.path = current.defaultPath

    current.mark()
    current.save()
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if IDraftable.__identifier__ in fti.behaviors:
            draft = getCurrentDraft(request, create=False)
            target = getattr(draft, '_draftAddFormTarget',
                             createContent(form.portal_type))

            if draft is None:
                IMutableUUID(target).set('++add++%s' % form.portal_type)
                beginDrafting(target.__of__(context), None)
                draft = getCurrentDraft(request, create=True)
                draft._draftAddFormTarget = target

                # Disable Plone 5 implicit CSRF when no form action
                if HAS_PLONE_PROTECT:
                    if not ([key for key in request.form
                             if key.startswith('form.buttons.')]):
                        alsoProvides(request, IDisableCSRFProtection)
            else:
                current = ICurrentDraftManagement(request)
                current.mark()

            context = DraftProxy(draft, target.__of__(context))
            alsoProvides(request, IAddFormDrafting)

        super(DefaultAddFormFieldWidgets, self).__init__(form, request, context)  # noqa
Exemple #3
0
 def test_mark(self):
     request = self.request
     
     current = ICurrentDraftManagement(request)
     current.mark()
     self.failIf(IDrafting.providedBy(request))
     
     current.targetKey = u"123"
     current.mark()
     self.failUnless(IDrafting.providedBy(request))
Exemple #4
0
    def test_mark(self):
        request = self.request

        current = ICurrentDraftManagement(request)
        current.mark()
        self.assertFalse(IDrafting.providedBy(request))

        current.targetKey = u'123'
        current.mark()
        self.assertTrue(IDrafting.providedBy(request))
Exemple #5
0
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=context.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey is not None:
                current.mark()

            if current.draft:
                context = DraftProxy(current.draft, context)

        super(DefaultDisplayFormFieldWidgets, self).__init__(form, request, context)  # noqa
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=context.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey is not None:
                current.mark()

            if current.draft:
                context = DraftProxy(current.draft, context)

        super(DefaultDisplayFormFieldWidgets,
              self).__init__(form, request, context)  # noqa
Exemple #7
0
    def update(self):

        # Set up draft information if required
        currentDraft = ICurrentDraftManagement(self.request)
        currentDraft.mark()

        # Override to check the tile add/edit permission
        if not IDeferSecurityCheck.providedBy(self.request):
            if not checkPermission(self.tileType.add_permission, self.context):
                raise Unauthorized(
                    "You are not allowed to add this kind of tile")

        super(TileForm, self).update()
Exemple #8
0
    def update(self):

        # Set up draft information if required
        currentDraft = ICurrentDraftManagement(self.request)
        currentDraft.mark()

        # Override to check the tile add/edit permission
        if not IDeferSecurityCheck.providedBy(self.request):
            if not checkPermission(self.tileType.add_permission, self.context):
                raise Unauthorized(
                    "You are not allowed to add this kind of tile")

        super(TileForm, self).update()
Exemple #9
0
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey is None:
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = IUUID(context)
                current.save()
            else:
                current.mark()

            if current.draft:
                context = DraftProxy(current.draft, context)
                alsoProvides(request, IEditFormDrafting)

        super(DefaultEditFormFieldWidgets, self).__init__(form, request, context)  # noqa
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey is None:
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = IUUID(context)
                current.save()
            else:
                current.mark()

            if current.draft:
                context = DraftProxy(current.draft, context)
                alsoProvides(request, IEditFormDrafting)

        super(DefaultEditFormFieldWidgets,
              self).__init__(form, request, context)  # noqa
Exemple #11
0
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey != '++add++{0}'.format(form.portal_type):
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = '++add++{0}'.format(form.portal_type)
                current.save()
            else:
                current.mark()

            target = getattr(current.draft, '_draftAddFormTarget', None)
            if current.draft and target:
                context = DraftProxy(current.draft, target.__of__(context))
                alsoProvides(request, IAddFormDrafting)

        super(DefaultAddFormFieldWidgets, self).__init__(form, request, context)  # noqa
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey != '++add++{0}'.format(form.portal_type):
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = '++add++{0}'.format(form.portal_type)
                current.save()
            else:
                current.mark()

            target = getattr(current.draft, '_draftAddFormTarget', None)
            if current.draft and target:
                context = DraftProxy(current.draft, target.__of__(context))
                alsoProvides(request, IAddFormDrafting)

        super(DefaultAddFormFieldWidgets,
              self).__init__(form, request, context)  # noqa
Exemple #13
0
    def __call__(self):

        # Set up draft information if required
        currentDraft = ICurrentDraftManagement(self.request)
        currentDraft.mark()

        self.request['disable_border'] = True

        confirm = self.request.form.get('confirm', False)

        self.tileTypeName = self.request.form.get('type', None)
        self.tileId = self.request.form.get('id', None)

        self.deleted = False

        if confirm and self.tileTypeName and self.tileId:

            tileType = getUtility(ITileType, name=self.tileTypeName)

            if not checkPermission(tileType.add_permission, self.context):
                raise Unauthorized("You are not allowed to modify this " + \
                                   "tile type")

            tile = self.context.restrictedTraverse(
                '@@%s/%s' % (self.tileTypeName, self.tileId,))

            dm = ITileDataManager(tile)
            dm.delete()

            notify(ObjectRemovedEvent(tile, self.context, self.tileId))

            self.deleted = True

        elif 'form.button.Ok' in self.request.form:
            self.request.response.redirect(
                self.context.absolute_url() + '/view')
            return ''

        return self.index()
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if IDraftable.__identifier__ in fti.behaviors:
            draft = getCurrentDraft(request, create=False)

            if draft is None:
                beginDrafting(context, None)
                draft = getCurrentDraft(request, create=True)

                # Disable Plone 5 implicit CSRF when no form action
                if HAS_PLONE_PROTECT:
                    if not ([key for key in request.form
                             if key.startswith('form.buttons.')]):
                        alsoProvides(request, IDisableCSRFProtection)
            else:
                current = ICurrentDraftManagement(request)
                current.mark()

            context = DraftProxy(draft, context)
            alsoProvides(request, IEditFormDrafting)

        super(DefaultEditFormFieldWidgets, self).__init__(form, request, context)  # noqa