diff -u b/core/modules/rest/rest.install b/core/modules/rest/rest.install --- b/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -98,24 +98,23 @@ */ function rest_update_8204() { $config_factory = \Drupal::configFactory(); + $process_auth = function ($auth_option) { + switch ($auth_option) { + case 'user': + return 'cookie'; + } + + return $auth_option; + }; + foreach ($config_factory->listAll('views.view.') as $view_config_name) { $save = FALSE; $view = $config_factory->getEditable($view_config_name); $displays = $view->get('display'); - foreach ($displays as $display_name => &$display) { - if ($display['display_plugin'] == 'rest_export') { - if (!empty($display['display_options']['auth'])) { - $display['display_options']['auth'] = array_map(function ($auth_option) { - switch ($auth_option) { - case 'user': - return 'cookie'; - case 'basic_auth': - default: - return $auth_option; - } - }, $display['display_options']['auth']); - $save = TRUE; - } + foreach ($displays as $display_name => $display) { + if ('rest_export' === $display['display_plugin'] && !empty($display['display_options']['auth'])) { + $displays[$display_name]['display_options']['auth'] = array_map($process_auth, $display['display_options']['auth']); + $save = TRUE; } } if ($save) { diff -u b/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php --- b/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -461,12 +461,12 @@ $dependencies = parent::calculateDependencies(); $dependencies += ['module' => []]; - $modules = array_filter(array_map(function ($authentication_provider) { - // During the update path, the providers these options are maybe still - // wrong. - return isset($this->authenticationProviders[$authentication_provider]) ? $this->authenticationProviders[$authentication_provider] : NULL; - }, $this->getOption('auth'))); - $dependencies['module'] = array_merge($dependencies['module'], $modules); + $dependencies['module'] = array_merge($dependencies['module'], array_filter(array_map(function ($provider) { + // During the update path the provider options might be wrong. + return isset($this->authenticationProviders[$provider]) + ? $this->authenticationProviders[$provider] + : NULL; + }, $this->getOption('auth')))); return $dependencies; } diff -u b/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php b/core/modules/rest/src/Tests/Update/RestExportAuthUpdateTest.php --- b/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php +++ b/core/modules/rest/src/Tests/Update/RestExportAuthUpdateTest.php @@ -9,7 +9,7 @@ * * @group Update */ -class RestExportAuthCorrectionUpdateTest extends UpdatePathTestBase { +class RestExportAuthUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} @@ -17,7 +17,7 @@ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../tests/fixtures/update/rest-export-with-authentication-correction.php', + __DIR__ . '/../../../tests/fixtures/update/rest-export-with-authentication.php', ]; } @@ -28,9 +28,9 @@ $this->runUpdates(); // Get particular view. - $view = \Drupal::entityTypeManager()->getStorage('view')->load('rest_export_with_authorization_correction'); + $view = \Drupal::entityTypeManager()->getStorage('view')->load('rest_export_with_authorization'); $displays = $view->get('display'); - $this->assertIdentical($displays['rest_export_1']['display_options']['auth'], ['cookie'], 'Cookie is used for authentication'); + $this->assertIdentical($displays['rest_export_1']['display_options']['auth'], ['basic_auth'], 'Basic authentication is set as authentication method.'); } } diff -u b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php --- b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php +++ b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php @@ -2,14 +2,13 @@ /** * @file - * Test fixture for \Drupal\rest\Tests\Update\RestExportAuthUpdateTest. + * Test fixture for \Drupal\rest\Tests\Update\RestExportAuthCorrectionUpdateTest. */ use Drupal\Core\Database\Database; use Drupal\Core\Serialization\Yaml; $connection = Database::getConnection(); -$config = $connection; // Set the schema version. $connection->insert('key_value') @@ -39,13 +38,12 @@ ->condition('name', 'core.extension') ->execute(); -$config = [ - 'link_domain' => '~', -]; -$data = $connection->insert('config') +$connection->insert('config') ->fields([ 'name' => 'rest.settings', - 'data' => serialize($config), + 'data' => serialize([ + 'link_domain' => '~', + ]), 'collection' => '', ]) ->execute(); diff -u b/core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization_correction.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization.yml --- b/core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization_correction.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization.yml @@ -8,7 +8,7 @@ - node - rest - user -id: rest_export_with_authorization_correction +id: rest_export_with_authorization label: 'Rest Export' module: views description: '' @@ -204,7 +204,7 @@ display_extenders: { } path: unpublished-content auth: - - user + - basic_auth cache_metadata: max-age: -1 contexts: only in patch2: unchanged: --- /dev/null +++ b/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php @@ -0,0 +1,36 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../tests/fixtures/update/rest-export-with-authentication-correction.php', + ]; + } + + /** + * Ensures that update hook is run for "rest" module. + */ + public function testUpdate() { + $this->runUpdates(); + + // Get particular view. + $view = \Drupal::entityTypeManager()->getStorage('view')->load('rest_export_with_authorization_correction'); + $displays = $view->get('display'); + $this->assertIdentical($displays['rest_export_1']['display_options']['auth'], ['cookie'], 'Cookie is used for authentication'); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization_correction.yml @@ -0,0 +1,216 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.teaser + - user.role.authenticated + module: + - node + - rest + - user +id: rest_export_with_authorization_correction +label: 'Rest Export' +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: role + options: + role: + authenticated: authenticated + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Filter + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: full + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: '‹ Previous' + next: 'Next ›' + first: '« First' + last: 'Last »' + quantity: 9 + style: + type: default + row: + type: 'entity:node' + options: + view_mode: teaser + fields: + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + label: '' + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + settings: + link_to_entity: true + plugin_id: field + relationship: none + group_type: group + admin_label: '' + exclude: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_alter_empty: true + click_sort_column: value + type: string + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + filters: + status: + id: status + table: node_field_data + field: status + relationship: none + group_type: group + admin_label: '' + operator: '=' + value: '0' + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: boolean + entity_type: node + entity_field: status + sorts: + created: + id: created + table: node_field_data + field: created + order: DESC + entity_type: node + entity_field: created + plugin_id: date + relationship: none + group_type: group + admin_label: '' + exposed: false + expose: + label: '' + granularity: second + title: 'Rest Export' + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.roles + tags: { } + rest_export_1: + display_plugin: rest_export + id: rest_export_1 + display_title: 'REST export' + position: 2 + display_options: + display_extenders: { } + path: unpublished-content + auth: + - user + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - request_format + - 'user.node_grants:view' + - user.roles + tags: { }