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

Queues - show competitions using the queue #1317

merged 1 commit into from
Feb 9, 2024

Conversation

ihsaan-ullah
Copy link
Collaborator

@ihsaan-ullah ihsaan-ullah commented Feb 9, 2024

@ mention of reviewers

@Didayolo

A brief description of the purpose of the changes contained in this PR.

When viewing queue details, now you can see which competitions are using this queue with the following conditions:

  1. Super admin can see all competitions using this queue
  2. Admins/Organizers can see public competitions and competitions which they are organzining (cannot see private competitions where use is not admin)
  3. Normal user can see public competitions using this queue (canont see private competitions)

Screenshot:

Screenshot 2024-02-09 at 4 41 38 PM

Issues this PR resolves

Checklist

  • Code review by me
  • Hand tested by me
  • I'm proud of my work
  • Code review by reviewer
  • Hand tested by reviewer
  • CircleCi tests are passing
  • Ready to merge

@ihsaan-ullah ihsaan-ullah linked an issue Feb 9, 2024 that may be closed by this pull request
@Didayolo
Copy link
Collaborator

Didayolo commented Feb 9, 2024

Perfect.

@Didayolo Didayolo merged commit 81c4dc3 into develop Feb 9, 2024
1 check passed
@Didayolo Didayolo deleted the queue_used branch February 9, 2024 17:05
@Didayolo
Copy link
Collaborator

Didayolo commented Feb 9, 2024

@ihsaan-ullah There is a problem with this change:

In src/apps/api/serializers/queues.py:

   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

get_competitions is used in codabench/src/static/riot/competitions/competition_list.tag.

When a user is not logged in and try to access the competition list, it raises the following error:

TypeError: Cannot cast AnonymousUser to int. Are you trying to use it in place of User?
Capture d’écran 2024-02-09 à 21 03 42

@Didayolo
Copy link
Collaborator

Didayolo commented Feb 9, 2024

Not sure if it's incidental (same naming for two different functions) or if the function should be edited.

@ihsaan-ullah
Copy link
Collaborator Author

Not sure if it's incidental (same naming for two different functions) or if the function should be edited.

Solved in #1320

@ihsaan-ullah
Copy link
Collaborator Author

@ihsaan-ullah There is a problem with this change:

In src/apps/api/serializers/queues.py:

   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

get_competitions is used in codabench/src/static/riot/competitions/competition_list.tag.

Actually the problem is something else and not the function name.

The backend code really need rewriting but I am delaying it till we separate the frontend and backend, that could be a good opportunity to rewrite most of the code and simplify things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Queue used in competiitons
2 participants