Skip to content

Commit

Permalink
Allow pending talks to be public, by TalkType
Browse files Browse the repository at this point in the history
Add a new flag to TalkType to control whether pending talks are publicly
visible.

Closes: #252
  • Loading branch information
stefanor committed Oct 15, 2023
1 parent 5a312e2 commit 1e41c61
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
7 changes: 5 additions & 2 deletions wafer/talks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ def review_score(self, obj):


class TalkTypeAdmin(VersionAdmin):
list_display = ('name', 'order', 'disable_submission', 'css_class', 'submission_deadline', 'accept_late_submissions')
list_display = ('name', 'order', 'disable_submission', 'css_class',
'submission_deadline', 'accept_late_submissions',
'show_pending_submissions')
readonly_fields = ('css_class',)
list_editable = ('submission_deadline', 'accept_late_submissions')
list_editable = ('submission_deadline', 'accept_late_submissions',
'show_pending_submissions')


class TrackAdmin(VersionAdmin):
Expand Down
23 changes: 23 additions & 0 deletions wafer/talks/migrations/0023_talktype_show_pending_submissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.6 on 2023-10-08 10:31

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("talks", "0022_talk_language"),
]

operations = [
migrations.AddField(
model_name="talktype",
name="show_pending_submissions",
field=models.BooleanField(
default=False,
help_text="Whether to publicly show pending submissions, before acceptance",
verbose_name="show pending submissions",
),
),
]
8 changes: 7 additions & 1 deletion wafer/talks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ class TalkType(models.Model):
default=False,
help_text=_("Whether submissions after the deadline should be accepted")
)

show_speakers = models.BooleanField(
_('Show authors in speakers list'),
default=True,
help_text=_("Whether to show the authors for this talk type in the speakers list")
)
show_pending_submissions = models.BooleanField(
_('show pending submissions'),
default=False,
help_text=_("Whether to publicly show pending submissions, before acceptance")
)

objects = TalkTypeManager()

Expand Down Expand Up @@ -343,6 +347,8 @@ def can_view(self, user):
return True
if self.accepted or self.cancelled:
return True
if self.talk_type and self.talk_type.show_pending_submissions:
return True
return False

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions wafer/talks/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from wafer.tests.utils import create_user


def create_talk_type(name):
def create_talk_type(name, **kwargs):
"""Create a talk type"""
return TalkType.objects.create(name=name)
return TalkType.objects.create(name=name, **kwargs)


def create_talk(title, status, username=None, user=None, talk_type=None):
Expand Down
16 changes: 16 additions & 0 deletions wafer/talks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ def test_user_with_view_all(self):

class TalkViewTests(TestCase):
def setUp(self):
public_type = create_talk_type(name="BoF", show_pending_submissions=True)
self.talk_a = create_talk("Talk A", ACCEPTED, "author_a")
self.talk_r = create_talk("Talk R", REJECTED, "author_r")
self.talk_s = create_talk("Talk S", SUBMITTED, "author_s")
self.talk_sp = create_talk("Talk SP", SUBMITTED, "author_sp",
talk_type=public_type)
self.talk_u = create_talk("Talk U", UNDER_CONSIDERATION, "author_u")
self.talk_up = create_talk("Talk UP", UNDER_CONSIDERATION, "author_up",
talk_type=public_type)
self.talk_p = create_talk("Talk P", PROVISIONAL, "author_p")
self.talk_pp = create_talk("Talk PP", PROVISIONAL, "author_pp",
talk_type=public_type)
self.talk_c = create_talk("Talk C", CANCELLED, "author_c")
self.client = Client()

Expand All @@ -77,15 +84,24 @@ def test_view_rejected_not_logged_in(self):
def test_view_cancelled_not_logged_in(self):
self.check_talk_view(self.talk_c, 200)

def test_view_public_submitted_not_logged_in(self):
self.check_talk_view(self.talk_sp, 200)

def test_view_submitted_not_logged_in(self):
self.check_talk_view(self.talk_s, 403)

def test_view_consideration_not_logged_in(self):
self.check_talk_view(self.talk_u, 403)

def test_view_public_consideration_not_logged_in(self):
self.check_talk_view(self.talk_up, 200)

def test_view_provisional_not_logged_in(self):
self.check_talk_view(self.talk_p, 403)

def test_view_public_provisional_not_logged_in(self):
self.check_talk_view(self.talk_pp, 200)

def test_view_accepted_author(self):
self.check_talk_view(self.talk_a, 200, auth={
'username': 'author_a', 'password': 'author_a_password',
Expand Down
24 changes: 17 additions & 7 deletions wafer/talks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

from wafer.talks.models import (
Review, Talk, TalkType, TalkUrl, Track,
ACCEPTED, CANCELLED, SUBMITTED, UNDER_CONSIDERATION, WITHDRAWN)
ACCEPTED, CANCELLED, PROVISIONAL, SUBMITTED, UNDER_CONSIDERATION,
WITHDRAWN)
from wafer.talks.forms import ReviewForm, get_talk_form_class
from wafer.talks.serializers import TalkSerializer, TalkUrlSerializer
from wafer.users.models import UserProfile
Expand Down Expand Up @@ -51,7 +52,11 @@ def get_queryset(self):
if self.request and Talk.can_view_all(self.request.user):
talks = Talk.objects.all()
else:
talks = Talk.objects.filter(Q(status=ACCEPTED) | Q(status=CANCELLED))
talks = Talk.objects.filter(
Q(status__in=(ACCEPTED, CANCELLED))
| Q(status__in=(SUBMITTED, UNDER_CONSIDERATION, PROVISIONAL),
talk_type__show_pending_submissions=True)
)
return talks.prefetch_related(
"talk_type", "corresponding_author", "authors", "authors__userprofile"
)
Expand Down Expand Up @@ -313,18 +318,23 @@ def get_queryset(self):
# to people who aren't part of the management group
if self.request.user.id is None:
# Anonymous user, so just accepted or cancelled talks
return Talk.objects.filter(Q(status=ACCEPTED) |
Q(status=CANCELLED))
return Talk.objects.filter(
Q(status__in=(ACCEPTED, CANCELLED))
| Q(status__in=(SUBMITTED, UNDER_CONSIDERATION, PROVISIONAL),
talk_type__show_pending_submissions=True)
)
elif Talk.can_view_all(self.request.user):
return Talk.objects.all()
else:
# Also include talks owned by the user
# XXX: Should this be all authors rather than just
# the corresponding author?
return Talk.objects.filter(
Q(status=ACCEPTED) |
Q(status=CANCELLED) |
Q(corresponding_author=self.request.user))
Q(status__in=(ACCEPTED, CANCELLED))
| Q(status__in=(SUBMITTED, UNDER_CONSIDERATION, PROVISIONAL),
talk_type__show_pending_submissions=True)
| Q(corresponding_author=self.request.user)
)


class TalkExistsPermission(BasePermission):
Expand Down
11 changes: 9 additions & 2 deletions wafer/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser, Group
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import Http404
from django.urls import reverse
from django.views.generic import UpdateView
Expand All @@ -12,7 +13,8 @@
from rest_framework import viewsets
from rest_framework.permissions import IsAdminUser

from wafer.talks.models import ACCEPTED, CANCELLED
from wafer.talks.models import (
ACCEPTED, CANCELLED, PROVISIONAL, SUBMITTED, UNDER_CONSIDERATION)
from wafer.users.forms import UserForm, UserProfileForm
from wafer.users.serializers import UserSerializer
from wafer.users.models import UserProfile, PROFILE_GROUP
Expand All @@ -30,7 +32,12 @@ class UsersView(PaginatedBuildableListView):
def get_queryset(self, *args, **kwargs):
qs = super().get_queryset(*args, **kwargs)
if not settings.WAFER_PUBLIC_ATTENDEE_LIST:
qs = qs.filter(talks__status__in=(ACCEPTED, CANCELLED)).distinct()
qs = qs.filter(
Q(talks__status__in=(ACCEPTED, CANCELLED))
| Q(talks__status__in=(SUBMITTED, UNDER_CONSIDERATION,
PROVISIONAL),
talks__talk_type__show_pending_submissions=True)
).distinct()
qs = qs.order_by('first_name', 'last_name', 'username')
return qs

Expand Down

0 comments on commit 1e41c61

Please sign in to comment.