Expected behavior: Creating a new node and relating a node have different permissions.
Actual behavior: Both use the permissions for relating a node.

The routes for group/{group}/node/create and group/{group}/node/add set a flag called $create_mode to signify which of the two is being done.

However, as the permissions go through the core entity layer, that flag is lost. When GroupContentAccessControlHandler::checkCreateAccess() checks the permission it only calls GroupContentEnablerBase::createAccess() which is appropriate when we're relating/adding existing node but not creating a new one.

GroupContentAccessControlHandler::checkCreateAccess() needs to have an if/else somehow and call createAccess() for /add (relating) or createEntityAccess() for /create

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericras created an issue. See original summary.

ericras’s picture

Issue summary: View changes
ericras’s picture

Here's a patch

ericras’s picture

Status: Active » Needs review
ericras’s picture

I've been looking at problems with permissions related to Group Menu as well. It looks like checkAccess also needs a checkEntityAccess counterpart like createAccess/createEntityAccess. Currently, checkAccess looks at 'create' permissions which are related to creating relations; 'entity' permissions related to new entity creation are nowhere to be found.

So if a user has permission to edit the Group Menu entities but not the relations, they don't have proper abilities.

ericras’s picture

Title: group/{group}/node/create use's the permissions of group/{group}/node/add » group/{group}/node/create uses the permissions of group/{group}/node/add
bojan_dev’s picture

I was getting an notice (Undefined index: create_mode), on the membership group content. Also I have added the EntityHandlerInterface, so dependency injection would be available.

idebr’s picture

jnicola’s picture

Bringing my patch over from the duplicate.

Reviewing what's here versus what I wrote, I think what I wrote is probably the correct approach. That said, I'll let you all review and decide for yourselves.

Instead of having an if in checkCreateAccess, I adjust the check for just this page with a new method that is called. No route matching or any other jank such as that.

lemming’s picture

Adding the "create_mode" parameter to the GroupContentAccessControlHandler::checkCreateAccess() makes the most sense to me. This allows the checkCreateAccess() function in other contexts, other than ones where the route specifically manages this argument.

The access handler also calls the GroupContentEnablerInterface::definesEntityAccess() function to check if this group content plugin supports the separate set of group access for entity creation operations.

lemming’s picture

The last submitted patch, 10: group-content-create-mode-permission.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 10: group-content-create-mode-permission.patch, failed testing. View results

Amazee’s picture

Status: Needs work » Needs review
fskreuz’s picture

Patch #10 worked for me. Tested on a bare install of 8.7.1 against gnode as well as a custom entity plugin.

Feng-Shui’s picture

Patch #10 worked for me re gnode on 8.8.0-rc1.

LOBsTerr’s picture

Hey, I was trying to test in order to write the tests for this case, but I was able to reproduce it.
I have content type 'fff'. If I give permission "create group_node:fff content" for a member role, I can access group/[GID]/content/create/group_node%3Afff, but I can't access group/[GID]/content/add/group_node%3Afff.

And if I give permission "create group_node:fff entity" I can't access group/[GID]/content/add/group_node%3Afff, but I can access group/[GID]/content/create/group_node%3Afff.

So, it works as expected or I missing something?

jnicola’s picture

I think you got your can and can't mixed up in there... since all you have are can't statements?

LOBsTerr’s picture

@jnicola, my bad :( I have edited the comment. Briefly, I tried to debug it for me it works as expected. Could you tell what is your case? I have checked all comments above , the latest patches and also your post.

alternativo’s picture

Hi, I put patch#10 but I cannot see changes in permission to add existing node or create new one.
What I need is to have only the permission for members to create new nodes, and not to add relationship to existing nodes..
Is that possible?
I thought it was 'Relationship: Add entity relation' that 'Allows you to add an existing contenuto entity to the group.'...it is unchecked, but members can still add existing node ...

Thanks in advance
:)

idebr’s picture

There is an issue describing the same symptoms in #2842630: Empty page when trying to create group node.

kekkis’s picture

Rerolled patch against 8.x-1.x - the one in #10 applies cleanly to 8.x-1.0-rc5 but won't apply to the 8.x-1.x branch.

gnuget’s picture

Component: Group (group) » Code
Status: Needs review » Reviewed & tested by the community

I reviewed and tested this patch and looks good to me.

Thanks @kekkis!

Dubs’s picture

This patch works for me too - please can this be merged in?

SocialNicheGuru’s picture

deleted comment. meant for another issue.