Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
Readjust how group access level parameters are applied and document why.
  • Loading branch information
manthey committed Sep 25, 2024
1 parent ab6b961 commit 3bac9b6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docs/girder_config_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ The yaml file has the following structure:
<key>: <value>
# groups can specify access based on user or admin, too.
access: ...
# The users key specifies that a specific user has distinct settings
users:
<user login>:
<key>: <value>
# If __inherit__ is true, then merge this config file with the next config
# file in the parent folder hierarchy.
__inherit__: true
Expand Down
35 changes: 23 additions & 12 deletions girder/girder_large_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,26 +476,38 @@ 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:
for group in Group().find(
{'_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)
Expand All @@ -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()})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion girder/test_girder/test_large_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion girder/test_girder/web_client_specs/imageViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 3bac9b6

Please sign in to comment.