X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ac2e9ceea7cf6a59810081d52b64d9c22861c62d..e069e118b79156ab03fcc32b3e1c7b766b7ae92c:/apps/api/handlers/manage_handlers.py diff --git a/apps/api/handlers/manage_handlers.py b/apps/api/handlers/manage_handlers.py index 96159582..b3e2760b 100644 --- a/apps/api/handlers/manage_handlers.py +++ b/apps/api/handlers/manage_handlers.py @@ -6,7 +6,9 @@ __doc__ = "Module documentation." 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',) @@ -19,7 +21,64 @@ class PullRequestListHandler(BaseHandler): 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 + }) + + + + + + +