Exemplo n.º 1
0
 def test_restore_object(self):
     doc = api.content.create(type='Document',
                              id='doc1',
                              container=self.portal)
     trash.object(doc)
     self.assertTrue(ITrashed.providedBy(doc))
     trash.restore(doc)
     self.assertFalse(ITrashed.providedBy(doc))
Exemplo n.º 2
0
 def getData(self, obj):
     if ITrashed.providedBy(obj):
         return None
     data = super(NextPrevious, self).getData(obj)
     if data:
         data['obj'] = obj
     return data
Exemplo n.º 3
0
 def __call__(self):
     # we're overriding so we can provide extra status messages
     # just an easy way to hook in
     if ITrashed.providedBy(self.context):
         # warn user they are in no-no land
         api.portal.show_message(
             'You are viewing content that is in the recycling bin. '
             'You are still free to view and manage this object '
             'before it is restored or deleted.',
             request=self.request,
             type='error')
     return super(GlobalStatusMessageTile, self).__call__()
Exemplo n.º 4
0
    def _check(self, folder=None):
        valid = True
        if folder is None:
            folder = self.get_folder()
        if folder is not None:
            portal_types = getToolByName(self.context, 'portal_types')
            type_id = self.get_type_id()

            # Templates need special handling based on type_id
            try:
                if ITemplate.providedBy(self.context['template-repository'][type_id]):
                    type_id = self.context['template-repository'][type_id].portal_type
            except KeyError:
                pass

            pt = portal_types[type_id]
            add_perm = utils.get_permission_title(pt.add_permission)

            if valid and not self.can_add(folder, type_id):
                valid = False
                self.status = 'You are not allowed to add this content type here'
            elif valid and not self.sm.checkPermission(add_perm, folder):
                valid = False
                self.status = 'You do not have permission to add content here.'
            elif valid and self.request.form['id'] in folder.objectIds():
                valid = False
                ob = folder[self.request.form['id']]
                if ITrashed.providedBy(ob):
                    self.status = ('Content in recycling bin with same id exists. '
                                   'Delete, rename or restore recycled content to use this.')
                else:
                    self.status = 'Content with same ID already exists'
            elif not self.valid_id(folder, self.request.form['id']):
                valid = False
                self.status = '"%s" is not valid to be used in a path' % self.request.form['id']
        else:
            valid = False
            if not self.status:
                self.status = 'Could not validate folder'

        for idx, part in enumerate(self.request.form.get('basePath', '/').split('/')):
            if not part:
                continue
            if part in self.context:
                continue
            if not self.valid_id(self.context, part):
                valid = False
                self.status = '"%s" is not valid to be used in a path' % part
                break
        return valid, folder
Exemplo n.º 5
0
def event(obj, event=None):

    if event is None:
        # some events don't include object
        event = obj
        obj = None

    iface = providedBy(event).declared[0]
    if iface in _registered:
        try:
            registry = getUtility(IRegistry)
        except ComponentLookupError:
            return
        if not registry.get(
                'collective.elasticsearch.interfaces.IElasticSettings.enabled',
                False):  # noqa
            return

        if obj is not None and ITrashed.providedBy(obj):
            # special handling for ITrashed...
            # we don't want to record transition events for trashing
            # and we want a special psuedo trash event
            # then, we still want an event when it gets deleted for good
            if iface not in (IAfterTransitionEvent, IObjectRemovedEvent):
                # dive out if not IAfterTransitionEvent or object removed event
                return
            if iface == IObjectRemovedEvent:
                audit_data = _registered[iface]
            else:
                audit_data = _registered[ITrashed]
        else:
            audit_data = _registered[iface]

        recorder = audit_data.get_recorder(event, obj)
        site_path = '/'.join(api.portal.get().getPhysicalPath())
        transaction.get().addAfterCommitHook(
            record,
            args=(recorder, site_path, ESConnectionFactoryFactory(registry)))
    else:
        pass
Exemplo n.º 6
0
def trashed(obj):
    while obj:
        if ITrashed.providedBy(obj):
            return True
        obj = aq_parent(obj)
    return False