Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
def load_initial_data(apps, schema_editor): | ||
"""Load initial data.""" | ||
User = apps.get_model("core", "User") | ||
user = User(username="admin", is_superuser=True) | ||
user.set_password("password") | ||
user.save() | ||
|
||
ObjectAccess = apps.get_model("core", "ObjectAccess") | ||
ObjectAccess.objects.create(user=user, content_object=user, is_owner=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(load_initial_data) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
modoboa/extensions/admin/migrations/0002_load_initial_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
from modoboa.lib.migration_tools import add_permissions_to_group | ||
|
||
PERMISSIONS = [ | ||
["core", "user", "add_user"], | ||
["core", "user", "change_user"], | ||
["core", "user", "delete_user"], | ||
["admin", "domain", "view_domain"], | ||
["admin", "mailbox", "add_mailbox"], | ||
["admin", "mailbox", "change_mailbox"], | ||
["admin", "mailbox", "delete_mailbox"], | ||
["admin", "alias", "add_alias"], | ||
["admin", "alias", "change_alias"], | ||
["admin", "alias", "delete_alias"], | ||
["admin", "mailbox", "view_mailboxes"], | ||
["admin", "alias", "view_aliases"], | ||
["admin", "domainalias", "view_domainaliases"], | ||
["admin", "domainalias", "add_domainalias"], | ||
["admin", "domainalias", "change_domainalias"], | ||
["admin", "domainalias", "delete_domainalias"] | ||
] | ||
|
||
def load_initial_data(apps, schema_editor): | ||
"""Load initial data.""" | ||
Group = apps.get_model("auth", "Group") | ||
dadmins = Group.objects.create(name="DomainAdmins") | ||
add_permissions_to_group(apps, dadmins, PERMISSIONS) | ||
Group.objects.create(name="SimpleUsers") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('admin', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(load_initial_data) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
"""Additional functions available for migration scripts.""" | ||
|
||
|
||
def add_permissions_to_group(apps, groupname, permissions): | ||
def add_permissions_to_group(apps, group, permissions): | ||
"""Add the specified permissions to a django group.""" | ||
Group = apps.get_model("auth", "Group") | ||
Permission = apps.get_model("auth", "Permission") | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
|
||
grp = Group.objects.get(name=groupname) | ||
if isinstance(group, basestring): | ||
Group = apps.get_model("auth", "Group") | ||
group = Group.objects.get(name=group) | ||
|
||
for appname, modelname, permname in permissions: | ||
ct = ContentType.objects.get_by_natural_key( | ||
appname, modelname) | ||
grp.permissions.add( | ||
group.permissions.add( | ||
Permission.objects.get(content_type=ct, codename=permname) | ||
) |