Beispiel #1
0
 def _available_badges(self):
     '''
     Return the badges that are editable by a user.
     '''
     c.groups = [{'permission': 'global.admin',
                  'label': _('In all instances'),
                  'show_label': True}]
     if c.instance:
         c.groups.append(
             {'permission': 'instance.admin',
              'label': _('In instance "%s"') % c.instance.label,
              'show_label': h.has_permission('global.admin')})
     badges = {}
     if has('global.admin'):
         badges['global.admin'] = {
             'instance': InstanceBadge.all(instance=None),
             'user': UserBadge.all(instance=None),
             'delegateable': DelegateableBadge.all(instance=None),
             'category': CategoryBadge.all(instance=None),
             'thumbnail': ThumbnailBadge.all(instance=None)}
     if has('instance.admin') and c.instance is not None:
         badges['instance.admin'] = {
             'instance': InstanceBadge.all(instance=c.instance),
             'user': UserBadge.all(instance=c.instance),
             'delegateable': DelegateableBadge.all(instance=c.instance),
             'category': CategoryBadge.all(instance=c.instance),
             'thumbnail': ThumbnailBadge.all(instance=c.instance)}
     return badges
Beispiel #2
0
    def test_get_all_badgets(self):
        #setup
        from adhocracy.model import Badge, CategoryBadge, DelegateableBadge, \
            InstanceBadge
        from adhocracy.model import UserBadge, Instance
        instance = Instance.find(u'test')
        # create for each type a global scope and an instance scope badge
        InstanceBadge.create(u'badge ü', u'#ccc', u'description ü')
        InstanceBadge.create(u'badge ü', u'#ccc', u'description ü',
                                 instance=instance)
        UserBadge.create(u'badge ü', u'#ccc', u'description ü')
        UserBadge.create(u'ü', u'#ccc', u'ü', instance=instance)
        DelegateableBadge.create(u'badge ü', u'#ccc', u'description ü')
        DelegateableBadge.create(u'badge ü', u'#ccc', u'description ü',
                                 instance=instance)
        CategoryBadge.create(u'badge ü', u'#ccc', u"desc")
        CategoryBadge.create(u'badge ü', u'#ccc', u"desc", instance=instance)

        # all instance badges
        self.assert_(len(InstanceBadge.all()) == 1)
        self.assert_(len(InstanceBadge.all(instance=instance)) == 1)
        # all delegateable badges
        self.assert_(len(DelegateableBadge.all()) == 1)
        self.assert_(len(DelegateableBadge.all(instance=instance)) == 1)
        # all delegateable category badges
        self.assert_(len(CategoryBadge.all()) == 1)
        self.assert_(len(CategoryBadge.all(instance=instance)) == 1)
        # all user badgets
        self.assert_(len(UserBadge.all()) == 1)
        self.assert_(len(UserBadge.all(instance=instance)) == 1)
        # We can get all Badges by using `Badge`
        self.assert_(len(Badge.all()) == 4)
        self.assert_(len(Badge.all(instance=instance)) == 4)

        self.assert_(len(Badge.all_q().all()) == 8)
Beispiel #3
0
    def new(self, id=None, errors={}, format=u'html'):

        if id is None:
            require.perm('global.message')
            template = '/massmessage/new.html'
            c.preview_url = h.base_url('/message/preview')
        else:
            c.page_instance = InstanceController._get_current_instance(id)
            require.instance.message(c.page_instance)
            template = '/instance/message.html'
            c.preview_url = h.base_url('/instance/%s/message/preview' % id)

        defaults = dict(request.params)
        defaults.setdefault('include_footer', 'on')

        data = {
            'instances': self._get_allowed_instances(c.user),
            'sender_options': self._get_allowed_sender_options(c.user),
            'userbadges': UserBadge.all(instance=c.instance,
                                        include_global=True)
        }

        return htmlfill.render(render(template,
                                      data,
                                      overlay=format == u'overlay'),
                               defaults=defaults,
                               errors=errors,
                               force_defaults=False)
Beispiel #4
0
    def new(self, id=None, errors={}, format=u'html'):

        if id is None:
            require.perm('global.message')
            template = '/massmessage/new.html'
            c.preview_url = h.base_url('/message/preview')
        else:
            c.page_instance = InstanceController._get_current_instance(id)
            require.instance.message(c.page_instance)
            template = '/instance/message.html'
            c.preview_url = h.base_url(
                '/instance/%s/message/preview' % id)

        defaults = dict(request.params)
        defaults.setdefault('include_footer', 'on')

        data = {
            'instances': self._get_allowed_instances(c.user),
            'sender_options': self._get_allowed_sender_options(c.user),
            'userbadges': UserBadge.all(instance=c.instance,
                                        include_global=True)
        }

        return htmlfill.render(render(template, data,
                                      overlay=format == u'overlay'),
                               defaults=defaults, errors=errors,
                               force_defaults=False)
Beispiel #5
0
 def test_we_already_have_two_userbadges(self):
     """
     Due to the setup code in `adhocracy.lib.install` and the definition
     of example user badges in `test.ini` for the Shibboleth tests, we
     already have two badges from the beginning.
     """
     from adhocracy.model import UserBadge
     self.assertEqual(len(UserBadge.all()), 2)
Beispiel #6
0
    def test_get_all_badges(self):
        # setup
        from adhocracy.model import Badge, CategoryBadge, DelegateableBadge, \
            InstanceBadge, ThumbnailBadge
        from adhocracy.model import UserBadge, Instance
        instance = Instance.find(u'test')
        # create for each type a global scope and an instance scope badge
        InstanceBadge.create(u'badge ü', u'#ccc', True, u'description ü')
        InstanceBadge.create(u'badge ü', u'#ccc', True, u'description ü',
                             instance=instance)
        UserBadge.create(u'badge ü', u'#ccc', True, u'description ü')
        UserBadge.create(u'ü', u'#ccc', True, u'ü', instance=instance)
        DelegateableBadge.create(u'badge ü', u'#ccc', True, u'description ü')
        DelegateableBadge.create(u'badge ü', u'#ccc', True, u'description ü',
                                 instance=instance)
        CategoryBadge.create(u'badge ü', u'#ccc', True, u"desc")
        CategoryBadge.create(u'badge ü', u'#ccc', True, u"desc",
                             instance=instance)

        ThumbnailBadge.create(u'badge ü', u'#ccc', True, u"desc",
                              thumbnail=b'binary')
        ThumbnailBadge.create(u'badge ü', u'#ccc', True, u"desc",
                              thumbnail=b'binary', instance=instance)

        # all instance badges
        self.assertEqual(len(InstanceBadge.all()), 1)
        self.assertEqual(len(InstanceBadge.all(instance=instance)), 1)
        # all delegateable badges
        self.assertEqual(len(DelegateableBadge.all()), 1)
        self.assertEqual(len(DelegateableBadge.all(instance=instance)), 1)
        # all delegateable category badges
        self.assertEqual(len(CategoryBadge.all()), 1)
        self.assertEqual(len(CategoryBadge.all(instance=instance)), 1)
        # all delegateable thumbnail badges
        self.assertEqual(len(ThumbnailBadge.all()), 1)
        self.assertEqual(len(ThumbnailBadge.all(instance=instance)), 1)
        # all user badges
        self.assertEqual(len(UserBadge.all()), 3)
        self.assertEqual(len(UserBadge.all(instance=instance)), 1)
        # We can get all Badges by using `Badge`
        self.assertEqual(len(Badge.all()), 7)
        self.assertEqual(len(Badge.all(instance=instance)), 5)

        self.assertEqual(len(Badge.all_q().all()), 12)
Beispiel #7
0
    def test_get_all_badgets(self):
        #setup
        from adhocracy.model import Badge, CategoryBadge, DelegateableBadge, \
            InstanceBadge
        from adhocracy.model import UserBadge, Instance
        instance = Instance.find(u'test')
        # create for each type a global scope and an instance scope badge
        InstanceBadge.create(u'badge ü', u'#ccc', u'description ü')
        InstanceBadge.create(u'badge ü',
                             u'#ccc',
                             u'description ü',
                             instance=instance)
        UserBadge.create(u'badge ü', u'#ccc', u'description ü')
        UserBadge.create(u'ü', u'#ccc', u'ü', instance=instance)
        DelegateableBadge.create(u'badge ü', u'#ccc', u'description ü')
        DelegateableBadge.create(u'badge ü',
                                 u'#ccc',
                                 u'description ü',
                                 instance=instance)
        CategoryBadge.create(u'badge ü', u'#ccc', u"desc")
        CategoryBadge.create(u'badge ü', u'#ccc', u"desc", instance=instance)

        # all instance badges
        self.assert_(len(InstanceBadge.all()) == 1)
        self.assert_(len(InstanceBadge.all(instance=instance)) == 1)
        # all delegateable badges
        self.assert_(len(DelegateableBadge.all()) == 1)
        self.assert_(len(DelegateableBadge.all(instance=instance)) == 1)
        # all delegateable category badges
        self.assert_(len(CategoryBadge.all()) == 1)
        self.assert_(len(CategoryBadge.all(instance=instance)) == 1)
        # all user badgets
        self.assert_(len(UserBadge.all()) == 1)
        self.assert_(len(UserBadge.all(instance=instance)) == 1)
        # We can get all Badges by using `Badge`
        self.assert_(len(Badge.all()) == 4)
        self.assert_(len(Badge.all(instance=instance)) == 4)

        self.assert_(len(Badge.all_q().all()) == 8)
Beispiel #8
0
    def new(self, id=None, errors={}):

        if id is None:
            require.perm('global.message')
            template = '/massmessage/new.html'
        else:
            c.page_instance = InstanceController._get_current_instance(id)
            require.message.create(c.page_instance)
            c.settings_menu = InstanceController.settings_menu(c.page_instance,
                                                               'massmessage')
            template = '/instance/settings_massmessage.html'

        defaults = dict(request.params)

        data = {
            'instances': self.get_allowed_instances(c.user),
            'sender_options': self.get_allowed_sender_options(c.user),
            'userbadges': UserBadge.all(instance=c.instance,
                                        include_global=True)
        }

        return htmlfill.render(render(template, data),
                               defaults=defaults, errors=errors,
                               force_defaults=False)