OJS 3.3.0.13 (upgraded from 3.1.1.0) - user edit throws 'Failed Ajax request or invalid JSON returned.'

Describe the issue or problem
Our OJS deployment was recently upgraded from 3.1.1.0 to 3.3.0.13. When we try to edit a newly created user (after the upgrade) the website responds with ‘Failed Ajax request or invalid JSON returned.’. All the users previously created on before the upgrade can be edited without an issue.

What application are you using?
OJS 3.3.0.13
PHP 8.0.27
Database: PostgreSQL 15.1
OS: Ubuntu 22.04

Additional information
http server log reports the following error:

[Thu Jan 19 19:08:38.361395 2023] [php:error] [pid 1269] [client 127.0.0.1:50506] PHP Fatal error:  Uncaught TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/plugins/modifier.escape.php:39
Stack trace:
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/plugins/modifier.escape.php(39): htmlspecialchars()
/srv/hosting/domain.org/lib/pkp/classes/template/PKPTemplateManager.inc.php(1784): smarty_modifier_escape()
/srv/hosting/domain.org/cache/t_compile/2122dd4b4d038d06701b7a5cbc73d21546ea835d_0.app.formtextInput.tpl.php(125): PKPTemplateManager->smartyEscape()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_63c96616b2a031_79831576()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(232): Smarty_Internal_Template->render()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(116): Smarty_Internal_TemplateBase->_execute()
 /srv/hosting/domain.org/lib/pkp/classes/form/FormBuilderVocabulary.inc.php(434): Smarty_Internal_TemplateBase->fetch()
 /srv/hosting/domain.org/lib/pkp/classes/form/FormBuilderVocabulary.inc.php(288): FormBuilderVocabulary->_smartyFBVTextInput()
 /srv/hosting/domain.org/cache/t_compile/e688bd52a60a2f40254f746518d02cb6c45d5a61^e565cf5500e8246b7982cbf0654d2bdb3bbd22b6_0.app.commonuserDetails.tpl.php(369): FormBuilderVocabulary->smartyFBVElement()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_63c96625bdaac7_61714098()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(385): Smarty_Internal_Template->render()
 /srv/hosting/domain.org/cache/t_compile/e688bd52a60a2f40254f746518d02cb6c45d5a61^8556fb23e7fb57ad227780d4140a6e81b73ea93a_0.app.controllersgridsettingsus.php(71): Smarty_Internal_Template->_subTemplateRender()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_63c96625b87584_74959646()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render()
 /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(232): Smarty_Internal_Template->render()
/srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(116): Smarty_Internal_TemplateBase->_execute()
 /srv/hosting/domain.org/lib/pkp/classes/template/PKPTemplateManager.inc.php(1072): Smarty_Internal_TemplateBase->fetch()
 /srv/hosting/domain.org/lib/pkp/classes/form/Form.inc.php(197): PKPTemplateManager->fetch()
 /srv/hosting/domain.org/lib/pkp/controllers/grid/settings/user/form/UserForm.inc.php(83): Form->fetch()
 /srv/hosting/domain.org/lib/pkp/controllers/grid/settings/user/form/UserDetailsForm.inc.php(192): UserForm->display()
 /srv/hosting/domain.org/lib/pkp/controllers/grid/settings/user/UserGridHandler.inc.php(287): UserDetailsForm->display()
 /srv/hosting/domain.org/lib/pkp/classes/core/PKPRouter.inc.php(395): UserGridHandler->editUser()
 /srv/hosting/domain.org/lib/pkp/classes/core/PKPComponentRouter.inc.php(257): PKPRouter->_authorizeInitializeAndCallRequest()
 /srv/hosting/domain.org/lib/pkp/classes/core/Dispatcher.inc.php(144): PKPComponentRouter->route()
 /srv/hosting/domain.org/lib/pkp/classes/core/PKPApplication.inc.php(362): Dispatcher->dispatch()
 /srv/hosting/domain.org/index.php(68): PKPApplication->execute()
 {main}
   thrown in /srv/hosting/domain.org/lib/pkp/lib/vendor/smarty/smarty/libs/plugins/modifier.escape.php on line 39, referer: https://domain.org/index.php/scpe/management/settings/access

I have checked the http call triggered when the user edit popup should show up:

https://domain.org/index.php/scpe/$$$call$$$/grid/settings/user/user-grid/edit-user?gridId=grid-settings-user-usergrid&rowId=2956&grid-settings-user-usergridPage=1&grid-settings-user-usergridItemsPerPage=500&oldUserId=0

and for the users created after the upgrade it returns an HTML content but for the users previously created it is a JSON content (and the HTML is embedded in the JSON).

Now, the HTML content is not rendered successfully because it suddenly ends with:

<div class="inline pkp_helpers_threeQuarter">
		<input	type="text"
		class="field text"
						name="affiliation[en_US]"
		value="

I’ve checked the database, user_settings table and the affiliation setting_value of type object with value:

{"en_US":"The Institute of Something"}

Previously created users have this entry of type string.

I think this might be the issue but I don’t know what to do further. Any help would be appreciated.

Thanks,
Silviu.

Context : OJS 3.3.0-14, bilingual instance (French and English, with fr_CA being the main locale).

As an admin or editor, when attempting to edit a newly registered user, an error message reading “Failed Ajax request or invalid JSON returned” appears, preventing access to the user’s profile information.

This issue occurs when a user registers using a non-English interface, (at least I tested with the fr_CA interface), and fills out the “Affiliation” field.

For the affected user, attempting to access their profile results in the “Contact” tab being blank on the fr_CA interface. The English interface displays the “Contact” tab correctly, which is where the affiliation information is normally displayed.

Upon further investigation, it appears that the “setting_value” in the “user_settings” table is registered as an array, and the “setting_type” is set to “object” instead of “string.” :

52 fr_CA affiliation 0 0 {"fr_CA":"Université Laurentienne"} object

Manually editing the entry for:

52 fr_CA affiliation 0 0 Université Laurentienne string

does solve the problem for this user.

I also ran a test with the English interface and also get the problem (remember fr_CA is the main locale). The database reads:

54	fr_CA	givenName	0	0	Angelo	string
54	fr_CA	familyName	0	0	Caruso	string
54	fr_CA	affiliation	0	0	{"fr_CA":"University of Capri"}	object
54	en_US	givenName	0	0	Angelo	string
54	en_US	familyName	0	0	Caruso	string
54	en_US	affiliation	0	0	{"fr_CA":"University of Capri"}	object

I’ve had to clean up the entry in the database a few times to unblock the editing of the user’s information. PKP team, I think a fix is needed…

1 Like

Unable to re-produce this issue in the installation of OJS 3.3.0-14 . In a multilingual setup, the setting_value for setting_name affiliation is always getting saved as a string not as a json decodable object . Also manually changing the value to a json data such as {"fr_CA":"Université Laurentienne"} does not cause any issue when trying to edit an user form Settings --> Users & Roles --> Users .

I conduct the following approach to re-produce the issue as

  1. Multilingual OJS 3.3.0-14 set up with French(fr_CA) set as the primary language
  2. Register a new user from with data given for affiliation as Some new institute. Verify that user to make sure user can login .
  3. Login as newly register user and access the profile section , no issues
  4. Login as admin/JM and edit registered user from Settings --> Users & Roles --> Users, save it. No issue .

@Marie-Helene can you confirm the above step produce this issue for you ? Or some other approach require to re-produce it if I am misunderstanding it .

Regards
PKP Team

Thank you @touhidur for taking the time to resolve this issue. You have listed the steps that fit my situation perfectly. I just tested with another 3.3.0.14 instance and indeed the problem did not recur. The same test in another 3.3.0.14 instance causes the problem… which is good news because I can now investigate the differences. I’ll get back to you.

I think I have found the problem. This one occurs when using the Bootstrap3 theme (version 3.2.0.5). The Default theme does not cause the problem. I have been able to change/switch between these two themes and the problem is consistent when the Bootstrap theme is active. Are you seeing the same thing on your end?

Is that related maybe? Affiliation should not be localized on registration form · Issue #159 · pkp/bootstrap3 · GitHub

I confirm that I am using Bootstrap 3 Base theme on my instance.

1 Like

@silviu , @touhidur

It seems there was a former fix for this issue : Fix affiliation issue on register by gopalkildoliya · Pull Request #152 · pkp/bootstrap3 · GitHub

I applied it and it solved the problem.

Not sure why it reappeared in Bootstrap3 version 3.2.0.5. (@NateWr)… (?)

Marie-Hélène

1 Like

@Marie-Helene you are right and I also not sure how it reverted back . Also when I checked the main repo code for latest main branch and stable-3.3.0, the required change is not there that fix this issue . same goes for released packages from github.

@NateWr may be you can shed some light on this .

In the mean time I will create new PRs to have this fixed in the next package release .

1 Like

@Marie-Helene, I confirm that the fix works. Thanks.

Previously, I used a psql query to fix users_settings entries:

UPDATE user_settings SET setting_value = SUBSTRING(setting_value, '{"en_US":"(.*)"}'), setting_type='string' WHERE setting_value ~* '{"en_US":".*"}' and setting_type='object'

1 Like

Thanks for all who reported and responded to this thread; I encountered the same issue in our system (currently on 3.3.0-14 in combination with the bootstrap3 theme).

Fixing the registrationForm.tpl (link from above) in combination with the following MySQL command (mariadb) solved the issue. Posting it here as it might help others.

UPDATE user_settings SET setting_type = 'string', setting_value = REGEXP_REPLACE(setting_value, '^{"en_US":"(.*)"}', '\\1')
WHERE setting_value like "%en\_US%" AND setting_name = 'affiliation';
1 Like