# 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,
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
+ })
+
+
+
+
+
+
+
{'emitter_format': 'json'} ),
url(r"^pull-requests/(?P<prq_id>\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"),
# =================
# = 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} )
+{% extends 'base.html' %}
+
+{% block extrahead %}
+<link rel="stylesheet" href="{{ STATIC_URL }}css/managment.css" type="text/css" />
+<script type="text/javascript">
+
+
+ $(function() {
+
+ function refreshRow(id) {
+ var row = $('#request-' +id);
+
+ $.ajax({
+ url: "http://localhost:8000/api/pull-requests/" + id,
+ dataType: 'json',
+ type: 'GET',
+ success: function(data) {
+ row.removeClass('status-N');
+ row.removeClass('status-R');
+ row.removeClass('status-A');
+ row.addClass('status-'+ data.status);
+
+ $('.column-doc', row).html(data.document);
+ $('.column-status', row).html(data.status);
+
+ alert('Merge accepted.');
+ }
+ });
+
+ }
+
+ $('.accept-button').click(function()
+ {
+ var id = parseInt($(this).attr('title'));
+
+
+ $.ajax({
+ url: "http://localhost:8000/api/pull-requests/" + id,
+ data: {action: 'accept'},
+ dataType: 'json',
+ type: 'PUT',
+ success: function(data) {
+ refreshRow(id);
+ }
+ });
+
+ });
+
+ });
+</script>
+{% endblock %}
+
+{% block maincontent %}
+<table class="request-report" cellspacing="0">
+ <tr>
+ <th>Utwór</th><th>Użytkownik</th><th>Komentarz</th><th>Stan</th>
+ <th>Akcje</th>
+ </tr>
{% if objects %}
{% for pullreq in objects %}
- <p>{{ pullreq }}</p>
+ <tr class="status-{{pullreq.status}}" id="request-{{pullreq.id}}">
+ <td class="column-doc">{{ pullreq.document }}</td>
+ <td class="column-user">{{ pullreq.comitter }}</td>
+ <td class="column-comment">{{ pullreq.comment }}</td>
+ <td class="column-status"> {{ pullreq.status }}</td>
+ <td><button type="button" class="accept-button" title="{{pullreq.id}}">Akceptuj</button></td>
+ </tr>
+
{% endfor %}
{% else %}
- <p>Brak żądań</p>
+ <tr><td colspan="*">Brak żądań</td></tr>
{% endif %}
+</table>
+
+{% endblock %}
# 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<folder>[^/]+)/$', 'explorer.views.folder_images', name='folder_image'),
# url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'),
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') ),