Skip to content

Commit

Permalink
fix: add if condition to append "::" in auth::verify_with_role
Browse files Browse the repository at this point in the history
  • Loading branch information
thounyy committed Dec 6, 2024
1 parent 5eca606 commit 83d9531
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/actions/sources/kiosk.move
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public fun delist<Config, Outcome, Nft: key + store>(
account: &mut Account<Config, Outcome>,
kiosk: &mut Kiosk,
name: String,
nft: ID,
nft_id: ID,
) {
auth.verify_with_role<DelistCommand>(account.addr(), name);
assert!(has_lock(account, name), ENoLock);

let cap: &KioskOwnerCap = account.borrow_managed_object(KioskOwnerKey { name }, version::current());
kiosk.delist<Nft>(cap, nft);
kiosk.delist<Nft>(cap, nft_id);
}

/// Members can withdraw the profits to the account
Expand Down
6 changes: 4 additions & 2 deletions packages/actions/tests/access_control_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::access_control::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
12 changes: 8 additions & 4 deletions packages/actions/tests/config_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::config::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

fun upgrade_policies_role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::upgrade_policies::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
6 changes: 4 additions & 2 deletions packages/actions/tests/currency_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::currency::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
6 changes: 4 additions & 2 deletions packages/actions/tests/kiosk_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::kiosk::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
6 changes: 4 additions & 2 deletions packages/actions/tests/treasury_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::treasury::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
6 changes: 4 additions & 2 deletions packages/actions/tests/upgrade_policies_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ fun role(action: vector<u8>, name: vector<u8>): String {
let mut full_role = @account_actions.to_string();
full_role.append_utf8(b"::upgrade_policies::");
full_role.append_utf8(action);
full_role.append_utf8(b"::");
full_role.append_utf8(name);
if (!name.is_empty()) {
full_role.append_utf8(b"::");
full_role.append_utf8(name);
};
full_role
}

Expand Down
7 changes: 5 additions & 2 deletions packages/protocol/sources/auth.move
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ public fun verify_with_role<Role>(
name: String,
) {
let mut r = type_name::get<Role>().into_string().to_string();
r.append_utf8(b"::");
r.append(name);

if (!name.is_empty()) {
r.append_utf8(b"::");
r.append(name);
};

let Auth { role, account_addr } = auth;

Expand Down

0 comments on commit 83d9531

Please sign in to comment.