Skip to content

Commit

Permalink
fix: allow club officers to expire announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
alanzhu0 committed Oct 5, 2024
1 parent fbab690 commit 51721c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
10 changes: 5 additions & 5 deletions intranet/apps/announcements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Meta:
model = Announcement
fields = ["title", "author", "content", "groups", "expiration_date", "notify_post", "notify_email_all", "update_added_date", "pinned"]
help_texts = {
"expiration_date": "By default, announcements expire after two weeks. To change this, click in the box above.",
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
"notify_post": "If this box is checked, students who have signed up for notifications will receive an email.",
"notify_email_all": "This will send an email notification to all of the users who can see this post. This option does NOT take users' email notification preferences into account, so please use with care.",
"update_added_date": "If this announcement has already been added, update the added date to now so that the announcement is pushed to the top. If this option is not selected, the announcement will stay in its current position.",
Expand Down Expand Up @@ -55,7 +55,7 @@ class Meta:
model = Announcement
fields = ["activity", "title", "content", "expiration_date"]
help_texts = {
"expiration_date": "By default, announcements expire after two weeks. To change this, click in the box above.",
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
}


Expand All @@ -71,7 +71,7 @@ class Meta:
model = Announcement
fields = ["title", "content", "expiration_date"]
help_texts = {
"expiration_date": "By default, announcements expire after two weeks. To change this, click in the box above.",
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
}


Expand All @@ -80,7 +80,7 @@ class AnnouncementEditForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["expiration_date"].help_text = "By default, announcements expire after two weeks. To change this, click in the box above."
self.fields["expiration_date"].help_text = "By default, announcements expire after two weeks. Choose the shortest time necessary."

self.fields["notify_post_resend"].help_text = "If this box is checked, students who have signed up for notifications will receive an email."

Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self, *args, **kwargs):
"Otherwise, your name will appear in this field automatically."
)
self.fields["content"].help_text = "The contents of the news post which will appear on Intranet."
self.fields["expiration_date"].help_text = "By default, announcements expire after two weeks. To change this, click in the box above."
self.fields["expiration_date"].help_text = "By default, announcements expire after two weeks. Choose the shortest time necessary."
self.fields["notes"].help_text = (
"Any information about this announcement you wish to share with the Intranet "
"administrators and teachers selected above. If you want to restrict this posting "
Expand Down
41 changes: 19 additions & 22 deletions intranet/apps/announcements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,38 +426,35 @@ def modify_announcement_view(request, announcement_id=None):
return render(request, "announcements/add_modify.html", context)


@announcements_admin_required
@deny_restricted
def delete_announcement_view(request, announcement_id):
"""Delete an announcement.
announcement_id: announcement id
"""
announcement = get_object_or_404(Announcement, id=announcement_id)

if not (request.user.is_announcements_admin or announcement.is_club_announcement and announcement.can_modify(request.user)):
messages.error(request, "You do not have permission to delete this announcement.")
return redirect("index")

if request.method == "POST":
post_id = None
try:
post_id = request.POST["id"]
except AttributeError:
post_id = None
try:
a = Announcement.objects.get(id=post_id)
if request.POST.get("full_delete", False):
a.delete()
messages.success(request, "Successfully deleted announcement.")
logger.info("Admin %s deleted announcement: %s (%s)", request.user, a, a.id)
else:
a.expiration_date = timezone.localtime()
a.save()
messages.success(request, "Successfully expired announcement.")
logger.info("Admin %s expired announcement: %s (%s)", request.user, a, a.id)
except Announcement.DoesNotExist:
pass
if request.POST.get("full_delete", False) and request.user.is_announcements_admin:
announcement.delete()
messages.success(request, "Successfully deleted announcement.")
logger.info("Admin %s deleted announcement: %s (%s)", request.user, announcement, announcement.id)
else:
announcement.expiration_date = timezone.localtime()
announcement.save()
messages.success(request, "Successfully expired announcement.")
logger.info("%s expired announcement: %s (%s)", request.user, announcement, announcement.id)

if announcement.is_club_announcement:
return redirect("club_announcements")
return redirect("index")
else:
announcement = get_object_or_404(Announcement, id=announcement_id)
return render(request, "announcements/delete.html", {"announcement": announcement})

return render(request, "announcements/delete.html", {"announcement": announcement})


@login_required
Expand Down
1 change: 1 addition & 0 deletions intranet/templates/announcements/club-request.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{% if request.user.is_teacher %}
$("#id_teachers_requested")[0].selectize.setValue({{ request.user.id }});
{% endif %}
$("#no-expire-btn").hide();
});
</script>
{% endblock %}
Expand Down
9 changes: 9 additions & 0 deletions intranet/templates/announcements/delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@

{% block main %}
<div class="announcements primary-content">
{% if request.user.is_announcements_admin %}
<h3>Are you sure you want to delete this announcement?</h3>
<p>Please <b>EXPIRE</b> this announcement instead of deleting it, unless the announcement was created by accident.</p>
{% else %}
<h3>Are you sure you want to expire this club announcement?</h3>
<p>Expiring an announcement will remove it from the dashboard, but it will still be accessible in the archive.
To request full deletion of a club announcement, email <a href="mailto:[email protected]">[email protected]</a>.</p>
{% endif %}
<br>
<b>{{ announcement.title }}</b>
<br>
<br>
Expand All @@ -49,7 +56,9 @@ <h3>Are you sure you want to delete this announcement?</h3>
<input type="submit" value="Expire">
<br>
<br>
{% if request.user.is_announcements_admin %}
<a href="#" id="delete" class="button"><i class='fas fa-exclamation-triangle'></i> Full Delete</a> &nbsp;
{% endif %}
</form>
</div>
<script>
Expand Down

0 comments on commit 51721c0

Please sign in to comment.