Add custom Group model that relates to organization.

This commit is contained in:
Roberto Rosario
2016-05-25 01:06:20 -04:00
parent 433e295d07
commit a3a03ec095
2 changed files with 53 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.contrib.auth.models
import organizations.shortcuts
class Migration(migrations.Migration):
dependencies = [
('organizations', '0002_add_data_default_organization'),
('auth', '0006_require_contenttypes_0002'),
('user_management', '0002_auto_20160504_0638'),
]
operations = [
migrations.CreateModel(
name='MayanGroup',
fields=[
('group_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='auth.Group')),
('organization', models.ForeignKey(default=organizations.shortcuts.get_current_organization, to='organizations.Organization')),
],
bases=('auth.group',),
managers=[
('objects', django.contrib.auth.models.GroupManager()),
],
),
migrations.AddField(
model_name='mayanuser',
name='organization_groups',
field=models.ManyToManyField(related_query_name='user', related_name='organization_user_set', to='user_management.MayanGroup', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='Groups'),
),
]

View File

@@ -1,6 +1,8 @@
from __future__ import unicode_literals
from django.contrib.auth.models import AbstractUser, UserManager
from django.contrib.auth.models import (
AbstractUser, Group, GroupManager, UserManager
)
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@@ -11,10 +13,26 @@ from organizations.managers import CurrentOrganizationManager
from organizations.shortcuts import get_current_organization
class MayanGroup(Group):
organization = models.ForeignKey(
Organization, default=get_current_organization
)
objects = GroupManager()
on_organization = CurrentOrganizationManager()
class MayanUser(AbstractUser):
organization = models.ForeignKey(
Organization, default=get_current_organization
)
organization_groups = models.ManyToManyField(
MayanGroup, blank=True, help_text=_(
'The groups this user belongs to. A user will get all permissions '
'granted to each of their groups.'
), related_name='organization_user_set', related_query_name='user',
verbose_name=_('Groups')
)
objects = UserManager()
on_organization = CurrentOrganizationManager()