Skip to content

Commit fe24b41

Browse files
committed
feat: Permission::is_allowed() as convenience method (#450)
1 parent 33f8b92 commit fe24b41

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

git-sec/src/permission.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ where
2727
impl<R> std::error::Error for Error<R> where R: std::fmt::Debug {}
2828

2929
impl Permission {
30+
/// Return true if this instance is `Permission::Allow`.
31+
pub fn is_allowed(&self) -> bool {
32+
matches!(self, Permission::Allow)
33+
}
3034
/// Check this permissions and produce a reply to indicate if the `resource` can be used and in which way.
3135
///
3236
/// Only if this permission is set to `Allow` will the resource be usable.

git-sec/tests/sec.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ mod permission {
2525
assert_eq!(Permission::Deny.check_opt("hi"), None);
2626
assert_eq!(Permission::Forbid.check_opt("hi"), None);
2727
}
28+
29+
#[test]
30+
fn is_allowed() {
31+
assert!(Permission::Allow.is_allowed());
32+
assert!(!Permission::Deny.is_allowed());
33+
assert!(!Permission::Forbid.is_allowed());
34+
}
2835
}
2936

3037
mod identity;

0 commit comments

Comments
 (0)