Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SS-1191: Bugfix related to environment and flavor deletion #243

Merged
merged 38 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9c6ddf4
bugfix SS-1191 - environment and flavor deletion
akochari Oct 21, 2024
91bc0b6
better naming in the loop
akochari Oct 22, 2024
4d0eaeb
better naming in the loop
akochari Oct 22, 2024
83d860c
remove commented out line
akochari Oct 22, 2024
8d684ca
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Oct 22, 2024
9ca5daf
remove unneccesary logging statement
akochari Oct 22, 2024
27c2f72
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 19, 2024
c9418bc
allow instructions for local docker for gradio and streamlit apps (sm…
akochari Nov 19, 2024
ac5585c
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 20, 2024
576069a
prohibit deleting environments when they are in use by an app
akochari Nov 21, 2024
e023356
general function for checking if flavor or env can be deleted
akochari Nov 21, 2024
9a93db4
add e2e tests for flavor and environment deletion functionality
akochari Nov 21, 2024
c1897dd
precommit fix
akochari Nov 21, 2024
367d4c8
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 21, 2024
d4c39fe
manual logout and login where cypress doesn't want to get back to a s…
akochari Nov 22, 2024
0fc1629
migration for changes to environment field
akochari Nov 22, 2024
fdcc6b5
remove unused bits of code
akochari Nov 26, 2024
989d1be
add unit tests for flavor creation
akochari Nov 26, 2024
bdc61d1
simplify function to check if ok to delete
akochari Nov 26, 2024
476c1bc
add flavor deletion tests
akochari Nov 26, 2024
3120ce4
pre-commit fix
akochari Nov 26, 2024
0618247
include more flavor deletion tests
akochari Nov 26, 2024
d228984
prohibit flavor and environment editing for regular users
akochari Nov 26, 2024
29e1559
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 26, 2024
dc7e594
add unit tests for environment creation and deletion
akochari Nov 27, 2024
b93efc7
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 27, 2024
b1dd402
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Nov 27, 2024
96e3843
add type hints for the new function
akochari Dec 6, 2024
7d64d26
merge changes from develop branch
akochari Dec 6, 2024
dbff588
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Dec 6, 2024
001a489
updated serve logo
akochari Dec 9, 2024
8c984fa
remove extra migrations file
akochari Dec 9, 2024
0d2c73f
split unit tests into smaller tests
akochari Dec 9, 2024
a322fb9
fix precommit
akochari Dec 9, 2024
8a9af69
uppercase names of global variables
akochari Dec 10, 2024
02b6b50
uppercase names for global variables
akochari Dec 10, 2024
fafe0db
follow redirects in tests
akochari Dec 10, 2024
a4e9243
Merge branch 'develop' into env-and-flavor-deletion-fixes
akochari Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/migrations/0017_alter_streamlitinstance_port.py
akochari marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.1 on 2024-10-21 13:12

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("apps", "0016_tagulous_streamlitinstance_tags_streamlitinstance"),
]

operations = [
migrations.AlterField(
model_name="streamlitinstance",
name="port",
field=models.IntegerField(default=8000),
),
]
39 changes: 36 additions & 3 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests as r
from django.apps import apps
from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.core.exceptions import FieldDoesNotExist
Expand Down Expand Up @@ -102,7 +103,9 @@ def settings(request, project_slug):
)

environments = Environment.objects.filter(project=project)
apps = Apps.objects.all().order_by("slug", "-revision").distinct("slug")
apps_with_environment_option = (
Apps.objects.filter(environment__isnull=False).order_by("slug", "-revision").distinct("slug")
)

flavors = Flavor.objects.filter(project=project)

Expand Down Expand Up @@ -207,7 +210,22 @@ def delete_environment(request, project_slug):
pk = request.POST.get("environment_pk")
# TODO: Check that the user has permission to delete this environment.
environment = Environment.objects.get(pk=pk, project=project)
environment.delete()

can_environment_be_deleted = True
for app_orm in APP_REGISTRY.iter_orm_models():
if hasattr(app_orm, "environment"):
queryset = app_orm.objects.filter(environment=environment)
if queryset:
messages.error(
request,
"Environment cannot be deleted because it is currently used by at least one app \
(can also be a deleted app).",
)
can_environment_be_deleted = False
akochari marked this conversation as resolved.
Show resolved Hide resolved
break

if can_environment_be_deleted:
environment.delete()

return HttpResponseRedirect(
reverse(
Expand Down Expand Up @@ -259,7 +277,22 @@ def delete_flavor(request, project_slug):
pk = request.POST.get("flavor_pk")
# TODO: Check that the user has permission to delete this flavor.
flavor = Flavor.objects.get(pk=pk, project=project)
flavor.delete()

can_flavor_be_deleted = True
for app_orm in APP_REGISTRY.iter_orm_models():
if hasattr(app_orm, "flavor"):
queryset = app_orm.objects.filter(flavor=flavor)
if queryset:
messages.error(
request,
"Flavor cannot be deleted because it is currently used by at least one app \
(can also be a deleted app).",
)
akochari marked this conversation as resolved.
Show resolved Hide resolved
can_flavor_be_deleted = False
break

if can_flavor_be_deleted:
flavor.delete()

return HttpResponseRedirect(
reverse(
Expand Down
10 changes: 6 additions & 4 deletions templates/projects/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ <h3 class="h3 mb-3">Project settings</h3>

<div class="col-md-9 col-xl-10 mt-4 mt-md-0">
<div class="tab-content">
{% include 'common/flash_messages.html' %}

<div class="tab-pane fade show active" id="projdesc" role="tabpanel">
<div class="card shadow border-0">

Expand Down Expand Up @@ -186,23 +188,23 @@ <h5 class="card-title mb-0">Environments</h5>
<div class="mb-3">
<label for="environment_name">Name</label>
<input type="text" name="environment_name" id="environment_name" value=""
class="form-control" />
placeholder="Lab X" class="form-control" />
</div>
<div class="mb-3">
<label for="environment_name">Repository</label>
<input type="text" name="environment_repository" id="environment_repository"
value="" class="form-control" />
placeholder="docker.io" value="" class="form-control" />
</div>
<div class="mb-3">
<label for="environment_image">Image</label>
<input type="text" name="environment_image" id="environment_image" value=""
class="form-control" />
placeholder="user/image:tag" class="form-control" />
</div>
<div class="mb-3">
<label for="environment_app">Applies to app:</label>
<select type="text" class="form-control" id="environment_app" name="environment_app"
maxlength="256" required>
{% for app in apps %}
{% for app in apps_with_environment_option %}
<option value="{{ app.pk }}">{{ app.name }}</option>
{% endfor %}
</select>
Expand Down