-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SS-1176 Users are able to set a custom default start URL for their ap…
…ps (#249) Co-authored-by: Arnold Kochari <[email protected]> Source: https://scilifelab.atlassian.net/browse/SS-1176 when we deploy an app it show app-subdomain.serve.scilifelab.se but if user wants the base page to be app-subdomain.serve.scilifelab.se/docs then that should be configurable.
- Loading branch information
1 parent
1b83c5e
commit 8163d0d
Showing
10 changed files
with
166 additions
and
13 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
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
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
23 changes: 23 additions & 0 deletions
23
apps/migrations/0018_customappinstance_default_url_subpath.py
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,23 @@ | ||
# Generated by Django 5.1.1 on 2024-11-19 13:27 | ||
|
||
import apps.models.app_types.custom.custom | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("apps", "0017_alter_streamlitinstance_port"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="customappinstance", | ||
name="default_url_subpath", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
max_length=255, | ||
validators=[apps.models.app_types.custom.custom.validate_default_url_subpath], | ||
), | ||
), | ||
] |
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,11 +1,40 @@ | ||
import regex as re | ||
from django.core.exceptions import ValidationError | ||
from django.db import models | ||
|
||
from apps.models import AppInstanceManager, BaseAppInstance | ||
|
||
from .base import AbstractCustomAppInstance | ||
|
||
|
||
def validate_default_url_subpath(candidate): | ||
""" | ||
Validates a custom default url path addition. | ||
The RegexValidator will raise a ValidationError if the input does not match the regular expression. | ||
It is up to the caller to handle the raised exception if desired. | ||
""" | ||
error_message = ( | ||
"Your custom URL subpath is not valid, please correct it. " | ||
"It must be 1-53 characters long." | ||
" It can contain only Unicode letters, digits, hyphens" | ||
" ( - ), forward slashes ( / ), and underscores ( _ )." | ||
" It cannot start or end with a hyphen ( - ) and " | ||
"cannot start with a forward slash ( / )." | ||
" It cannot contain consecutive forward slashes ( // )." | ||
) | ||
|
||
pattern = r"^(?!-)(?!/)(?!.*//)[\p{Letter}\p{Mark}0-9-/_]{1,53}(?<!-)$|^$" | ||
|
||
if not re.match(pattern, candidate): | ||
raise ValidationError(error_message) | ||
|
||
|
||
class CustomAppInstanceManager(AppInstanceManager): | ||
model_type = "customappinstance" | ||
|
||
|
||
class CustomAppInstance(AbstractCustomAppInstance, BaseAppInstance): | ||
default_url_subpath = models.CharField( | ||
validators=[validate_default_url_subpath], max_length=255, default="", blank=True | ||
) | ||
objects = CustomAppInstanceManager() |
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
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
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
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
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