Skip to content

Commit

Permalink
Merge pull request #700 from sgfost/file-safety
Browse files Browse the repository at this point in the history
improvements to file safety and digest page / ogp tags
  • Loading branch information
alee authored Mar 15, 2024
2 parents f52dfda + a6384f2 commit a69c01a
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 65 deletions.
6 changes: 0 additions & 6 deletions deploy/conf/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@ EMAIL_SUBJECT_PREFIX=[CoMSES Net]
MAILGUN_SENDER_DOMAIN=

# logging
LOG_DIRECTORY=/shared/logs
SENTRY_DSN=

GITHUB_CLIENT_ID=
ORCID_CLIENT_ID=

# storage
DATA_ROOT=/shared
LIBRARY_ROOT=/shared/library
REPOSITORY_ROOT=/shared/repository

# test
TEST_USER_ID=10000000
TEST_USERNAME=__test_user__
Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
{% block ogp_tags %}
{{ render_ogp_tags() }}
{{ render_ogp_tags(request) }}
{% endblock ogp_tags %}
<title>
{% block title %}CoMSES Net{% endblock %}
Expand Down
24 changes: 17 additions & 7 deletions django/core/jinja2/common.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,26 @@ Currently in <em><mark>{{ constants.DEPLOY_ENVIRONMENT }}</mark></em> mode.
{{ date.strftime('%B %d, %Y %I:%M %p') }}
{% endmacro %}

{% macro render_ogp_tags(url=None, title=None, description=None, image=None) %}
<!-- Open Graph Protocol Tags -->

{%
macro render_ogp_tags(
request,
title="The Network for Computational Modeling in the Social and Ecological Sciences (CoMSES Net)",
description="CoMSES Net is an international open research community dedicated to fostering good practices for computational / agent based modeling.",
image=None
)
%}
{% set url = request.build_absolute_uri() %}
{% set absolute_image_url = request.build_absolute_uri(image or static("images/logo-comses.png")) %}
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@comses" />
<meta name="twitter:description" content="{{ description }}">
<meta property="twitter:domain" content="comses.net" />
<meta property="og:url" content="{{ url or 'https://www.comses.net/'}}" />

<!-- Open Graph Protocol Tags -->
<meta property="og:url" content="{{ url }}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ title or 'The Network for Computational Modeling in the Social and Ecological Sciences (CoMSES Net)'}}" />
<meta property="og:description" content="{{ description or 'CoMSES Net is an international open research community dedicated to fostering good practices for computational / agent based modeling.'}}" />
<meta property="og:image" content="{{ image or static('images/logo-comses.png') }}" />
<meta property="og:title" content="{{ title }}" />
<meta property="og:description" content="{{ description }}" />
<meta property="og:image" content="{{ absolute_image_url }}" />
{% endmacro %}
2 changes: 1 addition & 1 deletion django/core/jinja2/core/events/list.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
{% endblock %}

{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/events/", title="Community Events", description="View all events related to CoMSES")}}
{{ render_ogp_tags(request, title="Community Events", description="View all events related to CoMSES.")}}
{% endblock ogp_tags %}


Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/core/events/retrieve.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% endblock %}

{% block ogp_tags %}
{{ render_ogp_tags(url=request.build_absolute_uri(absolute_url), title=title, description=summary) }}
{{ render_ogp_tags(request, title=title, description=summary) }}
{% endblock ogp_tags %}

{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/core/jobs/list.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/jobs/", title="Community Jobs", description="View all jobs related to CoMSES")}}
{{ render_ogp_tags(request, title="Community Jobs", description="View all jobs posted to CoMSES.")}}
{% endblock ogp_tags %}

{% macro render_job(item, detail_url_name) %}
Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/core/jobs/retrieve.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% endblock %}

{% block ogp_tags %}
{{ render_ogp_tags(url=request.build_absolute_uri(absolute_url), title=title, description=summary) }}
{{ render_ogp_tags(request, title=title, description=summary) }}
{% endblock ogp_tags %}

{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/core/member_profiles/list.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
search_tag_href, search_bar, render_ogp_tags %}

{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/users/", title="Member Profiles", description="View all users related to CoMSES")}}
{{ render_ogp_tags(request, title="Member Profiles", description="View member profiles on CoMSES Net.")}}
{% endblock ogp_tags %}

{% macro render_user(member_profile) %}
Expand Down
2 changes: 1 addition & 1 deletion django/core/jinja2/core/member_profiles/retrieve.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endblock %}

{% block ogp_tags %}
{{ render_ogp_tags(url=request.build_absolute_uri(absolute_url), title=profile.name, description=profile.bio)}}
{{ render_ogp_tags(request, title=profile.name, description=profile.bio)}}
{% endblock ogp_tags %}

{% block content %}
Expand Down
23 changes: 11 additions & 12 deletions django/core/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,19 @@ def is_test(self):
}
}

# FIXME: turn everything here into pathlib.Paths at some point
SHARE_DIR = "/shared"
LOG_DIRECTORY = os.getenv("LOG_DIRECTORY", os.path.join(BASE_DIR, "logs"))
LIBRARY_ROOT = os.getenv("LIBRARY_ROOT")
if not LIBRARY_ROOT:
raise ValueError("LIBRARY_ROOT not configured")
LOG_DIRECTORY = os.path.join(SHARE_DIR, "logs")
LIBRARY_ROOT = os.path.join(SHARE_DIR, "library")
PREVIOUS_SHARE_ROOT = os.path.join(SHARE_DIR, ".latest")
REPOSITORY_ROOT = os.getenv("REPOSITORY_ROOT")
BORG_ROOT = "/shared/backups/repo"
BACKUP_ROOT = "/shared/backups"
EXTRACT_ROOT = "/shared/extract"
REPOSITORY_ROOT = os.path.join(SHARE_DIR, "repository")
BORG_ROOT = os.path.join(SHARE_DIR, "backups", "repo")
BACKUP_ROOT = os.path.join(SHARE_DIR, "backups")
EXTRACT_ROOT = os.path.join(SHARE_DIR, "extract")

FILE_UPLOAD_MAX_MEMORY_SIZE = 104857600
FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_TEMP_DIR = "/shared/uploads/"
FILE_UPLOAD_TEMP_DIR = os.path.join(SHARE_DIR, "uploads")

for d in (LOG_DIRECTORY, LIBRARY_ROOT, REPOSITORY_ROOT, FILE_UPLOAD_TEMP_DIR):
try:
Expand Down Expand Up @@ -405,19 +404,19 @@ def is_test(self):
]

# django-vite settings
DJANGO_VITE_ASSETS_PATH = os.getenv("VITE_ROOT", "/shared/vite")
DJANGO_VITE_ASSETS_PATH = os.path.join(SHARE_DIR, "vite")
DJANGO_VITE_STATIC_URL_PREFIX = "bundles"
DJANGO_VITE_DEV_SERVER_PORT = 5000
DJANG_VITE_MANIFEST_PATH = os.path.join(
DJANGO_VITE_ASSETS_PATH, DJANGO_VITE_STATIC_URL_PREFIX, "manifest.json"
)

STATIC_ROOT = "/shared/static"
STATIC_ROOT = os.path.join(SHARE_DIR, "static")
STATIC_URL = "/static/"

STATICFILES_DIRS = [DJANGO_VITE_ASSETS_PATH]

MEDIA_ROOT = "/shared/media"
MEDIA_ROOT = os.path.join(SHARE_DIR, "media")
MEDIA_URL = "/media/"
APPEND_SLASH = True

Expand Down
7 changes: 3 additions & 4 deletions django/home/jinja2/home/digest.jinja
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{% extends "base.jinja" %}
{% from "common.jinja" import breadcrumb, subnav, import render_ogp_tags %}
{% from "common.jinja" import breadcrumb, subnav, render_ogp_tags %}

{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/", title="The COMSES Digest", description="CoMSES Net is an international open research community dedicated to fostering good practices for computational / agent based modeling.") }}
{{ render_ogp_tags(request, title="CoMSES Digests", description="View past issues of the CoMSES Digest newsletter") }}
{% endblock ogp_tags %}


{% block title %}CoMSES Digests{% endblock %}
{% block title %}CoMSES Digests {% endblock %}

{% block introduction %}<h1>CoMSES Digest</h1>{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion django/home/jinja2/home/education.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% from "common.jinja" import breadcrumb, render_ogp_tags %}

{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/", title="CoMSES Net Education", description="CoMSES Net training modules provide guidance on good practices for computational modeling and sharing your work with FAIR principles for research software (FAIR4RS) and FORCE11 Software Citation Principles in mind.") }}
{{ render_ogp_tags(request, title="CoMSES Net Education", description="CoMSES Net training modules provide guidance on good practices for computational modeling and sharing your work with FAIR principles for research software (FAIR4RS) and FORCE11 Software Citation Principles in mind.") }}
{% endblock ogp_tags %}

{% block title %}{{ page.title }}{% endblock %}
Expand Down
7 changes: 4 additions & 3 deletions django/library/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ def get_absolute_url(self, category: FileCategoryDirectories, relpath: Path):
def _create_msg_group(self):
return MessageGroup()

def validate_bagit(self):
bag = self.get_or_create_sip_bag()
def validate_bagit(self, sip_bag=None):
bag = sip_bag or self.get_or_create_sip_bag()
try:
bag.validate()
except bagit.BagValidationError as e:
Expand Down Expand Up @@ -526,7 +526,8 @@ def get_codemeta_json(self):

def build_published_archive(self, force=False):
self.create_or_update_codemeta(force=force)
self.get_or_create_sip_bag(self.bagit_info)
bag = self.get_or_create_sip_bag(self.bagit_info)
self.validate_bagit(bag)
self.build_aip()
self.build_archive(force=force)

Expand Down
2 changes: 1 addition & 1 deletion django/library/jinja2/library/codebases/list.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% endblock %}

{% block ogp_tags %}
{{ render_ogp_tags(url="https://www.comses.net/codebases/", title="Community Codebases", description="View all codebases related to CoMSES") }}
{{ render_ogp_tags(request, title="CoMSES Model Library", description="The Computational Model Library preserves computational models in accordance with FAIR principles for research software and best practices from SciCodes, the Consortium of Scientific Software Registries and Repositories.") }}
{% endblock ogp_tags %}

{% block content %}
Expand Down
28 changes: 8 additions & 20 deletions django/library/jinja2/library/codebases/releases/retrieve.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "sidebar_layout.jinja" %}
{% from "common.jinja" import breadcrumb, embed_discourse_comments, share_card, search_tag_href, member_profile_href %}
{% from "common.jinja" import breadcrumb, embed_discourse_comments, share_card, search_tag_href, member_profile_href, render_ogp_tags %}
{% from "library/review/includes/macros.jinja" import include_review_reminders, confirm_change_closed_modal %}

{% set open_code_badge_png_url = request.build_absolute_uri(static("images/icons/open-code-badge.png")) %}
Expand Down Expand Up @@ -58,25 +58,13 @@
{% endblock %}

{% block ogp_tags %}
<!-- Facebook Meta Tags -->
<meta property="og:url" content="{{ request.build_absolute_uri(absolute_url) }}">
<meta property="og:type" content="article">
<meta property="og:title" content="{{ codebase.title }}">
<meta property="og:description" content="{{ codebase.summarized_description }}">
{% if codebase.featured_images.exists() %}
<meta property="og:image" content="{{ codebase.get_featured_rendition_url() }}">
<meta property="twitter:image" content="{{ codebase.get_featured_rendition_url() }}">
{% else %}
<!-- Provide a fallback image URL -->
<meta property="og:image" content="{{ static('images/logo-comses.png') }}">
<meta property="twitter:image" content="{{ static('images/logo-comses.png') }}">
{% endif %}
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="comses.net">
<meta property="twitter:url" content="{{ request.build_absolute_uri(absolute_url) }}">
<meta name="twitter:title" content="{{ codebase.title }}">
<meta name="twitter:description" content="{{ codebase.summarized_description }}">
{{ render_ogp_tags(
request,
title=codebase.title,
description=codebase.summarized_description,
image=codebase.get_featured_rendition_url()
)
}}
{% endblock ogp_tags %}

{% block content %}
Expand Down
10 changes: 6 additions & 4 deletions django/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def create_release(
release = self.create_release_from_source(source_release, release_metadata)

if initialize:
release.get_fs_api().validate_bagit()
release.get_fs_api() # implicitly initializes the release filesystem

if release.is_published:
self.latest_version = release
Expand Down Expand Up @@ -2148,9 +2148,11 @@ def send_candidate_reviewer_email(self, resend=False):
cc=[settings.REVIEW_EDITOR_EMAIL],
)
self.review.log(
action=PeerReviewEvent.INVITATION_SENT
if resend
else PeerReviewEvent.INVITATION_RESENT,
action=(
PeerReviewEvent.INVITATION_SENT
if resend
else PeerReviewEvent.INVITATION_RESENT
),
author=self.editor,
message=f"{self.editor} sent an invitation to candidate reviewer {self.candidate_reviewer}",
)
Expand Down
4 changes: 4 additions & 0 deletions django/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ def build_archive_download_response(codebase_release, review_archive=False):
fs_api.build_review_archive()
archive_uri = fs_api.review_archive_uri
# response['Content-Length'] = fs_api.review_archive_size

# prevent failing silently if the archive is missing
if not pathlib.Path(archive_uri).exists():
raise FileNotFoundError
response["X-Accel-Redirect"] = "/library/internal/{0}".format(archive_uri)
return response

Expand Down

0 comments on commit a69c01a

Please sign in to comment.