Manual access tab defaults to Unrestricted

Created on 23 April 2024, 2 months ago
Updated 10 May 2024, about 2 months ago

I have followed this Private Content tutorial: https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... β†’

All works great with my custom entity type, except that the widget on the Access tab defaults to "Set access to: - Unrestricted -", I can select the policy ok in the widget but I would expect that following the exact steps in the tutorial that the widget would default to the access policy instead of - Unrestricted -?

I have tried turning off "Allow empty" in the selection mode settings but this made no difference.

If a select my policy and save the entity, then when i edit it again "- Unrestricted -" is gone and can no longer be selected. This is the behavior i should expect when first creating the entity as well?

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Problue Solutions Northern Ireland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Problue Solutions
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    I would need to see what settings you set for your access policy and permissions. However, make sure that the roles have the "Assign access policy" permission and that "First available" is selected under default policy. Otherwise it won't assign an access policy. This functionality has test coverage so it should all be working as expected.

    Feel free to reach out on Slack if you have any questions.

  • Status changed to Postponed: needs info 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    Were you able to resolve your issue?

  • πŸ‡¬πŸ‡§United Kingdom Problue Solutions Northern Ireland

    Hi, thanks for following up.

    Unfortunately no I was unable to figure it out.

    I started again and carefully followed the tutorial to ensure I hadn't missed anything but I got the same result, the widget still defaults to "- Unrestricted -", with "Me only" available to select.

    I thought maybe its something to do with it being a custom entity so I created the policy again for the node entity type but got the same result as above.

    I am testing with just the administrator account so I have required permissions.

  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    Would you be willing to share an export of your access policy?

  • πŸ‡¬πŸ‡§United Kingdom Problue Solutions Northern Ireland
    langcode: en-gb
    status: true
    dependencies: {  }
    id: me_only
    label: 'Me only'
    description: 'Only you and the users below have access to this content.'
    weight: 0
    access_rules:
      is_own:
        id: is_own
        group: ccs_entity
        plugin_id: is_own
        field: uid
        entity_type: ccs_entity
        settings:
          admin_label: ''
          query: true
        required: false
      field_grant_access_to_users_user_reference:
        id: field_grant_access_to_users_user_reference
        group: ccs_entity
        plugin_id: entity_field_standard
        field: field_grant_access_to_users
        entity_type: ccs_entity
        settings:
          admin_label: ''
          query: true
          operator: '='
          value:
            field: uid
          empty_behavior: deny
          widget:
            show: 1
            settings:
              field_widget: entity_reference_autocomplete
              hide_original_field: 1
          operations:
            - view
        required: false
    access_rule_operator: OR
    query: true
    target_entity_type_id: ccs_entity
    operations:
      view_unpublished:
        permission: false
        access_rules: true
        show_column: true
      view:
        permission: false
        access_rules: true
        show_column: true
      view_all_revisions:
        permission: false
        access_rules: true
        show_column: true
      edit:
        permission: false
        access_rules: true
        show_column: true
      delete:
        permission: false
        access_rules: true
        show_column: true
      manage_access:
        permission: true
        access_rules: true
        show_column: true
    type: group
    http_403_response: {  }
    selection_rules:
      is_own:
        id: is_own
        group: ccs_entity
        plugin_id: is_own
        field: uid
        entity_type: ccs_entity
        settings:
          id: 'ccs_entity:is_own'
          admin_label: ''
        required: false
    selection_rule_operator: AND
    selection_set: {  }
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    Thanks for sharing. I noticed that the language is set to en-gb, is that the default language? The "First available" setting will only work for content created in the default language.

    You can check that setting here: /admin/config/regional/language

    You can see more details here: https://www.drupal.org/project/access_policy/issues/3438598 πŸ› Access policy updates get ignored when not using default language Active

    If you have multiple policies, another issue that I've occasionally run into is when the weights of all the access policies are set to 0, sometimes their assignment doesn't behave predictably (still under investigation).

    As a quick workaround you can:

    1. Go to /admin/people/access-policies/node/settings
    2. Sort the access policies by dragging the handles (it doesn't matter which order).
    3. Click save
    4. Go back to /admin/people/access-policies/node/settings
    5. Sort the access policies in the order that you want.
    6. Click save, this should properly set the weight on the policies.
  • πŸ‡¬πŸ‡§United Kingdom Problue Solutions Northern Ireland

    Thanks for having a look.

    I didn't have the language module installed, so I installed it and added English, British (en-gb) and set it to default and cleared cache.

    I added a new entity and tried again but unfortunately the same behavior as before, widget defaults to Unrestricted.

    I did have other policies as I was testing both node entities and custom entities, so i deleted all policies except one and tried again, but unfortunately this didnt work either, the widget still defaults to Unrestricted.

    As i mentioned before, I also tried turning off "Allow empty" - "Allow authors to create and edit ccs entities without an access policy."

    I'm not sure what this is supposed to do as it does not prevent creating or editing entities when "- Unrestricted -" is selected in the widget. I tried turning off "Hide original field widget" in the access rule because if "Allow empty" being turned off works as described, I dont see how the entity could be created without setting the access policy before saving, but this made no difference and allowed me to go ahead and save the entity with "Set access to: Unrestricted" still selected when viewing the Access tab.

    Maybe this setting doesnt work as intended due to my orginal issue?

    Thank you again for taking the time to respond.

  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    Hi Problue Solutions,

    It's going to be a guessing game until I'm able to reproduce it. Are you able to determine at which point in the code the functionality is not working? For example as part of access_policy_entity_presave()? Are you available to connect on Slack? It think it will be easier to diagnose this in real time.

  • πŸ‡¬πŸ‡§United Kingdom Problue Solutions Northern Ireland

    Hi,

    Just confiming I did get this to work as descibed on a different site, I've no idea what modules or configuration may have been causing the issue on the other site and didnt have time to continue trying to work it out unfortunately.

Production build 0.69.0 2024