Exemplo n.º 1
0
    def plone_participations(self):
        if not self.context.has_participation_support():
            return []

        # get the participants
        phandler = IParticipationAware(self.context)
        results = list(phandler.get_participations())

        # also append the responsible
        class ResponsibleParticipant(object):
            pass

        responsible = ResponsibleParticipant()
        responsible.roles = _dossier(u'label_responsible', 'Responsible')
        responsible.role_list = responsible.roles

        dossier_adpt = IDossier(self.context)
        responsible.contact = dossier_adpt.responsible
        results.append(responsible)

        users = []
        for dossier in results:
            actor = Actor.lookup(dossier.contact)
            users.append({
                'Title': actor.get_label(),
                'getURL': actor.get_profile_url(),
                'css_class': 'function-user',
            })
        return users
Exemplo n.º 2
0
    def sharing(self):

        # get the participants
        phandler = IParticipationAware(self.context)
        results = list(phandler.get_participations())

        # also append the responsible
        class ResponsibleParticipant(object):
            pass

        responsible = ResponsibleParticipant()
        responsible.roles = _dossier(u'label_responsible', 'Responsible')
        responsible.role_list = responsible.roles

        dossier_adpt = IDossier(self.context)
        responsible.contact = dossier_adpt.responsible
        results.append(responsible)

        info = getUtility(IContactInformation)

        return [{
            'Title': info.describe(xx.contact),
            'getURL': info.get_profile_url(xx.contact),
            'css_class': 'function-user',
        } for xx in results]
Exemplo n.º 3
0
    def sharing(self):

        # get the participants
        phandler = IParticipationAware(self.context)
        results = list(phandler.get_participations())

        # also append the responsible
        class ResponsibleParticipant(object):
            pass

        responsible = ResponsibleParticipant()
        responsible.roles = _dossier(u'label_responsible', 'Responsible')
        responsible.role_list = responsible.roles

        dossier_adpt = IDossier(self.context)
        responsible.contact = dossier_adpt.responsible
        results.append(responsible)

        info = getUtility(IContactInformation)

        return [{
            'Title': info.describe(xx.contact),
            'getURL': info.get_profile_url(xx.contact),
            'css_class': 'function-user',
            }
            for xx in results]
Exemplo n.º 4
0
    def plone_participations(self):
        if not self.context.has_participation_support():
            return []

        # get the participants
        phandler = IParticipationAware(self.context)
        results = list(phandler.get_participations())

        # also append the responsible
        class ResponsibleParticipant(object):
            pass

        responsible = ResponsibleParticipant()
        responsible.roles = _dossier(u'label_responsible', 'Responsible')
        responsible.role_list = responsible.roles

        dossier_adpt = IDossier(self.context)
        responsible.contact = dossier_adpt.responsible
        results.append(responsible)

        users = []
        for dossier in results:
            actor = Actor.lookup(dossier.contact)
            users.append({
                'Title': actor.get_label(),
                'getURL': actor.get_profile_url(),
                'css_class': 'function-user',
            })
        return users
Exemplo n.º 5
0
 def handle_add(self, action):
     data, errors = self.extractData()
     if not errors:
         phandler = IParticipationAware(self.context)
         part = phandler.create_participation(**data)
         phandler.append_participiation(part)
         status = IStatusMessage(self.request)
         msg = _(u'info_participation_create', u'Participation created.')
         status.addStatusMessage(msg, type='info')
         return self._redirect_to_participants_tab()
Exemplo n.º 6
0
 def handle_add(self, action):
     data, errors = self.extractData()
     if not errors:
         phandler = IParticipationAware(self.context)
         part = phandler.create_participation(**data)
         phandler.append_participiation(part)
         status = IStatusMessage(self.request)
         msg = _(u'info_participation_create',
                 u'Participation created.')
         status.addStatusMessage(msg, type='info')
         return self._redirect_to_participants_tab()
Exemplo n.º 7
0
    def test_participant_labels_are_displayed(self, browser):
        self.login(self.regular_user, browser=browser)

        handler = IParticipationAware(self.dossier)
        participation = handler.create_participation(contact='robert.ziegler',
                                                     roles=['regard'])
        handler.append_participiation(participation)

        browser.open(self.dossier, view='tabbedview_view-overview')
        self.assertEqual(
            ['Ziegler Robert (robert.ziegler)'],
            browser.css('#participantsBox li:not(.moreLink) a').text)
Exemplo n.º 8
0
    def test_participant_labels_are_displayed(self, browser):
        self.login(self.regular_user, browser=browser)

        handler = IParticipationAware(self.tested_dossier)
        participation = handler.create_participation(contact='kathi.barfuss',
                                                     roles=['regard'])
        handler.append_participiation(participation)

        browser.open(self.tested_dossier, view='tabbedview_view-overview')
        self.assertListEqual(
            self.participants,
            browser.css('#participantsBox li:not(.moreLink) a').text)
Exemplo n.º 9
0
    def test_participant_labels_are_displayed(self, browser):
        self.login(self.regular_user, browser=browser)

        handler = IParticipationAware(self.tested_dossier)
        participation = handler.create_participation(
            contact='kathi.barfuss', roles=['regard'])
        handler.append_participiation(participation)

        browser.open(self.tested_dossier,
                     view='tabbedview_view-overview')
        self.assertListEqual(
            self.participants,
            browser.css('#participantsBox li:not(.moreLink) a').text)
Exemplo n.º 10
0
    def validate_base_query(self, query):
        """hacky: get the actual elements here because we are not
        able to use queries on annotations / lists ...
        """
        context = self.config.context

        phandler = IParticipationAware(context)
        results = list(phandler.get_participations())

        dossier_adpt = IDossier(context)
        responsible_name = _(u'label_responsible', 'Responsible')
        results.append(ParticipationResponsible(
            contact=dossier_adpt.responsible,
            responsible=responsible_name))

        return results
Exemplo n.º 11
0
 def __call__(self):
     oids = self.request.get('oids')
     if not oids:
         msg = _(u'warning_no_participants_selected',
                 default=u'You didn\'t select any participants.')
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
         return self.request.RESPONSE.redirect(self.redirect_url)
     phandler = IParticipationAware(self.context)
     for a in oids:
         oid = base64.decodestring(a)
         obj = self.context._p_jar[oid]
         phandler.remove_participation(obj)
     status = IStatusMessage(self.request)
     msg = _(u'info_removed_participations', 'Removed participations.')
     status.addStatusMessage(msg, type='info')
     return self.request.RESPONSE.redirect(self.redirect_url)
Exemplo n.º 12
0
    def validate_base_query(self, query):
        """hacky: get the actual elements here because we are not
        able to use queries on annotations / lists ...
        """
        context = self.config.context

        phandler = IParticipationAware(context)
        results = list(phandler.get_participations())

        dossier_adpt = IDossier(context)
        responsible_name = _(u'label_responsible', 'Responsible')
        results.append(
            ParticipationResponsible(contact=dossier_adpt.responsible,
                                     responsible=responsible_name))

        return results
Exemplo n.º 13
0
    def get_participants(self):
        dossier = IDossier(self.context)
        rows = []

        # add the responsible
        rows.append('%s, %s' % (
                readable_ogds_author(None, dossier.responsible),
                translate(_dossier(u'label_responsible', 'Responsible'),
                          context=self.request)))

        # add the participants
        participants = list(IParticipationAware(
                self.context).get_participations())

        for participant in participants:
            rows.append('%s, %s' % (
                    readable_ogds_author(participant, participant.contact),
                    role_list_helper(participant, participant.roles)))

        values = ['{', '\\vspace{-\\baselineskip}\\begin{itemize}']
        for row in self.convert_list(rows):
            values.append('\\item {}'.format(row))

        values.append('\\vspace{-\\baselineskip}\\end{itemize}')
        values.append('}')

        return ' \n'.join(values)
Exemplo n.º 14
0
 def __call__(self):
     oids = self.request.get('oids')
     if not oids:
         msg = _(u'warning_no_participants_selected',
                 default=u'You didn\'t select any participants.')
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
         return self.request.RESPONSE.redirect(self.redirect_url)
     phandler = IParticipationAware(self.context)
     for a in oids:
         oid = base64.decodestring(a)
         obj = self.context._p_jar[oid]
         phandler.remove_participation(obj)
     status = IStatusMessage(self.request)
     msg = _(u'info_removed_participations',
             'Removed participations.')
     status.addStatusMessage(msg, type='info')
     return self.request.RESPONSE.redirect(self.redirect_url)
Exemplo n.º 15
0
    def _migrate_participations(self, dossier):
        moved = []
        path = '/'.join(dossier.getPhysicalPath())

        if not IParticipationAwareMarker.providedBy(dossier):
            # No participation support - probably a template folder
            return moved

        phandler = IParticipationAware(dossier)
        participations = phandler.get_participations()
        for participation in participations:
            old_userid = participation.contact
            if old_userid in self.principal_mapping:
                new_userid = self.principal_mapping[old_userid]
                logger.info("Migrating participation for {} ({} -> {})".format(
                    path, old_userid, new_userid))
                self._verify_user(new_userid)
                participation.contact = new_userid
                moved.append((path, old_userid, new_userid))

        return moved
    def setUp(self):
        super(TestDossierMigratorForParticipants, self).setUp()
        self.portal = self.layer['portal']

        create(Builder('ogds_user').id('old.participant'))
        create(Builder('ogds_user').id('new.participant'))

        self.dossier = create(Builder('dossier')
                              .titled(u'Testdossier'))

        self.phandler = IParticipationAware(self.dossier)
        p = self.phandler.create_participation('old.participant', ['regard'])
        self.phandler.append_participiation(p)
class TestDossierMigratorForParticipants(FunctionalTestCase):

    def setUp(self):
        super(TestDossierMigratorForParticipants, self).setUp()
        self.portal = self.layer['portal']

        create(Builder('ogds_user').id('old.participant'))
        create(Builder('ogds_user').id('new.participant'))

        self.dossier = create(Builder('dossier')
                              .titled(u'Testdossier'))

        self.phandler = IParticipationAware(self.dossier)
        p = self.phandler.create_participation('old.participant', ['regard'])
        self.phandler.append_participiation(p)

    def test_dossier_participation_gets_migrated(self):

        migrator = DossierMigrator(
            self.portal, {'old.participant': 'new.participant'}, 'move')
        migrator.migrate()

        self.assertEquals('new.participant',
                          self.phandler.get_participations()[0].contact)

    def test_contacts_dont_match_principal_mapping(self):
        # Create a contact with the same name as a mapped user in order to
        # verify the mapping doesn't match the contact.id
        contact = create(Builder('contact')
                         .having(firstname='contact',
                                 lastname='old'))

        # Create a participation using that contact
        p = self.phandler.create_participation(contact.contactid(), ['regard'])
        self.phandler.append_participiation(p)

        migrator = DossierMigrator(self.portal, {contact.id: 'new'}, 'move')
        migrator.migrate()

        # Should not have been migrated, participation should still refer
        # to contact:old-contact
        self.assertEquals('contact:old-contact',
                          self.phandler.get_participations()[-1].contact)

    def test_raises_if_strict_and_user_doesnt_exist(self):
        migrator = DossierMigrator(
            self.portal, {'old.participant': 'doesnt.exist'}, 'move')

        with self.assertRaises(UserMigrationException):
            migrator.migrate()

    def test_doesnt_raise_if_not_strict_and_user_doesnt_exist(self):
        migrator = DossierMigrator(
            self.portal, {'old.participant': 'doesnt.exist'},
            'move', strict=False)

        migrator.migrate()

        self.assertEquals('doesnt.exist',
                          self.phandler.get_participations()[0].contact)

    def test_returns_proper_results_for_moving_participants(self):
        migrator = DossierMigrator(
            self.portal, {'old.participant': 'new.participant'}, 'move')
        results = migrator.migrate()

        self.assertEquals(
            [('/plone/dossier-1', 'old.participant', 'new.participant')],
            results['participations']['moved']
        )