Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
riceyrice committed Oct 18, 2023
1 parent 88cf709 commit 2274770
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api/audit/related_object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class RelatedObjectType(enum.Enum):
ENVIRONMENT = "Environment"
FEATURE = "Feature"
FEATURE_STATE = "Feature state"
GRANT = "Grant"
GROUP = "Group"
IMPORT_REQUEST = "Import request"
PERMISSION = "Permission"
PROJECT = "Project"
SEGMENT = "Segment"
USER = "User"
1 change: 0 additions & 1 deletion api/environments/permissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "environments.permissions.apps.EnvironmentPermissionsConfig"
5 changes: 3 additions & 2 deletions api/environments/permissions/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.apps import AppConfig
from core.apps import BaseAppConfig


class EnvironmentPermissionsConfig(AppConfig):
class EnvironmentPermissionsConfig(BaseAppConfig):
default = True
name = "environments.permissions"
label = "environment_permissions"
127 changes: 127 additions & 0 deletions api/environments/permissions/migrations/0008_historicalpermissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Generated by Django 3.2.20 on 2023-10-18 18:57

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('users', '0035_historicalffadminuser_historicaluserpermissiongroup'),
('api_keys', '0003_masterapikey_is_admin'),
('permissions', '0009_move_view_audit_log_permission'),
('environments', '0033_history_upgrade'),
('environment_permissions', '0007_add_unique_permission_constraint'),
]

operations = [
migrations.CreateModel(
name='HistoricalUserEnvironmentPermission',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('admin', models.BooleanField(default=False)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('environment', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', related_query_name='userpermission', to='environments.environment')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical user environment permission',
'verbose_name_plural': 'historical user environment permissions',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalUserPermissionGroupEnvironmentPermission',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('admin', models.BooleanField(default=False)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('environment', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', related_query_name='grouppermission', to='environments.environment')),
('group', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='users.userpermissiongroup')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
],
options={
'verbose_name': 'historical user permission group environment permission',
'verbose_name_plural': 'historical user permission group environment permissions',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.AddField(
model_name='userenvironmentpermission',
name='deleted_at',
field=models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True),
),
migrations.AddField(
model_name='userpermissiongroupenvironmentpermission',
name='deleted_at',
field=models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True),
),
migrations.CreateModel(
name='HistoricalUserPermissionGroupEnvironmentPermission_permissions',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('m2m_history_id', models.AutoField(primary_key=True, serialize=False)),
('history', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='environment_permissions.historicaluserpermissiongroupenvironmentpermission')),
('permissionmodel', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='permissions.permissionmodel')),
('userpermissiongroupenvironmentpermission', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='environment_permissions.userpermissiongroupenvironmentpermission')),
],
options={
'verbose_name': 'HistoricalUserPermissionGroupEnvironmentPermission_permissions',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalUserEnvironmentPermission_permissions',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('m2m_history_id', models.AutoField(primary_key=True, serialize=False)),
('history', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='environment_permissions.historicaluserenvironmentpermission')),
('permissionmodel', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='permissions.permissionmodel')),
('userenvironmentpermission', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='environment_permissions.userenvironmentpermission')),
],
options={
'verbose_name': 'HistoricalUserEnvironmentPermission_permissions',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalEnvironmentPermissionModel',
fields=[
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('key', models.CharField(db_index=True, max_length=100)),
('description', models.TextField()),
('type', models.CharField(choices=[('PROJECT', 'Project'), ('ENVIRONMENT', 'Environment'), ('ORGANISATION', 'Organisation')], max_length=100, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
],
options={
'verbose_name': 'historical environment permission model',
'verbose_name_plural': 'historical environment permission models',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
6 changes: 6 additions & 0 deletions api/environments/permissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Meta:
)
]

def _get_environment(self) -> Environment | None:
return self.environment


class UserPermissionGroupEnvironmentPermission(AbstractBasePermissionModel):
group = models.ForeignKey("users.UserPermissionGroup", on_delete=models.CASCADE)
Expand All @@ -50,3 +53,6 @@ class Meta:
name="unique_group_environment_permission",
)
]

def _get_environment(self) -> Environment | None:
return self.environment
1 change: 0 additions & 1 deletion api/organisations/permissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "organisations.permissions.apps.OrganisationPermissionsConfig"
5 changes: 3 additions & 2 deletions api/organisations/permissions/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.apps import AppConfig
from core.apps import BaseAppConfig


class OrganisationPermissionsConfig(AppConfig):
class OrganisationPermissionsConfig(BaseAppConfig):
default = True
name = "organisations.permissions"
label = "organisation_permissions"
125 changes: 125 additions & 0 deletions api/organisations/permissions/migrations/0005_historicalpermissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Generated by Django 3.2.20 on 2023-10-18 18:57

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('users', '0035_historicalffadminuser_historicaluserpermissiongroup'),
('organisations', '0046_allow_allowed_projects_to_be_null'),
('api_keys', '0003_masterapikey_is_admin'),
('permissions', '0009_move_view_audit_log_permission'),
('organisation_permissions', '0004_add_unique_permission_constraint'),
]

operations = [
migrations.CreateModel(
name='HistoricalUserOrganisationPermission',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
('organisation', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', related_query_name='userpermission', to='organisations.organisation')),
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical user organisation permission',
'verbose_name_plural': 'historical user organisation permissions',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalUserPermissionGroupOrganisationPermission',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('group', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='users.userpermissiongroup')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
('organisation', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', related_query_name='grouppermission', to='organisations.organisation')),
],
options={
'verbose_name': 'historical user permission group organisation permission',
'verbose_name_plural': 'historical user permission group organisation permissions',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.AddField(
model_name='userorganisationpermission',
name='deleted_at',
field=models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True),
),
migrations.AddField(
model_name='userpermissiongrouporganisationpermission',
name='deleted_at',
field=models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True),
),
migrations.CreateModel(
name='HistoricalUserPermissionGroupOrganisationPermission_permissions',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('m2m_history_id', models.AutoField(primary_key=True, serialize=False)),
('history', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='organisation_permissions.historicaluserpermissiongrouporganisationpermission')),
('permissionmodel', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='permissions.permissionmodel')),
('userpermissiongrouporganisationpermission', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='organisation_permissions.userpermissiongrouporganisationpermission')),
],
options={
'verbose_name': 'HistoricalUserPermissionGroupOrganisationPermission_permissions',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalUserOrganisationPermission_permissions',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('m2m_history_id', models.AutoField(primary_key=True, serialize=False)),
('history', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='organisation_permissions.historicaluserorganisationpermission')),
('permissionmodel', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='permissions.permissionmodel')),
('userorganisationpermission', models.ForeignKey(blank=True, db_constraint=False, db_tablespace='', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='organisation_permissions.userorganisationpermission')),
],
options={
'verbose_name': 'HistoricalUserOrganisationPermission_permissions',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalOrganisationPermissionModel',
fields=[
('deleted_at', models.DateTimeField(blank=True, db_index=True, default=None, editable=False, null=True)),
('key', models.CharField(db_index=True, max_length=100)),
('description', models.TextField()),
('type', models.CharField(choices=[('PROJECT', 'Project'), ('ENVIRONMENT', 'Environment'), ('ORGANISATION', 'Organisation')], max_length=100, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('master_api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_keys.masterapikey')),
],
options={
'verbose_name': 'historical organisation permission model',
'verbose_name_plural': 'historical organisation permission models',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
Loading

0 comments on commit 2274770

Please sign in to comment.