Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update global user principal #487

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/lib/shared_utils/src/common/utils/permissions.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use ic_cdk::{api::is_controller, caller};
use candid::Principal;
use crate::constant::{GLOBAL_SUPER_ADMIN_USER_ID, GOVERNANCE_CANISTER_ID, RECLAIM_CANISTER_PRINCIPAL_ID};
use crate::constant::{GLOBAL_SUPER_ADMIN_USER_ID, GLOBAL_SUPER_ADMIN_USER_ID_V1, GOVERNANCE_CANISTER_ID, RECLAIM_CANISTER_PRINCIPAL_ID};

pub fn is_reclaim_canister_id() -> Result<(), String> {
let caller = ic_cdk::caller();
let reclaim_canister_principal = Principal::from_text(RECLAIM_CANISTER_PRINCIPAL_ID).unwrap();

// Here accessing the args ???
let valid_principals = vec![RECLAIM_CANISTER_PRINCIPAL_ID, GLOBAL_SUPER_ADMIN_USER_ID_V1];

if caller == reclaim_canister_principal {

if valid_principals.contains(&caller.to_string().as_ref()) {
Ok(())
} else {
Err("Caller is not allowed.".to_string())
Expand All @@ -17,7 +17,11 @@ pub fn is_reclaim_canister_id() -> Result<(), String> {


pub fn is_caller_global_admin() -> Result<(), String> {
if !caller().to_string().eq(GLOBAL_SUPER_ADMIN_USER_ID) {

let valid_canisters = vec![GLOBAL_SUPER_ADMIN_USER_ID_V1, GLOBAL_SUPER_ADMIN_USER_ID];


if !valid_canisters.contains(&caller().to_string().as_str()){
return Err("Unauthorize".into())
}
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/lib/shared_utils/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ pub const NNS_LEDGER_CANISTER_ID: &str = "ryjl3-tyaaa-aaaaa-aaaba-cai";
pub const SNS_WASM_W_PRINCIPAL_ID: &'static str = "qaa6y-5yaaa-aaaaa-aaafa-cai";
pub const GLOBAL_SUPER_ADMIN_USER_ID: &str =
"7gaq2-4kttl-vtbt4-oo47w-igteo-cpk2k-57h3p-yioqe-wkawi-wz45g-jae";

pub const GLOBAL_SUPER_ADMIN_USER_ID_V1: &str = "zg7n3-345by-nqf6o-3moz4-iwxql-l6gko-jqdz2-56juu-ja332-unymr-fqe";
pub const RECLAIM_CANISTER_PRINCIPAL_ID: &str =
"7gaq2-4kttl-vtbt4-oo47w-igteo-cpk2k-57h3p-yioqe-wkawi-wz45g-jae";

Expand Down