Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $lib.graph.revoke, fix _initEasyPerm (SYN-8007, SYN-8005) #3950

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changes/33127175adaff42214b2e19af4688fab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
desc: Fix an issue where the default permission level specified when adding a graph
projection was overwritten.
prs: []
type: bug
...
5 changes: 5 additions & 0 deletions changes/44763e312940ac2d6b448d82442020c4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
desc: Add .graph.revoke() API for revoking user/role permissions on a graph projection.
Cisphyx marked this conversation as resolved.
Show resolved Hide resolved
Cisphyx marked this conversation as resolved.
Show resolved Hide resolved
prs: []
type: feat
...
2 changes: 1 addition & 1 deletion synapse/lib/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3560,7 +3560,7 @@ def _initEasyPerm(self, item, default=PERM_READ):
item.setdefault('permissions', {})
item['permissions'].setdefault('users', {})
item['permissions'].setdefault('roles', {})
item['permissions']['default'] = default
item['permissions'].setdefault('default', default)

async def getTeleApi(self, link, mesg, path):

Expand Down
17 changes: 17 additions & 0 deletions synapse/lib/stormlib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ class GraphLib(s_stormtypes.Lib):
),
'returns': {'type': 'null', }}},

{'name': 'revoke', 'desc': 'Revoke permissions granted to users/roles on a graph projection.',
'type': {'type': 'function', '_funcname': '_methGraphRevoke',
'args': (
{'name': 'gden', 'type': 'str', 'desc': 'Iden of the graph projection to modify.'},
{'name': 'scope', 'type': 'str', 'desc': 'The scope, either "users" or "roles".'},
{'name': 'iden', 'type': 'str', 'desc': 'The user/role iden depending on scope.'},
),
'returns': {'type': 'null'}}},

{'name': 'activate', 'desc': 'Set the graph projection to use for the top level Storm Runtime.',
'type': {'type': 'function', '_funcname': '_methGraphActivate',
'args': (
Expand All @@ -174,6 +183,7 @@ def getObjLocals(self):
'mod': self._methGraphMod,
'list': self._methGraphList,
'grant': self._methGraphGrant,
'revoke': self._methGraphRevoke,
'activate': self._methGraphActivate,
}

Expand Down Expand Up @@ -219,6 +229,13 @@ async def _methGraphGrant(self, gden, scope, iden, level):

await self.runt.snap.core.setStormGraphPerm(gden, scope, iden, level, user=self.runt.user)

async def _methGraphRevoke(self, gden, scope, iden):
gden = await s_stormtypes.tostr(gden)
scope = await s_stormtypes.tostr(scope)
iden = await s_stormtypes.tostr(iden)

await self.runt.snap.core.setStormGraphPerm(gden, scope, iden, None, user=self.runt.user)

async def _methGraphActivate(self, iden):
gdef = await self._methGraphGet(iden)
self.runt.setGraph(gdef)
15 changes: 15 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3929,6 +3929,15 @@ def checkGraph(seeds, alldefs):
opts['vars']['useriden'] = visi.iden

await self.asyncraises(s_exc.AuthDeny, core.nodes('$lib.graph.del($iden2)', opts=uopts))
await core.nodes('$lib.graph.grant($iden2, users, $useriden, 3)', opts=opts)

await core.nodes('$lib.graph.mod($iden2, ({"name": "newname"}))', opts=uopts)
gdef = await core.callStorm('return($lib.graph.get($iden2))', opts=opts)
self.eq(gdef['name'], 'newname')

await core.nodes('$lib.graph.revoke($iden2, users, $useriden)', opts=opts)
await self.asyncraises(s_exc.AuthDeny, core.nodes('$lib.graph.mod($iden2, ({"name": "newp"}))', opts=uopts))

await core.nodes('$lib.graph.grant($iden2, users, $useriden, 3)', opts=opts)
await core.nodes('$lib.graph.del($iden2)', opts=uopts)

Expand Down Expand Up @@ -4018,6 +4027,12 @@ def checkGraph(seeds, alldefs):
async with self.getTestCore(dirn=dirn) as core:
self.len(3, await core.callStorm('return($lib.graph.list())', opts=opts))

gdef = await core.callStorm('return($lib.graph.add(({"name": "nodef"})))')
self.eq(1, gdef['permissions']['default'])

gdef = await core.callStorm('return($lib.graph.add(({"name": "def", "permissions": {"default": 0}})))')
self.eq(0, gdef['permissions']['default'])

async def test_storm_two_level_assignment(self):
async with self.getTestCore() as core:
q = '$foo=baz $bar=$foo [test:str=$bar]'
Expand Down
Loading