- Issue created by @marco5775
- π¨π¦Canada Jaypan
I've figured out why this is happening. There is no access control handler for message entities, so the access result is Neutral. The ECA module treats access result neutral as access denied.
The solution is to implement hook_ENTITY_TYPE_create_access(). However, I was setting the fields on the entity as well in ECA, and when you set a field value, it also checks hook_ENTITY_TYPE_access() for the operation 'update', so you need to return an access result for that as well.
The below is very rudimentary - but is enough for testing purposes. Adapt your actual results as necessary.
/** * Implements hook_ENTITY_TYPE_create_access(). */ function pod_message_create_accesshook_ENTITY_TYPE_create_access(\Drupal\Core\Session\AccountInterface $account, array $context, $entity_bundle) { return AccessResult::allowed(); } /** * Implements hook_ENTITY_TYPE_create_access(). */ function pod_message_access(EntityInterface $entity, $operation, AccountInterface $account) { if ($operation == 'update') { return AccessResult::allowed(); } }
For the Message module moderators, this problem could be solved if the Message entity had an access control handler, and dynamic permissions per message template type, as users would then be able to set access permissions on entities, rather than the default access handler that just returns neutral.
- πΊπΈUnited States bluegeek9
Hi @Jaypan,
Have you tried using the Message UI β module? It provides additional permissions.
This might be related to π JSON:API PATCH request wants permission that doesn't exist? Fixed .
You might need to run the dev branch. I plan to make a new release of Message UI in two weeks.
- Status changed to Postponed
10 months ago 11:53pm 17 January 2024 - πΊπΈUnited States bluegeek9
There is no create permission because creating a message is done in response to an event, and the user is not relevant if a message is created or not.
- π¨π¦Canada Jaypan
There is no create permission because creating a message is done in response to an event, and the user is not relevant if a message is created or not.
It shouldn't be, yet this issue shows that the user is in fact relevant - hence the access denied error when a script tries to create a message, due to the current user being anonymous.
- πΊπΈUnited States bluegeek9
ECA requires the user to have create permission. Message is intended to be extended with custom code. It does not provide out-of-the-box functionality. It does provide an example module to help you write your own.
The user does not go to a form to create a message. Messages are created with code.
- πΊπΈUnited States bluegeek9
ECA Message β is a project that handles integration with ECA.
It says it exists until an issue with ECA is resolved.
- π¨π¦Canada Jaypan
That module does the same thing I did earlier in this thread - sets an access result on message entity access.
- πΊπΈUnited States bluegeek9
Message Notify ECA β might be another solution.
- πΊπΈUnited States SocialNicheGuru
please view the following for access control handling π Create access control handler and create permision Needs review
- Status changed to Closed: duplicate
3 months ago 6:44pm 7 September 2024 - π¨π¦Canada Jaypan
Duplicate of https://www.drupal.org/project/message/issues/2916602 π Create access control handler and create permision Needs review