Пример #1
0
    def test_existing_objects_are_indexed_when_installing(self):
        with freeze(datetime(2010, 1, 1)):
            folder = create(Builder('folder'))
        with freeze(datetime(2010, 1, 2)):
            create(Builder('document'))
        with freeze(datetime(2010, 1, 3)):
            create(Builder('document').within(folder))
        with freeze(datetime(2010, 1, 4)):
            folder.notifyModified()

        get_activity_soup().clear()
        applyProfile(self.portal, 'ftw.activity:default')

        self.maxDiff = None
        self.assertEquals(
            [{'path': '/plone/folder',
              'action': 'added',
              'date': DateTime('2010/01/01')},
             {'path': '/plone/document',
              'action': 'added',
              'date': DateTime('2010/01/02')},
             {'path': '/plone/folder/document',
              'action': 'added',
              'date': DateTime('2010/01/03')},
             {'path': '/plone/folder',
              'action': 'changed',
              'date': DateTime('2010/01/04')}],

            get_soup_activities(('path', 'action', 'date')))
Пример #2
0
    def test_comment_removed_activity(self):
        document = create(Builder('document').titled('The Document'))
        conversation = IConversation(document)

        comment = createObject('plone.Comment')
        comment.text = 'Comment text'
        comment_id = conversation.addComment(comment)

        with freeze(datetime(2010, 12, 25, 13, 30)):
            record_id = comment_removed(document, comment)
        record = get_activity_soup().get(record_id)

        self.assertEquals({'path': '/plone/the-document',
                           'allowed_roles_and_users': ['Anonymous'],
                           'uuid': 'testcommentremovedactivity000001',
                           'portal_type': 'Document',
                           'title': 'The Document',
                           'timestamp': 1293280200000L,
                           'action': 'comment:removed',
                           'date': DateTime('2010/12/25 13:30:00'),
                           'actor': TEST_USER_ID,
                           'comment_id': comment_id,
                           'comment_text': 'Comment text',
                           'comment_text_mime_type': 'text/plain'},
                          dict(record.attrs))
Пример #3
0
def index_soup(site):
    soup = get_activity_soup()
    if len(soup.data) > 0:
        return

    catalog = getToolByName(site, 'portal_catalog')
    for brain in catalog.unrestrictedSearchResults({}):
        obj = site.unrestrictedTraverse(brain.getPath())
        index_object(obj)
Пример #4
0
 def __call__(self):
     self.install_upgrade_profile()
     soup = get_activity_soup()
     index = soup.catalog['date'] = CatalogFieldIndex(
         NodeAttributeIndexer(u'timestamp'))
     msg = 'Reindex souper catalog "date" index'
     for record in ProgressLogger(msg, soup.data.values()):
         record.attrs['timestamp'] = DateTime(record.attrs['date']).millis()
         index.reindex_doc(record.intid, record)
Пример #5
0
    def test_fetch_more_events(self, browser):
        self.grant('Manager')
        foo = create(Builder('page').titled('Foo'))
        bar = create(Builder('page').titled('Bar'))
        get_activity_soup().clear()

        with freeze(datetime(2010, 1, 2, 1)) as clock:
            def touch(obj):
                obj.setTitle(obj.Title() + '*')
                object_changed(obj)
                clock.forward(hours=1)

            touch(foo)
            touch(bar)
            touch(foo)
            touch(bar)
            touch(foo)
            touch(bar)

        transaction.commit()

        browser.login().open(view='activity?amount_of_events=2')
        events = activity.events()
        self.assertEquals(['Bar***', 'Foo***'],
                          map(attrgetter('title'), events))

        browser.open(view='activity?amount_of_events=2&last_activity={0}'.format(
                events[-1].activity_id))
        events = activity.events()
        self.assertEquals(['Bar**', 'Foo**'],
                          map(attrgetter('title'), events))

        browser.open(view='activity?amount_of_events=2&last_activity={0}'.format(
                events[-1].activity_id))
        events = activity.events()
        self.assertEquals(['Bar*', 'Foo*'],
                          map(attrgetter('title'), events))

        browser.open(view='activity?amount_of_events=2&last_activity={0}'.format(
                events[-1].activity_id))
        events = activity.events()
        self.assertEquals([],
                          map(attrgetter('title'), events))
Пример #6
0
def role_changed(obj, event, actor_userid=None, date=None):
    record = ActivityRecord(obj, 'participation:role_changed',
                            actor_userid=actor_userid, date=date)
    record.attrs['roles:userid'] = event.userid
    record.attrs['roles:old'] = tuple(event.old_roles)
    record.attrs['roles:new'] = tuple(event.new_roles)
    record.attrs['roles:removed'] = tuple(
        set(event.old_roles) - set(event.new_roles))
    record.attrs['roles:added'] = tuple(
        set(event.new_roles) - set(event.old_roles))
    return get_activity_soup().add(record)
def notification_email_sent_activity(
        obj, event, actor_userid=None, date=None,
        comment=None, to_userids=None, cc_userids=None):
    record = ActivityRecord(obj, 'notification:email_sent',
                            actor_userid=actor_userid, date=date)

    record.attrs['notification:comment'] = comment or event.comment
    record.attrs['notification:to_userids'] = tuple(
        to_userids or event.to_userids)
    record.attrs['notification:cc_userids'] = tuple(
        cc_userids or event.cc_userids)
    return get_activity_soup().add(record)
Пример #8
0
    def test_querying_by_path(self):
        soup = get_activity_soup()
        folder = create(Builder('folder'))
        doc1 = create(Builder('document').titled('One').within(folder))
        doc2 = create(Builder('document').titled('Two'))

        soup.clear()
        map(object_added, (folder, doc1, doc2))

        results = map(lambda record: record.attrs['path'],
                      query_soup(Eq('path', '/'.join(folder.getPhysicalPath()))))

        self.assertItemsEqual(['/plone/folder', '/plone/folder/one'],
                              results)
Пример #9
0
    def test_deleted_activity(self):
        document = create(Builder('document').titled('The Document'))
        with freeze(datetime(2010, 12, 25, 13, 30)):
            record_id = object_deleted(document)
        record = get_activity_soup().get(record_id)

        self.assertEquals({'path': '/plone/the-document',
                           'allowed_roles_and_users': ['Anonymous'],
                           'uuid': 'testdeletedactivity0000000000001',
                           'portal_type': 'Document',
                           'title': 'The Document',
                           'timestamp': 1293280200000L,
                           'action': 'deleted',
                           'date': DateTime('2010/12/25 13:30:00'),
                           'actor': TEST_USER_ID},
                          dict(record.attrs))
Пример #10
0
    def test_querying(self):
        soup = get_activity_soup()
        document = create(Builder('document'))
        soup.clear()

        with freeze(datetime(2010, 1, 1)):
            object_added(document)
        with freeze(datetime(2010, 1, 2)):
            object_changed(document)
        with freeze(datetime(2010, 1, 3)):
            object_changed(document)

        results = map(lambda record: (record.attrs['action'], record.attrs['date']),
                      query_soup(Eq('action', 'changed'),
                                 sort_index='date',
                                 reverse=True))

        self.assertEquals([('changed', DateTime('2010/01/03')),
                           ('changed', DateTime('2010/01/02'))],
                          results)
Пример #11
0
def role_removed(obj, event, actor_userid=None, date=None):
    record = ActivityRecord(obj, 'participation:role_removed',
                            actor_userid=actor_userid, date=date)
    record.attrs['roles:userid'] = event.userid
    return get_activity_soup().add(record)
Пример #12
0
def invitation_retracted(obj, event, actor_userid=None, date=None):
    record = create_record_from_invitation(
        obj, event.invitation, 'participation:invitation_retracted')
    return get_activity_soup().add(record)
Пример #13
0
def invitation_created(obj, event, actor_userid=None, date=None):
    record = create_record_from_invitation(
        obj, event.invitation, 'participation:invitation_created')
    record.attrs['invitation:comment'] = event.comment
    return get_activity_soup().add(record)
Пример #14
0
 def __call__(self):
     self.install_upgrade_profile()
     soup = get_activity_soup()
     if len(soup.data) > 0:
         return
     map(index_object, self.objects({}, 'Index activity catalog.'))
Пример #15
0
def file_downloaded(context, actor_userid=None, date=None):
    record = ActivityRecord(context, "file:downloaded", actor_userid=actor_userid, date=date)
    return get_activity_soup().add(record)