diff --git a/config/galaxy.yml.sample b/config/galaxy.yml.sample index 2070698798b..086b2f5667d 100644 --- a/config/galaxy.yml.sample +++ b/config/galaxy.yml.sample @@ -1050,6 +1050,11 @@ galaxy: # in their directory. #user_library_import_dir: null + # If user_library_import_dir is set, this option will auto create a + # library import directory for every user (based on their email) upon + # login. + #user_library_import_dir_auto_creation: false + # For security reasons, users may not import any files that actually # lie outside of their `user_library_import_dir` (e.g. using symbolic # links). A list of directories can be allowed by setting the diff --git a/doc/source/admin/galaxy_options.rst b/doc/source/admin/galaxy_options.rst index 47b6f824ca2..3576f1362e7 100644 --- a/doc/source/admin/galaxy_options.rst +++ b/doc/source/admin/galaxy_options.rst @@ -2188,6 +2188,18 @@ :Type: str +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``user_library_import_dir_auto_creation`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:Description: + If user_library_import_dir is set, this option will auto create a + library import directory for every user (based on their email) + upon login. +:Default: ``false`` +:Type: bool + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``user_library_import_symlink_whitelist`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/galaxy/config.py b/lib/galaxy/config.py index b7eb91a67d5..2986111a710 100644 --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -431,6 +431,7 @@ class Configuration(object): self.user_library_import_dir = kwargs.get('user_library_import_dir', None) self.user_library_import_symlink_whitelist = listify(kwargs.get('user_library_import_symlink_whitelist', []), do_strip=True) self.user_library_import_check_permissions = string_as_bool(kwargs.get('user_library_import_check_permissions', False)) + self.user_library_import_dir_auto_creation = string_as_bool(kwargs.get('user_library_import_dir_auto_creation', False)) if self.user_library_import_dir else False # Searching data libraries self.ftp_upload_dir = kwargs.get('ftp_upload_dir', None) self.ftp_upload_dir_identifier = kwargs.get('ftp_upload_dir_identifier', 'email') # attribute on user - email, username, id, etc... diff --git a/lib/galaxy/web/framework/webapp.py b/lib/galaxy/web/framework/webapp.py index 91491195bf4..b13b6cf6454 100644 --- a/lib/galaxy/web/framework/webapp.py +++ b/lib/galaxy/web/framework/webapp.py @@ -24,10 +24,11 @@ from sqlalchemy.orm import joinedload from sqlalchemy.orm.exc import NoResultFound from galaxy import util -from galaxy.exceptions import MessageException +from galaxy.exceptions import ConfigurationError, MessageException from galaxy.managers import context from galaxy.util import ( asbool, + safe_makedirs, safe_str_cmp ) from galaxy.util.sanitize_html import sanitize_html @@ -630,16 +631,31 @@ class GalaxyWebTransaction(base.DefaultWebTransaction, self.set_cookie(self.security.encode_guid(self.galaxy_session.session_key), name=name, path=self.app.config.cookie_path) + def check_user_library_import_dir(self, user): + if getattr(self.app.config, "user_library_import_dir_auto_creation", False): + # try to create a user library import directory + try: + safe_makedirs(os.path.join(self.app.config.user_library_import_dir, user.email)) + except ConfigurationError as e: + self.log_event(str(e)) + + def user_checks(self, user): + """ + This could contain more checks around a user upon login + """ + self.check_user_library_import_dir(user) + def handle_user_login(self, user): """ Login a new user (possibly newly created) - + - do some 'system' checks (if any) for this user - create a new session - associate new session with user - if old session had a history and it was not associated with a user, associate it with the new session, otherwise associate the current session's history with the user - add the disk usage of the current session to the user's total disk usage """ + self.user_checks(user) # Set the previous session prev_galaxy_session = self.galaxy_session prev_galaxy_session.is_valid = False diff --git a/lib/galaxy/webapps/galaxy/config_schema.yml b/lib/galaxy/webapps/galaxy/config_schema.yml index e4f1ead8bf8..bfb0ab9d001 100644 --- a/lib/galaxy/webapps/galaxy/config_schema.yml +++ b/lib/galaxy/webapps/galaxy/config_schema.yml @@ -1629,6 +1629,14 @@ mapping: must contain sub-directories named the same as the non-admin user's Galaxy login ( email ). The non-admin user is restricted to uploading files or sub-directories of files contained in their directory. + + user_library_import_dir_auto_creation: + type: bool + default: false + required: false + desc: | + If user_library_import_dir is set, this option will auto create a library + import directory for every user (based on their email) upon login. user_library_import_symlink_whitelist: type: str