Allow admins to trigger project builds
@@ -6,9 +6,13 @@ import logging
from django.shortcuts import get_object_or_404
from django.views.generic import ListView, DetailView
-from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect
-from django.conf import settings
+from django.http import (
+ HttpResponseForbidden,
+ HttpResponsePermanentRedirect,
+ HttpResponseRedirect,
+)
from django.contrib.auth.decorators import login_required
+from readthedocs.core.permissions import AdminPermission
from django.core.urlresolvers import reverse
from django.utils.decorators import method_decorator
@@ -38,10 +42,11 @@ class BuildTriggerMixin(object):
@method_decorator(login_required)
def post(self, request, project_slug):
- project = get_object_or_404(
- Project.objects.for_admin_user(self.request.user),
- slug=project_slug
- )
+ project = get_object_or_404(Project, slug=project_slug)
+
+ if not AdminPermission.is_admin(request.user, project):
+ return HttpResponseForbidden()
+
version_slug = request.POST.get('version_slug')
version = get_object_or_404(
Version,
