Page MenuHomePhabricator

D6858.diff
No OneTemporary

D6858.diff

diff --git a/services/feature-flags/src/main.rs b/services/feature-flags/src/main.rs
--- a/services/feature-flags/src/main.rs
+++ b/services/feature-flags/src/main.rs
@@ -5,6 +5,7 @@
pub mod config;
pub mod constants;
pub mod database;
+pub mod service;
fn configure_logging() -> Result<()> {
let filter = EnvFilter::builder()
diff --git a/services/feature-flags/src/service.rs b/services/feature-flags/src/service.rs
new file mode 100644
--- /dev/null
+++ b/services/feature-flags/src/service.rs
@@ -0,0 +1,57 @@
+use crate::database::{DatabaseClient, FeatureConfig, Platform};
+use comm_services_lib::database::Error;
+use std::collections::HashSet;
+
+pub struct FeatureFlagsService {
+ _db: DatabaseClient,
+}
+
+impl FeatureFlagsService {
+ pub fn new(db_client: DatabaseClient) -> Self {
+ FeatureFlagsService { _db: db_client }
+ }
+
+ pub async fn _enabled_features_set(
+ db: &DatabaseClient,
+ platform: Platform,
+ code_version: i32,
+ is_staff: bool,
+ ) -> Result<HashSet<String>, Error> {
+ let features_config = db.get_features_configuration(platform).await?;
+ Ok(
+ features_config
+ .into_values()
+ .filter_map(|config| {
+ Self::_feature_name_if_enabled(code_version, is_staff, config)
+ })
+ .collect(),
+ )
+ }
+
+ fn _feature_name_if_enabled(
+ code_version: i32,
+ is_staff: bool,
+ feature_config: FeatureConfig,
+ ) -> Option<String> {
+ feature_config
+ .config
+ .keys()
+ .filter(|version| *version <= &code_version)
+ .max()
+ .and_then(|version| feature_config.config.get(version))
+ .map(|config| {
+ if is_staff {
+ config.staff
+ } else {
+ config.non_staff
+ }
+ })
+ .and_then(|is_enabled| {
+ if is_enabled {
+ Some(feature_config.name)
+ } else {
+ None
+ }
+ })
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 12:41 AM (21 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595289
Default Alt Text
D6858.diff (1 KB)

Event Timeline