Passed
Push — master ( e32157...9a4845 )
by Alexander
04:03
created

tcms.bugs.migrations.0002_add_permissions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A forwards_add_perms() 0 12 1
A backwards() 0 6 1
1
from django.db import migrations
2
3
4
def forwards_add_perms(apps, schema_editor):
5
    """
6
        Adds permissions for this app to the group 'Tester'.
7
        This is useful in case that is an existing installation
8
        upgrading post 7.0.
9
    """
10
    Group = apps.get_model('auth', 'Group')
11
    Permission = apps.get_model('auth', 'Permission')
12
13
    tester = Group.objects.get(name='Tester')
14
    app_perms = Permission.objects.filter(content_type__app_label__contains='bugs')
15
    tester.permissions.add(*app_perms)
16
17
18
def backwards(apps, schema_editor):
19
    Group = apps.get_model('auth', 'Group')
20
    Permission = apps.get_model('auth', 'Permission')
21
    tester = Group.objects.get(name='Tester')
22
    app_perms = Permission.objects.filter(content_type__app_label__contains='bugs')
23
    tester.permissions.remove(*app_perms)
24
25
26
class Migration(migrations.Migration):
27
    dependencies = [
28
        ('bugs', '0001_initial'),
29
        ('core', '0001_squashed'),
30
    ]
31
32
    operations = [
33
        migrations.RunPython(forwards_add_perms, backwards),
34
    ]
35