summary refs log tree commit diff
diff options
context:
space:
mode:
authorH. Shay <hillerys@element.io>2023-05-01 14:24:49 -0700
committerH. Shay <hillerys@element.io>2023-05-01 21:01:58 -0700
commitf9e7a0a3a4ccb918a9afaf8ed261350a02628f45 (patch)
tree5fd29eb8adfbe300bc110c7b68bc0c48c57fd8c5
parentre-add parameters to test (diff)
downloadsynapse-f9e7a0a3a4ccb918a9afaf8ed261350a02628f45.tar.xz
add a db function to tell if just one feature is enabled
-rw-r--r--synapse/storage/databases/main/experimental_features.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/experimental_features.py b/synapse/storage/databases/main/experimental_features.py
index cf3226ae5a..f88598794a 100644
--- a/synapse/storage/databases/main/experimental_features.py
+++ b/synapse/storage/databases/main/experimental_features.py
@@ -73,3 +73,35 @@ class ExperimentalFeaturesStore(CacheInvalidationWorkerStore):
             )
 
             await self.invalidate_cache_and_stream("list_enabled_features", (user,))
+
+    async def get_feature_enabled(self, user_id: str, feature: str) -> bool:
+        """
+        Checks to see if a given feature is enabled for the user
+        Args:
+            user:
+                the user to be queried on
+            feature:
+                the feature in question
+        Returns:
+                True if the feature is enabled, False if it is not or if the feature was
+                not found.
+        """
+
+        res = await self.db_pool.simple_select_one(
+            "per_user_experimental_features",
+            {"user_id": user_id, "feature": feature},
+            ["enabled"],
+            allow_none=True,
+        )
+
+        if not res:
+            res = {"enabled": False}
+
+        # Deal with Sqlite boolean return values
+        if res["enabled"] == 0:
+            res["enabled"] = False
+        if res["enabled"] == 1:
+            res["enabled"] = True
+
+        return res["enabled"]
+>>>>>>> 6c2267f83d... add a db function to tell if just one feature is enabled