Skip to content

Commit

Permalink
Merge pull request #107 from influenceth/account-perms
Browse files Browse the repository at this point in the history
support crew's account siblings in permission check
  • Loading branch information
prof197 authored Nov 18, 2024
2 parents 2fec5cc + bf806c1 commit 53155ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influenceth/sdk",
"version": "2.3.6",
"version": "2.3.7",
"description": "Influence SDK",
"type": "module",
"module": "./build/index.js",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,20 @@ const getPermissionPolicy = (entity, rawPermId, crew, blockTime = null) => {
permPolicy.crewStatus = '';
if (crew) {
if (entity.Control?.controller?.id === crew.id) permPolicy.crewStatus = 'controller';
else if ((crew._siblingCrewIds || []).includes(entity.Control?.controller?.id)) permPolicy.crewStatus = 'controller';

// if not exclusive, policy is "granted" just by being public or on allowlist
else if (!TYPES[permId].isExclusive && permPolicy.policyType === POLICY_IDS.PUBLIC) permPolicy.crewStatus = 'granted';
else if (!TYPES[permId].isExclusive && permPolicy.allowlist.find((c) => c.id === crew.id)) permPolicy.crewStatus = 'granted';
else if (!TYPES[permId].isExclusive && crew?.Crew?.delegatedTo && permPolicy.accountAllowlist.find((a) => Address.areEqual(a, crew?.Crew?.delegatedTo))) permPolicy.crewStatus = 'granted';

// else, granted if have explicit agreement
else if (permPolicy.agreements?.find((a) => a.permitted?.id === crew.id)) permPolicy.crewStatus = 'granted';

// for exclusive perms, also worth noting when being excluded
else if (TYPES[permId].isExclusive && permPolicy.agreements?.length > 0) permPolicy.crewStatus = 'under contract';
else if (POLICY_TYPES[permPolicy.policyType]?.agreementKey) permPolicy.crewStatus = 'available';

else permPolicy.crewStatus = 'restricted';
}

Expand Down

0 comments on commit 53155ac

Please sign in to comment.