diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index e3f0d99a3f..7f9eef227f 100755 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -555,6 +555,21 @@ def run(hs): clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000) # End of monthly active user settings + if hs.config.autocreate_support_user: + localpart = hs.config.autocreate_support_user['localpart'] + password = hs.config.autocreate_support_user['password'] + user_id = UserID(localpart, hs.hostname).to_string() + # check not already created + support_user = yield hs.get_datastore().get_users_by_id_case_insensitive(user_id) + # if not create + if not support_user: + registration_handler = hs.get_handlers().registration_handler + (user_id, token) = yield registration_handler.register( + localpart=localpart, + password=password, + ) + + if hs.config.report_stats: logger.info("Scheduling stats reporting for 3 hour intervals") clock.looping_call(start_phone_stats_home, 3 * 60 * 60 * 1000) diff --git a/synapse/config/server.py b/synapse/config/server.py index c1c7c0105e..e045edd5cd 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -86,6 +86,8 @@ class ServerConfig(Config): "mau_trial_days", 0, ) + self.autocreate_support_user = config.get('autocreate_support_user', None) + # Options to disable HS self.hs_disabled = config.get("hs_disabled", False) self.hs_disabled_message = config.get("hs_disabled_message", "") diff --git a/synapse/storage/monthly_active_users.py b/synapse/storage/monthly_active_users.py index 0fe8c8e24c..0cb08b0884 100644 --- a/synapse/storage/monthly_active_users.py +++ b/synapse/storage/monthly_active_users.py @@ -33,6 +33,8 @@ class MonthlyActiveUsersStore(SQLBaseStore): self._clock = hs.get_clock() self.hs = hs self.reserved_users = () + localpart = self.hs.config.autocreate_support_user['localpart'] + self.support_user = UserId(localpart, hs.hostName).to_sting() @defer.inlineCallbacks def initialise_reserved_users(self, threepids): @@ -172,6 +174,9 @@ class MonthlyActiveUsersStore(SQLBaseStore): Deferred[bool]: True if a new entry was created, False if an existing one was updated. """ + # Support user never to be included in MAU stats + if user_id is self.support_user: + return False # Am consciously deciding to lock the table on the basis that is ought # never be a big table and alternative approaches (batching multiple # upserts into a single txn) introduced a lot of extra complexity. diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py index a8781b0e5d..b8981cdb6d 100644 --- a/synapse/storage/user_directory.py +++ b/synapse/storage/user_directory.py @@ -86,6 +86,9 @@ class UserDirectoryStore(SQLBaseStore): users_with_profile (dict): Users to add to directory in the form of mapping of user_id -> ProfileInfo """ + # TODO Filter out support user + + if isinstance(self.database_engine, PostgresEngine): # We weight the loclpart most highly, then display name and finally # server name