From 6c2414cf24f42317c0157e1f7f311d445c967f6c Mon Sep 17 00:00:00 2001 From: megrogan Date: Tue, 23 Jul 2024 12:19:40 +0100 Subject: [PATCH 1/3] Add `NoAccess` gate --- backend/canisters/group_index/impl/src/lib.rs | 3 +++ backend/libraries/gated_groups/src/lib.rs | 1 + backend/libraries/types/can.did | 2 ++ backend/libraries/types/src/gated_groups.rs | 3 +++ 4 files changed, 9 insertions(+) diff --git a/backend/canisters/group_index/impl/src/lib.rs b/backend/canisters/group_index/impl/src/lib.rs index 410e8e1160..5d6f9ee442 100644 --- a/backend/canisters/group_index/impl/src/lib.rs +++ b/backend/canisters/group_index/impl/src/lib.rs @@ -380,6 +380,8 @@ pub struct AccessGateMetrics { pub token_balance: u32, #[serde(default)] pub composite: u32, + #[serde(default)] + pub no_access: u32, } impl AccessGateMetrics { @@ -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, } } } diff --git a/backend/libraries/gated_groups/src/lib.rs b/backend/libraries/gated_groups/src/lib.rs index b890156763..ee6190095b 100644 --- a/backend/libraries/gated_groups/src/lib.rs +++ b/backend/libraries/gated_groups/src/lib.rs @@ -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), } } diff --git a/backend/libraries/types/can.did b/backend/libraries/types/can.did index 19f12e6b8e..75518c2bbb 100644 --- a/backend/libraries/types/can.did +++ b/backend/libraries/types/can.did @@ -1526,6 +1526,7 @@ type AccessGate = variant { inner : vec AccessGate; and : bool; }; + NoAccess; }; type AccessGateUpdate = variant { @@ -1577,6 +1578,7 @@ type GateCheckFailedReason = variant { PaymentFailed : ICRC2_TransferFromError; InsufficientBalance : nat; FailedVerifiedCredentialCheck : text; + NoAccessGate; }; type VerifiedCredentialGateArgs = record { diff --git a/backend/libraries/types/src/gated_groups.rs b/backend/libraries/types/src/gated_groups.rs index 01b6e0ed52..3d844d467e 100644 --- a/backend/libraries/types/src/gated_groups.rs +++ b/backend/libraries/types/src/gated_groups.rs @@ -16,6 +16,7 @@ pub enum AccessGate { Payment(PaymentGate), TokenBalance(TokenBalanceGate), Composite(CompositeGate), + NoAccess, } impl AccessGate { @@ -45,6 +46,7 @@ impl AccessGate { AccessGate::Payment(_) => "payment", AccessGate::TokenBalance(_) => "token_balance", AccessGate::Composite(_) => "composite", + AccessGate::NoAccess => "no_access", } } } @@ -101,6 +103,7 @@ pub enum GateCheckFailedReason { PaymentFailed(TransferFromError), InsufficientBalance(u128), FailedVerifiedCredentialCheck(String), + NoAccessGate, } #[derive(CandidType, Serialize, Deserialize, Clone, Debug)] From c68f8e5304765ff5123ad3d67578e436d7d7db95 Mon Sep 17 00:00:00 2001 From: megrogan Date: Tue, 23 Jul 2024 13:02:37 +0100 Subject: [PATCH 2/3] CHANGELOGs --- backend/canisters/community/CHANGELOG.md | 4 ++++ backend/canisters/group/CHANGELOG.md | 4 ++++ backend/canisters/group_index/CHANGELOG.md | 4 ++++ backend/canisters/local_group_index/CHANGELOG.md | 4 ++++ backend/canisters/local_user_index/CHANGELOG.md | 1 + backend/canisters/user/CHANGELOG.md | 4 ++++ 6 files changed, 21 insertions(+) diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index 534839dde3..ddbb57c71f 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Added + +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) + ### Changed - Fix fee then retry transfer if fee too high ([#6063](https://github.com/open-chat-labs/open-chat/pull/6063)) diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 3ccdd6f671..2fb08131c5 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Added + +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) + ### Changed - Fix fee then retry transfer if fee too high ([#6063](https://github.com/open-chat-labs/open-chat/pull/6063)) diff --git a/backend/canisters/group_index/CHANGELOG.md b/backend/canisters/group_index/CHANGELOG.md index b4109dabb2..c73961f76b 100644 --- a/backend/canisters/group_index/CHANGELOG.md +++ b/backend/canisters/group_index/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Added + +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) + ### Changed - Clear old data from the failed upgrades log ([#6062](https://github.com/open-chat-labs/open-chat/pull/6062)) diff --git a/backend/canisters/local_group_index/CHANGELOG.md b/backend/canisters/local_group_index/CHANGELOG.md index b80c4055b3..7c68ae2c58 100644 --- a/backend/canisters/local_group_index/CHANGELOG.md +++ b/backend/canisters/local_group_index/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Added + +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) + ### Changed - Clear old data from the failed upgrades log ([#6062](https://github.com/open-chat-labs/open-chat/pull/6062)) diff --git a/backend/canisters/local_user_index/CHANGELOG.md b/backend/canisters/local_user_index/CHANGELOG.md index 4c9ec52246..b6d420c84b 100644 --- a/backend/canisters/local_user_index/CHANGELOG.md +++ b/backend/canisters/local_user_index/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Support submitting proof of uniqueness to LocalUserIndex ([#6068](https://github.com/open-chat-labs/open-chat/pull/6068)) - Support submitting proof of diamond membership to LocalUserIndex ([#6084](https://github.com/open-chat-labs/open-chat/pull/6084)) +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/user/CHANGELOG.md b/backend/canisters/user/CHANGELOG.md index 9d00b748be..7dc26684c7 100644 --- a/backend/canisters/user/CHANGELOG.md +++ b/backend/canisters/user/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Added + +- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) + ### Changed - Improve check for empty and dormant users ([#6073](https://github.com/open-chat-labs/open-chat/pull/6073)) From 48f7f9646b309e3fc0983d70abaa6c148c7e97e4 Mon Sep 17 00:00:00 2001 From: megrogan Date: Tue, 23 Jul 2024 13:48:15 +0100 Subject: [PATCH 3/3] Rename NoAccess -> Locked --- backend/canisters/community/CHANGELOG.md | 2 +- backend/canisters/group/CHANGELOG.md | 2 +- backend/canisters/group_index/CHANGELOG.md | 2 +- backend/canisters/group_index/impl/src/lib.rs | 4 ++-- backend/canisters/local_group_index/CHANGELOG.md | 2 +- backend/canisters/local_user_index/CHANGELOG.md | 2 +- backend/canisters/user/CHANGELOG.md | 2 +- backend/libraries/gated_groups/src/lib.rs | 2 +- backend/libraries/types/can.did | 4 ++-- backend/libraries/types/src/gated_groups.rs | 6 +++--- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index ddbb57c71f..6b1fcc02c2 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 2fb08131c5..d18b864548 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/group_index/CHANGELOG.md b/backend/canisters/group_index/CHANGELOG.md index c73961f76b..d44140fb3a 100644 --- a/backend/canisters/group_index/CHANGELOG.md +++ b/backend/canisters/group_index/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/group_index/impl/src/lib.rs b/backend/canisters/group_index/impl/src/lib.rs index 5d6f9ee442..c196300b39 100644 --- a/backend/canisters/group_index/impl/src/lib.rs +++ b/backend/canisters/group_index/impl/src/lib.rs @@ -381,7 +381,7 @@ pub struct AccessGateMetrics { #[serde(default)] pub composite: u32, #[serde(default)] - pub no_access: u32, + pub locked: u32, } impl AccessGateMetrics { @@ -395,7 +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, + AccessGate::Locked => self.locked += 1, } } } diff --git a/backend/canisters/local_group_index/CHANGELOG.md b/backend/canisters/local_group_index/CHANGELOG.md index 7c68ae2c58..fd1b0ef212 100644 --- a/backend/canisters/local_group_index/CHANGELOG.md +++ b/backend/canisters/local_group_index/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/local_user_index/CHANGELOG.md b/backend/canisters/local_user_index/CHANGELOG.md index b6d420c84b..936c1d86ec 100644 --- a/backend/canisters/local_user_index/CHANGELOG.md +++ b/backend/canisters/local_user_index/CHANGELOG.md @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Support submitting proof of uniqueness to LocalUserIndex ([#6068](https://github.com/open-chat-labs/open-chat/pull/6068)) - Support submitting proof of diamond membership to LocalUserIndex ([#6084](https://github.com/open-chat-labs/open-chat/pull/6084)) -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/canisters/user/CHANGELOG.md b/backend/canisters/user/CHANGELOG.md index 7dc26684c7..6dfdc7b890 100644 --- a/backend/canisters/user/CHANGELOG.md +++ b/backend/canisters/user/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- Add `NoAccess` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) +- Add `Locked` gate ([#6095](https://github.com/open-chat-labs/open-chat/pull/6095)) ### Changed diff --git a/backend/libraries/gated_groups/src/lib.rs b/backend/libraries/gated_groups/src/lib.rs index ee6190095b..3953f6c7b6 100644 --- a/backend/libraries/gated_groups/src/lib.rs +++ b/backend/libraries/gated_groups/src/lib.rs @@ -67,7 +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), + AccessGate::Locked => CheckIfPassesGateResult::Failed(GateCheckFailedReason::Locked), } } diff --git a/backend/libraries/types/can.did b/backend/libraries/types/can.did index 75518c2bbb..adc0722f53 100644 --- a/backend/libraries/types/can.did +++ b/backend/libraries/types/can.did @@ -1526,7 +1526,7 @@ type AccessGate = variant { inner : vec AccessGate; and : bool; }; - NoAccess; + Locked; }; type AccessGateUpdate = variant { @@ -1578,7 +1578,7 @@ type GateCheckFailedReason = variant { PaymentFailed : ICRC2_TransferFromError; InsufficientBalance : nat; FailedVerifiedCredentialCheck : text; - NoAccessGate; + Locked; }; type VerifiedCredentialGateArgs = record { diff --git a/backend/libraries/types/src/gated_groups.rs b/backend/libraries/types/src/gated_groups.rs index 3d844d467e..87a59dc7fc 100644 --- a/backend/libraries/types/src/gated_groups.rs +++ b/backend/libraries/types/src/gated_groups.rs @@ -16,7 +16,7 @@ pub enum AccessGate { Payment(PaymentGate), TokenBalance(TokenBalanceGate), Composite(CompositeGate), - NoAccess, + Locked, } impl AccessGate { @@ -46,7 +46,7 @@ impl AccessGate { AccessGate::Payment(_) => "payment", AccessGate::TokenBalance(_) => "token_balance", AccessGate::Composite(_) => "composite", - AccessGate::NoAccess => "no_access", + AccessGate::Locked => "locked", } } } @@ -103,7 +103,7 @@ pub enum GateCheckFailedReason { PaymentFailed(TransferFromError), InsufficientBalance(u128), FailedVerifiedCredentialCheck(String), - NoAccessGate, + Locked, } #[derive(CandidType, Serialize, Deserialize, Clone, Debug)]