Skip to content

Commit

Permalink
Add NoAccess gate
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan committed Jul 23, 2024
1 parent 7dc7c88 commit 6c2414c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/canisters/group_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ pub struct AccessGateMetrics {
pub token_balance: u32,
#[serde(default)]
pub composite: u32,
#[serde(default)]
pub no_access: u32,
}

impl AccessGateMetrics {
Expand All @@ -393,6 +395,7 @@ impl AccessGateMetrics {
AccessGate::Payment(_) => self.payment += 1,
AccessGate::TokenBalance(_) => self.token_balance += 1,
AccessGate::Composite(_) => self.composite += 1,
AccessGate::NoAccess => self.no_access += 1,
}
}
}
1 change: 1 addition & 0 deletions backend/libraries/gated_groups/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async fn check_non_composite_gate(gate: AccessGate, args: CheckGateArgs) -> Chec
AccessGate::Payment(g) => try_transfer_from(&g, args.user_id, args.this_canister, args.now).await,
AccessGate::TokenBalance(g) => check_token_balance_gate(&g, args.user_id).await,
AccessGate::Composite(_) => unreachable!(),
AccessGate::NoAccess => CheckIfPassesGateResult::Failed(GateCheckFailedReason::NoAccessGate),
}
}

Expand Down
2 changes: 2 additions & 0 deletions backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ type AccessGate = variant {
inner : vec AccessGate;
and : bool;
};
NoAccess;
};

type AccessGateUpdate = variant {
Expand Down Expand Up @@ -1577,6 +1578,7 @@ type GateCheckFailedReason = variant {
PaymentFailed : ICRC2_TransferFromError;
InsufficientBalance : nat;
FailedVerifiedCredentialCheck : text;
NoAccessGate;
};

type VerifiedCredentialGateArgs = record {
Expand Down
3 changes: 3 additions & 0 deletions backend/libraries/types/src/gated_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum AccessGate {
Payment(PaymentGate),
TokenBalance(TokenBalanceGate),
Composite(CompositeGate),
NoAccess,
}

impl AccessGate {
Expand Down Expand Up @@ -45,6 +46,7 @@ impl AccessGate {
AccessGate::Payment(_) => "payment",
AccessGate::TokenBalance(_) => "token_balance",
AccessGate::Composite(_) => "composite",
AccessGate::NoAccess => "no_access",
}
}
}
Expand Down Expand Up @@ -101,6 +103,7 @@ pub enum GateCheckFailedReason {
PaymentFailed(TransferFromError),
InsufficientBalance(u128),
FailedVerifiedCredentialCheck(String),
NoAccessGate,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
Expand Down

0 comments on commit 6c2414c

Please sign in to comment.