Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Limiting sending private messages (I only want certain roles to be able to send them)?
martz
New
Is it possible to limit access to sending private messages to certain roles only?
I only want this option to be allowed for members who have a certain role. It is not an option in the role configuration dashboard, but hopefully there is a way to achieve this.
1
Comments
it would be tricky - because if someone sends a message to the inbox to someone without permission to read inbox - what do you do!(rhetorical question).
probably a mod to core or possibly a plugin (not by me).
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
It is purely meant for sending. So, that would make it a bit easier.
I think it could be done with a plugin, without having to touch the Core. Basically, this is what the plugin should do:
CanStartNewConversation
.newconversation.php
. It should be a copy of /applications/conversations/views/modules/newconversation.php, with an extra check at the beginning. In pseudocode, the check would be the followingif(User is not allowed to start a new Conversation) { display nothing }
. That would prevent the "Start a New Conversation" button from displaying.Now that the button is hidden, normal Users would not be able to click on it. However, they would still be able to access the New Discussion page by typing its URL. To prevent this, plugin should intercept the
Add()
action, but this requires a little trick.When a User clicks on "Start a New Conversation", "MessageController::Add()" is executed. Such method doesn't check permissions, nor does it call event handlers. Therefore, the plugin must prevent such method from running, unless User has proper permissions.
How to do it
MessagesController_NewConversation_Create()
. This method will perform the usual check, i.e. Is User allowed to start a new Conversation? and, if it passes, it will callMessageController::Add()
.Setup()
method, add the following route:Route: ^messages/add(/.*)?$
Destination: /messages/newconversation$1
Now, every time a User will open /messages/add, he will be routed to /messages/newconversation, which will execute the code in the plugin and display an error in case of lack of permissions.
Notes
Plugin::OnDisable()
method to remove the route added to "hijack" the Start a New Conversation process. Failing to do so, when the plugin is disabled, any attempt to start a new conversation would result in a Page not found error. Clean up after yourself is in the top ten of best practices.MessagesController::AssMessage()
, which is not altered.My shop | About Me
lol freudian slip?
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@businessdad Thanks! In this case, just hiding the button would be enough. On my forum I'm setting up a new role, in between guest and member. In that role you'll have limited functionality until you have proven yourself worthy. Normally you would only remain in that role for a few days.
@Lincoln - would it not be a nice addition to the core? More fine grained permissions are a must have for larger forums.
LOOOOL! I would say more of a sleepy-slip, it was very late when I wrote the post.
My shop | About Me