def approve(self, request, uuid=None):
# We can't use `self.get_object()` because:
# 1) It filters only for active repos and this one is potentially
# not active yet
# 2) We want to always return a response even if the current user
# does not have access to this particular repo
repo = get_object_or_404(models.Repository, uuid=uuid)
# See if we're going to approve this repo
if ((repo.status == models.Repository.Status.PendingInviterApproval) and
(repo.inviter_login == request.user.username)):
repo.approve_by_inviter(request.user)
# Select which serializer class to use based on the current user's access
serializer_class = RepositoryApproveSerializer
if request.user in repo.admins.all():
serializer_class = self.get_serializer_class()
serializer = serializer_class(repo, context=self.get_serializer_context())
return Response(serializer.data)
################################################################################
# Views
################################################################################
评论列表
文章目录