Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Disable / turn off direct messages #7073

Closed
george-angel opened this issue Mar 13, 2020 · 6 comments
Closed

Disable / turn off direct messages #7073

george-angel opened this issue Mar 13, 2020 · 6 comments

Comments

@george-angel
Copy link

Description:

Hello, we have a rather specific use-case where we would like to use matrix internally for teams in the company, but we would like to only allow room conversations, no direct messages (apart from few select members may be).

Is this at all possible? Happy to hear any hacky solution you might have.

Currently we are looking to use Slack and to drop packages on the firewall where URI matches structures of a DM.

So yes, you could say we are flexible.

@ara4n
Copy link
Member

ara4n commented Mar 13, 2020

Yes, you can do this by forbidding users on the server to issue invites; only to join rooms. The antispam module API in synapse has a can_invite hook which you can return false in.

@george-angel
Copy link
Author

Brilliant - thank you very much.

@a-fellerer
Copy link

@george-angel Can you describe how you did that?

Did @ara4n mean "block_invites:true" in mjolnir.AntiSpam or something else?

@george-angel
Copy link
Author

@Chatcloud we didn't end up using this, but looking through past commits this is the code used in the PoC:

spam.py:

import logging

logger = logging.getLogger(__name__)


class Checker:
    def __init__(self, config, api):
        self.config = config
        self.api = api

    def check_event_for_spam(self, foo):
        return False  # allow all events

    def user_may_invite(self, inviter_userid, invitee_userid, room_id):
        """
        prevent users from inviting others to rooms unless they are in the
        configured list of admins

        this is primarily done to block users from initiating direct messages
        """
        if inviter_userid in self.config["admins"]:
            return True
        return False

    def user_may_create_room(self, userid):
        return True  # allow all room creations

    def user_may_create_room_alias(self, userid, room_alias):
        return True  # allow all room aliases

    def user_may_publish_room(self, userid, room_id):
        return True  # allow publishing of all rooms

    def check_username_for_spam(self, user_profile):
        return False  # allow all usernames

    @staticmethod
    def parse_config(config):
        return config

@phewitt-uw
Copy link

@Chatcloud - I have used a similar variation of the above spam file as well, but in our case we preferred to set "create_room" to false for non-admin users as this would prevent a DM from being created as well (a DM is effectively a room with only 2 people in it). This would mean that users can still invite other users to a room they are members in, BUT the caveat is that your admins will have to then create/manage the rooms and their members directly.

@a-fellerer
Copy link

@phewitt-uw that sounds good. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants