Skip to content

Commit

Permalink
Admin panel (#1464)
Browse files Browse the repository at this point in the history
* Initial configuration for admin-panel

* Remove duplicated configuration

* Allow empty values in dependencies M2M field

* Refactor urls

* Fix tests for permissions

* Added new migration

* Changed url name

* Original migration file recovered

* Create a new migration file

* Changed url name
  • Loading branch information
Tansito authored Aug 23, 2024
1 parent 4b088ae commit 0e14adf
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 29 deletions.
38 changes: 34 additions & 4 deletions gateway/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
"""Admin module."""

from django.contrib import admin
from .models import Job, Program, ComputeResource
from api.models import JobConfig, Provider, Program, ComputeResource, Job, RuntimeJob


@admin.register(JobConfig)
class JobConfigAdmin(admin.ModelAdmin):
"""JobConfigAdmin."""


@admin.register(Provider)
class ProviderAdmin(admin.ModelAdmin):
"""ProviderAdmin."""

search_fields = ["name"]


@admin.register(Program)
class ProgramAdmin(admin.ModelAdmin):
"""ProgramAdmin."""

search_fields = ["title", "author__username"]
list_filter = ["provider", "type"]
exclude = ["env_vars"]


@admin.register(ComputeResource)
class ComputeResourceAdmin(admin.ModelAdmin):
"""ComputeResourceAdmin."""

search_fields = ["title", "owner__username"]
list_filter = ["active"]


@admin.register(Job)
class JobAdmin(admin.ModelAdmin):
"""JobAdmin."""

search_fields = ["author__username", "program__title"]
list_filter = ["status"]
exclude = ["arguments", "env_vars", "logs"]

@admin.register(ComputeResource)
class ComputeResourceAdmin(admin.ModelAdmin):
"""ComputeResourceAdmin."""

@admin.register(RuntimeJob)
class RuntimeJobAdmin(admin.ModelAdmin):
"""RuntimeJobAdmin."""

search_fields = ["job__id"]
19 changes: 19 additions & 0 deletions gateway/api/migrations/0030_alter_program_instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1 on 2024-08-21 18:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0029_program_additional_info_program_documentation_url_and_more"),
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.AlterField(
model_name="program",
name="instances",
field=models.ManyToManyField(blank=True, to="auth.group"),
),
]
2 changes: 1 addition & 1 deletion gateway/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Program(ExportModelOperationsMixin("program"), models.Model):
env_vars = models.TextField(null=False, blank=True, default="{}")
dependencies = models.TextField(null=False, blank=True, default="[]")

instances = models.ManyToManyField(Group)
instances = models.ManyToManyField(Group, blank=True)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
Expand Down
5 changes: 2 additions & 3 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
Expand All @@ -71,6 +72,7 @@
"django_prometheus.middleware.PrometheusBeforeMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
Expand Down Expand Up @@ -273,9 +275,6 @@
"REFRESH_TOKEN_LIFETIME": timedelta(days=20),
}

MEDIA_ROOT = os.path.join(sanitize_file_path(str(BASE_DIR)), "media")
MEDIA_URL = "/media/"

# custom token auth
SETTINGS_TOKEN_AUTH_URL = os.environ.get("SETTINGS_TOKEN_AUTH_URL", None)
SETTINGS_TOKEN_AUTH_USER_FIELD = os.environ.get(
Expand Down
27 changes: 12 additions & 15 deletions gateway/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include, re_path
from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
Expand All @@ -40,13 +41,18 @@

router = routers.DefaultRouter()

urlpatterns = [
path("readiness/", probes.views.readiness, name="readiness"),
path("liveness/", probes.views.liveness, name="liveness"),
path("version/", version.views.version, name="version"),
path("", include("django_prometheus.urls")),
path("backoffice/", admin.site.urls),
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
urlpatterns = [
path("readiness/", probes.views.readiness, name="readiness"),
path("liveness/", probes.views.liveness, name="liveness"),
path("version/", version.views.version, name="version"),
path("", include("django_prometheus.urls")),
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
urlpatterns += [
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema.without_ui(cache_timeout=0),
Expand All @@ -62,12 +68,3 @@
),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
else:
urlpatterns = [
path("readiness/", probes.views.readiness, name="readiness"),
path("liveness/", probes.views.liveness, name="liveness"),
path("version/", version.views.version, name="version"),
path("", include("django_prometheus.urls")),
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
]
4 changes: 2 additions & 2 deletions gateway/tests/fixtures/catalog_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@
"pk": 100,
"fields": {
"name": "ibm-q/open/main",
"permissions": [60]
"permissions": [64]
}
},
{
"model": "auth.group",
"pk": 105,
"fields": {
"name": "admin-group",
"permissions": [60, 61]
"permissions": [64, 65]
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions gateway/tests/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@
"pk": 100,
"fields": {
"name": "runner",
"permissions": [61]
"permissions": [65]
}
},
{
"model": "auth.group",
"pk": 101,
"fields": {
"name": "viewer",
"permissions": [60]
"permissions": [64]
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions gateway/tests/fixtures/tasks_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"pk": 100,
"fields": {
"name": "runner",
"permissions": [60]
"permissions": [64]
}
},
{
"model": "auth.group",
"pk": 101,
"fields": {
"name": "manager",
"permissions": [60]
"permissions": [64]
}
}
]
Expand Down

0 comments on commit 0e14adf

Please sign in to comment.