mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 13:54:20 +03:00
permission: fully deprecate and remove unnecessary logic
This commit is contained in:
parent
e41c974230
commit
3bc4be631e
@ -1,47 +1,22 @@
|
||||
:: permission-group-hook [landscape]:
|
||||
:: permission-group-hook [landscape]: deprecated
|
||||
::
|
||||
:: groups into permissions
|
||||
/+ default-agent
|
||||
::
|
||||
:: mirror the ships in specified groups to specified permission paths
|
||||
::
|
||||
/- *group-store, *permission-group-hook
|
||||
/+ *permission-json, default-agent, verb, dbug
|
||||
::
|
||||
|%
|
||||
+$ state
|
||||
$% [%0 state-0]
|
||||
==
|
||||
::
|
||||
+$ group-path path
|
||||
::
|
||||
+$ permission-path path
|
||||
::
|
||||
+$ state-0
|
||||
$: relation=(map group-path (set permission-path))
|
||||
==
|
||||
::
|
||||
+$ card card:agent:gall
|
||||
--
|
||||
::
|
||||
=| state-0
|
||||
=| [%1 ~]
|
||||
=* state -
|
||||
::
|
||||
%+ verb |
|
||||
%- agent:dbug
|
||||
^- agent:gall
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
do ~(. +> bowl)
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
^- (quip card _this)
|
||||
[~ this(state !<(state-0 old))]
|
||||
[~ this]
|
||||
::
|
||||
++ on-poke on-poke:def
|
||||
++ on-poke on-poke:def
|
||||
++ on-agent on-agent:def
|
||||
++ on-peek on-peek:def
|
||||
++ on-watch on-watch:def
|
||||
|
@ -1,349 +1,26 @@
|
||||
:: permission-hook [landscape]:
|
||||
:: permission-hook [landscape]: deprecated
|
||||
::
|
||||
:: mirror remote permissions
|
||||
/+ default-agent
|
||||
::
|
||||
:: allows mirroring permissions between local and foreign ships.
|
||||
:: local permission path are exposed according to the permssion paths
|
||||
:: configured for them as `access-control`.
|
||||
::
|
||||
/- *permission-hook
|
||||
/+ *permission-json, default-agent, verb, dbug
|
||||
::
|
||||
~% %permission-hook-top ..is ~
|
||||
|%
|
||||
+$ state
|
||||
$% [%0 state-0]
|
||||
==
|
||||
::
|
||||
+$ owner-access [ship=ship access-control=path]
|
||||
::
|
||||
+$ state-0
|
||||
$: synced=(map path owner-access)
|
||||
access-control=(map path (set path))
|
||||
boned=(map wire (list bone))
|
||||
==
|
||||
::
|
||||
+$ card card:agent:gall
|
||||
--
|
||||
::
|
||||
=| state-0
|
||||
=| [%1 ~]
|
||||
=* state -
|
||||
::
|
||||
%- agent:dbug
|
||||
%+ verb |
|
||||
^- agent:gall
|
||||
=<
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
do ~(. +> bowl)
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
^- (quip card _this)
|
||||
[~ this(state !<(state-0 old))]
|
||||
::
|
||||
++ on-poke
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
?+ mark (on-poke:def mark vase)
|
||||
%permission-hook-action
|
||||
=^ cards state
|
||||
(handle-permission-hook-action:do !<(permission-hook-action vase))
|
||||
[cards this]
|
||||
==
|
||||
::
|
||||
++ on-watch
|
||||
|= =path
|
||||
^- (quip card _this)
|
||||
?. ?=([%permission ^] path) (on-watch:def path)
|
||||
=^ cards state
|
||||
(handle-watch-permission:do t.path)
|
||||
[cards this]
|
||||
::
|
||||
++ on-agent
|
||||
|= [=wire =sign:agent:gall]
|
||||
^- (quip card _this)
|
||||
?- -.sign
|
||||
%poke-ack (on-agent:def wire sign)
|
||||
::
|
||||
%fact
|
||||
?. ?=(%permission-update p.cage.sign)
|
||||
(on-agent:def wire sign)
|
||||
=^ cards state
|
||||
(handle-permission-update:do wire !<(permission-update q.cage.sign))
|
||||
[cards this]
|
||||
::
|
||||
%watch-ack
|
||||
?~ p.sign [~ this]
|
||||
?> ?=(^ wire)
|
||||
:_ this(synced (~(del by synced) t.wire))
|
||||
::NOTE we could've gotten rejected for permission reasons, so we don't
|
||||
:: try to resubscribe automatically.
|
||||
%. ~
|
||||
%- slog
|
||||
:* leaf+"permission-hook failed subscribe on {(spud t.wire)}"
|
||||
leaf+"stack trace:"
|
||||
u.p.sign
|
||||
==
|
||||
::
|
||||
%kick
|
||||
?> ?=([* ^] wire)
|
||||
:: if we're not actively using it, we can safely ignore the %kick.
|
||||
::
|
||||
?. (~(has by synced) t.wire)
|
||||
[~ this]
|
||||
:: otherwise, resubscribe.
|
||||
::
|
||||
=/ =owner-access (~(got by synced) t.wire)
|
||||
:_ this
|
||||
[%pass wire %agent [ship.owner-access %permission-hook] %watch wire]~
|
||||
==
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek on-peek:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
::
|
||||
|_ =bowl:gall
|
||||
++ handle-permission-hook-action
|
||||
|= act=permission-hook-action
|
||||
^- (quip card _state)
|
||||
?- -.act
|
||||
%add-owned
|
||||
?> (team:title our.bowl src.bowl)
|
||||
?: (~(has by synced) owned.act)
|
||||
[~ state]
|
||||
=. synced (~(put by synced) owned.act [our.bowl access.act])
|
||||
=. access-control
|
||||
(~(put ju access-control) access.act owned.act)
|
||||
=/ perm-path [%permission owned.act]
|
||||
:_ state
|
||||
[%pass perm-path %agent [our.bowl %permission-store] %watch perm-path]~
|
||||
::
|
||||
%add-synced
|
||||
?> (team:title our.bowl src.bowl)
|
||||
?: (~(has by synced) path.act)
|
||||
[~ state]
|
||||
=. synced (~(put by synced) path.act [ship.act ~])
|
||||
=/ perm-path [%permission path.act]
|
||||
:_ state
|
||||
[%pass perm-path %agent [ship.act %permission-hook] %watch perm-path]~
|
||||
::
|
||||
%remove
|
||||
=/ owner-access=(unit owner-access)
|
||||
(~(get by synced) path.act)
|
||||
?~ owner-access
|
||||
[~ state]
|
||||
:: if we own it, and it's us asking,
|
||||
::
|
||||
?: ?& =(ship.u.owner-access our.bowl)
|
||||
(team:title our.bowl src.bowl)
|
||||
==
|
||||
:: delete the permission path and its subscriptions from this hook.
|
||||
::
|
||||
:- :- [%give %kick [%permission path.act]~ ~]
|
||||
(leave-permission path.act)
|
||||
%_ state
|
||||
synced (~(del by synced) path.act)
|
||||
::
|
||||
access-control
|
||||
(~(del by access-control) access-control.u.owner-access)
|
||||
==
|
||||
:: else, if either source = ship or source = us,
|
||||
::
|
||||
?: |(=(ship.u.owner-access src.bowl) (team:title our.bowl src.bowl))
|
||||
:: delete a foreign ship's path.
|
||||
::
|
||||
:- (leave-permission path.act)
|
||||
%_ state
|
||||
synced (~(del by synced) path.act)
|
||||
boned (~(del by boned) [%permission path.act])
|
||||
==
|
||||
:: else, ignore action entirely.
|
||||
::
|
||||
[~ state]
|
||||
==
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ handle-watch-permission
|
||||
|= =path
|
||||
^- (quip card _state)
|
||||
=/ =owner-access (~(got by synced) path)
|
||||
?> =(our.bowl ship.owner-access)
|
||||
:: scry permissions to check if subscriber is allowed
|
||||
::
|
||||
?> (permitted src.bowl access-control.owner-access)
|
||||
=/ pem (permission-scry path)
|
||||
:_ state
|
||||
[%give %fact ~ %permission-update !>([%create path pem])]~
|
||||
::
|
||||
++ handle-permission-update
|
||||
|= [=wire diff=permission-update]
|
||||
^- (quip card _state)
|
||||
?: (team:title our.bowl src.bowl)
|
||||
(handle-local diff)
|
||||
(handle-foreign diff)
|
||||
::
|
||||
++ handle-local
|
||||
|= diff=permission-update
|
||||
^- (quip card _state)
|
||||
?- -.diff
|
||||
%initial [~ state]
|
||||
%create [~ state]
|
||||
%add (change-local-permission %add [path who]:diff)
|
||||
%remove (change-local-permission %remove [path who]:diff)
|
||||
::
|
||||
%delete
|
||||
?. (~(has by synced) path.diff)
|
||||
[~ state]
|
||||
=/ control=(unit path)
|
||||
=+ (~(got by synced) path.diff)
|
||||
?. =(our.bowl ship) ~
|
||||
`access-control
|
||||
:_ %_ state
|
||||
synced (~(del by synced) path.diff)
|
||||
access-control ?~ control access-control
|
||||
(~(del ju access-control) u.control path.diff)
|
||||
==
|
||||
:_ ~
|
||||
:* %pass
|
||||
[%permission path.diff]
|
||||
%agent
|
||||
[our.bowl %permission-store]
|
||||
[%leave ~]
|
||||
==
|
||||
==
|
||||
::
|
||||
++ change-local-permission
|
||||
|= [kind=?(%add %remove) pax=path who=(set ship)]
|
||||
^- (quip card _state)
|
||||
:_ state
|
||||
:- ?- kind
|
||||
%add (update-subscribers [%permission pax] [%add pax who])
|
||||
%remove (update-subscribers [%permission pax] [%remove pax who])
|
||||
==
|
||||
=/ access-paths=(unit (set path)) (~(get by access-control) pax)
|
||||
:: check if this path changes the access permissions for other paths
|
||||
?~ access-paths ~
|
||||
(quit-subscriptions kind pax who u.access-paths)
|
||||
::
|
||||
++ handle-foreign
|
||||
|= diff=permission-update
|
||||
^- (quip card _state)
|
||||
?- -.diff
|
||||
%initial [~ state]
|
||||
?(%create %add %remove)
|
||||
(change-foreign-permission path.diff diff)
|
||||
::
|
||||
%delete
|
||||
?> ?=([* ^] path.diff)
|
||||
=/ owner-access=(unit owner-access)
|
||||
(~(get by synced) path.diff)
|
||||
?~ owner-access
|
||||
[~ state]
|
||||
?. =(ship.u.owner-access src.bowl)
|
||||
[~ state]
|
||||
:_ state(synced (~(del by synced) path.diff))
|
||||
:~ (permission-poke diff)
|
||||
::
|
||||
:* %pass
|
||||
[%permission path.diff]
|
||||
%agent
|
||||
[src.bowl %permission-hook]
|
||||
[%leave ~]
|
||||
==
|
||||
==
|
||||
==
|
||||
::
|
||||
++ change-foreign-permission
|
||||
|= [=path diff=permission-update]
|
||||
^- (quip card _state)
|
||||
?> ?=([* ^] path)
|
||||
=/ owner-access=(unit owner-access)
|
||||
(~(get by synced) path)
|
||||
:_ state
|
||||
?~ owner-access ~
|
||||
?. =(src.bowl ship.u.owner-access) ~
|
||||
[(permission-poke diff)]~
|
||||
::
|
||||
++ quit-subscriptions
|
||||
|= $: kind=?(%add %remove)
|
||||
perm-path=path
|
||||
who=(set ship)
|
||||
access-paths=(set path)
|
||||
==
|
||||
^- (list card)
|
||||
=/ perm (permission-scry perm-path)
|
||||
:: if the change resolves to "allow",
|
||||
::
|
||||
?. ?| ?&(=(%black kind.perm) =(%add kind))
|
||||
?&(=(%white kind.perm) =(%remove kind))
|
||||
==
|
||||
:: do nothing.
|
||||
~
|
||||
:: else, it resolves to "deny"/"ban".
|
||||
:: kick subscriptions for all ships, at all affected paths.
|
||||
::
|
||||
%- zing
|
||||
%+ turn ~(tap in who)
|
||||
|= check-ship=ship
|
||||
^- (list card)
|
||||
%+ turn ~(tap in access-paths)
|
||||
|= access-path=path
|
||||
[%give %kick [%permission access-path]~ `check-ship]
|
||||
::
|
||||
++ permission-scry
|
||||
|= pax=path
|
||||
^- permission
|
||||
=. pax
|
||||
;: weld
|
||||
/(scot %p our.bowl)/permission-store/(scot %da now.bowl)/permission
|
||||
pax
|
||||
/noun
|
||||
==
|
||||
(need .^((unit permission) %gx pax))
|
||||
::
|
||||
++ permitted
|
||||
|= [who=ship =path]
|
||||
.^ ?
|
||||
%gx
|
||||
(scot %p our.bowl)
|
||||
%permission-store
|
||||
(scot %da now.bowl)
|
||||
%permitted
|
||||
(scot %p src.bowl)
|
||||
(snoc path %noun)
|
||||
==
|
||||
::
|
||||
++ permission-poke
|
||||
|= act=permission-action
|
||||
^- card
|
||||
:* %pass
|
||||
/permission-action
|
||||
%agent
|
||||
[our.bowl %permission-store]
|
||||
%poke
|
||||
%permission-action
|
||||
!>(act)
|
||||
==
|
||||
::
|
||||
++ update-subscribers
|
||||
|= [=path upd=permission-update]
|
||||
^- card
|
||||
[%give %fact ~[path] %permission-update !>(upd)]
|
||||
::
|
||||
++ leave-permission
|
||||
|= =path
|
||||
^- (list card)
|
||||
=/ owner-access=(unit owner-access)
|
||||
(~(get by synced) path)
|
||||
?~ owner-access ~
|
||||
:_ ~
|
||||
=/ perm-path [%permission path]
|
||||
?: =(ship.u.owner-access our.bowl)
|
||||
[%pass perm-path %agent [our.bowl %permission-store] %leave ~]
|
||||
[%pass perm-path %agent [ship.u.owner-access %permission-hook] %leave ~]
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
[~ this]
|
||||
++ on-poke on-poke:def
|
||||
++ on-watch on-watch:def
|
||||
++ on-agent on-agent:def
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek on-peek:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
|
||||
|
@ -1,203 +1,36 @@
|
||||
:: permission-store [landscape]:
|
||||
::
|
||||
:: track black- and whitelists of ships
|
||||
::
|
||||
/- *permission-store
|
||||
/+ default-agent, verb, dbug
|
||||
:: permission-store [landscape]: deprecated
|
||||
::
|
||||
/+ default-agent
|
||||
|%
|
||||
+$ card card:agent:gall
|
||||
::
|
||||
+$ versioned-state
|
||||
$% state-zero
|
||||
$% state-0
|
||||
state-1
|
||||
==
|
||||
::
|
||||
+$ state-zero
|
||||
$: %0
|
||||
permissions=permission-map
|
||||
==
|
||||
+$ state-0 [%0 *]
|
||||
+$ state-1 [%1 ~]
|
||||
--
|
||||
=| state-zero
|
||||
::
|
||||
=| state-1
|
||||
=* state -
|
||||
::
|
||||
%- agent:dbug
|
||||
%+ verb |
|
||||
^- agent:gall
|
||||
=<
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
permission-core +>
|
||||
pc ~(. permission-core bowl)
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
`this(state !<(state-zero old))
|
||||
::
|
||||
++ on-poke
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
?> (team:title our.bowl src.bowl)
|
||||
=^ cards state
|
||||
?: ?=(%permission-action mark)
|
||||
(poke-permission-action:pc !<(permission-action vase))
|
||||
(on-poke:def mark vase)
|
||||
[cards this]
|
||||
::
|
||||
++ on-watch
|
||||
|= =path
|
||||
^- (quip card _this)
|
||||
?> (team:title our.bowl src.bowl)
|
||||
|^
|
||||
=/ cards=(list card)
|
||||
?+ path (on-watch:def path)
|
||||
[%all ~] (give %permission-update !>([%initial permissions]))
|
||||
[%updates ~] ~
|
||||
[%permission @ *]
|
||||
=/ =vase !>([%create t.path (~(got by permissions) t.path)])
|
||||
(give %permission-update vase)
|
||||
==
|
||||
[cards this]
|
||||
::
|
||||
++ give
|
||||
|= =cage
|
||||
^- (list card)
|
||||
[%give %fact ~ cage]~
|
||||
--
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek
|
||||
|= =path
|
||||
^- (unit (unit cage))
|
||||
?+ path (on-peek:def path)
|
||||
[%x %keys ~] ``noun+!>(~(key by permissions))
|
||||
[%x %permission *]
|
||||
?~ t.t.path ~
|
||||
``noun+!>((~(get by permissions) t.t.path))
|
||||
::
|
||||
[%x %permitted @ *]
|
||||
?~ t.t.t.path ~
|
||||
=/ pem (~(get by permissions) t.t.t.path)
|
||||
?~ pem ~
|
||||
=/ who (slav %p i.t.t.path)
|
||||
=/ has (~(has in who.u.pem) who)
|
||||
``noun+!>(?-(kind.u.pem %black !has, %white has))
|
||||
==
|
||||
++ on-agent on-agent:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
|_ bol=bowl:gall
|
||||
++ on-init on-init:def
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
[~ this]
|
||||
::
|
||||
++ poke-permission-action
|
||||
|= action=permission-action
|
||||
^- (quip card _state)
|
||||
?> (team:title our.bol src.bol)
|
||||
?- -.action
|
||||
%initial [~ state]
|
||||
%add (handle-add action)
|
||||
%remove (handle-remove action)
|
||||
%create (handle-create action)
|
||||
%delete (handle-delete action)
|
||||
%allow (handle-allow action)
|
||||
%deny (handle-deny action)
|
||||
==
|
||||
::
|
||||
++ handle-add
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%add -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
:: TODO: calculate diff
|
||||
:: =+ new=(~(dif in who.what.action) who.u.pem)
|
||||
:: ?~(new ~ `what.action(who new))
|
||||
?. (~(has by permissions) path.act)
|
||||
[~ state]
|
||||
:- (send-diff path.act act)
|
||||
=/ perm (~(got by permissions) path.act)
|
||||
=. who.perm (~(uni in who.perm) who.act)
|
||||
state(permissions (~(put by permissions) path.act perm))
|
||||
::
|
||||
++ handle-remove
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%remove -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
?. (~(has by permissions) path.act)
|
||||
[~ state]
|
||||
=/ perm (~(got by permissions) path.act)
|
||||
=. who.perm (~(dif in who.perm) who.act)
|
||||
:: TODO: calculate diff
|
||||
:: =+ new=(~(int in who.what.action) who.u.pem)
|
||||
:: ?~(new ~ `what.action(who new))
|
||||
:- (send-diff path.act act)
|
||||
state(permissions (~(put by permissions) path.act perm))
|
||||
::
|
||||
++ handle-create
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%create -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
?: (~(has by permissions) path.act)
|
||||
[~ state]
|
||||
:: TODO: calculate diff
|
||||
:- (send-diff path.act act)
|
||||
state(permissions (~(put by permissions) path.act permission.act))
|
||||
::
|
||||
++ handle-delete
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%delete -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
?. (~(has by permissions) path.act)
|
||||
[~ state]
|
||||
:- (send-diff path.act act)
|
||||
state(permissions (~(del by permissions) path.act))
|
||||
::
|
||||
++ handle-allow
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%allow -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
=/ perm (~(get by permissions) path.act)
|
||||
?~ perm
|
||||
[~ state]
|
||||
?: =(kind.u.perm %white)
|
||||
(handle-add [%add +.act])
|
||||
(handle-remove [%remove +.act])
|
||||
::
|
||||
++ handle-deny
|
||||
|= act=permission-action
|
||||
^- (quip card _state)
|
||||
?> ?=(%deny -.act)
|
||||
?~ path.act
|
||||
[~ state]
|
||||
=/ perm (~(get by permissions) path.act)
|
||||
?~ perm
|
||||
[~ state]
|
||||
?: =(kind.u.perm %black)
|
||||
(handle-add [%add +.act])
|
||||
(handle-remove [%remove +.act])
|
||||
::
|
||||
++ update-subscribers
|
||||
|= [pax=path upd=permission-update]
|
||||
^- (list card)
|
||||
[%give %fact ~[pax] %permission-update !>(upd)]~
|
||||
::
|
||||
++ send-diff
|
||||
|= [pax=path upd=permission-update]
|
||||
^- (list card)
|
||||
%- zing
|
||||
:~ (update-subscribers /all upd)
|
||||
(update-subscribers /updates upd)
|
||||
(update-subscribers [%permission pax] upd)
|
||||
==
|
||||
++ on-poke on-poke:def
|
||||
++ on-peek on-peek:def
|
||||
++ on-watch on-watch:def
|
||||
++ on-leave on-leave:def
|
||||
++ on-agent on-agent:def
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user