Skip to content

Commit

Permalink
Alternative organization model
Browse files Browse the repository at this point in the history
  • Loading branch information
cutwater committed Feb 5, 2024
1 parent 1b7dbbb commit eb750d9
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
126 changes: 126 additions & 0 deletions galaxy_ng/app/migrations/0049_organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Generated by Django 4.2.9 on 2024-02-05 16:05

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


class Migration(migrations.Migration):
dependencies = [
("galaxy", "0048_update_collection_remote_rhcertified_url"),
]

operations = [
migrations.CreateModel(
name="Organization",
fields=[
(
"id",
models.AutoField(
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, unique=True
),
),
(
"description",
models.TextField(
blank=True, 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,
),
),
(
"main_group",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="galaxy.group",
),
),
(
"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="OrganizationTeam",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
"organization",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="galaxy.organization",
),
),
(
"team",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="galaxy.group",
),
),
],
),
migrations.AddField(
model_name="organization",
name="teams",
field=models.ManyToManyField(through="galaxy.OrganizationTeam", to="galaxy.group"),
),
migrations.AddConstraint(
model_name="organizationteam",
constraint=models.UniqueConstraint(
models.F("organization"), models.F("team"), name="uq_organization_team"
),
),
]
4 changes: 3 additions & 1 deletion galaxy_ng/app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ContainerRegistryRepos

)

from .organization import Organization, OrganizationTeam
from .aiindex import AIIndexDenyList

__all__ = (
Expand All @@ -39,5 +39,7 @@
'ContainerNamespace',
'ContainerRegistryRemote',
'ContainerRegistryRepos',
'Organization',
'OrganizationTeam',
'AIIndexDenyList',
)
22 changes: 22 additions & 0 deletions galaxy_ng/app/models/organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models
from ansible_base.lib.abstract_models import AbstractOrganization

from .auth import Group


class Organization(AbstractOrganization):
"""An organization model."""
main_group = models.OneToOneField(Group, on_delete=models.CASCADE, related_name='+')

teams = models.ManyToManyField(Group, through="OrganizationTeam")


class OrganizationTeam(models.Model):
"""A team to organization relationship joint table."""
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, related_name='+')
team = models.OneToOneField(Group, on_delete=models.CASCADE, related_name='+')

class Meta:
constraints = [
models.UniqueConstraint("organization", "team", name="uq_organization_team"),
]
2 changes: 2 additions & 0 deletions galaxy_ng/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,5 @@
# When set to True will enable the DYNAMIC settungs feature
# Individual allowed dynamic keys are set on ./dynamic_settings.py
GALAXY_DYNAMIC_SETTINGS = False

ANSIBLE_BASE_ORGANIZATION_MODEL = 'galaxy.Organization'

0 comments on commit eb750d9

Please sign in to comment.