+ doc.owner_organization = org
+ doc.owner_user = None
+ doc.save()
+ if not error:
+ return redirect('catalogue_user')
+
+ return render(request, 'catalogue/book_owner.html', {
+ 'doc': doc,
+ 'error': error,
+ })
+
+
+@login_required
+def book_delete(request, pk):
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ if not (doc.owner_user == request.user or doc.owner_organization.is_member(request.user)):
+ raise Http404
+
+ if request.method == 'POST':
+ doc.deleted = True
+ doc.save()
+ return redirect('catalogue_user')
+
+ return render(request, 'catalogue/book_delete.html', {
+ 'doc': doc,
+ })
+
+
+@require_POST
+@login_required
+def publish(request, pk):
+ from wiki import forms
+ from .models import PublishRecord
+ from dvcs.models import Revision
+
+ # FIXME: check permissions
+
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ form = forms.DocumentTextPublishForm(request.POST, prefix="textpublish")
+ if form.is_valid():
+ rev = Revision.objects.get(pk=form.cleaned_data['revision'])
+ # FIXME: check if in tree
+ # if PublishRecord.objects.filter(revision=rev, document=doc).exists():
+ # return http.HttpResponse('exists')
+ if not doc.published:
+ site = Site.objects.get_current()
+ send_notify_email(
+ 'New published document in MIL/PEER',
+ '''New published document in MIL/PEER: %s. View it in browser: https://%s%s.
+
+--
+MIL/PEER team.''' % (doc.meta()['title'], site.domain, reverse('catalogue_html', args=[doc.pk])))
+ PublishRecord.objects.create(revision=rev, document=doc, user=request.user)
+ doc.published = True
+ doc.save()
+ if request.is_ajax():
+ return http.HttpResponse('ok')
+ else:
+ return redirect('catalogue_html', doc.pk)