Skip to content

Commit

Permalink
Merge 4e64e34 into 9358d2b
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 10, 2024
2 parents 9358d2b + 4e64e34 commit e5ade4b
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [RDMO 2.1.2](https://github.com/rdmorganiser/rdmo/compare/2.1.1...2.1.2)

* Fix a bug with webpack font paths
* Fix a bug with option set provider plugins

## [RDMO 2.1.1](https://github.com/rdmorganiser/rdmo/compare/2.1.0...2.1.1) (Dec 21, 2023)

* Fix translations
Expand Down
2 changes: 1 addition & 1 deletion rdmo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.1"
__version__ = "2.2.0.dev1"
9 changes: 6 additions & 3 deletions rdmo/options/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ def get_options(self, project, search=None):
return [
{
'id': 'simple_1',
'text': 'Simple answer 1'
'text': 'Simple answer 1',
'help': 'One'
},
{
'id': 'simple_2',
'text': 'Simple answer 2'
'text': 'Simple answer 2',
'help': 'Two'
},
{
'id': 'simple_3',
'text': 'Simple answer 3'
'text': 'Simple answer 3',
'help': 'Three'
}
]
15 changes: 12 additions & 3 deletions rdmo/projects/static/projects/js/project_questions/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,15 @@ angular.module('project_questions')
value.autocomplete_text = option.text_and_help;
}
});
} else if (value.external_id) {
value.autocomplete_locked = false;
angular.forEach(question.options, function(option) {
if (value.autocomplete_locked === false && option.id === value.external_id) {
value.autocomplete_locked = true;
value.autocomplete_input = option.text_and_help;
value.autocomplete_text = option.text_and_help;
}
});
} else if (value.text) {
value.autocomplete_locked = true;
value.autocomplete_input = value.text;
Expand Down Expand Up @@ -776,7 +785,7 @@ angular.module('project_questions')
// loop over options
angular.forEach(question.options, function(option) {
if (option.has_provider && value.selected === option.id) {
value.text = option.text_and_help;
value.text = option.text; // has to be value.text, since the help is not supposed to be stored
value.external_id = option.id;
} else if (value.selected === option.id.toString()) {
// get text from additional_input for the selected option
Expand Down Expand Up @@ -1492,8 +1501,8 @@ angular.module('project_questions')
// store the option
value.text = '';
value.selected = option.id.toString();
value.autocomplete_text = option.text;
value.autocomplete_input = option.text;
value.autocomplete_text = option.text_and_help;
value.autocomplete_input = option.text_and_help;
}

service.changed(value, true);
Expand Down
48 changes: 48 additions & 0 deletions rdmo/projects/tests/test_viewset_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'detail': 'v1-projects:project-detail',
'overview': 'v1-projects:project-overview',
'navigation': 'v1-projects:project-navigation',
'options': 'v1-projects:project-options',
'resolve': 'v1-projects:project-resolve',
}

Expand All @@ -54,6 +55,10 @@

section_id = 1

optionset_id = 4

project_id = 1

@pytest.mark.parametrize('username,password', users)
def test_list(db, client, username, password):
client.login(username=username, password=password)
Expand Down Expand Up @@ -311,3 +316,46 @@ def test_resolve(db, client, username, password, project_id, condition_id):
assert response.status_code == 404
else:
assert response.status_code == 401


@pytest.mark.parametrize('username,password', users)
def test_options(db, client, username, password):
client.login(username=username, password=password)

url = reverse(urlnames['options'], args=[project_id]) + f'?optionset={optionset_id}'
response = client.get(url)

if project_id in view_project_permission_map.get(username, []):
assert response.status_code == 200
assert isinstance(response.json(), list)

for item in response.json():
assert item['text_and_help'] == '{text} [{help}]'.format(**item)
else:
if password:
assert response.status_code == 404
else:
assert response.status_code == 401


def test_options_text_and_help(db, client, mocker):
mocker.patch('rdmo.options.providers.SimpleProvider.get_options', return_value=[
{
'id': 'simple_1',
'text': 'Simple answer 1'
}
])

client.login(username='author', password='author')

url = reverse(urlnames['options'], args=[project_id]) + f'?optionset={optionset_id}'
response = client.get(url)

assert response.status_code == 200
assert response.json() == [
{
'id': 'simple_1',
'text': 'Simple answer 1',
'text_and_help': 'Simple answer 1'
}
]
1 change: 1 addition & 0 deletions rdmo/projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def send_invite_email(request, invite):
context = {
'invite_url': request.build_absolute_uri(project_invite_path),
'invite_user': invite.user,
'invite_email': invite.email,
'project': invite.project,
'user': request.user,
'site': Site.objects.get_current()
Expand Down
17 changes: 13 additions & 4 deletions rdmo/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,19 @@ def options(self, request, pk=None):
project.catalog.prefetch_elements()
if Question.objects.filter_by_catalog(project.catalog).filter(optionsets=optionset) and \
optionset.provider is not None:
options = [
dict(**option, text_and_help=option.get('text_and_help', 'text'))
for option in optionset.provider.get_options(project, search=request.GET.get('search'))
]
options = []
for option in optionset.provider.get_options(project, search=request.GET.get('search')):
if 'id' not in option:
raise RuntimeError(f"'id' is missing in options of '{optionset.provider.class_name}'")
elif 'text' not in option:
raise RuntimeError(f"'text' is missing in options of '{optionset.provider.class_name}'")
if 'text_and_help' not in option:
if 'help' in option:
option['text_and_help'] = '{text} [{help}]'.format(**option)
else:
option['text_and_help'] = '{text}'.format(**option)
options.append(option)

return Response(options)

except OptionSet.DoesNotExist:
Expand Down
4 changes: 3 additions & 1 deletion webpack/common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const base = {
test: /(fonts|files)\/.*\.(svg|woff2?|ttf|eot|otf)(\?.*)?$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
name: '[name].[ext]',
outputPath: 'fonts',
postTransformPublicPath: (p) => `'../' + ${p}`
}
}
]
Expand Down

0 comments on commit e5ade4b

Please sign in to comment.