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

RFC: Use setting to get submit_info form #4393

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions src/submission/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re

from django import forms
from django.utils.module_loading import import_string
from django.utils.translation import gettext, gettext_lazy as _

from submission import models
Expand All @@ -22,6 +23,28 @@
from tinymce.widgets import TinyMCE


def get_submit_info_form(request):
if request.user.is_editor(request):
custom_form = setting_handler.get_setting(
"general", "submit_info_form_editor_version", request.journal
)
else:
custom_form = setting_handler.get_setting(
"general", "submit_info_form_general_version", request.journal
)
form_path = custom_form.processed_value
return import_string(form_path)



def get_submit_info_edit_form(request):
custom_form = setting_handler.get_setting(
"general", "submit_info_form_general_version", request.journal
)
form_path = custom_form.processed_value
return import_string(form_path)

Comment on lines +26 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat idea. One thing to consider is that the settings have been configured to be accessible by both editors and journal managers; Since all it takes is a path to a python module, it opens up a window for arbitrary code execution.

It would be safer to implement a registry of allowed forms (perhaps controlled in settings.py so that it can be expanded on) and then only exposing editors to a choice field.

The implementation could be similar to other registry-based loaders (e.g. template tag/filter registry). We could assist with that if needed.


class PublisherNoteForm(forms.ModelForm):

class Meta:
Expand Down
9 changes: 3 additions & 6 deletions src/submission/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ def submit_info(request, article_id):
request.journal,
).processed_value

# Determine the form to use depending on whether the user is an editor.
article_info_form = forms.ArticleInfoSubmit
if request.user.is_editor(request):
article_info_form = forms.EditorArticleInfoSubmit
article_info_form = forms.get_submit_info_form(request)

form = article_info_form(
instance=article,
Expand Down Expand Up @@ -733,7 +730,7 @@ def edit_metadata(request, article_id):
article=article,
)

info_form = forms.ArticleInfo(
info_form = forms.get_submit_info_edit_form(request)(
instance=article,
additional_fields=additional_fields,
submission_summary=submission_summary,
Expand Down Expand Up @@ -767,7 +764,7 @@ def edit_metadata(request, article_id):
return redirect(reverse_url)

if 'metadata' in request.POST:
info_form = forms.ArticleInfo(
info_form = forms.get_submit_info_edit_form(request)(
request.POST,
instance=article,
additional_fields=additional_fields,
Expand Down
38 changes: 38 additions & 0 deletions src/utils/install/journal_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -5117,5 +5117,43 @@
"value": {
"default": ""
}
},
{
"group": {
"name": "general"
},
"setting": {
"description": "Dotted path of the form used during the submission phase for editors.",
"is_translatable": true,
"name": "submit_info_form_editor_version",
"pretty_name": "General Publication Editor info form",
"type": "char"
},
"value": {
"default": "submission.forms.EditorArticleInfoSubmit"
},
"editable_by": [
"editor",
"journal-manager"
]
},
{
"group": {
"name": "general"
},
"setting": {
"description": "Dotted path of the form used during the submission phase for authors.",
"is_translatable": true,
"name": "submit_info_form_general_version",
"pretty_name": "General Publication info form",
"type": "char"
},
"value": {
"default": "submission.forms.ArticleInfoSubmit"
},
"editable_by": [
"editor",
"journal-manager"
]
}
]
10 changes: 10 additions & 0 deletions src/utils/install/submission_items.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@
"group": "special",
"name": "sections",
"title": "sections"
},
{
"group": "general",
"name": "submit_info_form_editor_version",
"title": "submission.forms.EditorArticleInfoSubmit"
},
{
"group": "general",
"name": "submit_info_form_general_version",
"title": "submission.forms.ArticleInfoSubmit"
}
]