1
# Django
2 3
from django.conf import settings # noqa
3

4
# CyBorgBackup
5 3
from cyborgbackup.main.models.base import * # noqa
6 3
from cyborgbackup.main.models.jobs import Job
7 3
from cyborgbackup.main.models.users import User
8 3
from cyborgbackup.main.models.events import JobEvent
9 3
from cyborgbackup.main.models.channels import ChannelGroup
10 3
from cyborgbackup.main.models.clients import Client
11 3
from cyborgbackup.main.models.schedules import Schedule
12 3
from cyborgbackup.main.models.repositories import Repository
13 3
from cyborgbackup.main.models.catalogs import Catalog
14 3
from cyborgbackup.main.models.policies import Policy
15 3
from cyborgbackup.main.models.activity_streams import ActivityStream
16 3
from cyborgbackup.api.versioning import reverse
17

18
# Monkeypatch Django serializer to ignore django-taggit fields (which break
19
# the dumpdata command; see https://github.com/alex/django-taggit/issues/155).
20 3
from django.core.serializers.python import Serializer as _PythonSerializer
21 3
_original_handle_m2m_field = _PythonSerializer.handle_m2m_field
22

23

24 3
def _new_handle_m2m_field(self, obj, field):
25 0
    try:
26 0
        field.rel.through._meta
27 0
    except AttributeError:
28 0
        return
29 0
    return _original_handle_m2m_field(self, obj, field)
30

31

32 3
_PythonSerializer.handle_m2m_field = _new_handle_m2m_field
33

34
# Add custom methods to User model for permissions checks.
35 3
from django.contrib.auth.models import User  # noqa
36

37

38 3
@property
39
def user_is_system_auditor(user):
40 0
    if not hasattr(user, '_is_system_auditor'):
41 0
        if user.pk:
42 0
            user._is_system_auditor = user.roles.filter(
43
                singleton_name='system_auditor', role_field='system_auditor').exists()
44
        else:
45
            # Odd case where user is unsaved, this should never be relied on
46 0
            return False
47 0
    return user._is_system_auditor
48

49
# Import signal handlers only after models have been defined.
50 3
import cyborgbackup.main.signals # noqa
51

52 3
from cyborgbackup.main.registrar import activity_stream_registrar # noqa
53

54 3
activity_stream_registrar.connect(Client)
55 3
activity_stream_registrar.connect(User)
56 3
activity_stream_registrar.connect(Repository)
57 3
activity_stream_registrar.connect(Schedule)
58 3
activity_stream_registrar.connect(Policy)
59 3
activity_stream_registrar.connect(Client)
60

61
# prevent API filtering on certain Django-supplied sensitive fields
62 3
prevent_search(User._meta.get_field('password'))

Read our documentation on viewing source code .

Loading