Example #1
0
    def create_committee_membership(
        self,
        committee,
        member_id_register_name,
        firstname,
        lastname,
        email,
        date_from,
        date_to,
    ):
        member = create(
            Builder('member').having(firstname=firstname,
                                     lastname=lastname,
                                     email=email))

        create(
            Builder('membership').having(
                committee=committee,
                member=member,
                date_from=date_from,
                date_to=date_to,
            ))

        create_session().flush()  # trigger id generation, part of path

        self.register_url(
            member_id_register_name,
            member.get_url(self.committee_container).encode('utf-8'),
        )

        return member
Example #2
0
    def record_digest(self, userid):
        digest = Digest.query.get_by_userid(userid)
        if not digest:
            digest = Digest(userid=userid, last_dispatch=utcnow_tz_aware())
            create_session().add(digest)

        digest.last_dispatch = utcnow_tz_aware()
Example #3
0
    def record_digest(self, userid):
        digest = Digest.query.get_by_userid(userid)
        if not digest:
            digest = Digest(userid=userid, last_dispatch=utcnow_tz_aware())
            create_session().add(digest)

        digest.last_dispatch = utcnow_tz_aware()
    def test_all_team_members_are_notified_for_a_new_team_task(self, browser):
        self.login(self.regular_user, browser)
        browser.open(self.dossier)
        factoriesmenu.add('Task')

        browser.fill({'Title': u'Team Task', 'Task Type': 'To comment'})
        form = browser.find_form_by_field('Responsible')
        form.find_widget('Responsible').fill('team:2')
        browser.find('Save').click()
        create_session().flush()

        task = self.dossier.get('task-3')

        center = notification_center()
        # Assign watchers to a local variable in order to avoid having
        # a "stale association proxy" when the GC collects within the
        # list comprehension.
        watchers = center.get_watchers(task)
        self.assertEquals([u'team:2', u'kathi.barfuss'],
                          [watcher.actorid for watcher in watchers])

        activity = Activity.query.one()

        self.assertEquals([u'franzi.muller', u'herbert.jager'],
                          [note.userid for note in activity.notifications])
Example #5
0
    def create_contacts(self):
        self.contactfolder = self.register('contactfolder', create(
            Builder('contactfolder')
            .titled(u'Kontakte')
            .having(id='kontakte')))

        self.contactfolder.manage_setLocalRoles(
            self.org_unit.users_group_id, ('Reader',))
        self.contactfolder.manage_setLocalRoles(
            self.org_unit.users_group_id, ('Reader', 'Contributor', 'Editor'))
        self.contactfolder.reindexObjectSecurity()

        self.hanspeter_duerr = self.register('hanspeter_duerr', create(
            Builder('contact')
            .within(self.contactfolder)
            .having(firstname=u'Hanspeter',
                    lastname='D\xc3\xbcrr'.decode('utf-8'))))

        self.franz_meier = self.register('franz_meier', create(
            Builder('contact')
            .within(self.contactfolder)
            .having(firstname=u'Franz', lastname=u'Meier',
                    email=u'*****@*****.**')))

        self.josef_buehler = create(
            Builder('person')
            .having(firstname=u'Josef', lastname=u'B\xfchler'))

        self.meier_ag = create(Builder('organization').named(u'Meier AG'))
        create_session().flush()
    def test_all_team_members_are_notified_for_a_new_team_task(self, browser):
        self.login(self.regular_user, browser)

        with self.observe_children(self.dossier) as children:
            browser.open(self.dossier)
            factoriesmenu.add('Task')
            browser.fill({'Title': u'Team Task', 'Task Type': 'To comment'})
            form = browser.find_form_by_field('Responsible')
            form.find_widget('Responsible').fill('team:2')
            browser.find('Save').click()
            create_session().flush()

        task = children.get('added').pop()
        center = notification_center()
        # Assign watchers to a local variable in order to avoid having
        # a "stale association proxy" when the GC collects within the
        # list comprehension.
        watchers = center.get_watchers(task)
        self.assertEquals(
            [u'team:2', u'kathi.barfuss'],
            [watcher.actorid for watcher in watchers]
        )

        activity = Activity.query.one()

        self.assertEquals(
            [u'franzi.muller', u'herbert.jager'],
            [note.userid for note in activity.notifications])
Example #7
0
    def test_result_is_html_escaped(self):
        self.login(self.meeting_user)
        self.committee_president.model.lastname = u'<script></script>Sch\xf6ller'
        self.committee_president.model.email = None

        create_session().flush()  # the fullname property needs a nudge
        self.assertEqual(u'&lt;script&gt;&lt;/script&gt;Sch\xf6ller Heidrun',
                         self.committee_president.model.get_title())
Example #8
0
    def get_or_create_setting(self, kind):
        setting = self.get_setting(kind)
        if not setting:
            setting = NotificationSetting(
                kind=kind, userid=api.user.get_current().getId())
            create_session().add(setting)

        return setting
    def test_migrates_watcher_actor_ids(self):
        watcher = create(Builder('watcher').having(actorid='HANS.MUSTER'))

        OGDSUserReferencesMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        create_session().refresh(watcher)
        self.assertEquals('hans.muster', watcher.actorid)
    def test_lists_also_inactive_teams_with_all_filter(self, browser):
        Team.get('1').active = False
        create_session().flush()

        self.login(self.regular_user, browser)
        browser.open(self.contactfolder, view='tabbedview_view-teams', data={'team_state_filter': 'filter_all'})
        expected_teams = [u'Projekt \xdcberbaung Dorfmatte', 'Sekretariat Abteilung Null', 'Sekretariat Abteilung XY']
        self.assertEqual(expected_teams, [team.get('Title') for team in browser.css('.listing').first.dicts()])
Example #11
0
    def get_or_create_setting(self, kind):
        setting = self.get_setting(kind)
        if not setting:
            setting = NotificationSetting(
                kind=kind, userid=api.user.get_current().getId())
            create_session().add(setting)

        return setting
    def test_migrates_watcher_actor_ids(self):
        watcher = create(Builder('watcher').having(actorid='HANS.MUSTER'))

        OGDSUserReferencesMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        create_session().refresh(watcher)
        self.assertEquals('hans.muster', watcher.actorid)
Example #13
0
    def get_or_create(cls, userid):
        setting = cls.query.filter_by(userid=userid).one_or_none()
        if setting is None:
            # User has no personal setting
            setting = cls(userid=userid)
            create_session().add(setting)
            setting = cls.query.filter_by(userid=userid).one()

        return setting
Example #14
0
    def test_result_is_html_escaped(self):
        self.login(self.meeting_user)
        self.committee_president.model.lastname = u'<script></script>Sch\xf6ller'
        self.committee_president.model.email = None

        create_session().flush()  # the fullname property needs a nudge
        self.assertEqual(
            u'&lt;script&gt;&lt;/script&gt;Sch\xf6ller Heidrun',
            self.committee_president.model.get_title())
    def test_migrates_task_issuers(self):
        ogds_task = create(Builder('globalindex_task')
                           .having(issuer='HANS.MUSTER'))

        OGDSUserReferencesMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        create_session().refresh(ogds_task)
        self.assertEquals('hans.muster', ogds_task.issuer)
    def test_migrates_task_issuers(self):
        ogds_task = create(
            Builder('globalindex_task').having(issuer='HANS.MUSTER'))

        OGDSUserReferencesMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        create_session().refresh(ogds_task)
        self.assertEquals('hans.muster', ogds_task.issuer)
    def test_migrates_task_principals(self):
        ogds_task = create(Builder('globalindex_task')
                           .having(responsible='foo',
                                   principals=['HANS.MUSTER']))

        OGDSUserReferencesMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        create_session().refresh(ogds_task)
        self.assertEquals(['hans.muster'], ogds_task.principals)
Example #18
0
    def execute(self):
        model = self.proposal.load_model()
        jsondata = {'committee_oguid': model.committee.oguid.id,
                    'proposal_oguid': model.oguid.id}
        request_data = {REQUEST_KEY: json.dumps(jsondata)}
        response = dispatch_json_request(
            self.admin_unit_id, '@@create_submitted_proposal', data=request_data)

        self.submitted_proposal_path = response['path']
        create_session().add(Submitted(proposal=model))
    def test_migrates_task_principals(self):
        ogds_task = create(
            Builder('globalindex_task').having(responsible='foo',
                                               principals=['HANS.MUSTER']))

        OGDSUserReferencesMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        create_session().refresh(ogds_task)
        self.assertEquals(['hans.muster'], ogds_task.principals)
    def test_removes_old_responsible_from_watchers_list(self, browser):
        self.reassign(browser, self.meeting_user, u'Bitte Abkl\xe4rungen erledigen.')

        self.login(self.regular_user, browser)
        resource = notification_center().fetch_resource(self.task)
        create_session().refresh(resource)
        subscriptions = resource.subscriptions

        self.assertItemsEqual(
            [(u'herbert.jager', TASK_RESPONSIBLE_ROLE)],
            [(sub.watcher.actorid, sub.role) for sub in subscriptions])
    def test_migrates_activity_actor_ids(self):
        resource = create(Builder('resource').oguid('client1:123'))
        activity = create(Builder('activity')
                          .having(resource=resource,
                                  actor_id='HANS.MUSTER'))

        OGDSUserReferencesMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        create_session().refresh(activity)
        self.assertEquals('hans.muster', activity.actor_id)
Example #22
0
    def test_removes_old_responsible_from_watchers_list(self, browser):
        self.reassign(browser, self.meeting_user,
                      u'Bitte Abkl\xe4rungen erledigen.')

        self.login(self.regular_user, browser)
        resource = notification_center().fetch_resource(self.task)
        create_session().refresh(resource)
        subscriptions = resource.subscriptions

        self.assertItemsEqual([(u'herbert.jager', TASK_RESPONSIBLE_ROLE)],
                              [(sub.watcher.actorid, sub.role)
                               for sub in subscriptions])
    def test_migrates_activity_actor_ids(self):
        resource = create(Builder('resource').oguid('client1:123'))
        activity = create(
            Builder('activity').having(resource=resource,
                                       actor_id='HANS.MUSTER'))

        OGDSUserReferencesMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        create_session().refresh(activity)
        self.assertEquals('hans.muster', activity.actor_id)
    def test_lists_only_active_teams_by_default(self, browser):
        self.login(self.regular_user, browser)
        browser.open(self.contactfolder, view='tabbedview_view-teams')
        expected_teams = [u'Projekt \xdcberbaung Dorfmatte', 'Sekretariat Abteilung Null', 'Sekretariat Abteilung XY']
        self.assertEqual(expected_teams, [team.get('Title') for team in browser.css('.listing').first.dicts()])

        Team.get('1').active = False
        create_session().flush()

        browser.open(self.contactfolder, view='tabbedview_view-teams')
        expected_teams = ['Sekretariat Abteilung Null', 'Sekretariat Abteilung XY']
        self.assertEquals(expected_teams, [team.get('Title') for team in browser.css('.listing').first.dicts()])
Example #25
0
    def add_watcher(self, actorid, role):
        watcher = Watcher.query.get_by_actorid(actorid)
        if not watcher:
            watcher = Watcher(actorid=actorid)
            create_session().add(watcher)

        subscription = Subscription.query.fetch(self, watcher, role)
        if not subscription:
            subscription = Subscription(resource=self, watcher=watcher, role=role)
            create_session().add(subscription)

        return watcher
    def test_add_members_handles_participants_are_no_longer_committee_memberships(self):
        create_session().delete(self.membership_peter)

        self.assertEquals(
            {
                "members": [
                    {"fullname": u"Peter M\xfcller", "role": None, "email": None},
                    {"fullname": u"Franz M\xfcller", "role": None, "email": u"*****@*****.**"},
                ]
            },
            ProtocolData(self.meeting).add_members(),
        )
Example #27
0
    def add(self, userid, obj):
        favorite = Favorite(userid=userid,
                            oguid=Oguid.for_object(obj),
                            title=obj.Title().decode('utf-8'),
                            portal_type=obj.portal_type,
                            icon_class=get_css_class(obj),
                            plone_uid=IUUID(obj),
                            position=self.get_next_position(userid))

        create_session().add(favorite)
        create_session().flush()
        return favorite
    def disable_additional_org_units(self, org_unit_ids=None):
        if org_unit_ids is None:
            org_unit_ids = ('rk',)

        current_ou = get_current_org_unit()
        if current_ou in org_unit_ids:
            raise ValueError

        for ou_id in org_unit_ids:
            ou = OrgUnit.get(ou_id)
            create_session().delete(ou)

        current_ou._chosen_strategy = None
    def disable_additional_org_units(self, org_unit_ids=None):
        if org_unit_ids is None:
            org_unit_ids = ('rk',)

        current_ou = get_current_org_unit()
        if current_ou in org_unit_ids:
            raise ValueError

        for ou_id in org_unit_ids:
            ou = OrgUnit.get(ou_id)
            create_session().delete(ou)

        current_ou._chosen_strategy = None
Example #30
0
    def add_watcher(self, actorid, role):
        watcher = Watcher.query.get_by_actorid(actorid)
        if not watcher:
            watcher = Watcher(actorid=actorid)
            create_session().add(watcher)

        subscription = Subscription.query.fetch(self, watcher, role)
        if not subscription:
            subscription = Subscription(
                resource=self, watcher=watcher, role=role)
            create_session().add(subscription)

        return watcher
Example #31
0
    def test_add_favorite(self):
        favorite = Favorite(
            oguid=Oguid.parse('fd:123'),
            userid=self.regular_user.getId(),
            title=u'Testposition 1',
            position=2,
            portal_type='opengever.repositoryfolder.repositoryfolder',
            icon_class='contenttype-opengever-repository-repositoryfolder',
            plone_uid='127bad76e535451493bb5172c28eb38d')

        create_session().add(favorite)

        self.assertEqual(1, Favorite.query.count())
        self.assertEqual(u'Testposition 1', Favorite.query.one().title)
    def test_migrates_notification_userids(self):
        resource = create(Builder('resource').oguid('client1:123'))
        activity = create(Builder('activity')
                          .having(resource=resource))

        notification = create(Builder('notification')
                              .having(activity=activity,
                                      userid='HANS.MUSTER', is_read=False))

        OGDSUserReferencesMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        create_session().refresh(notification)
        self.assertEquals('hans.muster', notification.userid)
Example #33
0
    def test_add_favorite(self):
        favorite = Favorite(
            oguid=Oguid.parse('fd:123'),
            userid=self.regular_user.getId(),
            title=u'Testposition 1',
            position=2,
            portal_type='opengever.repositoryfolder.repositoryfolder',
            icon_class='contenttype-opengever-repository-repositoryfolder',
            plone_uid='127bad76e535451493bb5172c28eb38d')

        create_session().add(favorite)

        self.assertEqual(1, Favorite.query.count())
        self.assertEqual(u'Testposition 1', Favorite.query.one().title)
Example #34
0
    def add(self, userid, obj):
        truncated_title = Favorite.truncate_title(obj.Title().decode('utf-8'))
        favorite = Favorite(
            userid=userid,
            oguid=Oguid.for_object(obj),
            title=truncated_title,
            portal_type=obj.portal_type,
            icon_class=get_css_class(obj),
            plone_uid=IUUID(obj),
            position=self.get_next_position(userid))

        create_session().add(favorite)
        create_session().flush()
        return favorite
Example #35
0
    def create_meetings(self):
        meeting_dossier = self.register('meeting_dossier', create(
            Builder('meeting_dossier').within(self.repofolder00)
            .titled(u'Sitzungsdossier 9/2017')
            .having(start=date(2016, 9, 12),
                    relatedDossier=[self.dossier],
                    responsible=self.committee_responsible.getId())))
        self.meeting = create(
            Builder('meeting')
            .having(title=u'9. Sitzung der Rechnungspr\xfcfungskommission',
                    committee=self.committee.load_model(),
                    location=u'B\xfcren an der Aare',
                    start=datetime(2016, 9, 12, 15, 30, tzinfo=pytz.UTC),
                    end=datetime(2016, 9, 12, 17, 0, tzinfo=pytz.UTC),
                    presidency=self.committee_president,
                    secretary=self.committee_secretary,
                    participants=[self.committee_participant_1,
                                  self.committee_participant_2])
            .link_with(meeting_dossier))
        create_session().flush()  # trigger id generation, part of path
        self.register_path(
            'meeting', self.meeting.physical_path.encode('utf-8'))

        decided_meeting_dossier = self.register(
            'decided_meeting_dossier', create(
                Builder('meeting_dossier').within(self.repofolder00)
                .titled(u'Sitzungsdossier 8/2017')
                .having(start=date(2016, 8, 17),
                        responsible=self.committee_responsible.getId())))
        self.decided_meeting = create(
            Builder('meeting')
            .having(title=u'8. Sitzung der Rechnungspr\xfcfungskommission',
                    committee=self.committee.load_model(),
                    location=u'B\xfcren an der Aare',
                    start=datetime(2016, 7, 17, 15, 30, tzinfo=pytz.UTC),
                    end=datetime(2016, 7, 17, 16, 30, tzinfo=pytz.UTC),
                    presidency=self.committee_president,
                    secretary=self.committee_secretary,
                    participants=[self.committee_participant_1,
                                  self.committee_participant_2])
            .link_with(decided_meeting_dossier))
        create_session().flush()  # trigger id generation, part of path
        self.register_path(
            'decided_meeting',
            self.decided_meeting.physical_path.encode('utf-8'))

        self.decided_meeting.schedule_proposal(
            self.decided_proposal.load_model())
        self.decided_meeting.close()
Example #36
0
    def reset(self):
        """Reset a personal setting
        """
        kind = self.request.form['kind']

        if ALIASES.get(kind):
            kinds = ALIASES.get(kind)
        else:
            kinds = (kind, )

        for kind in kinds:
            setting = self.get_setting(kind)
            create_session().delete(setting)

        return JSONResponse(self.request).proceed().dump()
Example #37
0
    def test_add_members_handles_participants_are_no_longer_committee_memberships(self):
        create_session().delete(self.membership_peter)

        self.assertEquals(
            {'members': [{'fullname': u'B\xe4nni Anna',
                          'email': '*****@*****.**',
                         'role': None},
                         {'fullname': u'M\xfcller Franz',
                          'role': None,
                          'email': u'*****@*****.**'},
                         {'fullname': u'M\xfcller Peter',
                          'role': None,
                          'email': None},
                         ]},
            ProtocolData(self.meeting).add_members())
    def test_migrates_notification_userids(self):
        resource = create(Builder('resource').oguid('client1:123'))
        activity = create(Builder('activity').having(resource=resource))

        notification = create(
            Builder('notification').having(activity=activity,
                                           userid='HANS.MUSTER',
                                           is_read=False))

        OGDSUserReferencesMigrator(self.portal, {
            'HANS.MUSTER': 'hans.muster'
        }, 'move').migrate()

        create_session().refresh(notification)
        self.assertEquals('hans.muster', notification.userid)
Example #39
0
def remove_favorites(context, event):
    """Event handler which removes all existing favorites for the
    current context.
    """

    # Skip plone site removals. Unfortunately no deletion-order seems to be
    # guaranteed, when removing the plone site, so it might happen that the
    # intid utility is removed before removing content.
    if IPloneSiteRoot.providedBy(event.object):
        return

    oguid = Oguid.for_object(context)

    stmt = Favorite.__table__.delete().where(Favorite.oguid == oguid)
    create_session().execute(stmt)
Example #40
0
    def test_does_cast_integer_fields_on_oracle_backends(self):
        original_dialect = create_session().connection().dialect.name
        failed = False

        try:
            create_session().connection().dialect.name = 'oracle'
            field = Task.sequence_number
            self.assertIsInstance(cast_to_string(field), InstrumentedAttribute)
            self.assertIsInstance(cast_to_string(field).type, Integer)
        except BaseException:
            failed = True
        finally:
            create_session().connection().dialect.name = original_dialect

        self.assertFalse(failed, 'Something went wrong when changing the dialect.')
Example #41
0
    def reset(self):
        """Reset a personal setting
        """
        kind = self.request.form['kind']

        if ALIASES.get(kind):
            kinds = ALIASES.get(kind)
        else:
            kinds = (kind, )

        for kind in kinds:
            setting = self.get_setting(kind)
            create_session().delete(setting)

        return JSONResponse(self.request).proceed().dump()
Example #42
0
def remove_favorites(context, event):
    """Event handler which removes all existing favorites for the
    current context.
    """

    # Skip plone site removals. Unfortunately no deletion-order seems to be
    # guaranteed, when removing the plone site, so it might happen that the
    # intid utility is removed before removing content.
    if IPloneSiteRoot.providedBy(event.object):
        return

    oguid = Oguid.for_object(context)

    stmt = Favorite.__table__.delete().where(Favorite.oguid == oguid)
    create_session().execute(stmt)
Example #43
0
    def delete(self, userid, fav_id):
        favorite = Favorite.query.by_userid_and_id(fav_id, userid).first()
        if not favorite:
            # inexistent favorite-id or not ownded by given user
            raise NotFound

        # update positions
        favorites_to_reduce = Favorite.query.by_userid(userid).filter(
            Favorite.position > favorite.position).with_for_update()

        for new_pos, fav_to_reduce in enumerate(favorites_to_reduce,
                                                start=favorite.position):
            fav_to_reduce.position = new_pos

        create_session().delete(favorite)
Example #44
0
    def migrate(self):
        log.info("Migrating notification settings for aliased groups...")
        self.session = create_session()
        self.new_settings_to_insert = {}

        # Determine notification defaults *once*, ahead of time
        self.notification_defaults = {
            default.kind: default
            for default in NotificationDefault.query
        }

        # Get a list of distinct userids of users that have any settings stored
        users_with_settings = [
            r[0]
            for r in self.session.query(NotificationSetting.userid.distinct())
        ]

        # For each user, homogenize their settings
        for userid in users_with_settings:
            self.homogenize_settings(userid)

        # Finally, add any new setting rows that were missing (necessary where
        # only some kinds of an alias group had non-default settings)
        self.insert_newly_required_settings()
        log.info("Done migrating notification settings for aliased groups")
Example #45
0
    def reset_tasktemplates_dict_storage(self):
        session = create_session()
        query = session.query(DictStorageModel).filter(
            DictStorageModel.key.contains('tabbedview_view-tasktemplates'))

        for record in query:
            # Deal with broken DictStorage entries (NULL)
            if record.value is None:
                log.warn("DictStorage record with key '%s' has "
                         "NULL value - skipping record!" % record.key)
                continue

            try:
                data = json.loads(record.value.encode('utf-8'))
            except ValueError:
                log.warn("DictStorage record with key '%s' has invalid value "
                         "- skipping record!" % record.key)
                continue

            columns = data.get('columns')
            for column in columns:
                column["sortable"] = False

            data['columns'] = columns
            record.value = json.dumps(data)
Example #46
0
    def setUpPloneSite(self, portal):
        session.current_session = session.BuilderSession()
        session.current_session.session = create_session()
        super(ContentFixtureLayer, self).setUpPloneSite(portal)

        portal.portal_languages.use_combined_language_codes = True
        portal.portal_languages.addSupportedLanguage('de-ch')

        if not DB_CACHE_MANAGER.is_loaded_from_cache(CACHE_GEVER_FIXTURE):
            sqlite_testing.create_tables()
            # Avoid circular imports:
            from opengever.testing.fixtures import OpengeverContentFixture
            setRequest(portal.REQUEST)
            self['fixture_lookup_table'] = OpengeverContentFixture()()
            setRequest(None)
            DB_CACHE_MANAGER.data['fixture_lookup_table'] = (
                self['fixture_lookup_table'])
            DB_CACHE_MANAGER.dump_to_cache(self['zodbDB'], CACHE_GEVER_FIXTURE)
        else:
            DB_CACHE_MANAGER.apply_cache_fixes(CACHE_GEVER_FIXTURE)
            self['fixture_lookup_table'] = (
                DB_CACHE_MANAGER.data['fixture_lookup_table'])

        # bumblebee should only be turned on on-demand with the feature flag.
        # if this assertion fails a profile in the fixture enables bumblebee,
        # or if was left on by mistake after fixture setup.
        assert not is_bumblebee_feature_enabled()
Example #47
0
def memory_session_factory():
    sqlite_testing.setup_memory_database()
    sess = session.BuilderSession()
    sess.auto_commit = False
    sess.auto_flush = True
    sess.session = create_session()
    return sess
Example #48
0
 def get_ogds_config(self):
     """Returns the DSN URL for the OGDS DB connection currently being
     used.
     """
     session = create_session()
     engine = session.bind
     return engine.url
Example #49
0
def create_ogds_user(userid, session=None,
                     groups=('og_mandant1_users',),
                     assigned_client=[], **properties):

    session = session or create_session()

    defaults = {'firstname': 'Hugo',
                'lastname': 'Boss',
                'email': '*****@*****.**'}

    options = defaults.copy()
    options.update(properties)

    try:
        user = session.query(User).filter_by(userid=userid).one()
    except NoResultFound:
        user = User(userid, **options)
    else:
        for key, value in options.items():
            setattr(user, key, value)

    session.add(user)

    for groupid in groups:
        ogds_add_user_to_group(user, groupid, session=session)

    for client in assigned_client:
        assign_user_to_client(user, client, session=session)

    reset_ogds_sync_stamp(getSite())

    return user
Example #50
0
    def delete(self, userid, fav_id):
        favorite = Favorite.query.by_userid_and_id(fav_id, userid).first()
        if not favorite:
            # inexistent favorite-id or not ownded by given user
            raise NotFound

        # update positions
        favorites_to_reduce = Favorite.query.by_userid(userid).filter(
            Favorite.position > favorite.position).with_for_update().order_by(
                Favorite.position)

        for new_pos, fav_to_reduce in enumerate(
                favorites_to_reduce, start=favorite.position):
            fav_to_reduce.position = new_pos

        create_session().delete(favorite)
Example #51
0
    def schedule(self, meeting):
        assert self.can_be_scheduled()

        self.execute_transition('submitted-scheduled')
        session = create_session()
        meeting.agenda_items.append(AgendaItem(proposal=self))
        session.add(proposalhistory.Scheduled(proposal=self, meeting=meeting))
Example #52
0
    def __init__(self, site):
        self.site = site
        self.db_session = create_session()
        self.setup_builders()
        self.committee_law = self.site['sitzungen']['committee-1']
        self.committee_law_model = self.committee_law.load_model()

        self.committee_accounting = self.site['sitzungen']['committee-2']
        self.committee_accounting_model = self.committee_accounting.load_model()

        self.committee_assembly = self.site['sitzungen']['committee-3']
        self.committee_assembly_model = self.committee_assembly.load_model()

        self.dossier_baumann = self.site.restrictedTraverse(
            'ordnungssystem/ressourcen-und-support/personal/personalrekrutierung/dossier-4')
        self.dossier_taxes_1 = self.site.restrictedTraverse(
            'ordnungssystem/ressourcen-und-support/finanzen/planung/finanzplanung/dossier-5')
        self.dossier_taxes_2 = self.site.restrictedTraverse(
            'ordnungssystem/ressourcen-und-support/finanzen/planung/finanzplanung/dossier-6')
        self.dossier_equipment = self.site.restrictedTraverse(
            'ordnungssystem/ressourcen-und-support/finanzen/planung/investitionsplanung/dossier-7')
        self.repository_folder_meeting = self.site.restrictedTraverse(
            'ordnungssystem/fuehrung/gemeindeversammlung-gemeindeparlament-legislative/versammlungen-sitzungen')

        self.document_baumann_1 = self.dossier_baumann['document-2']
        self.document_baumann_2 = self.dossier_baumann['document-3']

        self.document_taxes_1 = self.dossier_taxes_1['document-4']
        self.document_taxes_2 = self.dossier_taxes_1['document-5']
        self.document_taxes_3 = self.dossier_taxes_2['document-6']

        self.document_equipment_1 = self.dossier_equipment['document-7']
        self.document_equipment_2 = self.dossier_equipment['document-8']
    def render(self):
        self.result = []
        session = create_session()

        meta = MetaData()
        meta.reflect(bind=session.bind)

        for name, table in meta.tables.items():
            rows = session.execute(table.select())
            self.display("=" * 78)
            self.display("Checking table: {}".format(name))
            self.display("=" * 78)
            for row in rows:
                for value, column in zip(row, table.columns):
                    if hasattr(column.type, 'length'):
                        if value is None:
                            # NULL value
                            continue
                        if column.type.length is None:
                            # Infinite length
                            continue
                        if len(value) >= column.type.length:
                            self.display("COLUMN: {}".format(repr(column)))
                            self.display("VALUE: {}".format(value))
            self.display('')
        return '\n'.join(self.result)
    def test_get_attending_members_handles_participants_are_no_longer_committee_memberships(self):
        create_session().delete(self.membership_anna)

        self.assertEquals(
            [{'firstname': 'Anna',
              'lastname': u'B\xe4nni',
              'fullname': u'B\xe4nni Anna',
              'email': '*****@*****.**',
             'role': None},
             {'email': u'*****@*****.**',
              'firstname': u'Franz',
              'fullname': u'M\xfcller Franz',
              'lastname': u'M\xfcller',
              'role': None},
             ],
            ProtocolData(self.meeting).get_attending_members())
Example #55
0
    def schedule(self, meeting):
        assert self.can_be_scheduled()

        self.execute_transition('submitted-scheduled')
        session = create_session()
        meeting.agenda_items.append(AgendaItem(proposal=self))
        session.add(proposalhistory.Scheduled(proposal=self, meeting=meeting))
    def setUpPloneSite(self, portal):
        session.current_session = session.BuilderSession()
        session.current_session.session = create_session()
        super(TestserverLayer, self).setUpPloneSite(portal)

        applyProfile(portal, 'plonetheme.teamraum:gever')

        portal.portal_languages.use_combined_language_codes = True
        portal.portal_languages.addSupportedLanguage('de-ch')

        api.portal.set_registry_record('use_solr',
                                       True,
                                       interface=ISearchSettings)
        activate_bumblebee_feature()

        setRequest(portal.REQUEST)
        print 'Installing fixture. Have patience.'
        self.get_fixture_class()()
        print 'Finished installing fixture.'
        setRequest(None)

        # Commit before creating the solr backup, since collective.indexing
        # flushes on commit.
        transaction.commit()
        SolrReplicationAPIClient.get_instance().create_backup('fixture')
Example #57
0
    def __call__(self):

        session = create_session()
        query = session.query(DictStorageModel).filter(
            or_(DictStorageModel.key.contains('tabbedview_view-documents'),
                DictStorageModel.key.contains('tabbedview_view-mydocuments')))

        for record in query:
            # Deal with broken DictStorage entries (NULL)
            if record.value is None:
                log.warn("DictStorage record with key '%s' has "
                         "NULL value - skipping record!" % record.key)
                continue

            try:
                data = json.loads(record.value.encode('utf-8'))
            except ValueError:
                log.warn("DictStorage record with key '%s' has invalid value "
                         "- skipping record!" % record.key)
                continue

            columns = data.get('columns')
            if PUBLIC_TRIAL_COL_ID not in [col.get('id') for col in columns]:

                if columns[-1].get('id') == u'dummy':
                    columns.insert(len(columns) - 1, PUBLIC_TRIAL_COL_CONFIG)
                else:
                    columns.append(PUBLIC_TRIAL_COL_CONFIG)

                data['columns'] = columns

                record.value = json.dumps(data)