Skip to content
Merged
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
4 changes: 3 additions & 1 deletion promgen/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ class TokenGenerationForm(forms.Form):
user_timezone = forms.CharField(required=False, widget=forms.HiddenInput())
expiration = forms.DateTimeField(
required=bool(settings.API_TOKEN_TTL_DAYS),
widget=forms.DateInput(attrs={"type": "date"}),
widget=forms.DateInput(
attrs={"type": "date", "max_expiration_in_days": settings.API_TOKEN_TTL_DAYS}
),
)

def __init__(self, *args, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions promgen/static/js/promgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,16 @@ $(document).ready(function() {
// Set the user's current timezone for forms
$("#id_user_timezone").attr("value", luxon.DateTime.local().zoneName);

// Set the min and max expiration date for API tokens DatePicker
const tokenExpirationDatePicker = $('input[type="date"][name="expiration"]');
const today = luxon.DateTime.local();
tokenExpirationDatePicker.attr("min", today.toISODate());
const max = tokenExpirationDatePicker.attr("max_expiration_in_days");
if (max) {
const days = parseInt(max, 10);
if (Number.isFinite(days)) {
tokenExpirationDatePicker.attr("max", today.plus({ days }).toISODate());
}
}

});
2 changes: 1 addition & 1 deletion promgen/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{% include 'promgen/vue/silence_list_modal.html' %}
</script>
<script
src="{% static 'js/promgen.js' %}?v=11"
src="{% static 'js/promgen.js' %}?v=12"
integrity="{% sri_integrity_static 'js/promgen.js' %}"
crossorigin="anonymous"
></script>
Expand Down