Skip to content

Commit

Permalink
subscription: extract PrincsFilter::eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAnno committed Nov 1, 2024
1 parent 04d0a83 commit 59630e8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions common/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ impl PrincsFilter {
})
}

pub fn eval(&self, principal: &str) -> bool {
match self.operation {
None => true,
Some(PrincsFilterOperation::Only) => self.princs.contains(principal),
Some(PrincsFilterOperation::Except) => !self.princs.contains(principal),
}
}

pub fn princ_literals(&self) -> &HashSet<String> {
&self.princs
}
Expand Down Expand Up @@ -811,13 +819,7 @@ impl SubscriptionData {
return false;
}

match self.princs_filter().operation {
None => true,
Some(PrincsFilterOperation::Only) => self.princs_filter().princ_literals().contains(principal),
Some(PrincsFilterOperation::Except) => {
!self.princs_filter().princ_literals().contains(principal)
}
}
self.princs_filter().eval(principal)
}

pub fn revision(&self) -> Option<&String> {
Expand Down

0 comments on commit 59630e8

Please sign in to comment.