From 9186b07ad70787977f5b1e589bf20b7a4beed4c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Thu, 8 Oct 2009 17:27:34 +0200 Subject: [PATCH] Added simple interface to accept merge requests. --- apps/api/handlers/library_handlers.py | 2 +- apps/api/handlers/manage_handlers.py | 63 +++++++++++++++++- apps/api/urls.py | 4 +- apps/explorer/views.py | 14 +++- project/templates/manager/pull_request.html | 72 ++++++++++++++++++++- project/urls.py | 5 +- 6 files changed, 149 insertions(+), 11 deletions(-) diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index e80d75c6..d7438a18 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -551,7 +551,7 @@ class MergeHandler(BaseHandler): # User is not permitted to make a merge, right away # So we instead create a pull request in the database try: - prq, created = PullRequest.get_or_create( + prq, created = PullRequest.objects.get_or_create( source_revision = str(udoc.revision), defaults = { 'comitter': request.user, 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 + }) + + + + + + + diff --git a/apps/api/urls.py b/apps/api/urls.py index deac319a..d22d595a 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -33,8 +33,8 @@ urlpatterns = patterns('', {'emitter_format': 'json'} ), url(r"^pull-requests/(?P\d+)$", pullrequest_rsrc, - {'emitter_format': 'json'}, name="pullrequest_view" ), - + {'emitter_format': 'json'}, name="pullrequest_view" ), + # Documents url(r'^documents$', library_resource, {'emitter_format': 'json'}, name="document_list_view"), diff --git a/apps/explorer/views.py b/apps/explorer/views.py index 82376fc1..124a5743 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -147,6 +147,14 @@ def _get_issues_for_file(fileid): # ================= # = Pull requests = # ================= -#def pull_requests(request): -# return direct_to_template(request, 'manager/pull_request.html', extra_context = { -# 'objects': models.PullRequest.objects.all()} ) +def pull_requests(request): + from explorer.models import PullRequest + + objects = PullRequest.objects.order_by('status') + + if not request.user.has_perm('explorer.book.can_share'): + objects = objects.filter(comitter=request.user) + + + return direct_to_template(request, 'manager/pull_request.html', + extra_context = {'objects': objects} ) diff --git a/project/templates/manager/pull_request.html b/project/templates/manager/pull_request.html index c03caab3..9c234366 100644 --- a/project/templates/manager/pull_request.html +++ b/project/templates/manager/pull_request.html @@ -1,7 +1,75 @@ +{% extends 'base.html' %} + +{% block extrahead %} + + +{% endblock %} + +{% block maincontent %} + + + + + {% if objects %} {% for pullreq in objects %} -

{{ pullreq }}

+ + + + + + + + {% endfor %} {% else %} -

Brak żądań

+ {% endif %} +
UtwórUżytkownikKomentarzStanAkcje
{{ pullreq.document }}{{ pullreq.comitter }}{{ pullreq.comment }} {{ pullreq.status }}
Brak żądań
+ +{% endblock %} diff --git a/project/urls.py b/project/urls.py index c38f3f6c..e107635e 100644 --- a/project/urls.py +++ b/project/urls.py @@ -12,6 +12,9 @@ urlpatterns = patterns('', # Explorer: url(r'^$', 'explorer.views.file_list', name='file_list'), url(r'^file/upload', 'explorer.views.file_upload', name='file_upload'), + + + url(r'^managment/pull-requests$', 'explorer.views.pull_requests'), # url(r'^images/(?P[^/]+)/$', 'explorer.views.folder_images', name='folder_image'), # url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'), @@ -37,7 +40,7 @@ urlpatterns = patterns('', url(r'^admin/(.*)', admin.site.root), # Prototypes - url(r'^wysiwyg-proto/', include('wysiwyg.urls')), +# url(r'^wysiwyg-proto/', include('wysiwyg.urls')), # Our über-restful api url(r'^api/', include('api.urls') ), -- 2.20.1