SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit f2b21d17 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Allow Post creation on Meeting only if Meeting is ongoing

parent 3fc0bdce
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,7 @@
<td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td>
<td>{{ forum.latest_post }}</td>
<td>{{ forum.latest_post.posted_on|date:"Y-m-d" }}</td>
<td>{{ forum.nr_posts }}</td>
<td><span class="badge badge-primary badge-pill">{{ forum.nr_posts }}</span></td>
</tr>
{% empty %}
<tr>
......
......@@ -2,6 +2,8 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import datetime
from django import forms
from django.contrib import messages
from django.contrib.auth.models import Group
......@@ -170,6 +172,18 @@ class PostCreateView(UserPassesTestMixin, CreateView):
if self.request.user.has_perm('forums.add_forum'):
return True
forum = get_object_or_404(Forum, slug=self.kwargs.get('slug'))
# Only allow posting if it's within a Forum, or within an ongoing meeting.
try:
if datetime.date.today() > forum.meeting.date_until:
messages.error(self.request,
'Error: you cannot Post to a Meeting which is finished.')
raise PermissionDenied
elif datetime.date.today () < forum.meeting.date_from:
messages.warning(self.request,
'This meeting has not started yet, please come back later!')
raise PermissionDenied
except Meeting.DoesNotExist:
pass
if self.request.user.has_perm('can_post_to_forum', forum):
return True
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment