Intitial teams support #147

Merged
Oleg-Komarov merged 34 commits from teams-support into main 2024-05-23 19:43:54 +02:00
3 changed files with 27 additions and 2 deletions
Showing only changes of commit c3abe491c9 - Show all commits

View File

@ -2,6 +2,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.db import transaction
from django.db.models import Q
from django.shortcuts import get_object_or_404, redirect, reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView
@ -99,7 +100,24 @@ class ManageListView(LoginRequiredMixin, ListView):
template_name = 'extensions/manage/list.html'
def get_queryset(self):
return Extension.objects.authored_by(user_id=self.request.user.pk)
filter = Q(maintainer__user_id=self.request.user.pk)
user_teams = self.request.user.teams.all()
if user_teams:
filter = filter | Q(team__in=[t.pk for t in user_teams])
return (
Extension.objects.filter(filter)
.prefetch_related(
'authors',
'preview_set',
'preview_set__file',
'ratings',
'team',
'versions',
'versions__file',
'versions__tags',
)
.distinct()
)
class UpdateExtensionView(

View File

@ -1,4 +1,5 @@
from django.contrib.auth.mixins import UserPassesTestMixin
from django.db.models import Q
from django.shortcuts import get_object_or_404
from extensions.models import Extension
@ -31,8 +32,12 @@ class MaintainedExtensionMixin:
"""Fetch an extension by slug if current user is a maintainer."""
def dispatch(self, *args, **kwargs):
filter = Q(maintainer__user_id=self.request.user.pk)
user_teams = self.request.user.teams.all()
if user_teams:
filter = filter | Q(team__in=[t.pk for t in user_teams])
self.extension = get_object_or_404(
Extension.objects.authored_by(user_id=self.request.user.pk),
Extension.objects.filter(filter),
slug=self.kwargs['slug'],
)
return super().dispatch(*args, **kwargs)

View File

@ -50,6 +50,7 @@ class HomeView(ListedExtensionsView):
'preview_set',
'preview_set__file',
'ratings',
'team',
'versions',
'versions__file',
'versions__tags',
@ -107,6 +108,7 @@ class SearchView(ListedExtensionsView):
'preview_set',
'preview_set__file',
'ratings',
'team',
'versions',
'versions__file',
'versions__tags',