Example #1
0
 def _setObject(self, id, object):
     notify(ObjectWillBeAddedEvent(object, self, id))
     self._setOb(id, object)
     object = self._getOb(id)
     if hasattr(aq_base(object), 'manage_afterAdd'):
         object.manage_afterAdd(object, self)
     notify(ObjectAddedEvent(object, self, id))
     notifyContainerModified(self)
     return object
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """

        dossier1 = create(Builder('dossier'))
        dossier2 = create(Builder('dossier'))

        document = create(
            Builder('document').within(dossier1).titled(u'Document'))
        document2 = create(
            Builder('document').within(dossier2).titled(u'Document'))

        notify(
            ObjectMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(),
        )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(
            ObjectWillBeMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(dossier1,
                              action_type='Object cut',
                              action_title='Object cut: %s' %
                              document.title_or_id())

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName',
        ))
        self.assertTrue(length == get_journal_length(dossier1))
Example #3
0
    def addRelation(self, obj):
        """Override base to run manage_afterAdd like ObjectManager"""
        if self._objects.has_key(obj.getId()):
            log.debug("obj %s already exists on %s", obj.getPrimaryId(),
                      self.getPrimaryId())

        notify(ObjectWillBeAddedEvent(obj, self, obj.getId()))
        ToManyRelationshipBase.addRelation(self, obj)
        obj = obj.__of__(self)
        o = self._getOb(obj.id)
        notify(ObjectAddedEvent(o, self, obj.getId()))
Example #4
0
def _setObject(self,
               id,
               object,
               roles=None,
               user=None,
               set_owner=1,
               suppress_events=False):
    """Set an object into this container.

    Also sends IObjectAddedEvent.
    """
    ob = object  # better name, keep original function signature
    v = self._checkId(id)
    if v is not None:
        id = v
    t = getattr(ob, 'meta_type', None)

    # If an object by the given id already exists, remove it.
    for object_info in self._objects:
        if object_info['id'] == id:
            self._delObject(id)
            break

    if not suppress_events:
        notify(ObjectWillBeAddedEvent(ob, self, id))

    self._objects = self._objects + ({'id': id, 'meta_type': t}, )
    self._setOb(id, ob)
    ob = self._getOb(id)

    if set_owner:
        # TODO: eventify manage_fixupOwnershipAfterAdd
        # This will be called for a copy/clone, or a normal _setObject.
        ob.manage_fixupOwnershipAfterAdd()

    if set_owner:
        # Try to give user the local role "Owner", but only if
        # no local roles have been set on the object yet.
        if getattr(ob, '__ac_local_roles__', _marker) is None:
            user = getSecurityManager().getUser()
            if user is not None:
                userid = user.getId()
                if userid is not None:
                    ob.manage_setLocalRoles(userid, ['Owner'])

    if not suppress_events:
        notify(ObjectAddedEvent(ob, self, id))
        notifyContainerModified(self)

    compatibilityCall('manage_afterAdd', ob, ob, self)

    return id
Example #5
0
    def _add_element(self, element, event=True):
        element = aq_base(element)
        uid = self._generate_uid()
        IMutableUUID(element).set(uid)

        if event is True:
            notify(ObjectWillBeAddedEvent(element, self, uid))
        self._tree[uid] = element
        element.__parent__ = aq_base(self)

        if event is True:
            notify(ObjectCreatedEvent(element))
            notify(ObjectAddedEvent(element.__of__(self), self, uid))
            notify(ContainerModifiedEvent(self))
Example #6
0
    def addComment(self, comment):
        """Add a new comment. The parent id should have been set already. The
        comment id may be modified to find a free key. The id used will be
        returned.
        """

        # Make sure we don't have a wrapped object

        comment = aq_base(comment)

        id = long(time.time() * 1e6)
        while id in self._comments:
            id += 1

        comment.comment_id = id
        notify(ObjectWillBeAddedEvent(comment, self, id))
        self._comments[id] = comment

        comment.__parent__ = aq_base(self)

        # Record unique users who've commented (for logged in users only)
        commentator = comment.author_username
        if commentator:
            if not commentator in self._commentators:
                self._commentators[commentator] = 0
            self._commentators[commentator] += 1

        reply_to = comment.in_reply_to
        if not reply_to:
            # top level comments are in reply to the faux id 0
            comment.in_reply_to = reply_to = 0

        if not reply_to in self._children:
            self._children[reply_to] = LLSet()
        self._children[reply_to].insert(id)

        # Add the annotation if not already done
        annotions = IAnnotations(self.__parent__)
        if not ANNOTATION_KEY in annotions:
            annotions[ANNOTATION_KEY] = aq_base(self)

        # Notify that the object is added. The object must here be
        # acquisition wrapped or the indexing will fail.
        notify(ObjectCreatedEvent(comment))
        notify(ObjectAddedEvent(comment.__of__(self), self, id))
        notify(ContainerModifiedEvent(self))

        return id
Example #7
0
    def _setObject(self,
                   id,
                   object,
                   roles=None,
                   user=None,
                   set_owner=1,
                   suppress_events=False):
        ob = object  # better name, keep original function signature
        v = self._checkId(id)
        if v is not None:
            id = v

        # If an object by the given id already exists, remove it.
        if self.has_key(id):
            self._delObject(id)

        if not suppress_events:
            notify(ObjectWillBeAddedEvent(ob, self, id))

        self._setOb(id, ob)
        ob = self._getOb(id)

        if set_owner:
            # TODO: eventify manage_fixupOwnershipAfterAdd
            # This will be called for a copy/clone, or a normal _setObject.
            ob.manage_fixupOwnershipAfterAdd()

            # Try to give user the local role "Owner", but only if
            # no local roles have been set on the object yet.
            if getattr(ob, '__ac_local_roles__', _marker) is None:
                user = getSecurityManager().getUser()
                if user is not None:
                    userid = user.getId()
                    if userid is not None:
                        ob.manage_setLocalRoles(userid, ['Owner'])

        if not suppress_events:
            notify(ObjectAddedEvent(ob, self, id))
            notifyContainerModified(self)

        OFS.subscribers.compatibilityCall('manage_afterAdd', ob, ob, self)

        return id
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """
        portal = self.layer['portal']

        dossier1 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd1')
        dossier2 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd2')

        document = createContentInContainer(dossier1,
                                            'opengever.document.document',
                                            'doc1',
                                            title='Document')

        document2 = createContentInContainer(dossier2,
                                             'opengever.document.document',
                                             'doc2',
                                             title='Document2')

        notify(
            ObjectMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(),
        )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(
            ObjectWillBeMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object cut',
            action_title='Object cut: %s' % document.title_or_id(),
        )

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName',
        ))
        self.assertTrue(length == get_journal_length(dossier1))