-
Notifications
You must be signed in to change notification settings - Fork 50
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
1 parent
405792f
commit 752e0c6
Showing
15 changed files
with
216 additions
and
121 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 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 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,73 +1,11 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import AbstractUser | ||
from django.db import models | ||
|
||
from ansible_base.models import AbstractOrganization | ||
|
||
from ansible_base.rbac import permission_registry | ||
|
||
|
||
class Organization(AbstractOrganization): | ||
pass | ||
|
||
|
||
class User(AbstractUser): | ||
singleton_roles = models.ManyToManyField('ansible_base.RoleDefinition', related_name='singleton_users') | ||
|
||
|
||
class Team(models.Model): | ||
name = models.CharField(max_length=512) | ||
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) | ||
|
||
tracked_users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='tracked_teams') | ||
team_parents = models.ManyToManyField('Team', related_name='team_children') | ||
|
||
singleton_roles = models.ManyToManyField('ansible_base.RoleDefinition') | ||
|
||
class Meta: | ||
app_label = 'functional' | ||
permissions = [('member_team', 'Has all roles assigned to this team')] | ||
|
||
|
||
class Inventory(models.Model): | ||
"Simple example of a child object, it has a link to its parent organization" | ||
name = models.CharField(max_length=512) | ||
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
app_label = 'functional' | ||
permissions = [('update_inventory', 'Do inventory updates')] | ||
|
||
|
||
class InstanceGroup(models.Model): | ||
"Example of an object with no parent object, a root resource, a lone wolf" | ||
name = models.CharField(max_length=512) | ||
|
||
class Meta: | ||
app_label = 'functional' | ||
default_permissions = ('change', 'delete', 'view') | ||
|
||
|
||
class Namespace(models.Model): | ||
"Example of a child object with its own child objects" | ||
name = models.CharField(max_length=64, unique=True, blank=False) | ||
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) | ||
|
||
|
||
class CollectionImport(models.Model): | ||
"Example of a child of a child object, organization is implied by its namespace" | ||
name = models.CharField(max_length=64, unique=True, blank=False) | ||
namespace = models.ForeignKey(Namespace, on_delete=models.CASCADE) | ||
|
||
|
||
class ExampleEvent(models.Model): | ||
"Example of a model which is not registered in permission registry in the first place" | ||
name = models.CharField(max_length=64, unique=True, blank=False) | ||
|
||
|
||
permission_registry.register(Organization, Inventory, Namespace, Team) | ||
permission_registry.register(CollectionImport, parent_field_name='namespace') | ||
permission_registry.register(InstanceGroup, parent_field_name=None) | ||
|
||
permission_registry.track_relationship(Team, 'tracked_users', 'team-member') | ||
permission_registry.track_relationship(Team, 'team_parents', 'team-member') |
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 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 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 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 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 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 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 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 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,30 +1,69 @@ | ||
# Generated by Django 4.2.6 on 2024-01-12 12:27 | ||
# Generated by Django 4.2.8 on 2024-01-16 07:44 | ||
|
||
from django.conf import settings | ||
import django.contrib.auth.models | ||
import django.contrib.auth.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EncryptionModel', | ||
name='User', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), | ||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), | ||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), | ||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), | ||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), | ||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), | ||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), | ||
], | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Organization', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')), | ||
('modified_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')), | ||
('name', models.CharField(help_text='The name of this resource', max_length=512)), | ||
('testing1', models.CharField(default='a', max_length=1, null=True)), | ||
('testing2', models.CharField(default='b', max_length=1, null=True)), | ||
('name', models.CharField(help_text='The name of this resource', max_length=512, unique=True)), | ||
('description', models.TextField(default='', help_text='The organization description.')), | ||
('created_by', models.ForeignKey(default=None, editable=False, help_text='The user who created this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_created+', to=settings.AUTH_USER_MODEL)), | ||
('modified_by', models.ForeignKey(default=None, editable=False, help_text='The user who last modified this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_modified+', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Team', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=512)), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_app.organization')), | ||
('team_parents', models.ManyToManyField(related_name='team_children', to='test_app.team')), | ||
('tracked_users', models.ManyToManyField(related_name='tracked_teams', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'permissions': [('member_team', 'Has all roles assigned to this team')], | ||
}, | ||
), | ||
] |
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,93 @@ | ||
# Generated by Django 4.2.8 on 2024-01-16 07:49 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('ansible_base', '0011_RBAC'), | ||
('test_app', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ExampleEvent', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=64, unique=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='InstanceGroup', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=512)), | ||
], | ||
options={ | ||
'default_permissions': ('change', 'delete', 'view'), | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='team', | ||
name='singleton_roles', | ||
field=models.ManyToManyField(to='ansible_base.roledefinition'), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='singleton_roles', | ||
field=models.ManyToManyField(related_name='singleton_users', to='ansible_base.roledefinition'), | ||
), | ||
migrations.CreateModel( | ||
name='Namespace', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=64, unique=True)), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_app.organization')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Inventory', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=512)), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_app.organization')), | ||
], | ||
options={ | ||
'permissions': [('update_inventory', 'Do inventory updates')], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='EncryptionModel', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')), | ||
('modified_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')), | ||
('name', models.CharField(help_text='The name of this resource', max_length=512)), | ||
('testing1', models.CharField(default='a', max_length=1, null=True)), | ||
('testing2', models.CharField(default='b', max_length=1, null=True)), | ||
('created_by', models.ForeignKey(default=None, editable=False, help_text='The user who created this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_created+', to=settings.AUTH_USER_MODEL)), | ||
('modified_by', models.ForeignKey(default=None, editable=False, help_text='The user who last modified this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_modified+', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='CollectionImport', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=64, unique=True)), | ||
('namespace', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_app.namespace')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='organization', | ||
name='teams', | ||
field=models.ManyToManyField(help_text='The list of teams in this organization.', related_name='organizations', to='test_app.team'), | ||
), | ||
migrations.AddField( | ||
model_name='organization', | ||
name='users', | ||
field=models.ManyToManyField(help_text='The list of users in this organization.', related_name='organizations', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.