Skip to content

Commit

Permalink
Merge pull request #525 from NBISweden/develop
Browse files Browse the repository at this point in the history
Bugfixes for v22
  • Loading branch information
talavis authored Mar 11, 2019
2 parents 8103c39 + b8c0669 commit 4d31660
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
20 changes: 19 additions & 1 deletion backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ def get(self):

try:
dataset_version = db.get_dataset_version(dataset, version)
if dataset_version is None:
self.send_error(status_code=404)
return


if dataset_version.available_from > datetime.now():
# If it's not available yet, only return if user is admin.
if not (self.current_user and self.current_user.is_admin(version.dataset)):
if not (self.current_user and self.current_user.is_admin(dataset_version.dataset)):
self.send_error(status_code=403)
return

base_url = "%s://%s" % (self.request.protocol, self.request.host)
dataset_schema['url'] = base_url + "/dataset/" + dataset_version.dataset.short_name
Expand Down Expand Up @@ -162,6 +167,9 @@ def get(self, dataset, version=None):
future_version = False

version = db.get_dataset_version(dataset, version)
if version is None:
self.send_error(status_code=404)
return

if version.available_from > datetime.now():
future_version = True
Expand Down Expand Up @@ -215,6 +223,10 @@ class GenerateTemporaryLink(handlers.AuthorizedHandler):
def post(self, dataset, version=None):
user = self.current_user
dataset_version = db.get_dataset_version(dataset, version)
if dataset_version is None:
self.send_error(status_code=404)
return

lh = db.Linkhash.create(
user = user,
dataset_version = dataset_version,
Expand All @@ -239,6 +251,10 @@ def post(self, dataset, version=None):
class DatasetFiles(handlers.AuthorizedHandler):
def get(self, dataset, version=None):
dataset_version = db.get_dataset_version(dataset, version)
if dataset_version is None:
self.send_error(status_code=404)
return

ret = []
for f in dataset_version.files:
d = db.build_dict_from_row(f)
Expand Down Expand Up @@ -574,6 +590,7 @@ def get(self):
"""
if db.get_admin_datasets(self.current_user).count() <= 0:
self.finish({'user':None, 'expires':None, 'password':None})
return

password = None
username = None
Expand All @@ -599,6 +616,7 @@ def post(self):
"""
if db.get_admin_datasets(self.current_user).count() <= 0:
self.finish({'user':None, 'expires':None, 'password':None})
return

# Create a new password
username = "_".join(self.current_user.name.split()) + "_sftp"
Expand Down
2 changes: 1 addition & 1 deletion backend/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def get(self):
if self.get_argument("code", False):

if not self._check_state(self.get_argument('state', 'N/A')):
self.set_user_msg("We're beeing MITM:ed or something ABORT!", "error")
self.set_user_msg("We're being MITM:ed or something ABORT!", "error")
self.redirect("/security_warning")
return

Expand Down
29 changes: 20 additions & 9 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TextField,
fn,
)
import logging
import settings

database = MySQLDatabase(
Expand Down Expand Up @@ -295,16 +296,26 @@ def get_dataset(dataset):

def get_dataset_version(dataset, version=None):
if version:
dataset_version = (DatasetVersion
.select(DatasetVersion, Dataset)
.join(Dataset)
.where(DatasetVersion.version == version,
Dataset.short_name == dataset)).get()
try:
dataset_version = (DatasetVersion
.select(DatasetVersion, Dataset)
.join(Dataset)
.where(DatasetVersion.version == version,
Dataset.short_name == dataset)).get()
except DatasetVersion.DoesNotExist:
logging.error("get_dataset_version({}, {}): ".format(dataset, version) +
"cannot retrieve dataset version")
return
else:
dataset_version = (DatasetVersionCurrent
.select(DatasetVersionCurrent, Dataset)
.join(Dataset)
.where(Dataset.short_name == dataset)).get()
try:
dataset_version = (DatasetVersionCurrent
.select(DatasetVersionCurrent, Dataset)
.join(Dataset)
.where(Dataset.short_name == dataset)).get()
except DatasetVersionCurrent.DoesNotExist:
logging.error("get_dataset_version({}, version=None): ".format(dataset) +
"cannot retrieve dataset version")
return
return dataset_version


Expand Down
4 changes: 2 additions & 2 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ chmod -R ug+rw,o-rwx "$data_home"
# Remove temporary files before running the off-site backup.
rm -f "$tmpbackup" "$tmpbackup.gz"

# Do off-site backup.
/opt/tivoli/tsm/client/ba/bin/dsmc incr /data/SweFreq
# Do off-site backup. Don't let this run for more than 45 minutes.
timeout --kill-after=15m 30m /opt/tivoli/tsm/client/ba/bin/dsmc incr /data/SweFreq

0 comments on commit 4d31660

Please sign in to comment.