-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No-Issue
- Loading branch information
Showing
5 changed files
with
272 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
# 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, | ||
), | ||
), | ||
], | ||
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,36 @@ | ||
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() | ||
Organization.objects.using(db_alias).create( | ||
name=settings.DEFAULT_ORGANIZATION_NAME, | ||
description="A default organization.", | ||
created_on=now, | ||
modified_on=now, | ||
) | ||
|
||
|
||
def delete_default_organization(apps, schema_editor): | ||
db_alias = schema_editor.connection.alias | ||
Organization = apps.get_model("galaxy", "Organization") | ||
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", | ||
) |
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,34 @@ | ||
from __future__ import annotations | ||
|
||
from ansible_base.lib.abstract_models import AbstractOrganization, AbstractTeam | ||
from django.conf import settings | ||
from django.db import models | ||
|
||
|
||
class OrganizationManager(models.Manager): | ||
|
||
def get_default(self) -> Organization: | ||
"""Return default organization.""" | ||
return self.get(name=settings.DEFAULT_ORGANIZATION_NAME) | ||
|
||
|
||
class Organization(AbstractOrganization): | ||
"""An organization model.""" | ||
|
||
users = models.ManyToManyField( | ||
settings.AUTH_USER_MODEL, | ||
related_name="organizations", | ||
help_text="The list of users in this organization." | ||
) | ||
|
||
objects = OrganizationManager() | ||
|
||
|
||
class Team(AbstractTeam): | ||
"""A team model.""" | ||
|
||
users = models.ManyToManyField( | ||
settings.AUTH_USER_MODEL, | ||
related_name="teams", | ||
help_text="The list of users in 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