- if form.cleaned_data['type'] == 'share':
- success, changed = udoc.share(form.cleaned_data['message'])
+ if form.cleaned_data['type'] == 'share':
+ if not request.user.has_perm('explorer.document.can_share'):
+ # User is not permitted to make a merge, right away
+ # So we instead create a pull request in the database
+ try:
+ prq, created = PullRequest.objects.get_or_create(
+ source_revision = str(udoc.revision),
+ defaults = {
+ 'comitter': request.user,
+ 'document': docid,
+ 'status': "N",
+ 'comment': form.cleaned_data['message'] or '$AUTO$ Document shared.',
+ }
+ )
+
+ return response.RequestAccepted().django_response(\
+ ticket_status=prq.status, \
+ ticket_uri=reverse("pullrequest_view", args=[prq.id]) )
+ except IntegrityError:
+ return response.EntityConflict().django_response({
+ 'reason': 'request-already-exist'
+ })
+ else:
+ success, changed = udoc.share(form.cleaned_data['message'])