Skip to content

Commit

Permalink
Merge branch 'main' into django/1to2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Rosenberg committed Aug 23, 2023
2 parents 102fc5f + 51e7bb4 commit 686f2f8
Show file tree
Hide file tree
Showing 72 changed files with 3,665 additions and 1,344 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Setup Node.js for use with actions
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 16.x

- uses: actions/cache@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ docs/_build/
target/
venv/
metrics/
.python-version

# ignore Google Drive API secrets
*secrets.json
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

22 changes: 13 additions & 9 deletions conf/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
FROM node:16 as node_build
COPY package.json package-lock.json /designsafe/
WORKDIR /designsafe
RUN npm ci

COPY . /designsafe/
RUN npm run build


FROM python:3.7-buster

LABEL MAINTAINER="DesignSafe-CI <[email protected]>"
Expand Down Expand Up @@ -27,11 +36,7 @@ RUN apt-get update && apt-get install -y \
git \
vim

# install node 12.x
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs

RUN pip install poetry==1.4.0
RUN pip install poetry
COPY poetry.lock pyproject.toml /srv/www/
WORKDIR /srv/www
RUN poetry config virtualenvs.create false && \
Expand All @@ -41,11 +46,10 @@ RUN poetry config virtualenvs.create false && \
RUN groupadd --gid 816877 G-816877 && \
useradd --uid 458981 --gid G-816877 -m --shell /bin/bash tg458981 -d /home/tg458981

COPY . /srv/www/designsafe
RUN chown -R tg458981:G-816877 /srv/www/designsafe
COPY --from=node_build /designsafe/ /srv/www/designsafe
RUN chown tg458981:G-816877 /srv/www/designsafe /srv/www/designsafe/*
RUN chown -R tg458981:G-816877 /srv/www/designsafe/designsafe

USER tg458981

RUN echo "prefix=~/.npm-global" >> ~/.npmrc

WORKDIR /srv/www/designsafe
25 changes: 24 additions & 1 deletion designsafe/apps/api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
from django.core.exceptions import ObjectDoesNotExist
from pytas.http import TASClient

from designsafe.apps.data.models.elasticsearch import IndexedFile
from designsafe.apps.data.models.elasticsearch import IndexedFile, IndexedPublication
from designsafe.libs.elasticsearch.utils import new_es_client
from elasticsearch_dsl import Q, Search

logger = logging.getLogger(__name__)

def check_public_availability(username):
es_client = new_es_client()
query = Q({'multi_match': {'fields': ['project.value.teamMembers',
'project.value.coPis',
'project.value.pi'],
'query': username}})
res = IndexedPublication.search(using=es_client).filter(query).execute()
return res.hits.total.value > 0


class UsageView(SecureMixin, View):

Expand Down Expand Up @@ -56,6 +66,11 @@ def get(self, request):
resp_fields = ['first_name', 'last_name', 'email', 'username']
model = get_user_model()
q = request.GET.get('username')

# Do not return user details if the user is not part of a public project.
if not request.user.is_authenticated and not check_public_availability(q):
return JsonResponse({})

if q:
try:
user = model.objects.get(username=q)
Expand Down Expand Up @@ -95,6 +110,11 @@ def get(self, request):
if role:
logger.info(role)
user_rs = user_rs.filter(groups__name=role)

# Prevent endpoint from returning unfiltered user list.
if not q and not role:
return HttpResponseNotFound()

resp = [model_to_dict(u, fields=resp_fields) for u in user_rs]
if len(resp):
return JsonResponse(resp, safe=False)
Expand All @@ -113,6 +133,9 @@ def get(self, request):
try:
users = []
for username in nl:
# Do not return user details if the user is not part of a public project.
if not request.user.is_authenticated and not check_public_availability(username):
continue
try:
users.append(model.objects.get(username=username))
except model.DoesNotExist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<script type="text/javascript" src="{% static 'vendor/objectpath/lib/ObjectPath.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-schema-form/dist/schema-form.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-schema-form/dist/bootstrap-decorator.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-xeditable/dist/js/xeditable.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/codemirror/lib/codemirror.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-ui-codemirror/src/ui-codemirror.js' %}"></script>
Expand Down
3 changes: 3 additions & 0 deletions designsafe/apps/notifications/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin
from designsafe.apps.notifications.models import SiteMessage

# Register your models here.

admin.site.register(SiteMessage)
23 changes: 23 additions & 0 deletions designsafe/apps/notifications/migrations/0003_sitemessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2023-08-04 15:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('notifications', '0002_auto_20160301_2331'),
]

operations = [
migrations.CreateModel(
name='SiteMessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message', models.TextField(help_text='Text for the alert message')),
('display', models.BooleanField()),
],
),
]
7 changes: 7 additions & 0 deletions designsafe/apps/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def receive_notification(sender, **kwargs):
notification.save()

Event.send_event(event_type, event_users, event_data)


#pylint: enable=invalid-name
class SiteMessage(models.Model):
"""Warning message to display on all pages."""
message = models.TextField(help_text='Text for the alert message')
display = models.BooleanField()
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<script type="text/javascript" src="{% static 'vendor/objectpath/lib/ObjectPath.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-schema-form/dist/schema-form.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-schema-form/dist/bootstrap-decorator.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/angular-xeditable/dist/js/xeditable.js' %}"></script>
<script src="{% static 'vendor/angular-ui-codemirror/src/ui-codemirror.js' %}"></script>
{% endaddtoblock %}
Expand Down
6 changes: 3 additions & 3 deletions designsafe/libs/fedora/fedora_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def generate_manifest(walk_result, project_id, version=None):
manifest.append({
'parent_entity': entity['uuid'],
'corral_path': file_path,
'rel_path': rel_path,
'project_path': rel_path,
'checksum': get_sha1_hash(file_path),
'ffi': get_fido_output(fido_client, file_path)
})
Expand Down Expand Up @@ -751,8 +751,8 @@ def generate_package(project_id):

with ZipFile(archive_path, 'w') as zf:
for file in manifest:
print(file['rel_path'])
zf.write(file['corral_path'], file['rel_path'])
print(file['project_path'])
zf.write(file['corral_path'], file['project_path'])
zf.writestr('{}/manifest.json'.format(project_id), manifest_json)
zf.writestr('{}/metadata.json'.format(project_id), report_json)

Expand Down
20 changes: 19 additions & 1 deletion designsafe/libs/fedora/sim_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from designsafe.apps.data.models.elasticsearch import IndexedPublication
from django.contrib.auth import get_user_model
from designsafe.apps.api.publications.operations import _get_user_by_username
from designsafe.libs.fedora.fedora_operations import format_metadata_for_fedora, fedora_post, fedora_update, create_fc_version, upload_manifest, generate_manifest
from designsafe.libs.fedora.fedora_operations import format_metadata_for_fedora, fedora_post, fedora_update, create_fc_version, upload_manifest, generate_manifest, generate_report_experimental
import logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -303,3 +303,21 @@ def ingest_project_sim(project_id, version=None, amend=False):

if not amend:
upload_manifest_sim(project_id, version=version)


def generate_package_sim(project_id):
from zipfile import ZipFile
archive_path = '/corral-repl/tacc/NHERI/published/archives/{}.zip'.format(project_id)
walk_res = walk_sim(project_id)
manifest = generate_manifest(walk_res, project_id)
manifest_json = json.dumps(manifest, indent=4)
print(manifest_json)
report = generate_report_experimental(project_id)
report_json = json.dumps(report, indent=4)

with ZipFile(archive_path, 'w') as zf:
for file in manifest:
print(file['project_path'])
zf.write(file['corral_path'], file['project_path'])
zf.writestr('{}/manifest.json'.format(project_id), manifest_json)
zf.writestr('{}/metadata.json'.format(project_id), report_json)
9 changes: 9 additions & 0 deletions designsafe/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.deprecation import MiddlewareMixin
from designsafe.apps.notifications.models import SiteMessage

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,6 +64,14 @@ def process_request(self, request):
'Use is required for continued use of DesignSafe '
'resources.' % accept_url)
return None


class SiteMessageMiddleware:
def process_request(self, request):
for message in SiteMessage.objects.filter(display=True):
if settings.SITE_ID == 1:
messages.warning(request, message.message)


class RequestProfilingMiddleware(MiddlewareMixin):
"""Middleware to run cProfiler on each request"""
Expand Down
3 changes: 2 additions & 1 deletion designsafe/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

# SESSIONS
SESSION_COOKIE_DOMAIN = os.environ.get('SESSION_COOKIE_DOMAIN')
SESSION_COOKIE_SECURE = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECURITY WARNING: don't run with debug turned on in production!
Expand Down Expand Up @@ -148,6 +149,7 @@
'impersonate.middleware.ImpersonateMiddleware',
'designsafe.middleware.DesignSafeTermsMiddleware',
'designsafe.middleware.DesignsafeProfileUpdateMiddleware',
'designsafe.middleware.SiteMessageMiddleware',
)

ROOT_URLCONF = 'designsafe.urls'
Expand Down Expand Up @@ -254,7 +256,6 @@
('vendor/font-awesome', os.path.join(BASE_DIR, 'node_modules', 'font-awesome')),
('vendor/angular-toastr', os.path.join(BASE_DIR, 'node_modules', 'angular-toastr')),
('vendor/slick-carousel', os.path.join(BASE_DIR, 'node_modules', 'slick-carousel')),
('vendor/angular-drag-and-drop-lists', os.path.join(BASE_DIR, 'node_modules', 'angular-drag-and-drop-lists')),
('vendor/angular-xeditable', os.path.join(BASE_DIR, 'node_modules', 'angular-xeditable')),
('vendor/leaflet-measure', os.path.join(BASE_DIR, 'node_modules', 'leaflet-measure')),
('vendor/exif-js', os.path.join(BASE_DIR, 'node_modules', 'exif-js')),
Expand Down
1 change: 1 addition & 0 deletions designsafe/static/scripts/applications/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'jquery';
import angular from 'angular';
import _ from 'underscore';
import dndlists from 'angular-drag-and-drop-lists';

import './services/apps-wizard-service';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class NeesDoiListCtrl {

$onInit() {
this.project = this.resolve.project;
this.experimentDois = this.project.metadata.experiments.map((exp)=> {
this.experimentDois = this.project.metadata.experiments.filter(exp => !!exp.doi).map((exp)=> {
const authors = (exp.creators ? exp.creators.map((author) => `${author.lastName}, ${author.firstName}`).join('; ') : '')
const year = exp.endDate.split('T')[0].split('-')[0];
const doi = exp.doi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<div class="pipeline-page">
<div class="pipeline-header">
<h3>Confirm Author Order</h3>
<strong>You are required to confirm the list of Authors on your Citation(s) before continuing.</strong>
Click Save to confirm.
Your citation(s) will be updated to match what is shown in the preview.
Before proceeding, please review the list of authors and their order on your citation(s) and click "Save" to confirm. Your citation(s) will be updated accordingly.
<div ng-if="$ctrl.ui.loading">
<h3 class="text-center">
<i class="fa fa-spinner fa-spin"></i> Loading...
Expand Down Expand Up @@ -70,7 +68,7 @@ <h3 class="text-center">
<h5 style="font-family: Helvetica Neue">Citation Preview</h5>
<div class="well" style="margin-bottom:20px; background-color: white;" ng-show="!$ctrl.ui.loading">
<div>
<ds-author-list format="hname" authors="$ctrl.authors[pubEnt.uuid]"></ds-author-list>
<ds-author-list format="citation" authors="$ctrl.authors[pubEnt.uuid]"></ds-author-list>
<span>
({{ $ctrl.publishedDate }}) “{{ pubEnt.value.title }}”, in <i>{{ $ctrl.project.value.title }}</i>. DesignSafe-CI.
<a href="{{'https://doi.org/' + $ctrl.pubEnt.value.dois[0]}}">{{'https://doi.org/' + $ctrl.pubEnt.value.dois[0]}}</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ <h3 class="text-center">
<div ng-if="!$ctrl.ui.loading">
<div class="pipeline-section">
<ul>
<li>Please review the preview of your amended publication carefully.</li>
<li>Any acceptable changes you make from the project workspace are automatically imported to this preview.</li>
<li>This preview shows what your publication will look like once it is amended.</li>
<li>Categories may not be added or removed.</li>
<li>Files related to any categories may not be modified.</li>
<li>When you have finished proofreading your amended publication, click continue to move onto the next step.</li>
<li>Please review the amendable metadata carefully and make changes if necessary.</li>
<li>Any changes made in the project workspace are reflected in this preview.</li>
<li>Categories may not be added or removed and files related to any categories may not be modified.</li>
<li>When you have finished proofreading your amended publication, click "Continue to Authors".</li>
<li>If you need help, attend
<a href="/facilities/virtual-office-hours/" target="_blank" aria-describedby="msg-open-new-window">
curation office hours
</a>.
</li>
</ul>
</div>
<!-- Project Header Start -->
Expand Down Expand Up @@ -202,7 +205,7 @@ <h3 class="text-center">
</div>
</div>
<div class="entity-meta-field" ng-if="experiment.value.referencedData.length">
<div class="entity-meta-label-multi">Referenced Data</div>
<div class="entity-meta-label-multi">Referenced Data and Software</div>
<div class="entity-meta-data">
<div ng-repeat="reference in experiment.value.referencedData track by $index">
<referenced-data></referenced-data>
Expand Down
Loading

0 comments on commit 686f2f8

Please sign in to comment.