Skip to content

Commit 674fff0

Browse files
authored
Merge pull request #484 from ImagingDataCommons/idc-prod-sp
IDC v 1.1.0
2 parents 393a6eb + 8aef9ab commit 674fff0

File tree

18 files changed

+1365
-260
lines changed

18 files changed

+1365
-260
lines changed

idc/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
GCLOUD_PROJECT_NUMBER = os.environ.get('GCLOUD_PROJECT_NUMBER', '')
8181
BIGQUERY_PROJECT_ID = os.environ.get('BIGQUERY_PROJECT_ID', GCLOUD_PROJECT_ID)
8282
BIGQUERY_DATA_PROJECT_ID = os.environ.get('BIGQUERY_DATA_PROJECT_ID', GCLOUD_PROJECT_ID)
83+
BIGQUERY_USER_DATA_PROJECT_ID = os.environ.get('BIGQUERY_USER_DATA_PROJECT_ID', GCLOUD_PROJECT_ID)
84+
BIGQUERY_USER_MANIFEST_DATASET = os.environ.get('BIGQUERY_USER_MANIFEST_DATASET', 'dev_user_dataset')
8385

8486
# Deployment module
8587
CRON_MODULE = os.environ.get('CRON_MODULE')
@@ -473,6 +475,7 @@ def GET_BQ_COHORT_SETTINGS():
473475
ACCOUNT_EMAIL_REQUIRED = True
474476
ACCOUNT_USERNAME_REQUIRED = bool(os.environ.get('ACCOUNT_USERNAME_REQUIRED', 'False') == 'True')
475477
ACCOUNT_EMAIL_VERIFICATION = os.environ.get('ACCOUNT_EMAIL_VERIFICATION', 'mandatory').lower()
478+
476479
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[Imaging Data Commons] "
477480
ACCOUNTS_PASSWORD_EXPIRATION = os.environ.get('ACCOUNTS_PASSWORD_EXPIRATION',120) # Max password age in days
478481
ACCOUNTS_PASSWORD_HISTORY = os.environ.get('ACCOUNTS_PASSWORD_HISTORY', 5) # Max password history kept

idc/templatetags/custom_tags.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def ceiling(item):
123123
return math.ceil(item)
124124

125125

126+
@register.filter
127+
def floor(item):
128+
return math.floor(item)
129+
130+
126131

127132

128133
@register.filter

idc/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from django.contrib import admin
2222
from django.conf import settings
2323

24-
from . import views
24+
from . import views, views_api
2525

2626
admin.autodiscover()
2727

@@ -32,6 +32,7 @@
3232
url(r'^test_methods/', views.test_methods, name='test_methods'),
3333
url(r'^style_guide/', views.css_test),
3434
url(r'^users/(?P<user_id>\d+)/$', views.user_detail, name='user_detail'),
35+
url(r'^users/api/', views_api.user_detail, name='user_detail_api'),
3536
url(r'^cohorts/', include('cohorts.urls')),
3637
path('admin/', admin.site.urls),
3738
url(r'^accounts/', include('accounts.urls')),

idc/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ def explore_data_page(request):
234234
with_derived = (req.get('with_derived', "True").lower() == "true")
235235
collapse_on = req.get('collapse_on', 'SeriesInstanceUID')
236236
is_json = (req.get('is_json', "False").lower() == "true")
237+
uniques = json.loads(req.get('uniques', '[]'))
237238

238239
context = build_explorer_context(is_dicofdic, source, versions, filters, fields, order_docs, counts_only,
239-
with_related, with_derived, collapse_on, is_json)
240+
with_related, with_derived, collapse_on, is_json, uniques=uniques)
240241

241242
except Exception as e:
242243
logger.error("[ERROR] While attempting to load the search page:")

idc/views_api.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
###
2+
# Copyright 2015-2020, Institute for Systems Biology
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
###
16+
17+
import json
18+
from json import JSONEncoder
19+
import logging
20+
import sys
21+
22+
23+
from django.conf import settings
24+
from django.contrib.auth.models import User
25+
from allauth.socialaccount.models import SocialAccount
26+
from django.http import HttpResponse, JsonResponse
27+
28+
debug = settings.DEBUG
29+
logger = logging.getLogger('main_logger')
30+
from datetime import datetime
31+
32+
from django.views.decorators.csrf import csrf_exempt
33+
from django.views.decorators.http import require_http_methods
34+
from cohorts.decorators import api_auth
35+
36+
37+
class DateTimeEncoder(JSONEncoder):
38+
# Override the default method
39+
def default(self, obj):
40+
if isinstance(obj, datetime):
41+
encoded_object = obj.strftime('%s')
42+
else:
43+
encoded_object = super(self, obj)
44+
return encoded_object
45+
# if isinstance(obj, (datetime.date, datetime.datetime)):
46+
# return obj.isoformat()
47+
48+
# class JsonResponse(HttpResponse):
49+
# def __init__(self, content, mimetype='application/json', status=None, content_type='application/json'):
50+
# json_text = json.dumps(content, cls=DateTimeEncoder)
51+
# super(JsonResponse, self).__init__(
52+
# content=json_text,
53+
# status=status,
54+
# content_type=content_type)
55+
56+
@csrf_exempt
57+
@api_auth
58+
@require_http_methods(["GET"])
59+
def user_detail(request):
60+
if debug: logger.debug('Called ' + sys._getframe().f_code.co_name)
61+
62+
try:
63+
user = User.objects.get(email=request.GET.get('email', ''))
64+
except Exception as e:
65+
logger.error("[ERROR] {} is not a registered IDC web app user".format(request.GET.get('email', '')))
66+
logger.exception(e)
67+
user_details = {
68+
"message": "Not a registered IDC web app user",
69+
"code": 404
70+
}
71+
return JsonResponse(user_details)
72+
73+
try:
74+
social_account = SocialAccount.objects.get(user=user, provider='google')
75+
except Exception as e:
76+
# This is a local account
77+
social_account = None
78+
user_details = {
79+
'date_joined': user.date_joined,
80+
'email': user.email,
81+
'id': user.id,
82+
'last_login': user.last_login
83+
}
84+
85+
if social_account:
86+
user_details['extra_data'] = social_account.extra_data if social_account else None
87+
user_details['first_name'] = user.first_name
88+
user_details['last_name'] = user.last_name
89+
else:
90+
user_details['username'] = user.username
91+
92+
results = {"user_details": user_details}
93+
94+
return JsonResponse(results, encoder=DateTimeEncoder)
95+
96+
97+

shell/index.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CORE=${1:-test_core}
2+
SKIP_DOWNLOAD=${2:-true}
3+
4+
echo ""
5+
echo "Beginning index run for core ${CORE}"
6+
echo "-------------------------------------------------------"
7+
echo ""
8+
9+
if [[ "$SKIP_DOWNLOAD" = false ]]; then
10+
echo "Deleting current CSV files."
11+
rm dicom_derived_all_*.csv
12+
13+
echo "Downloading new index data."
14+
gsutil cp gs://idc-dev-files/dicom_derived_all_*.csv ./
15+
else
16+
echo "Skipping download. Files are assumed to be present in the directory."
17+
fi
18+
19+
echo ""
20+
echo "Deleting and re-creating the core."
21+
sudo -u solr /opt/bitnami/apache-solr/bin/solr delete -c $CORE
22+
sudo -u solr /opt/bitnami/apache-solr/bin/solr create -c $CORE -s 2 -rf 2
23+
24+
echo ""
25+
echo "Creating the core schema."
26+
echo '{"add-field":['$(cat core_schema.json)']}' | curl -u idc:$SOLR_PASSWORD -X POST -H 'Content-type:application/json' --data-binary @- https://localhost:8983/solr/$CORE/schema --cacert solr-ssl.pem
27+
28+
echo ""
29+
echo "Indexing the following files:"
30+
ls -l dicom_derived_all_*.csv
31+
32+
echo ""
33+
for CSV in $(ls dicom_derived_all_*.csv)
34+
do
35+
echo "Indexing file ${CSV}..."
36+
curl -u idc:$SOLR_PASSWORD -X POST https://localhost:8983/solr/$CORE/update?commit=yes --data-binary @$CSV -H 'Content-type:application/csv' --cacert solr-ssl.pem
37+
echo "...done."
38+
done

shell/install-deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ if [ -n "${CI}" ]; then
135135
TIER=${DEPLOYMENT_TIER,,}
136136
fi
137137
SHA=$(git rev-list -1 HEAD)
138-
echo "APP_VERSION=${TIER}.$(date '+%Y%m%d%H%M').${SHA: -6}" > ${HOMEROOT}/version.env
138+
echo "APP_VERSION=${TIER}.$(date '+%Y%m%d%H%M').${SHA:0:7}" > ${HOMEROOT}/version.env
139139
fi

static/css/search.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ tr {
303303
word-wrap: break-word; }
304304

305305

306+
#cases_table td, #cases_table_head th {
307+
width: 25%;
308+
word-wrap: break-word; }
309+
310+
311+
306312
#studies_table_head th, #studies_table td {
307313
word-break: break-word; }
308314
#studies_table_head th.project-name, th.case-id, th.study-id,

static/css/style.css

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)