Problem/Motivation

This is split off from #2825905: Field permissions are being shared across entity types as a new feature request. The downside to doing this is potentially 5x as many permissions for each instance a field has:

If we were to change this to per-instance settings, for a single field, say used on 5 bundles, this change would suddenly result in 25 individual permissions, which makes management 5 times as much work as it is now (and 5 times as error prone in making a mistake in permissions). Multiply this for a site with 50 or 100 fields...

Proposed resolution

Potentially make this feature configurable so only fields that need per-bundle permissions would generate them.

Remaining tasks

* Make this feature configurable so only fields that need per-bundle permissions would generate them. Right now all permissions are stored at the bundle level.

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#74 2881776-74.patch.txt74.03 KBjosephr5000
#68 2881776-68.patch72.54 KBgcb
#61 field_permissions-2881776-61.patch57.7 KBosopolar
#55 interdiff-2881776_47_55.txt1.01 KBosopolar
#55 2881776-55--packaged-45-fixed.patch55.41 KBosopolar
#50 interdiff_42_46.txt15.08 KBmariacha1
#47 2881776-packaged-45.patch55.41 KBgcb
#46 2881776-44.patch56.61 KBgcb
#43 reroll_diff_41_42.txt1.32 KBgcb
#42 reroll_diff_40_41.txt2.86 KBgcb
#42 2881776-42.patch54.16 KBgcb
#41 reroll_diff_40_41.txt2.86 KBgcb
#41 2881776-41.patch53.59 KBgcb
#40 reroll_diff_39-40.txt2.85 KBgcb
#40 2881776-40.patch53.33 KBgcb
#39 2881776-32-to-39.txt904 bytesmariacha1
#39 2881776-39.patch53.07 KBmariacha1
#33 2881776-32.patch52.37 KBosopolar
#33 interdiff-2881776-28-32.diff1.52 KBosopolar
#32 interdiff-2881776-18-28.diff1.51 KBosopolar
#32 2881776-18.whitespaces-fixed.patch53.19 KBosopolar
#28 2881776-28.patch53.18 KBlendude
#26 2881776-26.patch49.52 KBlendude
#21 2881776-21.patch53.1 KBethomas08
#18 2881776-18.patch53.12 KBjsutta
#17 2881776-17.patch51.99 KBjsutta
#15 2881776-13.patch47.76 KBpaulocs
#14 2881776-14.patch54.07 KBpaulocs
#13 2881776-13.patch47.76 KBpaulocs
#12 2881776-12.patch51.42 KBdipakmdhrm
#2 per-bundle-permissions-2881776-2.patch46.44 KBaschilling
#3 per-bundle-permissions-2881776-3.patch46.5 KBaschilling
#6 field_permissions-per_bundle_permissions-2881776-6.patch46.68 KBrobertom
#10 field_permissions-per_bundle_permissions-2881776-10.patch50.2 KBcodywyatt
#10 interdiff_6-10.txt3.66 KBcodywyatt
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jhedstrom created an issue. See original summary.

aschilling’s picture

StatusFileSize
new46.44 KB

I took a shot at it. The current version doesn't make it optional. The configuration is always per-bundle. This might overload the Field Permissions overview page, but it should keep the Drupal permissions page relatively clean, since only the field instances with "custom" field permissions are listed.

aschilling’s picture

StatusFileSize
new46.5 KB

The old version had the problem, that it saved the FieldConfig too early and this lead to an error when using certain contrib modules (e.g. geocoder), which needed the third party settings for communication. Now the FieldConfig is saved on form submit.

sgurlt’s picture

Tested and works very well in my current project :)

pifagor’s picture

Status: Active » Reviewed & tested by the community
robertom’s picture

Attached a rerolled patch for 8.x-1.0-rc2

attisan’s picture

would an update path be possible for - e.g. set all permissions to bundles according to the pre-patched permissions?

anruether’s picture

The patch works well, but an upgrade path would be great. Atm all existing field permissions do not have an effect any more.

jhedstrom’s picture

Status: Reviewed & tested by the community » Needs work

We either need an update hook to address #8, or even better, make this opt-in as noted in the IS:

Potentially make this feature configurable so only fields that need per-bundle permissions would generate them.

That way, no update hook is needed, existing sites will continue to function, and only fields that need per-bundle permissions will get them (thus preventing an explosion of permissions if all fields had per-bundler perms.)

codywyatt’s picture

Status: Needs work » Needs review
StatusFileSize
new3.66 KB
new50.2 KB

Was in need of this patch with updated permissions so I created an update to address #8. The update goes through field storages transferring settings to field configs and updating roles.

dipakmdhrm’s picture

Status: Needs review » Needs work
+++ b/src/FieldPermissionsService.php
@@ -135,8 +151,8 @@ class FieldPermissionsService implements FieldPermissionsServiceInterface, Conta
-  public function fieldGetPermissionType(FieldStorageConfigInterface $field) {
-    return $field->getThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PUBLIC);
+  public function fieldGetPermissionType(FieldConfigInterface $field_config) {
+    return $field_config->getThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PUBLIC);

This change results in the following error on some JsonAPI calls:

Argument 1 passed to Drupal\field_permissions\FieldPermissionsService::fieldGetPermissionType() must implement interface
Drupal\field\FieldConfigInterface, instance of Drupal\field\Entity\FieldStorageConfig given

There are still some calls present to this function that pass field storage definition instead of field instance definition.
One such example in FieldPermissionsService class:

  public function hasFieldViewAccessForEveryEntity(AccountInterface $account, FieldDefinitionInterface $field_definition) {
    $permission_type = $this->fieldGetPermissionType($field_definition->getFieldStorageDefinition());
dipakmdhrm’s picture

Status: Needs work » Needs review
StatusFileSize
new51.42 KB
paulocs’s picture

StatusFileSize
new47.76 KB

Patch #12 needs reroll. So I attached it.

paulocs’s picture

StatusFileSize
new54.07 KB

This is NOT the correct patch.

paulocs’s picture

StatusFileSize
new47.76 KB

Actually patch #13 is the right one.

I did a little mess with the files, so I'm attaching it again.
Sorry...

jsutta’s picture

#12 installed and worked for me on D8.9.13. I couldn't get #13 or #14 to install.

jsutta’s picture

StatusFileSize
new51.99 KB

I noticed I was getting a similar error to the one reported in #11. Mine was the following:

Argument 3 passed to Drupal\field_permissions\Plugin\FieldPermissionType\Manager::createInstance() must implement interface Drupal\field\FieldConfigInterface or be null, instance of Drupal\field\Entity\FieldStorageConfig given, called in /mnt/www/html/vcsweb/docroot/modules/contrib/field_permissions/src/FieldPermissionsService.php on line 232 in Drupal\field_permissions\Plugin\FieldPermissionType\Manager->createInstance() (line 51 of /mnt/www/html/vcsweb/docroot/modules/contrib/field_permissions/src/Plugin/FieldPermissionType/Manager.php) #0 /mnt/www/html/vcsweb/docroot/modules/contrib/field_permissions/src/FieldPermissionsService.php(232): Drupal\field_permissions\Plugin\FieldPermissionType\Manager->createInstance('custom', Array, Object(Drupal\field\Entity\FieldStorageConfig))

I was also getting it when I would do a JSON API call (via Entity Share).

I've rerolled the patch and corrected the issue reported in #11. I also checked and permissions set at a field level before installing the patch appear to be preserved.

My site uses D8.9.13, and I created the patch using the 8.x-1.x-dev branch (hopefully I got this terminology right, I'm still learning!).

jsutta’s picture

StatusFileSize
new53.12 KB

I ran into a few more errors where the issue mentioned in #11 wasn't fixed, so I've updated my version of the patch to correct those issues. I've double-checked to make sure that that all issues that existed in my use case have been fixed.

gcb’s picture

Priority: Normal » Major

I'm strongly in favor of adding this to the module: at the very least, the entity-type-level distinction seems like a huge bug. Is there consideration of merging this in? Maybe it needs to be 2.x to reflect the significant change in data structure?

mariacha1’s picture

This is the current blocker for merging: https://www.drupal.org/project/field_permissions/issues/2881776#comment-... -- the goal is to make the per-bundle option a configuration, not something you'd have to do on all entity types for all field permissions. The current patch does not allow this, and forces all entities to use per-bundle field permissions, and based on the number of bundles per entity, that might make this page: /admin/people/permissions unloadable.

I don't think adding the make-this-per-bundle configuration option would be too hard -- just none of the patches so far have done it!

I do also really like the idea of putting this into a 2.x branch as well though.

ethomas08’s picture

StatusFileSize
new53.1 KB

Re-rolled patch from comment 18 for the 8.x-1.1.0 release.

mmbk’s picture

Hi, I've installed and tested #18, (not using #21, since it does not patch the actual dev-HEAD.)
So far it is working as expected, after adjusting our implemented custom plugins that extend `Drupal\field_permissions\Plugin\FieldPermissionType\Base`

I do also really like the idea of putting this into a 2.x branch as well though.

Because of the interface changes, I strongly vote for leaving 1.x untouched and consider this as first new feature for the 2.x-branch

geek-merlin’s picture

Title: Consider implementing per-bundle (field instance) permissions » Implement field permissions per-bundle (field instance)
osopolar’s picture

Patch from #18 works for me too. I have many instances of a field in different bundles (and in different entity types).

In first place I could have named the fields differently for each entity type, which would have solved my issue. But I was not aware of the issue and now it would mean additional work, as it would imply creating migrations from old to new field. Luckily it got already fixed.

Would be nice if the patch could applied to the module ASAP, as there is an update hook involved. If there is a future update adding the same function (field_permissions_update_8001()) updating the patched version may get complicated.

For me it would be fine to pump the mayor version in case there are still concerns about compatibility or "performance" of the permission form (#3284722: Permissions not being saved).

osopolar’s picture

Status: Needs review » Reviewed & tested by the community
lendude’s picture

StatusFileSize
new49.52 KB

Reroll should apply to version 1.2

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 26: 2881776-26.patch, failed testing. View results

lendude’s picture

StatusFileSize
new53.18 KB

Install file went *poof* during reroll, let's put that back

osopolar’s picture

Status: Needs work » Needs review
osopolar’s picture

Trying to create an interdiff I got the error:

interdiff: Whitespace damage detected in input

Diff between #18 and #28 https://github.com/osopolar/patchdiff/commit/26e4d7b6c6ce0506fcbb8691b95...

osopolar’s picture

Status: Needs review » Needs work
Related issues: +#3228881: Allow plugins to opt-out for a given field
osopolar’s picture

I fixed the whitespace issue in 2881776-18.patch, see 2881776-18.whitespaces-fixed.patch by adding a whitespace on each empty line and created interdiff between #18 and #28.

osopolar’s picture

StatusFileSize
new1.52 KB
new52.37 KB

I modified the patch from #28 to work with version 8.x-1.2. Besides the patch I added the interdiff between #28 and #32. Interdiff shows no differences between #18 and #32.

Patch does not apply to current dev version, therefore I leave this issue on needs work.

mariacha1’s picture

I'm applying the patch from https://www.drupal.org/project/field_permissions/issues/2881776#comment-... in a new merge request open here:

https://git.drupalcode.org/project/field_permissions/-/merge_requests/10...

It does two things.

1. Applies to the latest version of the 8.x-1.x branch.
2. Updates the referenced class to be Drupal\Core\Field\FieldConfigInterface instead of Drupal\field\FieldConfigInterface. The first locks us from altering permissions on fields defined using \Drupal\Core\Field\Entity\BaseFieldOverride (like the promoted field) which was technically possible with the entity-wide version of the module (although to get it to work with the UI, you needed something like https://www.drupal.org/project/base_field_override_ui)

Tests are failing, so will keep reviewing.

mariacha1’s picture

Ok, at this point the only test failing is related to the d7 -> d8+ field migration, which checks to make sure that the third-party settings on the FieldStorage match between the d7 and d8+ config. Since this patch changes where the third-party settings for this module live, pushing them onto the field config (field.field) level, it's a valid failure.

That migration process would need to be rewritten to move the settings onto the bundle level, and then this test would need to be updated.

Alternatively, if this is going onto an 8.x-2.x branch, I suppose we could say that branch doesn't support migration from d7, and drop both the migration and drop the test. If we find ourselves beyond end of life for D7 and this hasn't been merged into a 2.x branch, that is the easy solution.

jhedstrom’s picture

Alternatively, if this is going onto an 8.x-2.x branch

I think this should go into a 2.x branch as it is a substantial change.

lind101’s picture

Can I suggest that if we're talking about a new 2.x branch that it might be worth rolling this and the following issue in together:

https://www.drupal.org/project/field_permissions/issues/3110867

The patch on that issue already uses patch #10 from this issue as a base.

mariacha1’s picture

StatusFileSize
new53.07 KB
new904 bytes

I'm attaching a patch that is compatible with the latest dev release and contains a fix to this patch that fails if you're looking at the field in a view (which does not provide a bundle, core issue: https://www.drupal.org/project/drupal/issues/2898635). This should fix https://www.drupal.org/project/field_permissions/issues/3373500 if people are seeing it.

I'll try to get this merged into the new 2.x branch this week or next so we can stop with all the patching.

gcb’s picture

StatusFileSize
new53.33 KB
new2.85 KB

Patch reroll against 1.3.

gcb’s picture

StatusFileSize
new53.59 KB
new2.86 KB

And how about a reroll that doesn't cause whitescreens!

gcb’s picture

StatusFileSize
new54.16 KB
new2.86 KB

And another reroll that lets the field configuration page load.

gcb’s picture

StatusFileSize
new1.32 KB

Reroll diff.

mariacha1’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Issue summary: View changes

I'm taking steps to move this issue onto the 8.x-2.x branch, which currently matches the 8.x-1.x branch. This per-bundle permissions feature will be the major difference between branches.

mariacha1’s picture

Issue summary: View changes
gcb’s picture

StatusFileSize
new56.61 KB

Attaching Snapshot PR of the latest version of the Merge Request by mariacha. works with the latest release and tested on D10.

gcb’s picture

StatusFileSize
new55.41 KB

Huh. The last patch doesn't apply in builds because it patches the info file and the info file has extra junk in it from automated D.O. packaging. Here's one usable for those cases.

mariacha1’s picture

I'm attaching the interdiff between 42 and 45 (ignoring the .info stuff). It's worth noting that the merge request is slightly different based on the need in https://www.drupal.org/project/field_permissions/issues/2881776#comment-....

It would be good to know if we are still trying to make the per-bundle option something a user can choose to configure. In the current patches all field permissions are per-bundle and none are per-entity.

mariacha1’s picture

Status: Needs work » Needs review
mariacha1’s picture

StatusFileSize
new15.08 KB

Here's the interdiff.

colan’s picture

Here's a link to this issue's previous comment with helpful d.o markup (so we know the comment #): #2881776-35: Implement field permissions per-bundle (field instance)

sassafrass’s picture

I first tried the patch: 2881776-packaged-45.patch to the latest stable version Field Permissions: 8.x-1.3 and it applied cleanly. However, I get the following error when trying to save a new field permission:

The website encountered an unexpected error. Try again later.

RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "create field_sidebar_sections", "edit own field_sidebar_sections", "view own field_sidebar_sections". in Drupal\user\Entity\Role->calculateDependencies() (line 207 of core/modules/user/src/Entity/Role.php).
Drupal\Core\Config\Entity\ConfigEntityBase->preSave(Object) (Line: 179)
Drupal\user\Entity\Role->preSave(Object) (Line: 528)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 352)
Drupal\Core\Entity\EntityBase->save() (Line: 609)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 96)
Drupal\field_permissions\Plugin\FieldPermissionType\CustomAccess->submitAdminForm(Array, Object, Object) (Line: 154)
field_permission_field_config_edit_form_submit(Array, Object)
call_user_func_array('field_permission_field_config_edit_form_submit', Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('field_config_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I then installed the 8.x-2.x-dev module version and tried to apply the patch: 2881776-packaged-45.patch. It couldn't apply.

colan’s picture

Status: Needs review » Needs work
osopolar’s picture

@gcb is patch in #47 actually working for you? Looking at field_permissions_entity_field_access():

- if (!$field_definition->isDisplayConfigurable($context) || empty($items) || !is_a($field_definition->getFieldStorageDefinition(), '\Drupal\field\FieldStorageConfigInterface')) {
+ if (!$field_definition->isDisplayConfigurable($context) || empty($items) || !is_a($field_definition->getFieldStorageDefinition(), '\Drupal\Core\Field\FieldConfigInterface') || !$field_definition->getTargetBundle()) {

I don't understand how $field_definition->getFieldStorageDefinition() can return \Drupal\Core\Field\FieldConfigInterface.

I did a diff between Merge request !10 and patch from #47, which also indicates that \Drupal\field\FieldStorageConfigInterface is the class to use (xdebug also suggests that):

- if (!$field_definition->isDisplayConfigurable($context) || empty($items) || !is_a($field_definition->getFieldStorageDefinition(), '\Drupal\field\FieldStorageConfigInterface')) {
-+ if (!$field_definition->isDisplayConfigurable($context) || empty($items) || !is_a($field_definition->getFieldStorageDefinition(), '\Drupal\field\FieldStorageConfigInterface') || !$field_definition->getTargetBundle()) {
++ if (!$field_definition->isDisplayConfigurable($context) || empty($items) || !is_a($field_definition->getFieldStorageDefinition(), '\Drupal\Core\Field\FieldConfigInterface') || !$field_definition->getTargetBundle()) {

Besides that difference the info file related stuff and the migration tests, which where removed in MR!10, I did not see other differences.

osopolar’s picture

This patch is the fixed version of patch from #47 (with \Drupal\field\FieldStorageConfigInterface instead of \Drupal\Core\Field\FieldConfigInterface)

camilo.escobar’s picture

Similar to @sassafrass in comment #52, I tried the patch 2881776-55--packaged-45-fixed.patch in the latest 1.3 version. It applied, but then when running the database updates, I'm getting:

  Module              Update ID   Type            Description                                                     
 ------------------- ----------- --------------- ---------------------------------------------------------------- 
  field_permissions   8001        hook_update_n   8001 - Migrates existing third party settings and permissions.  
 ------------------- ----------- --------------- ---------------------------------------------------------------- 
 // Do you wish to run the specified pending updates?: yes.                                                             

>  [notice] Update started: field_permissions_update_8001
>  [error]  Adding non-existent permissions to a role is not allowed. The incorrect permissions are "create field_1", "edit field_2", "edit field_3", "view field_4", ( ...)
>  [error]  Update failed: field_permissions_update_8001 
 [error]  Update aborted by: field_permissions_update_8001 
 [error]  Finished performing updates. 

I also tried with the the 8.x-2.x-dev module version and the patch didn't apply.

japerry’s picture

Version: 8.x-2.x-dev » 8.x-1.x-dev

Moving back to 8.x-1.x for now, in hopes we can redo the 2.x branch correctly (semantic versioning)

gcb’s picture

Alright, I've attempted to merge 8.x-1.4 into the work on this branch. There were a LOT of conflicts. I believe my branch is functioning as desired, but I have failed to get the automated tests fixed. I'm not terribly familiar with how these tests work, so I'd love some help getting those running on my branch.

osopolar’s picture

The reason why #55 worked for me and some others might be, that we ran the update hook under Drupal 9. In Drupal 10 and above all permissions in a user role must be defined in a module.permissions.yml file or a permissions callback, linking to the CR Permissions must exist.

osopolar’s picture

StatusFileSize
new57.7 KB

idebr made their first commit to this issue’s fork.

idebr’s picture

Status: Needs work » Needs review

The new MR34 did not merge all 8.x-1.x changes correctly. I updated the original MR10. The automated tests are green again.

idebr changed the visibility of the branch 2881776-consider-implementing-per-bundle_8x-14 to hidden.

tgauges made their first commit to this issue’s fork.

tgauges’s picture

Assigned: Unassigned » tgauges
Status: Needs review » Needs work
tgauges’s picture

Assigned: tgauges » Unassigned
Status: Needs work » Needs review
gcb’s picture

StatusFileSize
new72.54 KB

here's the latest state of the MR as a patch for stable builds:

andycarlberg’s picture

andycarlberg made their first commit to this issue’s fork.

I removed these commits because I don't think I got it right. There's more going on than simple class changes. After brief initial testing, it seems like the patch from #68 works for us for now.

tgauges’s picture

I merged the current 8.x-1.x version (1.5) into 2881776-consider-implementing-per-bundle: https://git.drupalcode.org/project/field_permissions/-/merge_requests/10/diffs?commit_id=e3c30a47aa8d4cf663d1db2e78be54bc037e7368

The conflicts were pretty straightforward. Tests are still good.

If you relied on a dynamic URL to patch your installation and don't want to update yet, you can download the previous diff here: https://git.drupalcode.org/project/field_permissions/-/merge_requests/10/diffs.diff?diff_id=1866781

megakeegman’s picture

I was testing patch #68 and ran into a funny issue. Notably I am only experiencing this issue with my admin permissions config, and it does not appear to have any functional consequences. It is just an issue with inconsistency in my config files.

I am only noticing this right now with 2 fields. One is called field_office_hours. The other is called field_order.

After I installed an configured field permissions with this issue patch (initially #68, but problem persists with latest on MR 10), I exported config and these are the changes I see in my admin config:

--- a/config/sync/user.role.administrator.yml
+++ b/config/sync/user.role.administrator.yml
@@ -1,11 +1,18 @@
uuid: ccb30dce-64b9-4253-b4d1-db37c7162ebc
langcode: en
status: true
-dependencies: {  }
+dependencies:
+  module:
+    - field_permissions
_core:
default_config_hash: deBO6rveioT0_Xi1uj--U3HrKSa0JjKdvdHRKy0rXNo
id: administrator
label: Administrator
weight: -5
is_admin: true
-permissions: {  }
+permissions:
+  - 'create field_order (node.office)'
+  - 'edit field_order (node.office)'
+  - 'edit own field_order (node.office)'
+  - 'view field_order (node.office)'
+  - 'view own field_order (node.office)'

Strange because usually admin permission changes do not get managed in code like this. I did not think anything of it at the time though.

Later, I made more updates to permissions and now see this diff:

diff --git a/config/sync/user.role.administrator.yml b/config/sync/user.role.administrator.yml
index 1515721..db77bc5 100644
--- a/config/sync/user.role.administrator.yml
+++ b/config/sync/user.role.administrator.yml
@@ -11,8 +11,8 @@ label: Administrator
weight: -5
is_admin: true
permissions:
-  - 'create field_order (node.office)'
-  - 'edit field_order (node.office)'
-  - 'edit own field_order (node.office)'
-  - 'view field_order (node.office)'
-  - 'view own field_order (node.office)'
+  - 'create field_office_hours (node.office)'
+  - 'edit field_office_hours (node.office)'
+  - 'edit own field_office_hours (node.office)'
+  - 'view field_office_hours (node.office)'
+  - 'view own field_office_hours (node.office)'

I found that if I go directly to the field_order field edit page and click save, this diff will revert and my git working tree will be clean. But if I do the same thing on the field_office_hours edit page, or click save on the overall permissions page, then this diff comes back. Like I said, I don't think it has any affect on anything functionally, but I do find this behavior a little bit concerning. Has anyone else seen something like this?

These are 2 of 9 fields on this content type. field_office_hours has no custom permissions set, where field_order is restricted to certain roles. There are multiple of both, but I have only seen these 2 permissions sneak their way into the admin permissions config file.

megakeegman’s picture

I see this in submitAdminForm (CustomAccess.php):

      if ($role->isAdmin()) {
        continue;
      }

Which makes it look like the issue I am reporting should not be able to occur

megakeegman’s picture

FWIW, I restored my admin permissions config file to the state it was before configuring field_permissions (no permissions or dependencies listed). After doing that, I have not been able to reproduce the issue I describe in #71.

josephr5000’s picture

StatusFileSize
new74.03 KB

Here's a patch for the changes in #69 #70 above

CORRECTED following helpful comment in #75 below.

osopolar’s picture

Thanks for all your work. I was using the patch from #61 (based on MR !34) until 8.x-1.5 broke it, so I decided to switch to MR !10 and reviewed the changes.

The update hook was improved meanwhile, but as we already ran it we do not need to run it again. The rest of the changes are compatible with #61, so switching to MR !10 should be safe.

The patch in #74 seems to refer to #70 (not #69), as it matches diff under https://git.drupalcode.org/project/field_permissions/-/merge_requests/10/diffs.diff?diff_id=1939210 (also safe to be used with composer patch) — which I didn't know before — you get this URL from the MR overview page (https://git.drupalcode.org/project/field_permissions/-/merge_requests/10) by taking the latest "Compare with previous version" link and adding .diff before ?diff_id=1939210 and removing the start_sha parameter.