Skip to content

Commit

Permalink
[DONE] Live event restriction (#1066)
Browse files Browse the repository at this point in the history
* Fixup. Format code with Prettier

* fix selector + display access_group field

* remove access_group if not restricted

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
mattbild and github-actions authored Mar 8, 2024
1 parent 66132f2 commit d1f21b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pod/live/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ def clean(self):
cleaned_data["is_restricted"] = False
cleaned_data["restrict_access_to_groups"] = []

if not cleaned_data.get("is_restricted", True):
cleaned_data["restrict_access_to_groups"] = []

class Meta(object):
model = Event
fields = [
Expand Down
11 changes: 7 additions & 4 deletions pod/live/static/js/broadcaster_from_building.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ document.addEventListener("DOMContentLoaded", function () {
let restrictedCheckBox = document.getElementById("event_is_restricted");
let restrictedHelp = document.getElementById("event_is_restrictedHelp");
let restrictedLabel = document.getElementsByClassName(
"field_is_restricted",
"field-is_restricted",
)[0];

let change_restriction = (restrict) => {
if (restrict === true) {
restrictedCheckBox.checked = true;
restrictedCheckBox.setAttribute("onclick", "return false");
if (!restrictedCheckBox.checked) {
restrictedCheckBox.click();
restrictedCheckBox.checked = true;
}
restrictedCheckBox.setAttribute("disabled", "disabled");
restrictedHelp.innerHTML = gettext(
"Restricted because the broadcaster is restricted",
);
restrictedLabel.style.opacity = "0.5";
} else {
restrictedCheckBox.removeAttribute("onclick");
restrictedCheckBox.removeAttribute("disabled");
restrictedHelp.innerHTML = gettext(
"If this box is checked, the event will only be accessible to authenticated users.",
);
Expand Down
17 changes: 9 additions & 8 deletions pod/live/templates/live/event_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,6 @@ <h2 class="h4 card-header card-title pl-2">{% trans "Event planning" %}</h2>

<script>

if (document.getElementById("event_is_draft")){
document.getElementById("event_is_draft").addEventListener("click", () => showRestrictions());
}
if (document.getElementById("event_is_restricted")){
document.getElementById("event_is_restricted").addEventListener("click", () => showGroups());
}
{# fields selectable only if not draft #}
let showRestrictions = () => {
document.querySelectorAll(".draft_access, .groups_access").forEach((draft_access) => {
Expand All @@ -178,7 +172,6 @@ <h2 class="h4 card-header card-title pl-2">{% trans "Event planning" %}</h2>
showGroups();
}
})

};

{# groups field available only if restricted #}
Expand All @@ -192,9 +185,17 @@ <h2 class="h4 card-header card-title pl-2">{% trans "Event planning" %}</h2>
gp_access.classList.add("hide");
}
})

};

if (document.getElementById("event_is_draft")){
showRestrictions();
document.getElementById("event_is_draft").addEventListener("click", () => showRestrictions());
}
if (document.getElementById("event_is_restricted")){
showGroups();
document.getElementById("event_is_restricted").addEventListener("click", () => showGroups());
}

document.addEventListener("DOMContentLoaded",function () {
DateTimeShortcuts.overrideTimeOptions = function () {
var clockCount = 0;
Expand Down

0 comments on commit d1f21b9

Please sign in to comment.