Skip to content
Snippets Groups Projects
Commit bedfe2c8 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

restrict to .pirati.cz urls

parent 0493f736
Branches
No related tags found
No related merge requests found
Pipeline #12299 passed
# Generated by Django 4.1.4 on 2023-04-12 09:21
from django.db import migrations
import contracts.models
class Migration(migrations.Migration):
dependencies = [
("contracts", "0040_alter_contract_agreement_url_and_more"),
]
operations = [
migrations.AlterField(
model_name="contract",
name="agreement_url",
field=contracts.models.SubdomainValidatedURLField(
blank=True,
help_text="Běžně odkaz na fórum. Využívá se např. u koaličních smluv. Musí začínat <code>https</code>.",
max_length=256,
null=True,
verbose_name="Odkaz na schválení",
),
),
migrations.AlterField(
model_name="contract",
name="tender_url",
field=contracts.models.SubdomainValidatedURLField(
blank=True,
help_text='Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>. Musí začínat <code>https</code>. a být pod doménou <code>pirati.cz</code>.',
max_length=256,
null=True,
verbose_name="Odkaz na výběrové řízení",
),
),
migrations.AlterField(
model_name="contractintent",
name="url",
field=contracts.models.SubdomainValidatedURLField(
help_text="Musí začínat <code>https</code>.",
max_length=256,
verbose_name="Odkaz",
),
),
]
# Generated by Django 4.1.4 on 2023-04-12 09:22
from django.db import migrations
import contracts.models
class Migration(migrations.Migration):
dependencies = [
("contracts", "0041_alter_contract_agreement_url_and_more"),
]
operations = [
migrations.AlterField(
model_name="contract",
name="agreement_url",
field=contracts.models.SubdomainValidatedURLField(
blank=True,
help_text="Běžně odkaz na fórum. Využívá se např. u koaličních smluv. Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>.",
max_length=256,
null=True,
verbose_name="Odkaz na schválení",
),
),
migrations.AlterField(
model_name="contract",
name="tender_url",
field=contracts.models.SubdomainValidatedURLField(
blank=True,
help_text='Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>. Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>.',
max_length=256,
null=True,
verbose_name="Odkaz na výběrové řízení",
),
),
migrations.AlterField(
model_name="contractintent",
name="url",
field=contracts.models.SubdomainValidatedURLField(
help_text="Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>.",
max_length=256,
verbose_name="Odkaz",
),
),
]
...@@ -5,7 +5,7 @@ import typing ...@@ -5,7 +5,7 @@ import typing
from django.conf import settings from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.validators import URLValidator from django.core.validators import RegexValidator, URLValidator
from django.db import models from django.db import models
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
...@@ -17,6 +17,13 @@ from shared.models import NameStrMixin ...@@ -17,6 +17,13 @@ from shared.models import NameStrMixin
from users.models import User from users.models import User
class SubdomainValidatedURLField(models.URLField):
validators = [
URLValidator(schemes=("https",)),
RegexValidator(regex=r"https:\/\/.*\.pirati.cz(\/|$).*"),
]
class OwnPermissionsMixin(models.Model): class OwnPermissionsMixin(models.Model):
class Meta: class Meta:
abstract = True abstract = True
...@@ -566,27 +573,25 @@ class Contract(NameStrMixin, models.Model): ...@@ -566,27 +573,25 @@ class Contract(NameStrMixin, models.Model):
verbose_name="Stav fyzického dokumentu", verbose_name="Stav fyzického dokumentu",
) )
tender_url = models.URLField( tender_url = SubdomainValidatedURLField(
max_length=256, max_length=256,
blank=True, blank=True,
null=True, null=True,
validators=(URLValidator(schemes=("https",)),),
verbose_name="Odkaz na výběrové řízení", verbose_name="Odkaz na výběrové řízení",
help_text=mark_safe( help_text=mark_safe(
'Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>. ' 'Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>. '
"Musí začínat <code>https</code>." "Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>."
), ),
) )
agreement_url = models.URLField( agreement_url = SubdomainValidatedURLField(
max_length=256, max_length=256,
blank=True, blank=True,
null=True, null=True,
validators=(URLValidator(schemes=("https",)),),
verbose_name="Odkaz na schválení", verbose_name="Odkaz na schválení",
help_text=mark_safe( help_text=mark_safe(
"Běžně odkaz na fórum. Využívá se např. u koaličních smluv. " "Běžně odkaz na fórum. Využívá se např. u koaličních smluv. "
"Musí začínat <code>https</code>." "Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>."
), ),
) # WARNING: Dependent on the type! ) # WARNING: Dependent on the type!
...@@ -996,11 +1001,12 @@ class ContractIntent(NameStrMixin, models.Model): ...@@ -996,11 +1001,12 @@ class ContractIntent(NameStrMixin, models.Model):
verbose_name="Jméno", verbose_name="Jméno",
) )
url = models.URLField( url = SubdomainValidatedURLField(
max_length=256, max_length=256,
verbose_name="Odkaz", verbose_name="Odkaz",
validators=(URLValidator(schemes=("https",)),), help_text=mark_safe(
help_text=mark_safe("Musí začínat <code>https</code>."), "Musí začínat <code>https</code> a být pod doménou <code>pirati.cz</code>."
),
) )
contract = models.ForeignKey( contract = models.ForeignKey(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment