diff --git a/Dockerfile b/Dockerfile index 8ec8137..1cb5576 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,14 @@ MAINTAINER Computer Science House ENV IMAGEIO_USERDIR /var/lib/gallery RUN apt-get update && \ - apt-get install -y libldap-dev libsasl2-dev libmagic-dev && \ + apt-get install -y libldap-dev libsasl2-dev libmagic-dev ghostscript && \ apt-get autoremove --yes && \ apt-get clean autoclean && \ rm -rf /var/lib/{apt,dpkg,cache,log}/ && \ mkdir -p /opt/gallery /var/lib/gallery +RUN pip install --upgrade pip + WORKDIR /opt/gallery ADD . /opt/gallery diff --git a/gallery/__init__.py b/gallery/__init__.py index 2fc5925..0161b6f 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -922,7 +922,6 @@ def render_dir(dir_id: int, auth_dict: Optional[Dict[str, Any]] = None): description = dir_model.description display_description = len(description) > 0 - display_parent = True if dir_model is None or dir_model.parent is None or dir_id == ROOT_DIR_ID: display_parent = False @@ -960,7 +959,7 @@ def render_file(file_id: int, auth_dict: Optional[Dict[str, Any]] = None): file_model = File.query.filter(File.id == file_id).first() if file_model is None: abort(404) - if file_model.hidden and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']): + if file_model.hidden and (not auth_dict['is_eboard'] and not auth_dict['is_rtp'] and not auth_dict['is_alumni']): abort(404) gallery_lockdown = util.get_lockdown_status() if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']): diff --git a/gallery/_version.py b/gallery/_version.py index f67c258..3fd7971 100644 --- a/gallery/_version.py +++ b/gallery/_version.py @@ -1,6 +1,6 @@ from os import environ as env -__version__ = "2.1.1" +__version__ = "2.1.2" BUILD_REFERENCE = env.get("OPENSHIFT_BUILD_REFERENCE") COMMIT_HASH = env.get("OPENSHIFT_BUILD_COMMIT") diff --git a/gallery/file_modules/pdf.py b/gallery/file_modules/pdf.py index 329009b..dcfdd54 100644 --- a/gallery/file_modules/pdf.py +++ b/gallery/file_modules/pdf.py @@ -1,4 +1,9 @@ +import os +from wand.image import Image +from wand.color import Color + from gallery.file_modules import FileModule +from gallery.util import hash_file class PDFFile(FileModule): @@ -8,3 +13,17 @@ def __init__(self, file_path, dir_path): self.mime_type = "application/pdf" self.generate_thumbnail() + + def generate_thumbnail(self): + self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" + + with Image(filename=self.file_path, resolution=300) as all_pages: + with Image(all_pages.sequence[0]) as first_page: + with Image(width=first_page.width, height=first_page.height, + background=Color("#EEEEEE")) as bg: + bg.composite(first_page, 0, 0) + size = first_page.width if first_page.width < first_page.height else first_page.height + bg.crop(width=size, height=size, gravity='north') # top of first page + bg.resize(256, 256) + bg.format = 'jpeg' + bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid)) diff --git a/gallery/ldap.py b/gallery/ldap.py index 4235426..0a08d66 100644 --- a/gallery/ldap.py +++ b/gallery/ldap.py @@ -41,6 +41,9 @@ def is_rtp(self, uid: str) -> bool: rtp_group = self._ldap.get_group('rtp') return rtp_group.check_member(self._ldap.get_member(uid, uid=True)) + def is_alumni(self, uid: str) -> bool: + return not is_member_of_group(self._ldap.get_member(uid, uid=True), 'current_student') + def get_members(self) -> List[Dict[str, str]]: if self._ldap is None: return [] diff --git a/gallery/templates/view_dir.html b/gallery/templates/view_dir.html index d86b054..840f687 100644 --- a/gallery/templates/view_dir.html +++ b/gallery/templates/view_dir.html @@ -35,7 +35,7 @@ {% if children|length >= 1 %}
{% for child_type, child in children %} - {% if not child.hidden or (auth_dict['is_eboard'] or auth_dict['is_rtp']) %} + {% if not child.hidden or (auth_dict['is_eboard'] or auth_dict['is_rtp']) or auth_dict['is_alumni'] %}
diff --git a/gallery/util.py b/gallery/util.py index 3051c25..6f67f20 100644 --- a/gallery/util.py +++ b/gallery/util.py @@ -74,6 +74,7 @@ def wrapped_function(*args: Any, **kwargs: Any) -> Any: name = ldap.convert_uuid_to_displayname(uuid) is_eboard = ldap.is_eboard(uid) is_rtp = ldap.is_rtp(uid) + is_alumni = ldap.is_alumni(uid) # NOTE(rossdylan): This is probably a more precise type than we need, # if different data is needed just expand the value type to Any @@ -83,6 +84,7 @@ def wrapped_function(*args: Any, **kwargs: Any) -> Any: auth_dict['name'] = name auth_dict['is_eboard'] = is_eboard auth_dict['is_rtp'] = is_rtp + auth_dict['is_alumni'] = is_alumni kwargs['auth_dict'] = auth_dict return func(*args, **kwargs) return wrapped_function diff --git a/requirements.txt b/requirements.txt index aae44a7..a74cbc9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ gunicorn==19.9.0 moviepy==0.2.3.5 imageio==2.4.0 boto3 +werkzeug == 0.16.1 diff --git a/setup.cfg b/setup.cfg index eb28da7..4dec8a5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ summary = Python Photo Gallery Written in Flask url = "https://github.com/ComputerScienceHouse/gallery" description-file = README.md license = MIT -version = 2.1.1 +version = 2.1.2 classifier = Natural Language :: English Operating System :: POSIX :: Linux