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

Accessing user notification settings from the site throws a fatal error #8592

Closed
Vitaliy-1 opened this issue Jan 31, 2023 · 9 comments · Fixed by #10068 or pkp/ojs#4321
Closed

Accessing user notification settings from the site throws a fatal error #8592

Vitaliy-1 opened this issue Jan 31, 2023 · 9 comments · Fixed by #10068 or pkp/ojs#4321
Assignees
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.

Comments

@Vitaliy-1
Copy link
Collaborator

Vitaliy-1 commented Jan 31, 2023

Describe the bug
When 2 or more journals are installed, site settings page becomes accessible to the admin user. That means that the admin user can edit own user profile from the site, without context being available. This leads to a fatal error when trying to view notification settings as they are bound to the context

PHP Fatal error:  Uncaught TypeError: APP\notification\form\NotificationSettingsForm::getNotificationSettingCategories(): Argument #1 ($context) must be of type PKP\context\Context, null given, called in /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/notification/form/PKPNotificationSettingsForm.php on line 131 and defined in /Users/vitalii/Documents/development/ojs-main/ojs/classes/notification/form/NotificationSettingsForm.php:27
Stack trace:
#0 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/notification/form/PKPNotificationSettingsForm.php(131): APP\notification\form\NotificationSettingsForm->getNotificationSettingCategories(NULL)
#1 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/controllers/tab/user/ProfileTabHandler.php(342): PKP\notification\form\PKPNotificationSettingsForm->fetch(Object(APP\core\Request))
#2 [internal function]: PKP\controllers\tab\user\ProfileTabHandler->notificationSettings(Array, Object(APP\core\Request))
#3 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/PKPRouter.php(465): call_user_func(Array, Array, Object(APP\core\Request))
#4 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/PKPComponentRouter.php(291): PKP\core\PKPRouter->_authorizeInitializeAndCallRequest(Array, Object(APP\core\Request), Array)
#5 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/Dispatcher.php(163): PKP\core\PKPComponentRouter->route(Object(APP\core\Request))
#6 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/PKPApplication.php(379): PKP\core\Dispatcher->dispatch(Object(APP\core\Request))
#7 /Users/vitalii/Documents/development/ojs-main/ojs/index.php(21): PKP\core\PKPApplication->execute()
#8 {main}
  thrown in /Users/vitalii/Documents/development/ojs-main/ojs/classes/notification/form/NotificationSettingsForm.php on line 27

To Reproduce
Steps to reproduce the behavior:

  1. OJS instance should have at least 2 journals installed
  2. Log in as an admin user, go to the Administration -> Site settings
  3. In the user navigation, click on the Edit Profile
  4. Click on the Notifications tab
  5. See the error

What application are you using?
OJS main branch. Stable branch also needs testing

Additional information

notifications

As it affects only users with an admin role and we don't have site-level notification settings, I'd probably just avoid loading notifications settings in this case, when context isn't available. Another option could be to display the settings for each journal, the same way as it's done for Roles.

PRs regarding issue reopening

@Vitaliy-1 Vitaliy-1 added the Bug:1:Low A bug that does not have a severe consequence or affects a small number of users. label Jan 31, 2023
@Vitaliy-1 Vitaliy-1 added this to the 3.4 milestone Jan 31, 2023
@NateWr
Copy link
Contributor

NateWr commented Feb 1, 2023

Confirmed on main. I tested on stable-3_3_0 and could not reproduce it.

@NateWr
Copy link
Contributor

NateWr commented Feb 1, 2023

Looking at stable-3_3_0, it looks like it is possible to save notification settings at the site level using CONTEXT_ID_NONE (0). And it looks like it's possible to request notifications blocked at the site level with PKPNotificationOperationManager::getUserBlockedNotifications(). However, I don't see any notifications created without a context, so the site-level setting is never used.

We now have a foreign key on the notification_subscription_settings table that references the context id, so such values will be invalid in 3.4.

It is only possible to access the user profile at the site level for users who have roles in more than one journal. So if the user lands on this page, it is because they have roles in more than one journal. I think there are two things to do:

  1. When viewing the user profile at the site-level, replace the form in the Notifications tab with a list of links to the user's profile in each context they are registered in. Like this:

Manage notifications for each journal you are registered with.

  1. Write a pre-flight check to ensure there are no entries in notification_subscription_settings with invalid context_id.

@asmecher just want to run this plan by you. Does this sound right to you?

@asmecher
Copy link
Member

asmecher commented Feb 1, 2023

I would also be game to have the notification_subscription_settings.context_id column be nullable in the database -- that's the equivalent to CONTEXT_ID_NONE in SQL-land that doesn't break referential integrity with a made-up ID of 0. But we're talking about hypotheticals, since we don't have a current use case for CONTEXT_ID_NONE in this case (and the notification toolset will eventually get a rewrite), so I'm OK either way.

NateWr added a commit to NateWr/pkp-lib that referenced this issue Feb 2, 2023
NateWr added a commit to NateWr/ojs that referenced this issue Feb 2, 2023
NateWr added a commit to NateWr/omp that referenced this issue Feb 2, 2023
NateWr added a commit to NateWr/ops that referenced this issue Feb 2, 2023
@NateWr
Copy link
Contributor

NateWr commented Feb 2, 2023

That was much easier, so I've done that. The context column in notification_subscription_settings is now nullable, which fixes this bug and allows subscription opt-outs to be saved at the site-wide level.

PRs:
#8600
pkp/ojs#3738
pkp/omp#1317
pkp/ops#453

NateWr added a commit that referenced this issue Feb 2, 2023
#8592 Fix site-wide notification subscriptions form
NateWr added a commit to pkp/ojs that referenced this issue Feb 2, 2023
NateWr added a commit to pkp/omp that referenced this issue Feb 2, 2023
NateWr added a commit to pkp/ops that referenced this issue Feb 2, 2023
@NateWr
Copy link
Contributor

NateWr commented Feb 2, 2023

Thanks all, merged to main.

@NateWr NateWr closed this as completed Feb 2, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in Infrastructure Feb 2, 2023
defstat added a commit to defstat/ojs that referenced this issue Feb 15, 2023
defstat added a commit to defstat/pkp-lib that referenced this issue Feb 15, 2023
defstat added a commit to defstat/ui-library that referenced this issue Feb 15, 2023
defstat added a commit to defstat/omp that referenced this issue Feb 15, 2023
defstat added a commit to defstat/ops that referenced this issue Feb 15, 2023
@jonasraoni
Copy link
Contributor

jonasraoni commented Jun 17, 2024

I'll reopen this one, the migration to setup the field with null was added (I8592_SiteNotificationSubscriptions), but the migration that creates the table is still the same.

Therefore, the migration will need to be re-run at > 3.4.

@jonasraoni jonasraoni reopened this Jun 17, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Infrastructure Jun 17, 2024
@asmecher
Copy link
Member

@jonasraoni, actually, could you open a new issue for the new part of this? Since the initial fix already went out in 3.4.0, I'd rather not change the milestone on this to 3.5.0 and lose that history.

@jonasraoni
Copy link
Contributor

I was thinking about it, so I'll proceed 😁

@jonasraoni jonasraoni closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Infrastructure Jun 17, 2024
jonasraoni added a commit to jonasraoni/pkp-lib that referenced this issue Jun 19, 2024
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…4 installations have the proper nullability
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…sionProgressType migration, in order to be re-executed and added helpful comments to the file.
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…92-fix-notification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/omp that referenced this issue Jun 19, 2024
…4 installations have the proper nullability
jonasraoni added a commit to jonasraoni/omp that referenced this issue Jun 19, 2024
…92-fix-notification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…4 installations have the proper nullability
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…92-fix-notification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…4 installations have the proper nullability
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…92-fix-notification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/pkp-lib that referenced this issue Jun 19, 2024
…otificationSubscriptions

(cherry picked from commit 1f26efa)
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
(cherry picked from commit cb168c1)
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…4 installations have the proper nullability

(cherry picked from commit d47004f)
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…sionProgressType migration, in order to be re-executed and added helpful comments to the file.

(cherry picked from commit 583010a)
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…otification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…4 installations have the proper nullability

(cherry picked from commit 49f92ae)
jonasraoni added a commit to jonasraoni/ops that referenced this issue Jun 19, 2024
…otification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/omp that referenced this issue Jun 19, 2024
…4 installations have the proper nullability

(cherry picked from commit e3b0c97)
jonasraoni added a commit to jonasraoni/omp that referenced this issue Jun 19, 2024
…otification_subscription_settings-integrity##
jonasraoni added a commit to jonasraoni/ojs that referenced this issue Jun 19, 2024
…otification_subscription_settings-integrity##
jonasraoni added a commit that referenced this issue Jun 19, 2024
…x-notification_subscription_settings-integrity

#8592 Updated field nullability to match the migration I85…
jonasraoni added a commit that referenced this issue Jun 19, 2024
…cation_subscription_settings-integrity

#8592 Updated field nullability to match the migration I85…
Hafsa-Naeem pushed a commit to Hafsa-Naeem/pkp-lib that referenced this issue Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Projects
Status: Done
5 participants