mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 11:50:42 +08:00
37 lines
907 B
TypeScript
37 lines
907 B
TypeScript
import { parseNodeId } from "@app/lib/utils";
|
|
|
|
export function isDelegate(
|
|
publicKey: string | undefined,
|
|
delegates: string[],
|
|
): true | undefined {
|
|
if (!publicKey) {
|
|
return undefined;
|
|
}
|
|
return (
|
|
delegates.some(delegate => parseNodeId(delegate)?.pubkey === publicKey) ||
|
|
undefined
|
|
);
|
|
}
|
|
|
|
function matchAuthor(
|
|
publicKey: string | undefined,
|
|
nid: string,
|
|
): true | undefined {
|
|
// Normalize the passed in NID
|
|
const parsedNid = parseNodeId(nid);
|
|
return (
|
|
(publicKey && parsedNid && parsedNid.pubkey === publicKey) || undefined
|
|
);
|
|
}
|
|
|
|
// All restricted actions are a combination of either:
|
|
// - the user is a delegate
|
|
// - the user is an author of the comment, issue, patch, etc.
|
|
export function isDelegateOrAuthor(
|
|
publicKey: string | undefined,
|
|
delegates: string[],
|
|
author: string,
|
|
) {
|
|
return isDelegate(publicKey, delegates) || matchAuthor(publicKey, author);
|
|
}
|