from karmaworld.apps.users.models import NoteKarmaEvent
from karmaworld.utils.ajax_utils import *
-from django.http import HttpResponse, HttpResponseBadRequest
+from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
from django.views.generic import DetailView, ListView
from django.views.generic import FormView
from django.views.generic import View
def post(self, request, *args, **kwargs):
self.object = self.get_object()
+ if not self.request.user.is_authenticated():
+ raise ValidationError("Only authenticated users may set keywords.")
+
formset = self.form_class(request.POST)
if formset.is_valid():
self.keyword_form_valid(formset)
definition = annotator_data['text']
ranges = json.dumps(annotator_data['ranges'])
+ if not request.user.is_authenticated():
+ return HttpResponseForbidden(json.dumps({'status': 'fail', 'message': "Only authenticated users may set keywords"}),
+ mimetype="application/json")
+
try:
if request.method in ('POST', 'PUT'):
set_keyword(annotation_uri, keyword, definition, ranges)
dstDoc.close();
}
-function setupAnnotator(noteElement) {
- noteElement.annotator();
+function setupAnnotator(noteElement, readOnly) {
+ noteElement.annotator({readOnly: readOnly});
noteElement.annotator('addPlugin', 'Store', {
prefix: '/ajax/annotations',
loadFromSearch: {
if ($('#note-markdown').length > 0) {
var note_markdown = $('#note-markdown');
note_markdown.html(marked(note_markdown.data('markdown')));
- setupAnnotator(note_markdown);
+ setupAnnotator(note_markdown, !user_authenticated);
} else {
$.ajax(note_contents_url, {
type: 'GET',
if ($('#page-container').length > 0) { \
document_selector = $('#page-container'); \
} \
- document_selector.annotator(); \
+ document_selector.annotator({readOnly: " + !user_authenticated + "}); \
document_selector.annotator('addPlugin', 'Store', { \
prefix: '/ajax/annotations', \
loadFromSearch: { \
var annotator_css_url = "{{ STATIC_URL }}css/annotator.min.css";
var setup_ajax_url = "{{ STATIC_URL }}js/setup-ajax.js";
var note_edit_url = "{% url 'edit_note' note.id %}";
+ var user_authenticated = {% if user.is_authenticated %}true{% else %}false{% endif %};
</script>
{% compress js %}
<script src="{{ STATIC_URL }}js/setup-ajax.js"></script>
<div id="keywords" class="content">
<div class="row">
<div class="small-12 columns">
- <p id="keyword-intro">These key terms and definitions have been defined by KarmaNotes users.
- You can edit them for accuracy and add more if you like.</p>
- <p><button id="edit-keywords-button" class="museo700"><i class="fa fa-edit"></i> Edit Key Terms & Definitions</button></p>
+ {% if user.is_authenticated %}
+ <p id="keyword-intro">These key terms and definitions have been defined by KarmaNotes users.
+ You can edit them for accuracy and add more if you like.</p>
+ <p><button id="edit-keywords-button" class="museo700"><i class="fa fa-edit"></i> Edit Key Terms & Definitions</button></p>
+ {% else %}
+ <p id="keyword-intro">These key terms and definitions have been defined by KarmaNotes users.</p>
+ {% endif %}
<table id="keywords-data-table">
<thead>
<tr>