Esempio n. 1
0
    def run(self):
        if self.options.models:
            model_names = split_strip(self.options.models)
            models = [engine.get_document_cls(name) for name in model_names]
        else:
            models = None

        try:
            from_ace = json.loads(self.options.from_ace)
        except ValueError as ex:
            raise ValueError('--from_ace: {}'.format(ex))

        try:
            to_ace = json.loads(self.options.to_ace)
        except ValueError as ex:
            raise ValueError('--to_ace: {}'.format(ex))

        six.print_('Updating documents ACE')

        update_ace(from_ace=from_ace, to_ace=to_ace, models=models)

        try:
            import transaction
            transaction.commit()
        except:
            pass

        six.print_('Done')
    def run(self):
        if self.options.models:
            model_names = split_strip(self.options.models)
            models = [engine.get_document_cls(name)
                      for name in model_names]
        else:
            models = None

        try:
            from_ace = json.loads(self.options.from_ace)
        except ValueError as ex:
            raise ValueError('--from_ace: {}'.format(ex))

        try:
            to_ace = json.loads(self.options.to_ace)
        except ValueError as ex:
            raise ValueError('--to_ace: {}'.format(ex))

        six.print_('Updating documents ACE')

        update_ace(from_ace=from_ace, to_ace=to_ace, models=models)

        try:
            import transaction
            transaction.commit()
        except:
            pass

        six.print_('Done')
Esempio n. 3
0
 def test_update_ace(self, mock_find, mock_group, mock_extr, mock_upd):
     to_ace = {"action": "allow", "principal": "a", "permission": "view"}
     Model = Mock()
     Model.get_by_ids.return_value = [4, 5, 6]
     mock_extr.return_value = {Model: [1, 2, 3]}
     acl_utils.update_ace({'z': 1}, to_ace, 'Z')
     mock_find.assert_called_once_with({'z': 1}, 'Z')
     mock_group.assert_called_once_with(mock_find(), 'Z')
     mock_extr.assert_called_once_with(mock_group())
     mock_upd.assert_called_once_with([4, 5, 6], {'z': 1}, to_ace)
     Model.get_by_ids.assert_called_once_with([1, 2, 3])
 def test_update_ace_end_to_end(self, mock_find, mock_eng):
     mock_find.return_value = [Mock(username='******', _type='User')]
     db_obj = Mock(_acl=[{'foo': 1}])
     User = Mock()
     User.pk_field.return_value = 'username'
     User.get_by_ids.return_value = [db_obj]
     mock_eng.get_document_cls.return_value = User
     to_ace = {
         "action": "allow",
         "principal": "user12",
         "permission": "view"}
     acl_utils.update_ace({'foo': 1}, to_ace)
     db_obj.update.assert_called_once_with({
         '_acl': [to_ace]})
Esempio n. 5
0
 def test_update_ace_end_to_end(self, mock_find, mock_eng):
     mock_find.return_value = [Mock(username='******', _type='User')]
     db_obj = Mock(_acl=[{'foo': 1}])
     User = Mock()
     User.pk_field.return_value = 'username'
     User.get_by_ids.return_value = [db_obj]
     mock_eng.get_document_cls.return_value = User
     to_ace = {
         "action": "allow",
         "principal": "user12",
         "permission": "view"
     }
     acl_utils.update_ace({'foo': 1}, to_ace)
     db_obj.update.assert_called_once_with({'_acl': [to_ace]})
 def test_update_ace(self, mock_find, mock_group, mock_extr, mock_upd):
     to_ace = {
         "action": "allow",
         "principal": "a",
         "permission": "view"}
     Model = Mock()
     Model.get_by_ids.return_value = [4, 5, 6]
     mock_extr.return_value = {Model: [1, 2, 3]}
     acl_utils.update_ace({'z': 1}, to_ace, 'Z')
     mock_find.assert_called_once_with({'z': 1}, 'Z')
     mock_group.assert_called_once_with(mock_find(), 'Z')
     mock_extr.assert_called_once_with(mock_group())
     mock_upd.assert_called_once_with(
         [4, 5, 6], {'z': 1}, to_ace)
     Model.get_by_ids.assert_called_once_with([1, 2, 3])
 def test_update_ace_invalid_ace(self, mock_find):
     with pytest.raises(ValueError) as ex:
         acl_utils.update_ace({}, {"action": "foo"}, 1)
     assert 'Invalid ACL action value: foo' in str(ex.value)
Esempio n. 8
0
 def test_update_ace_invalid_ace(self, mock_find):
     with pytest.raises(ValueError) as ex:
         acl_utils.update_ace({}, {"action": "foo"}, 1)
     assert 'Invalid ACL action value: foo' in str(ex.value)