From a691dc2dc85412dd8ad9546d0966b7635756c48d Mon Sep 17 00:00:00 2001 From: j Date: Mon, 28 Jan 2019 15:01:47 +0530 Subject: [PATCH 1/3] fix folder height --- static/js/folders.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/js/folders.js b/static/js/folders.js index d943e62..b34545d 100644 --- a/static/js/folders.js +++ b/static/js/folders.js @@ -362,8 +362,9 @@ oml.ui.folders = function() { oml.$ui.libraryList[index].options({ items: library }); + // library + public + lists oml.$ui.folder[index].$content - .css({height: 16 + items.length * 16 + 'px'}); + .css({height: 16 + 16 + items.length * 16 + 'px'}); oml.$ui.folderList[index].options({ items: items }) From a0a1b21aae9ec4f2eb5f276ce8d01e17f57c9ae7 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 28 Jan 2019 15:02:04 +0530 Subject: [PATCH 2/3] toggle annotations menu --- static/js/mainMenu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/js/mainMenu.js b/static/js/mainMenu.js index e8c4c35..45280e2 100644 --- a/static/js/mainMenu.js +++ b/static/js/mainMenu.js @@ -601,6 +601,7 @@ oml.ui.mainMenu = function() { that[data.value ? 'enableItem' : 'disableItem']('book'); that[data.value ? 'disableItem' : 'enableItem']('showfilters'); that[data.value ? 'enableItem' : 'disableItem']('showbrowser'); + that[data.value ? 'enableItem' : 'disableItem']('showannotations'); } }, oml_itemview: function(data) { From b1215fbc1b3ec6aa18fe9138e0251de173d94915 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 28 Jan 2019 15:02:31 +0530 Subject: [PATCH 3/3] add optional username/password protection --- oml/item/handlers.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/oml/item/handlers.py b/oml/item/handlers.py index 2dd4dcf..19d6460 100644 --- a/oml/item/handlers.py +++ b/oml/item/handlers.py @@ -6,6 +6,7 @@ import mimetypes import os from urllib.request import quote import zipfile +import base64 import ox @@ -26,7 +27,42 @@ import state import logging logger = logging.getLogger(__name__) -class OMLHandler(tornado.web.RequestHandler): + +class OptionalBasicAuthMixin(object): + class SendChallenge(Exception): + pass + + def prepare(self): + if settings.preferences.get('authentication'): + try: + self.authenticate_user() + except self.SendChallenge: + self.send_auth_challenge() + + def send_auth_challenge(self): + realm = "Open Media Library" + hdr = 'Basic realm="%s"' % realm + self.set_status(401) + self.set_header('www-authenticate', hdr) + self.finish() + return False + + def authenticate_user(self): + auth_header = self.request.headers.get('Authorization') + if not auth_header or not auth_header.startswith('Basic '): + raise self.SendChallenge() + + auth_data = auth_header.split(None, 1)[-1] + auth_data = base64.b64decode(auth_data).decode('ascii') + username, password = auth_data.split(':', 1) + + auth = settings.preferences.get('authentication') + if auth.get('username') == username and auth.get('password') == password: + self._current_user = username + else: + raise self.SendChallenge() + +class OMLHandler(OptionalBasicAuthMixin, tornado.web.RequestHandler): def initialize(self): pass @@ -140,7 +176,7 @@ class ReaderHandler(OMLHandler): path = os.path.join(settings.static_path, html) return serve_static(self, path, 'text/html') -class UploadHandler(tornado.web.RequestHandler): +class UploadHandler(OMLHandler): def initialize(self, context=None): self._context = context