Skip to content

Commit

Permalink
TECH-156 - Update issuer init
Browse files Browse the repository at this point in the history
  • Loading branch information
TYRONEMICHAEL committed May 15, 2024
1 parent f8cf6e2 commit e234f12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/civic_canister_backend/civic_canister_backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type StoredCredential = record {
issuer : text;
};
service : (opt IssuerInit) -> {
init: (opt IssuerConfig) -> ();
init: (opt IssuerInit) -> ();
add_credentials : (principal, vec StoredCredential) -> (text);
configure : (IssuerInit) -> ();
derivation_origin : (DerivationOriginRequest) -> (Result);
Expand Down
10 changes: 7 additions & 3 deletions src/civic_canister_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Default for IssuerConfig {
derivation_origin: derivation_origin.clone(),
frontend_hostname: derivation_origin,
admin: ic_cdk::api::caller(),
authorized_issuers: [ic_cdk::api::caller()],
authorized_issuers: vec![ic_cdk::api::caller()],
}
}
}
Expand Down Expand Up @@ -191,7 +191,10 @@ fn add_issuer(new_issuer: Principal) {

// Check if the caller is the admin and modify the config
if caller == current_config.admin {
current_config.authorized_issuers.insert(new_issuer);
// Ensure no duplicates if that's intended
if !current_config.authorized_issuers.contains(&new_issuer) {
current_config.authorized_issuers.push(new_issuer);
}
// Save the updated configuration
let _ = config.set(current_config); // Pass the modified IssuerConfig back to set
} else {
Expand All @@ -210,7 +213,8 @@ fn remove_issuer(issuer: Principal) {
let mut current_config = config.get().clone(); // Clone into a mutable local variable

if caller == current_config.admin {
current_config.authorized_issuers.remove(&issuer);
// Remove the issuer if they exist in the list
current_config.authorized_issuers.retain(|x| *x != issuer);
// Save the updated configuration
let _ = config.set(current_config); // Pass the modified IssuerConfig back to set
} else {
Expand Down

0 comments on commit e234f12

Please sign in to comment.