Skip to content

Commit

Permalink
Added new field latest_user_action
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredeen committed Dec 13, 2024
1 parent e6a2fcc commit d8e737b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 6 deletions.
26 changes: 26 additions & 0 deletions apps/migrations/0023_baseappinstance_latest_user_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.1.1 on 2024-12-13 14:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("apps", "0022_baseappinstance_k8s_user_app_status_and_more"),
]

operations = [
migrations.AddField(
model_name="baseappinstance",
name="latest_user_action",
field=models.CharField(
choices=[
("Creating", "Creating"),
("Changing", "Changing"),
("Deleting", "Deleting"),
("Redeploying", "Redeploying"),
],
default="Creating",
max_length=15,
),
),
]
10 changes: 9 additions & 1 deletion apps/models/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from apps.models.base.subdomain import Subdomain
from projects.models import Flavor, Project

USER_ACTION_STATUS_CHOICES = [
("Creating", "Creating"),
("Changing", "Changing"),
("Deleting", "Deleting"),
("Redeploying", "Redeploying"),
]


class AppInstanceManager(models.Manager):
model_type = "appinstance"
Expand Down Expand Up @@ -117,10 +124,11 @@ class BaseAppInstance(models.Model):
subdomain = models.OneToOneField(
Subdomain, on_delete=models.SET_NULL, related_name="%(class)s", null=True, blank=True
)

latest_user_action = models.CharField(max_length=15, default="Creating", choices=USER_ACTION_STATUS_CHOICES)
k8s_user_app_status = models.OneToOneField(
K8sUserAppStatus, on_delete=models.RESTRICT, related_name="%(class)s", null=True
)

# TODO: Break connection to model AppStatus and deprecate AppStatus
app_status = models.OneToOneField(AppStatus, on_delete=models.RESTRICT, related_name="%(class)s", null=True)

Expand Down
3 changes: 3 additions & 0 deletions apps/tests/test_app_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CustomAppInstance,
FilemanagerInstance,
JupyterInstance,
K8sUserAppStatus,
RStudioInstance,
ShinyInstance,
Subdomain,
Expand Down Expand Up @@ -42,6 +43,7 @@ def get_data(self, access):
app_instance_list = []
for i, model_class in enumerate(MODELS_LIST):
subdomain = Subdomain.objects.create(subdomain=f"test_internal_{i}")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")

app_instance = model_class.objects.create(
Expand All @@ -51,6 +53,7 @@ def get_data(self, access):
app=app,
project=project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)
app_instance_list.append(app_instance)
Expand Down
11 changes: 10 additions & 1 deletion apps/tests/test_app_settings_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

from projects.models import Project

from ..models import AppCategories, Apps, AppStatus, CustomAppInstance, Subdomain
from ..models import (
AppCategories,
Apps,
AppStatus,
CustomAppInstance,
K8sUserAppStatus,
Subdomain,
)

User = get_user_model()

Expand All @@ -24,6 +31,7 @@ def setUp(self) -> None:
self.project = Project.objects.create_project(name="test-perm", owner=self.user, description="")

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
self.app_instance = CustomAppInstance.objects.create(
access="public",
Expand All @@ -32,6 +40,7 @@ def setUp(self) -> None:
app=self.app,
project=self.project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
k8s_values={
"environment": {"pk": ""},
Expand Down
8 changes: 7 additions & 1 deletion apps/tests/test_create_app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from projects.models import Project

from ..models import Apps, AppStatus, JupyterInstance, Subdomain
from ..models import Apps, AppStatus, JupyterInstance, K8sUserAppStatus, Subdomain

User = get_user_model()

Expand Down Expand Up @@ -146,6 +146,7 @@ def test_has_permission_project_level(self):
self.assertEqual(response.status_code, 200)

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
_ = JupyterInstance.objects.create(
access="private",
Expand All @@ -154,6 +155,7 @@ def test_has_permission_project_level(self):
app=self.app,
project=project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down Expand Up @@ -217,6 +219,7 @@ def test_app_limit_is_per_project(self):
self.assertEqual(response.status_code, 200)

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
_ = JupyterInstance.objects.create(
access="private",
Expand All @@ -225,6 +228,7 @@ def test_app_limit_is_per_project(self):
app=self.app,
project=project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down Expand Up @@ -271,6 +275,7 @@ def test_app_limit_altered_for_project_v2(self):
self.assertEqual(response.status_code, 200)

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
_ = JupyterInstance.objects.create(
access="private",
Expand All @@ -279,6 +284,7 @@ def test_app_limit_altered_for_project_v2(self):
app=self.app,
project=project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down
11 changes: 10 additions & 1 deletion apps/tests/test_delete_app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

from projects.models import Project

from ..models import AppCategories, Apps, AppStatus, JupyterInstance, Subdomain
from ..models import (
AppCategories,
Apps,
AppStatus,
JupyterInstance,
K8sUserAppStatus,
Subdomain,
)

User = get_user_model()

Expand All @@ -26,6 +33,7 @@ def setUp(self) -> None:
self.project = Project.objects.create_project(name="test-perm", owner=self.user, description="")

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
self.app_instance = JupyterInstance.objects.create(
access="public",
Expand All @@ -34,6 +42,7 @@ def setUp(self) -> None:
app=self.app,
project=self.project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down
11 changes: 10 additions & 1 deletion apps/tests/test_get_status_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

from projects.models import Project

from ..models import AppCategories, Apps, AppStatus, JupyterInstance, Subdomain
from ..models import (
AppCategories,
Apps,
AppStatus,
JupyterInstance,
K8sUserAppStatus,
Subdomain,
)

User = get_user_model()

Expand All @@ -24,6 +31,7 @@ def setUp(self) -> None:
self.project = Project.objects.create_project(name="test-perm-get_status", owner=self.user, description="")

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
self.app_instance = JupyterInstance.objects.create(
access="public",
Expand All @@ -32,6 +40,7 @@ def setUp(self) -> None:
app=self.app,
project=self.project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down
4 changes: 3 additions & 1 deletion studio/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.test import TestCase
from guardian.shortcuts import assign_perm, remove_perm

from apps.models import Apps, AppStatus, JupyterInstance, Subdomain
from apps.models import Apps, AppStatus, JupyterInstance, K8sUserAppStatus, Subdomain
from common.models import EmailVerificationTable, UserProfile
from projects.models import Project
from scripts.app_instance_permissions import run
Expand All @@ -22,6 +22,7 @@ def get_data(self, user, access):
app = Apps.objects.create(name="FEDn Combiner")

subdomain = Subdomain.objects.create(subdomain="test_internal")
k8s_user_app_status = K8sUserAppStatus.objects.create()
app_status = AppStatus.objects.create(status="Created")
app_instance = JupyterInstance.objects.create(
access=access,
Expand All @@ -30,6 +31,7 @@ def get_data(self, user, access):
app=app,
project=project,
subdomain=subdomain,
k8s_user_app_status=k8s_user_app_status,
app_status=app_status,
)

Expand Down

0 comments on commit d8e737b

Please sign in to comment.