Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queues - show competitions using the queue #1317

Merged
merged 1 commit into from
Feb 9, 2024
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
25 changes: 24 additions & 1 deletion src/apps/api/serializers/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from api.mixins import DefaultUserCreateMixin
from queues.models import Queue

from profiles.models import User
from django.db.models import Q


class OrganizerSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -61,6 +61,7 @@ class QueueSerializer(QueueOwnerMixin, serializers.ModelSerializer):
is_owner = serializers.SerializerMethodField()
owner = serializers.CharField(source='owner.username', read_only=True)
organizers = OrganizerSerializer(many=True, read_only=True)
competitions = serializers.SerializerMethodField()

class Meta:
model = Queue
Expand All @@ -74,6 +75,7 @@ class Meta:
'created_when',
'is_owner',
'id',
'competitions',
)
# This serializer is read only, basically..
read_only_fields = (
Expand All @@ -85,4 +87,25 @@ class Meta:
'broker_url',
'created_when',
'is_owner',
'competitions',
)

def get_competitions(self, obj):
# get user from the context request
user = self.context['request'].user

# for super user return all competiitons using this queue
# for admin return competitions where this user is organizer using this queue
# for non-admin return public competitions using this queue
if user.is_superuser:
# Fetch all competitions
competitions = obj.competitions.all().values('id', 'title')
else:
# Fetch all competitions where user is organizer or competition is published
competitions = obj.competitions.filter(
Q(published=True) |
Q(created_by=user) |
Q(collaborators=user)
).values('id', 'title')

return competitions
19 changes: 14 additions & 5 deletions src/static/riot/queues/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,20 @@
</div>
<div class="content">
<h4>Broker URL:</h4>
<div class="ui field">
<textarea class="broker_url" value="{selected_queue.broker_url}" disabled></textarea>
</div>
<h4>Vhost</h4>
{selected_queue.vhost}
<span>{selected_queue.broker_url}</span>

<h4>Vhost:</h4>
<span>{selected_queue.vhost}</span>

<!-- Competitions using this queue -->
<h4 if="{ _.get(selected_queue, 'competitions.length', 0) }">Competitions using this queue:</h4>
<ul if="{ _.get(selected_queue, 'competitions.length', 0) }">
<li each="{ comp in selected_queue.competitions }">

<a class="link-no-deco" target="_blank" href="../competitions/{ comp.id }">{comp.title}</a>
</li>
</ul>

</div>
<div class="actions">
<div class="ui cancel button" onclick="{ close_broker_modal }">Close</div>
Expand Down