But this client also wants to disable private messages for at least most users, so that won’t work. (I tried )
One solution would be a site setting that would allow users to be able to send PMs to staff.
Perhaps I’m missing something, bu tI’m afraid the other solutions all require a plugin or some other app. (e.g., Canned replies works only for staff, right?)
If I’m reading you right, you want to restrict the target of pms to staff only?
You could do this relatively easily in a standalone plugin. The plugin.rb would read:
# name: only-pms-to-staff
# about: You can only send pms to staff
# version: 0.1
# authors: pfaffman
after_initialize do
add_to_class('guardian', :can_send_private_message?) do |target|
target.is_a?(User) &&
# User is authenticated
authenticated? &&
# Have to be a basic level at least
@user.has_trust_level?(SiteSetting.min_trust_to_send_messages) &&
# User disabled private message
(is_staff? || target.user_option.allow_private_messages) &&
# PMs are enabled
(is_staff? || SiteSetting.enable_private_messages) &&
# Can only send pms to staff
target.staff?
end
end
Here’s what I ended up with. If I were better at understanding the distributed properties of and and or, I’d have moved target.staff? outside of those three expressions, but this seems to do what I wanted. My scant tests show that it allows sending to an admin and if you send to an admin and another user, it is denied.
after_initialize do
add_to_class('guardian', :can_send_private_message?) do |target|
target.is_a?(User) &&
# User is authenticated
authenticated? &&
# Have to be a basic level at least
(target.staff? || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) &&
# User disabled private message
(target.staff? || is_staff? || target.user_option.allow_private_messages) &&
# PMs are enabled
(target.staff? || is_staff? || SiteSetting.enable_private_messages)
end
end
it doesn’t quite meet my standards for posting to #plugins just yet, but if anyone stumbles here and wants to do this, here’s this:
Any user who has the min trust level to send a pm, to send a message to any other user who has not disabled pms, regardless of whether or not they are staff.
The first alternative, i.e. target.staff?, is redundant, as the last alternative will always be true as long as pms are turned on.
The is_staff? check here is used to ensure that staff members can still perform an action even if that action is disabled (this is normal practice in the Discourse code). Keep those two as the only alternatives in that line, i.e.
There was an issue with my initial code, as it didn’t allow staff members to send messages to non-staff members. The way to fix that is by adding the is_staff? check to that line specifically, i.e.
(is_staff? || target.staff)
Any user of any trust level to send a message to a staff member (e.g. immediately after joining).
private messages are enabled (and they’re not for this site, which is what I’m trying to solve)
And I (or this client) want everyone to be able to send to staff.
Hooray! That’s what I wanted! (Of course, it could prove to be a problem, but we can solve it when there is one) It’s good advice to change that to TL1, though. I made a note of that too.
Ah, that’s (but one of the reasons) why I don’t think anyone should use this. For this site, I’m sure that no staff will be disallowing PMs. I should probably fix this one. I added a comment to remind me to do so when I can “test” – not to be confused with writing a proper test! (Or maybe I want to make sure that a staff member who needs to receive these messages doesn’t inadvertently disable PMs – A documented bug is a feature!)
Thanks again, @angus! A couple more trivial plugins under my belt and I might do something useful!
Prevent the user from taking the notify_user and notify_moderator post actions (see here). These post actions require private messages.
And there may be more instances of that setting being used to disable functionality in the future.
If I’m reading you right, your case is one of permissions, not one of functionality? You still want the functionality, just a restricted version of it.
edit: re-reading your first post, maybe you do want to disable the functionality entirely! Well at least we thought this through.
This is how my naive solution is so lucky! The plan is to use a URL to generate the initial message, so not being able to see the PM interface is a bonus!
That’s pretty fine too, as this is basically doing the same thing as using a Google form would be. It’s mostly for a one-way initiation of a conversation. I should check what happens if someone replies to the PM, though.
Ah, yes. The Royal “We”. Thanks very much for your help. You’ve taught me a lot and I appreciate it.
Estoy teniendo un problema similar que se resolvería de manera muy sencilla evitando los mensajes directos (PM) normales de 1 a 1. Es una organización de voluntarios y necesitan que los voluntarios se comuniquen con los coordinadores, pero idealmente no entre ellos mismos.
El plugin mencionado anteriormente (https://github.com/pfaffman/discourse-allow-pm-to-staff) funciona. No hago ninguna promesa, pero el cliente que lo encargó aún lo utiliza, por lo que se mantiene activamente e incluso cuenta con pruebas que se ejecutan en travis.
Entiendo que esto se proporcionó de forma gratuita sin garantías, lo cual es muy apreciado.
Solo para avisar, parece que actualmente no está funcionando. A menos que haya configurado algo incorrectamente, el plugin está instalado y activado.
Lo he probado con ‘confianza mínima para enviar mensajes’ establecido en 1, con un usuario TL0 intentando enviar un mensaje privado a un miembro del personal. También con ‘confianza mínima para enviar mensajes’ establecido en 2, con un usuario TL1 intentando enviar un mensaje privado a un miembro del personal.
En ambos casos, el botón de mensaje privado estaba oculto en los perfiles del personal para la cuenta de usuario regular si su nivel de confianza estaba por debajo del ajuste de ‘confianza mínima para enviar mensajes’. La recepción de mensajes privados también está habilitada en la configuración del usuario del personal destinatario.
Este es mi caso, tanto para la versión estable 2.5.0 como para la 2.6.0.beta1 (pruebas superadas).
En la versión estable también probé redactar manualmente un mensaje desde la página /u/username/messages e ingresar al miembro del personal como destinatario, pero el mensaje fue rechazado al enviarse.
Bueno, parece que está funcionando en mi instancia de desarrollo con 2.6.0.beta1 y también en una instancia de producción con 2.5.0.beta4, y los tests en Travis siguen aprobando.
Mi única suposición es que no funciona para multisitio y ¿estás ejecutando multisitio?
¡Qué bueno saber que funciona! Quizás me esté perdiendo algo obvio. Esto no era en multisitios, solo instalaciones estándar de Docker.
Los pasos seguidos fueron:
Instalar el plugin desde https://github.com/pfaffman/discourse-allow-pm-to-staff.git. No activé específicamente este plugin ni configuré ninguna opción específica del mismo. Sin embargo, en /admin/plugins aparece ‘enabled?’ establecido en S.
Ajustar ‘mínimo nivel de confianza para enviar mensajes’ y probar con una cuenta de usuario regular que esté por debajo del nivel de confianza seleccionado, intentando enviar mensajes al personal.
Intenté eliminar todos los plugins excepto este en la versión estable 2.5.0, por si había algún conflicto, pero no hizo ninguna diferencia.
No personalicé/configuré las pruebas de Travis, así que parece que eso impedía que el plugin funcionara.
Así que probé a eliminar todo excepto el archivo plugin.rb y empezó a funcionar para mí. También modifiqué ligeramente la lógica para mi caso de uso.
En su estado actual, los usuarios con nivel de confianza TL0+ pueden enviar mensajes a un administrador si su nivel de confianza cae por debajo del ‘mínimo de confianza para enviar mensajes’ configurado, pero no pueden enviar mensajes a un moderador.
Para modificar esto, hay que cambiar esta sección muy ligeramente (¡gracias por los comentarios claros ):
# Debe ser al menos un nivel básico -- y ahora: O ENVIANDO A UN ADMINISTRADOR
(is_group || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages) || notify_moderators || target.admin) &&
Si quieres permitir enviar mensajes a cualquier miembro del personal (que no haya desactivado específicamente la recepción de mensajes privados), cámbialo a:
# Debe ser al menos un nivel básico -- y ahora: O ENVIANDO A UN MIEMBRO DEL PERSONAL
(is_group || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages) || notify_moderators || target.staff?) &&
Si quieres habilitar el envío de mensajes solo a moderadores y no a administradores:
# Debe ser al menos un nivel básico -- y ahora: O ENVIANDO A UN MODERADOR
(is_group || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages) || notify_moderators || target.moderator) &&