from piston.handler import BaseHandler, AnonymousBaseHandler
+from api.utils import hglibrary
from explorer.models import PullRequest
+from api.response import *
class PullRequestListHandler(BaseHandler):
allowed_methods = ('GET',)
class PullRequestHandler(BaseHandler):
- allowed_methods = ('GET',)
+ allowed_methods = ('GET', 'PUT')
def read(self, request, prq_id):
- return PullRequest.objects.get(id=prq_id)
\ No newline at end of file
+ return PullRequest.objects.get(id=prq_id)
+
+ def update(self, request, prq_id):
+ """Change the status of request"""
+
+ if not request.user.has_perm('explorer.document.can_share'):
+ return AccessDenied().django_response("Insufficient priviliges")
+
+ prq = PullRequest.objects.get(id=prq_id)
+
+ if not prq:
+ return EntityNotFound().django_response()
+
+
+ action = request.PUT.get('action', None)
+
+ if action == 'accept' and prq.status == 'N':
+ return self.accept_merge(prq)
+ elif action == 'reject' and prq.status in ['N', 'R']:
+ return self.reject_merge(prq)
+ else:
+ return BadRequest().django_response()
+
+
+ @hglibrary
+ def accept_merge(self, prq, lib):
+ doc = lib.document( prq.document )
+ udoc = doc.take( prq.comitter.username )
+ success, changed = udoc.share(prq.comment)
+
+ if not success:
+ return EntityConflict().django_response()
+
+ doc = doc.latest()
+
+ prq.status = 'A'
+ prq.merged_revisions = unicode(doc.revision)
+ prq.save()
+
+ return SuccessAllOk().django_response({
+ 'status': prq.status
+ })
+
+
+ def reject_merge(self, prq, lib):
+ prq.status = 'R'
+ prq.save()
+
+ return SuccessAllOk().django_response({
+ 'status': prq.status
+ })
+
+
+
+
+
+
+