diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d989cf1c..608c6b470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements - Better handle images without enough tile layers ([#1648](../../pull/1648)) +- Add users option to config files; have a default config file ([#1649](../../pull/1649)) ## 1.29.11 diff --git a/docs/girder_config_options.rst b/docs/girder_config_options.rst index 069f50505..601504624 100644 --- a/docs/girder_config_options.rst +++ b/docs/girder_config_options.rst @@ -38,6 +38,10 @@ The yaml file has the following structure: : # groups can specify access based on user or admin, too. access: ... + # The users key specifies that a specific user has distinct settings + users: + : + : # If __inherit__ is true, then merge this config file with the next config # file in the parent folder hierarchy. __inherit__: true diff --git a/girder/girder_large_image/__init__.py b/girder/girder_large_image/__init__.py index b3b8af17d..02e5e1acb 100644 --- a/girder/girder_large_image/__init__.py +++ b/girder/girder_large_image/__init__.py @@ -476,12 +476,6 @@ def adjustConfigForUser(config, user): """ if not isinstance(config, dict): return config - if isinstance(config.get('access'), dict): - accessList = config.pop('access') - if user and isinstance(accessList.get('user'), dict): - config = _mergeDictionaries(config, accessList['user']) - if user and user.get('admin') and isinstance(accessList.get('admin'), dict): - config = _mergeDictionaries(config, accessList['admin']) if isinstance(config.get('groups'), dict): groups = config.pop('groups') if user: @@ -489,13 +483,31 @@ def adjustConfigForUser(config, user): {'_id': {'$in': user['groups']}}, sort=[('name', SortDir.ASCENDING)]): if isinstance(groups.get(group['name']), dict): config = _mergeDictionaries(config, groups[group['name']]) + # Do this after merging groups, because the group access-level values can + # override the base access-level options. For instance, if the base has + # an admin option, and the group has a user option, then doing this before + # group application can end up with user options for an admin. + if isinstance(config.get('access'), dict): + accessList = config.pop('access') + if user and isinstance(accessList.get('user'), dict): + config = _mergeDictionaries(config, accessList['user']) + if user and user.get('admin') and isinstance(accessList.get('admin'), dict): + config = _mergeDictionaries(config, accessList['admin']) if isinstance(config.get('users'), dict): users = config.pop('users') if user and user['login'] in users: config = _mergeDictionaries(config, users[user['login']]) return config + def addSettingsToConfig(config, user): + """ + Add the settings for showing thumbnails and images in item lists to a + config file if the itemList or itemListDialog options are not set. + + :param config: the config dictionary to modify. + :param user: the current user. + """ columns = [] showThumbnails = Setting().get(constants.PluginSettings.LARGE_IMAGE_SHOW_THUMBNAILS) @@ -514,7 +526,8 @@ def addSettingsToConfig(config, user): showExtra = json.loads(Setting().get(extraSetting)) except Exception: pass - if isinstance(showExtra, dict) and 'images' in showExtra and isinstance(showExtra['images'], list): + if (isinstance(showExtra, dict) and 'images' in showExtra and + isinstance(showExtra['images'], list)): for value in showExtra['images']: if value != '*': columns.append({'type': 'image', 'value': value, 'title': value.title()}) @@ -552,7 +565,8 @@ def yamlConfigFile(folder, name, user): if isinstance(config, list) and len(config) == 1: config = config[0] # combine and adjust config values based on current user - if isinstance(config, dict) and ('access' in config or 'groups' in config or 'users' in config): + if isinstance(config, dict) and ( + 'access' in config or 'groups' in config or 'users' in config): config = adjustConfigForUser(config, user) if addConfig and isinstance(config, dict): config = _mergeDictionaries(config, addConfig) @@ -581,11 +595,8 @@ def yamlConfigFile(folder, name, user): else: folder = Folder().load(folder['parentId'], user=user, level=AccessType.READ) - if addConfig is None: - addConfig = {} - + addConfig = {} if addConfig is None else addConfig addSettingsToConfig(addConfig, user) - return addConfig diff --git a/girder/test_girder/test_large_image.py b/girder/test_girder/test_large_image.py index c916e38a2..0b00a095e 100644 --- a/girder/test_girder/test_large_image.py +++ b/girder/test_girder/test_large_image.py @@ -482,7 +482,7 @@ def testYAMLConfigFile(server, admin, user, fsAssetstore): path='/folder/%s/yaml_config/sample.json' % str(colFolderB['_id']), method='GET') assert utilities.respStatus(resp) == 200 - assert resp.json is None + assert resp.json['itemList'] is not None colFolderConfig = Folder().createFolder( collection, '.config', parentType='collection', diff --git a/girder/test_girder/web_client_specs/imageViewerSpec.js b/girder/test_girder/web_client_specs/imageViewerSpec.js index a6d1d1bb7..5d56bf3fb 100644 --- a/girder/test_girder/web_client_specs/imageViewerSpec.js +++ b/girder/test_girder/web_client_specs/imageViewerSpec.js @@ -207,7 +207,7 @@ $(function () { }); it('test the metadata columns are not shown', function () { runs(function () { - expect($('.large_image_container').length).toBeGreaterThan(0); + expect($('.large_image_container').length).toBe(0); expect($('.large_image_thumbnail').length).toBeGreaterThan(0); expect($('.li-column-metadata').length).toBe(0); });