Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDMO 2.1.2 #892

Merged
merged 10 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

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

* Fix a bug with webpack font paths
* Fix a bug with option set provider plugins
* Fix a bug with the autocomplete widget
* Add invite.email to send_invite_email context

## [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.1.2.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'
}
]
24 changes: 20 additions & 4 deletions rdmo/projects/static/projects/js/project_questions/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,26 @@ angular.module('project_questions')
angular.forEach(question.options, function(option) {
if (value.autocomplete_locked === false && option.id === value.option) {
value.autocomplete_locked = true;
value.autocomplete_input = option.text_and_help;
value.autocomplete_text = option.text_and_help;
value.autocomplete_input = option.text;
value.autocomplete_text = option.text;
}
});
} 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;
value.autocomplete_text = option.text;
}
})

// if no option was found (for autocomplete search fields), use the text
if (value.text) {
value.autocomplete_locked = true;
value.autocomplete_input = value.text;
value.autocomplete_text = value.text;
}
} else if (value.text) {
value.autocomplete_locked = true;
value.autocomplete_input = value.text;
Expand Down Expand Up @@ -776,7 +792,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 @@ -1451,7 +1467,7 @@ angular.module('project_questions')
}
if (angular.isDefined(next)) {
next.active = true;
value.autocomplete_input = next.text_and_help;
value.autocomplete_input = next.text;
}
} else if ($event.code == 'Enter' || $event.code == 'NumpadEnter') {
if (value.autocomplete_input == '') {
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