Skip to content

Commit 63c6f24

Browse files
committed
check if datasets are protected before registering
1 parent 066955f commit 63c6f24

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ibllib/oneibl/registration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from one.converters import ConversionMixin
1313
import one.alf.exceptions as alferr
1414
from one.util import datasets2records, ensure_list
15+
from one.api import ONE
1516

1617
import ibllib
1718
import ibllib.io.extractors.base
@@ -78,6 +79,25 @@ def register_dataset(file_list, one=None, exists=False, versions=None, **kwargs)
7879
assert all(Path(f).exists() for f in file_list)
7980

8081
client = IBLRegistrationClient(one)
82+
83+
# Check for protected datasets
84+
# Account for cases where we are connected to cortex lab database
85+
if one.alyx.base_url == 'https://alyx.cortexlab.net':
86+
protected_status = IBLRegistrationClient(
87+
ONE(base_url='https://alyx.internationalbrainlab.org')).check_protected_files(file_list)
88+
else:
89+
protected_status = client.check_protected_files(file_list)
90+
91+
if isinstance(protected_status, list):
92+
protected = any(d['status_code'] == 403 for d in protected_status)
93+
else:
94+
protected = protected_status['status_code'] == 403
95+
96+
# If we find a protected dataset, and we don't have a force=True flag, raise an error
97+
if protected and not kwargs.pop('force', False):
98+
raise (FileExistsError, 'Protected datasets were found in the file list. To force the registration of datasets '
99+
'add the force=True argument.')
100+
81101
# If the repository is specified then for the registration client we want server_only=True to
82102
# make sure we don't make any other repositories for the lab
83103
if kwargs.get('repository') and not kwargs.get('server_only', False):

0 commit comments

Comments
 (0)