-
Notifications
You must be signed in to change notification settings - Fork 96
weko#62759 Fix title auto-fill leaving the title blank for non-standard item types #1912
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
base: develop_v2.0.5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2176,14 +2176,22 @@ function validateThumbnails(rootScope, scope, itemSizeCheckFlg, files) { | |
| }; | ||
|
|
||
| $scope.isExistingTitle = function () { | ||
| // The subitem key used for an item type's title varies by item | ||
| // type (e.g. `subitem_item_title` vs. | ||
| // `subitem_restricted_access_item_title`). It is resolved | ||
| // server-side (weko_workflow.views.get_title_subitem_keys) and | ||
| // passed down via these hidden inputs, falling back to the | ||
| // standard JPCOAR name if unresolved. | ||
| let titleSubKey = $("#title_subitem_key").val() || "subitem_item_title"; | ||
| let titleLanguageKey = $("#title_language_subitem_key").val() || "subitem_item_title_language"; | ||
| let model = $rootScope.recordsVM.invenioRecordsModel; | ||
| if (Object.keys(model).length === 0 && model.constructor === Object) { | ||
| return false; | ||
| } else { | ||
| let isExisted = false; | ||
| for (let key in model) { | ||
| if (model.hasOwnProperty(key) && model[key].length > 0) { | ||
| let title = model[key][0]['subitem_item_title']; | ||
| let title = model[key][0][titleSubKey]; | ||
| if (title){ | ||
| $scope.item_tile_key = key | ||
| let activity_id= title.match(/A-[0-9]{8}-[0-9]{5}/g); | ||
|
|
@@ -2194,7 +2202,7 @@ function validateThumbnails(rootScope, scope, itemSizeCheckFlg, files) { | |
| if (title && $("#auto_fill_title").val() !== '""') { | ||
| $scope.setFormReadOnly(key); | ||
| setTimeout(function () { | ||
| $("input[name='subitem_item_title'], select[name='subitem_item_title_language']").attr("disabled", "disabled"); | ||
| $("input[name='" + titleSubKey + "'], select[name='" + titleLanguageKey + "']").attr("disabled", "disabled"); | ||
| }, 3000); | ||
| isExisted = true; | ||
| break; | ||
|
|
@@ -2226,21 +2234,28 @@ function validateThumbnails(rootScope, scope, itemSizeCheckFlg, files) { | |
| userName = JSON.parse(userInfoData).results["subitem_displayname"]; | ||
| } | ||
| } | ||
| let titleSubKey = "subitem_item_title"; | ||
| let titleLanguageKey = "subitem_item_title_language"; | ||
| let titleSubKey = $("#title_subitem_key").val() || "subitem_item_title"; | ||
| let titleLanguageKey = $("#title_language_subitem_key").val() || "subitem_item_title_language"; | ||
| let recordsVM = $rootScope["recordsVM"]; | ||
| Object.entries(recordsVM["invenioRecordsSchema"].properties).forEach( | ||
| function ([key, value]) { | ||
| if (value && value.type === "array" && value.items) { | ||
| if (value.items.properties && value.items.properties.hasOwnProperty(titleSubKey)) { | ||
| // Not every title property declares a language sub-key | ||
| // (e.g. item_1578299480500 on item type 3007/3008) -- | ||
| // assigning an undeclared property breaks the whole | ||
| // array item and the record fails to save with a title. | ||
| let hasLanguageKey = value.items.properties.hasOwnProperty(titleLanguageKey); | ||
| $scope.item_tile_key = key; | ||
| let enTitle = {}; | ||
| let jaTitle = {}; | ||
| // TitleData and Username are mandatory, dataType either way | ||
| enTitle[titleSubKey] = dataType ? [dataType, titleData['en'], userName].join(" - ") : [titleData['en'], userName].join(" - "); | ||
| enTitle[titleLanguageKey] = "en"; | ||
| jaTitle[titleSubKey] = dataType ? [dataType, titleData['ja'], userName].join(" - ") : [titleData['ja'], userName].join(" - "); | ||
| jaTitle[titleLanguageKey] = "ja"; | ||
| if (hasLanguageKey) { | ||
| enTitle[titleLanguageKey] = "en"; | ||
| jaTitle[titleLanguageKey] = "ja"; | ||
| } | ||
|
Comment on lines
+2255
to
+2258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. app.js behavior lacks tests The PR changes title lookup and introduces the hasLanguageKey branch in app.js, but the added tests only exercise the Python key resolver. The client-side behavior for non-standard keys and schemas without language fields therefore lacks regression coverage. Agent Prompt
|
||
| recordsVM["invenioRecordsModel"][key] = [jaTitle, enTitle]; | ||
| } | ||
| } | ||
|
|
@@ -5266,8 +5281,8 @@ function validateThumbnails(rootScope, scope, itemSizeCheckFlg, files) { | |
| let defaultTitleEn = titleData['en'] + userName; | ||
| let defaultTitleJa = titleData['ja'] + userName; | ||
|
|
||
| let titleSubKey = "subitem_item_title"; | ||
| let titleLanguageKey = "subitem_item_title_language"; | ||
| let titleSubKey = $("#title_subitem_key").val() || "subitem_item_title"; | ||
| let titleLanguageKey = $("#title_language_subitem_key").val() || "subitem_item_title_language"; | ||
| let selectedUsageApplicationIDs = [] | ||
|
|
||
| let model = $rootScope["recordsVM"].invenioRecordsModel; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,7 +58,7 @@ | |||||||||||||||||||||||||||||||
| from weko_items_ui.utils import check_item_is_being_edit, get_workflow_by_item_type_id, \ | ||||||||||||||||||||||||||||||||
| get_current_user | ||||||||||||||||||||||||||||||||
| from weko_logging.activity_logger import UserActivityLogger | ||||||||||||||||||||||||||||||||
| from weko_records.api import FeedbackMailList, RequestMailList, ItemLink, ItemTypes, ItemApplication | ||||||||||||||||||||||||||||||||
| from weko_records.api import FeedbackMailList, RequestMailList, ItemLink, ItemTypes, ItemApplication, Mapping | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. mapping import is unsorted The newly added Mapping member is placed after ItemApplication rather than in alphabetic order. This violates the configured isort sorting requirement for from-import members. Agent Prompt
|
||||||||||||||||||||||||||||||||
| from weko_records.models import ItemMetadata | ||||||||||||||||||||||||||||||||
| from weko_records.serializers.utils import get_item_type_name | ||||||||||||||||||||||||||||||||
| from weko_records_ui.models import FilePermission | ||||||||||||||||||||||||||||||||
|
|
@@ -797,6 +797,37 @@ def verify_deletion(activity_id="0"): | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return jsonify(res), 200 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def get_title_subitem_keys(item_type_id): | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. Missing function separation The new top-level get_title_subitem_keys() definition has only one blank line after the preceding function. Flake8 reports this as E305, so the touched Python file does not pass static analysis. Agent Prompt
|
||||||||||||||||||||||||||||||||
| """Resolve the subitem key names used for an item type's title. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Different item types name their "title" subitem differently | ||||||||||||||||||||||||||||||||
| (e.g. ``subitem_item_title`` for the standard JPCOAR title | ||||||||||||||||||||||||||||||||
| property, ``subitem_restricted_access_item_title`` for the | ||||||||||||||||||||||||||||||||
| restricted-access reference item type). Rather than hardcoding | ||||||||||||||||||||||||||||||||
| one name, resolve it the same way | ||||||||||||||||||||||||||||||||
| :meth:`weko_deposit.api.WekoDeposit.get_titles` does: via the | ||||||||||||||||||||||||||||||||
| item type's ``jpcoar_mapping.title`` mapping entry. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| :param item_type_id: ID of the item type. | ||||||||||||||||||||||||||||||||
| :returns: (title_subitem_key, title_language_subitem_key), each | ||||||||||||||||||||||||||||||||
| an empty string if it could not be resolved. | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| title_subitem_key = "" | ||||||||||||||||||||||||||||||||
| title_language_subitem_key = "" | ||||||||||||||||||||||||||||||||
| item_type_mapping = Mapping.get_record(item_type_id) if item_type_id else None | ||||||||||||||||||||||||||||||||
| if item_type_mapping: | ||||||||||||||||||||||||||||||||
| for mapping_value in item_type_mapping.values(): | ||||||||||||||||||||||||||||||||
| if not isinstance(mapping_value, dict): | ||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||
| jpcoar_title = (mapping_value.get('jpcoar_mapping') or {}).get('title') | ||||||||||||||||||||||||||||||||
| if isinstance(jpcoar_title, dict) and jpcoar_title.get('@value'): | ||||||||||||||||||||||||||||||||
| title_subitem_key = jpcoar_title.get('@value') | ||||||||||||||||||||||||||||||||
| title_language_subitem_key = jpcoar_title.get( | ||||||||||||||||||||||||||||||||
| '@attributes', {}).get('xml:lang') or "" | ||||||||||||||||||||||||||||||||
|
Comment on lines
+822
to
+826
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): A truthy non-dict Triggers: When an item type mapping contains a non-empty malformed Suggested fix: Check that
Suggested change
Comment on lines
+822
to
+826
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4. Helper fails black formatting The newly added helper uses formatting that Black would rewrite, including single-quoted string literals. Consequently, black --check would not accept the modified Python code unchanged. Agent Prompt
|
||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||
| return title_subitem_key, title_language_subitem_key | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @workflow_blueprint.route('/activity/detail/<string:activity_id>', | ||||||||||||||||||||||||||||||||
| methods=['GET', 'POST']) | ||||||||||||||||||||||||||||||||
| @login_required_customize | ||||||||||||||||||||||||||||||||
|
|
@@ -955,6 +986,8 @@ def display_activity(activity_id="0", community_id=None): | |||||||||||||||||||||||||||||||
| step_item_login_url = None | ||||||||||||||||||||||||||||||||
| term_and_condition_content = '' | ||||||||||||||||||||||||||||||||
| title = "" | ||||||||||||||||||||||||||||||||
| title_subitem_key = "" | ||||||||||||||||||||||||||||||||
| title_language_subitem_key = "" | ||||||||||||||||||||||||||||||||
| user_lock_key = "workflow_userlock_activity_{}".format(str(current_user.get_id())) | ||||||||||||||||||||||||||||||||
| if action_endpoint in ['item_login', | ||||||||||||||||||||||||||||||||
| 'item_login_application', | ||||||||||||||||||||||||||||||||
|
|
@@ -1007,6 +1040,8 @@ def display_activity(activity_id="0", community_id=None): | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| title = auto_fill_title(item_type_name) | ||||||||||||||||||||||||||||||||
| title_subitem_key, title_language_subitem_key = \ | ||||||||||||||||||||||||||||||||
| get_title_subitem_keys(workflow_detail.itemtype_id) | ||||||||||||||||||||||||||||||||
| show_autofill_metadata = is_show_autofill_metadata(item_type_name) | ||||||||||||||||||||||||||||||||
| is_hidden_pubdate_value = is_hidden_pubdate(item_type_name) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -1209,6 +1244,8 @@ def display_activity(activity_id="0", community_id=None): | |||||||||||||||||||||||||||||||
| approval_preview=approval_preview, | ||||||||||||||||||||||||||||||||
| auto_fill_data_type=data_type, | ||||||||||||||||||||||||||||||||
| auto_fill_title=title, | ||||||||||||||||||||||||||||||||
| title_subitem_key=title_subitem_key, | ||||||||||||||||||||||||||||||||
| title_language_subitem_key=title_language_subitem_key, | ||||||||||||||||||||||||||||||||
| community_id=community_id, | ||||||||||||||||||||||||||||||||
| cur_step=cur_step, | ||||||||||||||||||||||||||||||||
| contributors=contributors, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Pr title lacks prefix
📘 Rule violation⚙ Maintainability