This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb7ced
commit 49b46bb
Showing
8 changed files
with
431 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,81 @@ | ||
import { RoleClaim } from './types.js'; | ||
|
||
import { | ||
SignedActionHashed, | ||
CreateLink, | ||
Link, | ||
DeleteLink, | ||
Delete, | ||
AppClient, | ||
Record, | ||
ActionHash, | ||
EntryHash, | ||
AgentPubKey, | ||
} from '@holochain/client'; | ||
import { EntryRecord, ZomeClient } from '@holochain-open-dev/utils'; | ||
import { | ||
ActionHash, | ||
AgentPubKey, | ||
AppClient, | ||
CreateLink, | ||
Delete, | ||
DeleteLink, | ||
EntryHash, | ||
Link, | ||
Record, | ||
SignedActionHashed, | ||
} from '@holochain/client'; | ||
|
||
import { RoleClaim } from './types.js'; | ||
import { RolesSignal } from './types.js'; | ||
|
||
export class RolesClient extends ZomeClient<RolesSignal> { | ||
constructor(public client: AppClient, public roleName: string, public zomeName = 'roles') { | ||
super(client, roleName, zomeName); | ||
} | ||
/** Role Claim */ | ||
|
||
async createRoleClaim(roleClaim: RoleClaim): Promise<EntryRecord<RoleClaim>> { | ||
const record: Record = await this.callZome('create_role_claim', roleClaim); | ||
return new EntryRecord(record); | ||
} | ||
|
||
async getRoleClaim(roleClaimHash: ActionHash): Promise<EntryRecord<RoleClaim> | undefined> { | ||
const record: Record = await this.callZome('get_role_claim', roleClaimHash); | ||
return record ? new EntryRecord(record) : undefined; | ||
} | ||
|
||
deleteRoleClaim(originalRoleClaimHash: ActionHash): Promise<ActionHash> { | ||
return this.callZome('delete_role_claim', originalRoleClaimHash); | ||
} | ||
|
||
getAllDeletesForRoleClaim(originalRoleClaimHash: ActionHash): Promise<Array<SignedActionHashed<Delete>>> { | ||
return this.callZome('get_all_deletes_for_role_claim', originalRoleClaimHash); | ||
} | ||
|
||
getOldestDeleteForRoleClaim(originalRoleClaimHash: ActionHash): Promise<SignedActionHashed<Delete> | undefined> { | ||
return this.callZome('get_oldest_delete_for_role_claim', originalRoleClaimHash); | ||
} | ||
|
||
/** All Roles */ | ||
|
||
async getAllRoles(): Promise<Array<Link>> { | ||
return this.callZome('get_all_roles', undefined); | ||
} | ||
constructor( | ||
public client: AppClient, | ||
public roleName: string, | ||
public zomeName = 'roles', | ||
) { | ||
super(client, roleName, zomeName); | ||
} | ||
/** Role Claim */ | ||
|
||
async createRoleClaim(roleClaim: RoleClaim): Promise<EntryRecord<RoleClaim>> { | ||
const record: Record = await this.callZome('create_role_claim', roleClaim); | ||
return new EntryRecord(record); | ||
} | ||
|
||
async getRoleClaim( | ||
roleClaimHash: ActionHash, | ||
): Promise<EntryRecord<RoleClaim> | undefined> { | ||
const record: Record = await this.callZome('get_role_claim', roleClaimHash); | ||
return record ? new EntryRecord(record) : undefined; | ||
} | ||
|
||
getAllDeletesForRoleClaim( | ||
originalRoleClaimHash: ActionHash, | ||
): Promise<Array<SignedActionHashed<Delete>>> { | ||
return this.callZome( | ||
'get_all_deletes_for_role_claim', | ||
originalRoleClaimHash, | ||
); | ||
} | ||
|
||
/** All Roles */ | ||
|
||
async getAllRoles(): Promise<Array<Link>> { | ||
return this.callZome('get_all_roles', undefined); | ||
} | ||
|
||
/** Assignees */ | ||
|
||
async getAssigneesForRole(role: string): Promise<Array<Link>> { | ||
return this.callZome('get_assignees_for_role', role); | ||
} | ||
|
||
async assignRole(role: string, assignee: AgentPubKey): Promise<void> { | ||
return this.callZome('assign_role', { | ||
role, | ||
assignee, | ||
}); | ||
} | ||
|
||
async requestUnassignRole( | ||
role: string, | ||
assignee: AgentPubKey, | ||
): Promise<void> { | ||
await this.callZome('request_unassign_role', { | ||
role, | ||
assignee, | ||
}); | ||
} | ||
|
||
async unassignMyRole(role: string): Promise<void> { | ||
return this.callZome('unassign_my_role', role); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
use hdi::prelude::*; | ||
|
||
use crate::had_role_claim_at_the_time; | ||
use crate::validate_agent_had_undeleted_role_claim_at_the_time; | ||
|
||
pub const ADMIN_ROLE: &'static str = "ADMIN"; | ||
|
||
pub fn was_admin_at_the_time(agent: &AgentPubKey, chain_top: &ActionHash) -> ExternResult<bool> { | ||
had_role_claim_at_the_time(agent, chain_top, &ADMIN_ROLE.to_string()) | ||
pub fn validate_agent_was_admin_at_the_time( | ||
agent: &AgentPubKey, | ||
chain_top: &ActionHash, | ||
) -> ExternResult<ValidateCallbackResult> { | ||
validate_agent_had_undeleted_role_claim_at_the_time(agent, chain_top, &ADMIN_ROLE.to_string()) | ||
} |
Oops, something went wrong.