Add better collaboration selection tool
This commit is contained in:
parent
c2f4724b11
commit
7f55626d7e
@ -92,4 +92,4 @@ def is_file(field):
|
||||
def add_class(field, css_class):
|
||||
if len(field.errors) > 0:
|
||||
css_class += " ~critical"
|
||||
return field.as_widget(attrs={"class": css_class})
|
||||
return field.as_widget(attrs={"class": field.css_classes(extra_classes=css_class)})
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,7 +1,8 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import Service
|
||||
from core.models import Service, User
|
||||
from allauth.account.admin import EmailAddress
|
||||
|
||||
|
||||
class ServiceForm(forms.ModelForm):
|
||||
@ -11,8 +12,7 @@ class ServiceForm(forms.ModelForm):
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
"origins": forms.TextInput(),
|
||||
"collaborators": forms.CheckboxSelectMultiple(),
|
||||
"respect_dnt": forms.RadioSelect(choices=[(True, "Yes"), (False, "No")])
|
||||
"respect_dnt": forms.RadioSelect(choices=[(True, "Yes"), (False, "No")]),
|
||||
}
|
||||
labels = {
|
||||
"origins": "Allowed Hostnames",
|
||||
@ -24,5 +24,26 @@ class ServiceForm(forms.ModelForm):
|
||||
"origins": _(
|
||||
"At what hostnames does the service operate? This sets CORS headers, so use '*' if you're not sure (or don't care)."
|
||||
),
|
||||
"respect_dnt": "Should visitors who have enabled <a href='https://en.wikipedia.org/wiki/Do_Not_Track'>Do Not Track</a> be excluded from all data?"
|
||||
"respect_dnt": "Should visitors who have enabled <a href='https://en.wikipedia.org/wiki/Do_Not_Track'>Do Not Track</a> be excluded from all data?",
|
||||
}
|
||||
|
||||
collaborators = forms.CharField(help_text="Which users should have read-only access to this service? (Comma separated list of emails.)", required=False)
|
||||
|
||||
|
||||
def clean_collaborators(self):
|
||||
collaborators = []
|
||||
for collaborator_email in self.cleaned_data["collaborators"].split(","):
|
||||
email = collaborator_email.strip()
|
||||
if email == "":
|
||||
continue
|
||||
collaborator_email_linked = EmailAddress.objects.filter(email__iexact=email).first()
|
||||
if collaborator_email_linked is None:
|
||||
raise forms.ValidationError(f"Email '{email}' is not registered")
|
||||
collaborators.append(collaborator_email_linked.user)
|
||||
return collaborators
|
||||
|
||||
def get_initial_for_field(self, field, field_name):
|
||||
initial = super(ServiceForm, self).get_initial_for_field(field, field_name)
|
||||
if field_name == "collaborators":
|
||||
return ", ".join([user.email for user in initial])
|
||||
return initial
|
||||
|
@ -8,7 +8,8 @@
|
||||
<meta name="robots" content="noindex">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{% include 'a17t/head.html' %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/litepicker/dist/js/main.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/litepicker@1.2.0/dist/js/main.js"
|
||||
integrity="sha256-mOlCEHUNWZPYIrc5OFL4Ab2rsJGzIPld3cy1ok7Cfx0=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.18.1/dist/apexcharts.min.js"
|
||||
integrity="sha256-RalQXBZdisB04aaBsm+6YZ0b/iRYjX1MZn90m19AnCY=" crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="{% static 'dashboard/css/global.css' %}">
|
||||
@ -33,7 +34,8 @@
|
||||
</span>
|
||||
</button>
|
||||
<hr class="sep h-4 md:h-8 w-full">
|
||||
<div id="navMenuExpanded" class="bg-white shadow-lg md:shadow-none p-4 hidden rounded-lg md:block md:bg-transparent md:border-none md:p-0 w-full">
|
||||
<div id="navMenuExpanded"
|
||||
class="bg-white shadow-lg md:shadow-none p-4 hidden rounded-lg md:block md:bg-transparent md:border-none md:p-0 w-full">
|
||||
{% if user.owning_services.all %}
|
||||
<p class="ml-2 mb-1 supra font-medium text-gray-500 pointer-events-none">Services</p>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user