The privatemsg_roles module does not implement the privatemsg hook to block messages (hook_privatemsg_block_message). This means that you cannot check whether a user can send messages to the role group in the same way you can other recipient types (by using module_invoke_all on that hook).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arithmetric’s picture

Status: Active » Needs review
FileSize
946 bytes

Attached is a patch for the privatemsg module that adds this hook to privatemsg_roles.

arithmetric’s picture

Updating the patch to clean up the PHP warnings in the test.

Berdir’s picture

There is a API function to check recipient type access: http://api.worldempire.ch/api/privatemsg/privatemsg.module/function/priv....

There is however now API function which does all necessary checks to verify if A can write B a message. There is http://api.worldempire.ch/api/privatemsg/privatemsg.module/function/priv... but it's not going to work for roles correctly.

My suggestion would be to extract a generic privatemsg_can_write($author, $recipient) (maybe a better name, maybe multiple recipients) function and use that in privatemsg_get_link(). There are probably also other places where we could use this. Because your patch means that any recipient type would need to implement this hook which is IMHO unecessary code duplication.

arithmetric’s picture

Fair enough... So in the generic function, we'd need a combination of privatemsg_recipient_access() for the recipient type access checks and an invocation of hook_privatemsg_block_message() for any modules that implement it?

Berdir’s picture

Yes exactly. And additionally a privatemsg_user_access('write privatemsg', $author) might make sense, similar to what privatemsg_get_link() does too. We loose a bit of performance when calling the function multiple times like it could happen in privatemsg_get_link() but it should be minimal and usually the function is only used for a single recipient anyway.

Status: Needs review » Needs work

The last submitted patch, privatemsg-1296372-2-roles_block_hook.patch, failed testing.

oadaeh’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.