forked from ansible/galaxy_ng
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add organization and team models (ansible#2094)
* Add organization and team models * Add new `Oranization` and `Team` models, that implement respective abstract models from DAB. * Add related database migrations and data migration, that creates a new default model. * Implement custom manager for the `Organization` model that retrieves the default organization. * Team model has a one-to-one relationship with the standard Group model. * When new Team record is created, a related Group model is automatically created as well. No-Issue * Create related teams for manually created groups And drop group prefix for the default organization. No-Issue
- Loading branch information
Showing
6 changed files
with
356 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Generated by Django 4.2.10 on 2024-02-15 17:33 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
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, | ||
), | ||
), | ||
( | ||
"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, | ||
), | ||
), | ||
( | ||
"users", | ||
models.ManyToManyField( | ||
help_text="The list of users in this organization.", | ||
related_name="organizations", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Team", | ||
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)), | ||
( | ||
"description", | ||
models.TextField(blank=True, default="", help_text="The team 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, | ||
), | ||
), | ||
( | ||
"organization", | ||
models.ForeignKey( | ||
help_text="The organization of this team.", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="teams", | ||
to="galaxy.organization", | ||
), | ||
), | ||
( | ||
"users", | ||
models.ManyToManyField( | ||
help_text="The list of users in this team.", | ||
related_name="teams", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"group", | ||
models.OneToOneField( | ||
help_text="Related group record.", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="+", | ||
to="galaxy.group", | ||
), | ||
|
||
) | ||
], | ||
options={ | ||
"ordering": ("organization__name", "name"), | ||
"abstract": False, | ||
"unique_together": {("organization", "name")}, | ||
}, | ||
), | ||
] |
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,48 @@ | ||
from django.conf import settings | ||
from django.db import migrations | ||
from django.utils import timezone | ||
|
||
|
||
def create_default_organization(apps, schema_editor): | ||
db_alias = schema_editor.connection.alias | ||
Organization = apps.get_model("galaxy", "Organization") | ||
|
||
now = timezone.now() | ||
org = Organization.objects.using(db_alias).create( | ||
name=settings.DEFAULT_ORGANIZATION_NAME, | ||
description="A default organization.", | ||
created_on=now, | ||
modified_on=now, | ||
) | ||
|
||
schema_editor.execute( | ||
""" | ||
INSERT INTO galaxy_team (name, description, created_on, modified_on, group_id, organization_id) | ||
SELECT grp.name, '', now(), now(), grp.id, %s | ||
FROM auth_group AS grp | ||
""", | ||
(org.id,), | ||
) | ||
|
||
|
||
def delete_default_organization(apps, schema_editor): | ||
db_alias = schema_editor.connection.alias | ||
Team = apps.get_model("galaxy", "Team") | ||
Organization = apps.get_model("galaxy", "Organization") | ||
|
||
Team.objects.using(db_alias).delete() | ||
|
||
Organization.objects.using(db_alias).filter(name=settings.DEFAULT_ORGANIZATION_NAME).delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("galaxy", "0049_organization"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=create_default_organization, | ||
reverse_code=delete_default_organization, | ||
) | ||
] |
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,43 +1,40 @@ | ||
from .auth import ( | ||
Group, | ||
User, | ||
) | ||
from .collectionimport import ( | ||
CollectionImport, | ||
) | ||
from .aiindex import AIIndexDenyList | ||
from .auth import Group, User | ||
from .collectionimport import CollectionImport | ||
from .config import Setting | ||
from .namespace import ( | ||
Namespace, | ||
NamespaceLink, | ||
) | ||
|
||
from .synclist import ( | ||
SyncList, | ||
) | ||
|
||
from .container import ( | ||
ContainerDistribution, | ||
ContainerDistroReadme, | ||
ContainerNamespace, | ||
ContainerRegistryRemote, | ||
ContainerRegistryRepos | ||
|
||
ContainerRegistryRepos, | ||
) | ||
|
||
from .aiindex import AIIndexDenyList | ||
from .namespace import Namespace, NamespaceLink | ||
from .organization import Organization, Team | ||
from .synclist import SyncList | ||
|
||
__all__ = ( | ||
'Group', | ||
'User', | ||
'CollectionImport', | ||
'Namespace', | ||
'NamespaceLink', | ||
'Setting', | ||
'SyncList', | ||
'ContainerDistribution', | ||
'ContainerDistroReadme', | ||
'ContainerNamespace', | ||
'ContainerRegistryRemote', | ||
'ContainerRegistryRepos', | ||
'AIIndexDenyList', | ||
# aiindex | ||
"AIIndexDenyList", | ||
# auth | ||
"Group", | ||
"User", | ||
# collectionimport | ||
"CollectionImport", | ||
# config | ||
"Setting", | ||
# container | ||
"ContainerDistribution", | ||
"ContainerDistroReadme", | ||
"ContainerNamespace", | ||
"ContainerRegistryRemote", | ||
"ContainerRegistryRepos", | ||
# namespace | ||
"Namespace", | ||
"NamespaceLink", | ||
# organization | ||
"Organization", | ||
"Team", | ||
# synclist | ||
"SyncList", | ||
) |
Oops, something went wrong.