Skip to content

feat: setup function as public #1612

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ spec:
secretKeyRef:
name: {{ .Values.secrets.servicePsql.name }}
key: {{ .Values.secrets.servicePsql.key.databasePassword }}
- name: PUBLIC_GROUP_NAME
value: {{ .Values.application.publicGroupName }}
- name: ALLOWED_HOSTS
value: {{ .Values.application.allowedHosts | quote }}
- name: CSRF_TRUSTED_ORIGINS
Expand Down
2 changes: 1 addition & 1 deletion gateway/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProgramAdmin(admin.ModelAdmin):
"""ProgramAdmin."""

search_fields = ["title", "author__username"]
list_filter = ["provider", "type"]
list_filter = ["provider", "type", "public"]
exclude = ["env_vars"]
filter_horizontal = ["instances", "trial_instances"]

Expand Down
18 changes: 18 additions & 0 deletions gateway/api/migrations/0037_program_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2025-04-04 13:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0036_groupmetadata"),
]

operations = [
migrations.AddField(
model_name="program",
name="public",
field=models.BooleanField(default=False, null=True),
),
]
2 changes: 2 additions & 0 deletions gateway/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Program(ExportModelOperationsMixin("program"), models.Model):
readable_title = models.CharField(
max_length=255, null=True, blank=True, default=None
)

public = models.BooleanField(default=False, null=True)
type = models.CharField(
max_length=20,
choices=PROGRAM_TYPES,
Expand Down
25 changes: 3 additions & 22 deletions gateway/api/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import logging
import os

from django.conf import settings
from django.contrib.auth.models import Group

# pylint: disable=duplicate-code
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
Expand Down Expand Up @@ -47,7 +44,6 @@ class CatalogViewSet(viewsets.GenericViewSet):
"""

BASE_NAME = "catalog"
PUBLIC_GROUP_NAME = settings.PUBLIC_GROUP_NAME

@staticmethod
def get_serializer_retrieve_catalog(*args, **kwargs):
Expand All @@ -61,38 +57,23 @@ def get_queryset(self):
"""
QuerySet to list public programs in the catalog
"""
public_group = Group.objects.filter(name=self.PUBLIC_GROUP_NAME).first()

if public_group is None:
logger.error("Public group [%s] does not exist.", self.PUBLIC_GROUP_NAME)
return []

return Program.objects.filter(instances=public_group).distinct()
return Program.objects.filter(public=True).distinct()

def get_retrieve_queryset(self, pk):
"""
QuerySet to retrieve a specifc public programs in the catalog
"""
public_group = Group.objects.filter(name=self.PUBLIC_GROUP_NAME).first()

if public_group is None:
logger.error("Public group [%s] does not exist.", self.PUBLIC_GROUP_NAME)
return None

return Program.objects.filter(id=pk, instances=public_group).first()
return Program.objects.filter(id=pk, public=True).first()

def get_by_title_queryset(self, title, provider_name):
"""
QuerySet to retrieve a specifc public programs in the catalog
"""
public_group = Group.objects.filter(name=self.PUBLIC_GROUP_NAME).first()

if public_group is None:
logger.error("Public group [%s] does not exist.", self.PUBLIC_GROUP_NAME)
return None

return Program.objects.filter(
title=title, provider__name=provider_name, instances=public_group
title=title, provider__name=provider_name, public=True
).first()

def list(self, request):
Expand Down
3 changes: 0 additions & 3 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,3 @@
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SESSION_COOKIE_AGE = 3600

# Public group name
PUBLIC_GROUP_NAME = os.environ.get("PUBLIC_GROUP_NAME", "ibm-q/open/main")
1 change: 1 addition & 0 deletions gateway/tests/fixtures/catalog_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"fields": {
"created": "2023-02-01T15:30:43.281796Z",
"title": "Public-Function",
"public": true,
"readable_title": "Public Function",
"type": "APPLICATION",
"image": "icr.io/awesome-namespace/awesome-title",
Expand Down
4 changes: 2 additions & 2 deletions gateway/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ deps = -rrequirements.txt
-rrequirements-dev.txt
commands =
pip check
python manage.py test
python manage.py test {posargs}

[testenv:lint]
skip_install = true
Expand All @@ -39,5 +39,5 @@ basepython = python3
setenv =
{[testenv]setenv}
commands =
coverage3 run --source api manage.py test
coverage3 run --source api manage.py test {posargs}
coverage3 report --fail-under=70