Skip to content

Commit

Permalink
subscription: deprecate field setters in ClientFilter
Browse files Browse the repository at this point in the history
This was used only by the CLI interface, which is deprecated.
Subscriptions are now config files, which represents the current state,
so no modifier methods are required.
  • Loading branch information
MrAnno committed Dec 11, 2024
1 parent ac62565 commit ad83fa7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cli/src/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,15 @@ async fn edit_filter(subscription: &mut SubscriptionData, matches: &ArgMatches)

match matches.subcommand() {
Some(("add", matches)) => {
#[allow(deprecated)]
filter.add_target(
matches
.get_one::<String>("principal")
.ok_or_else(|| anyhow!("Missing principal"))?,
)?;
}
Some(("delete", matches)) => {
#[allow(deprecated)]
filter.delete_target(
matches
.get_one::<String>("principal")
Expand All @@ -648,6 +650,7 @@ async fn edit_filter(subscription: &mut SubscriptionData, matches: &ArgMatches)
for identifier in identifiers {
princs.insert(identifier.clone());
}
#[allow(deprecated)]
filter.set_targets(princs)?;
}
None => {
Expand Down
21 changes: 17 additions & 4 deletions common/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub mod tests {
};

use super::{schema::Migrator, *};
use std::{collections::HashSet, thread::sleep, time::Duration, time::SystemTime};
use std::{collections::HashSet, thread::sleep, time::{Duration, SystemTime}};

async fn setup_db(db: Arc<dyn Database>) -> Result<()> {
db.setup_schema().await?;
Expand Down Expand Up @@ -272,9 +272,19 @@ pub mod tests {
.set_ignore_channel_error(true)
.set_revision(Some("1890".to_string()))
.set_data_locale(Some("fr-FR".to_string()));
let mut new_client_filter = tata.client_filter().cloned();
new_client_filter.as_mut().unwrap().add_target("semoule")?;
tata.set_client_filter(new_client_filter);


let orig_filter = &tata.client_filter().unwrap();
let mut new_targets: HashSet<String> = orig_filter.targets().iter().map(|&f| f.to_owned()).collect();
new_targets.insert("semoule".to_owned());

let new_client_filter = ClientFilter::try_new(orig_filter.operation().clone(),
orig_filter.kind().clone(),
orig_filter.flags().clone(),
new_targets
)?;

tata.set_client_filter(Some(new_client_filter));

db.store_subscription(&tata).await?;

Expand Down Expand Up @@ -313,7 +323,10 @@ pub mod tests {
assert!(tata2.public_version()? != tata_save.public_version()?);

let mut new_client_filter = tata2.client_filter().cloned();

#[allow(deprecated)]
new_client_filter.as_mut().unwrap().delete_target("couscous")?;
#[allow(deprecated)]
new_client_filter.as_mut().unwrap().set_operation(ClientFilterOperation::Except);
tata2.set_client_filter(new_client_filter);

Expand Down
4 changes: 4 additions & 0 deletions common/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,21 @@ impl ClientFilter {
}
}

#[deprecated(since = "0.4.0", note = "This should be used only by the legacy CLI interface. Use ClientFilter constructors instead")]
pub fn add_target(&mut self, target: &str) -> Result<()> {
self.targets.insert(target.to_owned());
Ok(())
}

#[deprecated(since = "0.4.0", note = "This should be used only by the legacy CLI interface. Use ClientFilter constructors instead")]
pub fn delete_target(&mut self, target: &str) -> Result<()> {
if !self.targets.remove(target) {
warn!("{} was not present in the targets set", target)
}
Ok(())
}

#[deprecated(since = "0.4.0", note = "This should be used only by the legacy CLI interface. Use ClientFilter constructors instead")]
pub fn set_targets(&mut self, targets: HashSet<String>) -> Result<()> {
self.targets = targets;
Ok(())
Expand All @@ -305,6 +308,7 @@ impl ClientFilter {
&self.operation
}

#[deprecated(since = "0.4.0", note = "This should be used only by the legacy CLI interface. Use ClientFilter constructors instead")]
pub fn set_operation(&mut self, operation: ClientFilterOperation) {
self.operation = operation;
}
Expand Down

0 comments on commit ad83fa7

Please sign in to comment.