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

4
# CyBorgBackup
5 6
from cyborgbackup.main.models.base import * # noqa
6 6
from cyborgbackup.main.models.jobs import Job
7 6
from cyborgbackup.main.models.users import User
8 6
from cyborgbackup.main.models.events import JobEvent
9 6
from cyborgbackup.main.models.channels import ChannelGroup
10 6
from cyborgbackup.main.models.clients import Client
11 6
from cyborgbackup.main.models.schedules import Schedule
12 6
from cyborgbackup.main.models.repositories import Repository
13 6
from cyborgbackup.main.models.catalogs import Catalog
14 6
from cyborgbackup.main.models.policies import Policy
15 6
from cyborgbackup.main.models.activity_streams import ActivityStream
16 6
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 6
from django.core.serializers.python import Serializer as _PythonSerializer
21 6
_original_handle_m2m_field = _PythonSerializer.handle_m2m_field
22

23

24 6
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 6
_PythonSerializer.handle_m2m_field = _new_handle_m2m_field
33

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

37

38 6
@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 6
import cyborgbackup.main.signals # noqa
51

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

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

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

Read our documentation on viewing source code .

Loading