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 15 additions and 9 deletions
Showing only changes of commit 85f8922837 - Show all commits

View File

@ -128,13 +128,19 @@ class ExtensionManager(models.Manager):
def unlisted(self):
return self.exclude(status=self.model.STATUSES.APPROVED)
def authored_by(self, user_id: int):
return self.filter(maintainer__user_id=user_id)
def authored_by(self, user):
filter = Q(maintainer__user_id=user.pk)
user_teams = user.teams.all()
if user_teams:
filter = filter | Q(team__in=[t.pk for t in user_teams])
return self.filter(filter).distinct()
def listed_or_authored_by(self, user_id: int):
return self.filter(
Q(status=self.model.STATUSES.APPROVED) | Q(maintainer__user_id=user_id)
).distinct()
def listed_or_authored_by(self, user):
filter = Q(status=self.model.STATUSES.APPROVED) | Q(maintainer__user_id=user.pk)
user_teams = user.teams.all()
if user_teams:
filter = filter | Q(team__in=[t.pk for t in user_teams])
return self.filter(filter).distinct()
class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Model):

View File

@ -24,7 +24,7 @@ class ExtensionQuerysetMixin:
if self.request.user.is_staff:
return Extension.objects.all()
if self.request.user.is_authenticated:
return Extension.objects.listed_or_authored_by(user_id=self.request.user.pk)
return Extension.objects.listed_or_authored_by(user=self.request.user)
return Extension.objects.listed

View File

@ -18,7 +18,7 @@ class UploadFileView(LoginRequiredMixin, CreateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
drafts = Extension.objects.authored_by(user_id=self.request.user.pk).filter(
drafts = Extension.objects.authored_by(user=self.request.user).filter(
status=Extension.STATUSES.INCOMPLETE
)
context['drafts'] = drafts
@ -41,7 +41,7 @@ class UploadFileView(LoginRequiredMixin, CreateView):
if parsed_extension_fields:
# Try to look up extension by the same author and file info
extension = (
Extension.objects.authored_by(user_id=self.request.user.pk)
Extension.objects.authored_by(user=self.request.user)
.filter(type=self.file.type, **parsed_extension_fields)
.first()
)