def test_update_comment_creates_log_entry(self):
        field_name = 'comment_field_name_texl2i7%sookqerpl29a'
        config['motions_comments'] = {
            '1': {
                'name': field_name,
                'public': False
            }
        }

        # Update Config cache
        CollectionElement.from_instance(
            ConfigStore.objects.get(key='motions_comments'))

        response = self.client.patch(reverse(
            'motion-detail', args=[self.motion.pk]), {
                'title': 'title_test_sfdAaufd56HR7sd5FDq7av',
                'text': 'text_test_fiuhefF86()ew1Ef346AF6W',
                'comments': {
                    '1': 'comment1_sdpoiuffo3%7dwDwW)'
                }
            },
                                     format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        motion_logs = MotionLog.objects.filter(motion=self.motion)
        self.assertEqual(motion_logs.count(), 2)

        motion_log = motion_logs.order_by('-time').first()
        self.assertTrue(field_name in motion_log.message_list[0])
Beispiel #2
0
    def test_add_someone_else_non_admin(self):
        admin = get_user_model().objects.get(username='******')
        group_admin = admin.groups.get(name='Admin')
        group_delegates = type(group_admin).objects.get(name='Delegates')
        admin.groups.add(group_delegates)
        admin.groups.remove(group_admin)
        CollectionElement.from_instance(admin)

        response = self.client.post(
            reverse('item-manage-speaker', args=[self.item.pk]),
            {'user': self.user.pk})
        self.assertEqual(response.status_code, 403)
Beispiel #3
0
    def test_add_someone_else_non_admin(self):
        admin = get_user_model().objects.get(username='******')
        group_admin = admin.groups.get(name='Admin')
        group_delegates = type(group_admin).objects.get(name='Delegates')
        admin.groups.add(group_delegates)
        admin.groups.remove(group_admin)
        CollectionElement.from_instance(admin)

        response = self.client.post(
            reverse('item-manage-speaker', args=[self.item.pk]),
            {'user': self.user.pk})
        self.assertEqual(response.status_code, 403)
Beispiel #4
0
async def set_config(key, value):
    """
    Set a config variable in the element_cache without hitting the database.
    """
    collection_string = config.get_collection_string()
    config_id = config.key_to_id[key]  # type: ignore
    full_data = {'id': config_id, 'key': key, 'value': value}
    await element_cache.change_elements(
        {get_element_id(collection_string, config_id): full_data})
    await sync_to_async(inform_data_collection_element_list)([
        CollectionElement.from_values(collection_string,
                                      config_id,
                                      full_data=full_data)
    ])
Beispiel #5
0
 def retrieve(self, request, *args, **kwargs):
     """
     Retrieves a config variable.
     """
     key = kwargs['pk']
     collection_element = CollectionElement.from_values(config.get_collection_string(), key)
     try:
         content = collection_element.as_dict_for_user(request.user)
     except ConfigStore.DoesNotExist:
         raise Http404
     if content is None:
         # If content is None, the user has no permissions to see the item.
         # See ConfigAccessPermissions or rather its parent class.
         self.permission_denied()
     return Response(content)
Beispiel #6
0
 def retrieve(self, request, *args, **kwargs):
     """
     Retrieves a config variable.
     """
     key = kwargs['pk']
     collection_element = CollectionElement.from_values(
         config.get_collection_string(), key)
     try:
         content = collection_element.as_dict_for_user(request.user)
     except ConfigStore.DoesNotExist:
         raise Http404
     if content is None:
         # If content is None, the user has no permissions to see the item.
         # See ConfigAccessPermissions or rather its parent class.
         self.permission_denied()
     return Response(content)
Beispiel #7
0
 def make_admin_delegate(self):
     group_staff = self.admin.groups.get(name='Staff')
     group_delegates = Group.objects.get(name='Delegates')
     self.admin.groups.remove(group_staff)
     self.admin.groups.add(group_delegates)
     CollectionElement.from_instance(self.admin)