Problem
When system generates context it switches users and invokes hook_logout and hook_login. If there is a SSO module which performs redirect on hook_logout then context generation process will be broken.

Proposed solution
Provide "Silent user switching" setting on provider settings form which will avoid invokation of listed above hooks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Loparev created an issue. See original summary.

Loparev’s picture

Status: Active » Needs review
FileSize
8.58 KB

Here is a patch.

What I've tested:
1. Context debug form:
+ 1.1. Silent switching is off: hooks are invoked - ok
+ 1.2. Silent switching is on: hooks aren't invoked - ok

2. Send context action:
+ 2.1. Silent switching is off: hooks are invoked - ok
+/- 2.2. Silent switching is on: hooks aren't invoked - ok, but there was no context in Smartling dashboard (in recent log messages was message "Context upload for file @file completed successfully."). I think it's problem with context service.

3. Queue worker send context action:
+ 3.1. Silent switching is off: hooks are invoked - ok
+ 3.2. Silent switching is on: hooks aren't invoked - ok

Loparev’s picture

Tested 2.2 once again - everything is ok.

Soul88’s picture

  1. +++ b/src/Form/SendContextActionApproveForm.php
    @@ -222,7 +222,8 @@ class SendContextActionApproveForm extends ConfirmFormBase {
    +    $context_silent_user_switching = \Drupal::config('tmgmt.translator.smartling')->get('settings.context_silent_user_switching');
    

    This way we retrieve username only from the first "Smartling" provider

  2. +++ b/src/SmartlingTranslatorUi.php
    @@ -71,6 +71,14 @@ class SmartlingTranslatorUi extends TranslatorPluginUiBase {
    +      '#title' => t('Switch users without invocation of "hook_logout" and "hook_login"'),
    

    Title: Context silent user authentication

  3. +++ b/src/SmartlingTranslatorUi.php
    @@ -71,6 +71,14 @@ class SmartlingTranslatorUi extends TranslatorPluginUiBase {
    +      '#description' => t('When system generates context it switches current user with a user from "Username for context retrieval" setting. Then it invokes "hook_logout" and "hook_login". If there is a SSO module in your Drupal installation which performs redirect on "hook_logout" then most probably you should enable this option.'),
    

    Description: "If checked, Smartling won't trigger hook_login and hook_logout during user authentication for retrieving context."

Soul88’s picture

  1. +++ b/src/Context/ContextUserAuth.php
    @@ -102,13 +103,13 @@ class ContextUserAuth {
    +   * @return \Symfony\Component\HttpFoundation\RedirectResponse A redirect response object.
    +   * A redirect response object.
    

    "A redirect response object." string duplication

  2. +++ b/src/Form/SendContextActionApproveForm.php
    @@ -222,7 +222,8 @@ class SendContextActionApproveForm extends ConfirmFormBase {
    +    $context_silent_user_switching = \Drupal::config('tmgmt.translator.smartling')->get('settings.context_silent_user_switching');
    

    If we retrieve settings this way, they will always come from the "main" Smartling translation provider.

Loparev’s picture

Loparev’s picture

Loparev’s picture

Loparev’s picture

Loparev’s picture

Soul88’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

  • Loparev committed c0895d7 on 8.x-1.x
    Issue #2863564 by Loparev: Add compatability with SSO modules
    
Soul88’s picture

Status: Reviewed & tested by the community » Fixed

  • Loparev committed c0895d7 on 8.x-2.x
    Issue #2863564 by Loparev: Add compatability with SSO modules
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.