Add notification endpoints

rtd2
Eric Holscher 2013-08-10 17:48:52 -07:00
parent 4d45bb933d
commit 81c68c3c1d
3 changed files with 24 additions and 10 deletions

View File

@ -233,7 +233,7 @@ def update_docs(pk, record=True, pdf=True, man=True, epub=True, dash=True,
symlink_cname(version)
# This requires database access, must disable it for now.
# symlink_translations(version)
# send_notifications(version, build)
send_notifications(version, build)
log.info("Purged %s" % version)
else:
log.warning("Failed HTML Build")
@ -607,7 +607,7 @@ def symlink_translations(version):
def send_notifications(version, build):
zenircbot_notification(version.id)
#zenircbot_notification(version.id)
for hook in version.project.webhook_notifications.all():
webhook_notification.delay(version.project.id, build, hook.url)
emails = (version.project.emailhook_notifications.all()

View File

@ -1,6 +1,7 @@
from rest_framework import routers
from .views import ProjectViewSet
from .views import ProjectViewSet, NotificationViewSet
router = routers.DefaultRouter()
router.register(r'project', ProjectViewSet, base_name="project")
router.register(r'project', ProjectViewSet)
router.register(r'notification', NotificationViewSet)
urlpatterns = router.urls

View File

@ -8,13 +8,11 @@ from rest_framework.renderers import JSONRenderer, BrowsableAPIRenderer
from rest_framework.response import Response
from betterversion.better import version_windows, BetterVersion
from projects.models import Project
from projects.models import Project, EmailHook
from .permissions import RelatedProjectIsOwner
class ProjectViewSet(viewsets.ModelViewSet):
"""
A simple ViewSet that for listing or retrieving users.
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
renderer_classes = (JSONRenderer, BrowsableAPIRenderer)
model = Project
@ -47,3 +45,18 @@ class ProjectViewSet(viewsets.ModelViewSet):
return Response({
'flat': version_strings,
})
class NotificationViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAuthenticated, RelatedProjectIsOwner)
renderer_classes = (JSONRenderer, BrowsableAPIRenderer)
model = EmailHook
def get_queryset(self):
"""
This view should return a list of all the purchases
for the currently authenticated user.
"""
user = self.request.user
if user.is_superuser:
return self.model.objects.all()
return self.model.objects.filter(project__users__in=[user.pk])