Problem/Motivation

I've upgraded from 1.x to 2.0.1@alpha in preparation for upgrading from Drupal core 10 > 11.

After upgrading the nodeacess module via Composer and exporting the updated configuration from Drupal, I noticed all settings had been emptied:

  • bundles_roles_grants
  • grants_tab_availability
  • map_rid_gid
  • roles_settings

There seemed to be no changes to the config's YAML data structure from 1.x > 2.x, so I discarded the changes and re-imported the config to match my site prior to the 2.x update. It imported without any errors/warnings.

Steps to reproduce

  1. Ensure you have at least one node with grants assigned
  2. Update drupal/nodeaccess in composer from ^1.0 > ^2.0@alpha
  3. View the page with grants assigned
  4. Select the Grants tab
  5. The grants should all be empty

However, when inspecting the database table, the grants data is still present.

Selecting grants in the browser UI and saving the page updates the database, and the change is then visible in the UI when refreshing the page. Further changes to the grants in the UI are also preserved correctly.

It seems like there is a disconnect between the form rendering the data.

Proposed resolution

Ensure the grant forms correctly reflect the database records.

Comments

timfletcher created an issue. See original summary.

timfletcher’s picture

Issue summary: View changes
d.fisher’s picture

Status: Active » Postponed (maintainer needs more info)

nodeaccess.settings.yml 1.x

grants:
  view: 1
  edit: 1
  delete: 1
priority: 0
preserve: 1

nodeaccess.settings.yml 2.x

allowed_grant_operations:
  grant_view: true
  grant_update: true
  grant_delete: true
bundles_roles_grants: {}
grants_tab_availability: {}
map_rid_gid: {}
roles_settings: {}

There is an update hook provided in nodeaccess.install:
https://git.drupalcode.org/project/nodeaccess/-/blob/2.0.x/nodeaccess.in...

/**
 * Migrates nodeaccess.settings.
 */
function nodeaccess_update_9002(&$sandbox) {
  $config = \Drupal::configFactory()->getEditable('nodeaccess.settings');
  // From grants to allowed_grant_operations.
  $old_grants = $config->get('grants');
  $config
    ->set('allowed_grant_operations', [
      'grant_view' => (boolean) $old_grants['view'],
      'grant_update' => (boolean) $old_grants['edit'],
      'grant_delete' => (boolean) $old_grants['delete'],
    ])
    ->clear('grants');

  // From allowed_types to grants_tab_availability.
  $old_allowed_types = $config->get('allowed_types') ?? [];
  $grants_tab_availability = [];
  foreach ($old_allowed_types as $bundle => $value) {
    $grants_tab_availability[$bundle] = (boolean) $value;
  }
  $config
    ->set('grants_tab_availability', $grants_tab_availability)
    ->clear('allowed_types');

  // From role_map to map_rid_gid.
  $old_role_map = $config->get('role_map');
  $config
    ->set('map_rid_gid', $old_role_map)
    ->clear('role_map');

  // From role_alias to roles_settings.
  $old_role_alias = $config->get('role_alias');
  $roles_settings = [];
  foreach ($old_role_alias as $role_id => $value) {
    $roles_settings[$role_id] = [
      'display_name' => $value['alias'],
      'name' => $value['name'],
      'weight' => (int) $value['weight'],
      'selected' => (boolean) $value['allow'],
    ];
  }
  $config
    ->set('roles_settings', $roles_settings)
    ->clear('role_alias');

  $bundles = array_keys($old_allowed_types);
  $bundles_roles_grants = [];
  foreach ($bundles as $bundle) {
    $old_bundle_settings = $config->get($bundle);
    foreach ($old_bundle_settings as $role_id => $grant) {
      $bundles_roles_grants[$bundle][$role_id] = [
        'grant_view' => (int) $grant['grant_view'],
        'grant_update' => (int) $grant['grant_update'],
        'grant_delete' => (int) $grant['grant_delete'],
      ];
    }
    $config->clear($bundle);
  }
  $config
    ->set('bundles_roles_grants', $bundles_roles_grants)
    ->clear('priority')
    ->clear('preserve')
    ->save();

}

Did you run drush updb / drush updatedb and drush cr / drush cache:rebuild?

Please let me know and I can investigate this further if you're still having issues?

d.fisher’s picture

Is this the same issue as:
https://www.drupal.org/project/nodeaccess/issues/3509391

If so we should also mark one of these as closed (duplicate).

quotientix’s picture

The settings are successfully migrated with updb.
But the individual grants per user are deleted during update (the ones I set on /node/123/grants).

thalles’s picture

The same thing happened to me.

d.fisher’s picture

Status: Postponed (maintainer needs more info) » Needs work