From b31978388af020d2ce1b98d384b26d5bed206211 Mon Sep 17 00:00:00 2001 From: ryjm Date: Thu, 17 Aug 2023 12:04:03 -0600 Subject: [PATCH 1/3] treaty: add desk permissions check --- desk/app/treaty.hoon | 18 +++++++++++++++++- desk/lib/treaty.hoon | 8 ++++++++ desk/sur/treaty.hoon | 2 +- ui/src/components/AppInfo.tsx | 20 ++++++++++++++------ ui/src/gear/docket/types.ts | 1 + 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index 0b040cac..a6206b85 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -78,6 +78,8 @@ =/ =treaty (treaty-from-docket:cc desk docket) =. sovereign (~(put by sovereign) desk treaty) :_ this + ?^ vips.treaty + [warp give]:so [publish warp give]:so :: %del @@ -271,7 +273,21 @@ |= [=desk =docket:docket] =+ .^(=cass:clay %cw (scry:io desk /desk/docket)) =+ .^(hash=@uv %cz (scry:io desk ~)) - [our.bowl desk da+da.cass hash docket] + =- [our.bowl desk - da+da.cass hash docket] + =, clay + =/ perms .^([r=dict w=dict] %cp (scry:io desk /)) + =/ =_who:*real who.rul.r.perms + =+ mod=mod.rul.r.perms + ?: ?=(%black mod) ~ + =- ?~ - (sy ~[our.bowl]) - + ^- crew + =; crews + ?~ ships=p.who crews + (~(uni in `crew`ships) crews) + ^- crew + %+ roll ~(val by q.who) + |= [=crew all=crew] + (~(uni in all) crew) :: +al: Side effects for allies ++ al |_ =ship diff --git a/desk/lib/treaty.hoon b/desk/lib/treaty.hoon index 93a8f9eb..5d2d9054 100644 --- a/desk/lib/treaty.hoon +++ b/desk/lib/treaty.hoon @@ -16,9 +16,17 @@ %- pairs :~ ship+s+(scot %p ship.t) desk+s+desk.t + vips+(vips `crew:clay`vips.t) cass+(case case.t) hash+s+(scot %uv hash.t) == + ++ vips + |= v=crew:clay + :- %a + %+ turn ~(tap in v) + |= =^ship + ^- json + s+(scot %p ship) :: ++ case |= c=^case diff --git a/desk/sur/treaty.hoon b/desk/sur/treaty.hoon index e57c881b..e31e61bb 100644 --- a/desk/sur/treaty.hoon +++ b/desk/sur/treaty.hoon @@ -8,7 +8,7 @@ :: Includes the docket itself, plus provenance generated by clay :: +$ treaty - [=ship =desk =case hash=@uv =docket:docket] + [=ship =desk vips=crew:clay =case hash=@uv =docket:docket] :: :: $update:treaty: Diff of treaty state :: diff --git a/ui/src/components/AppInfo.tsx b/ui/src/components/AppInfo.tsx index c6d52ff9..dff833a8 100644 --- a/ui/src/components/AppInfo.tsx +++ b/ui/src/components/AppInfo.tsx @@ -82,6 +82,7 @@ export const AppInfo: FC = ({ }, [publisher, desk]); const installing = installStatus === 'installing'; + const buttonText = treaty?.vips && treaty.vips.includes(window.ship) ? 'VIP' : 'Get App'; if (!docket) { // TODO: maybe replace spinner with skeletons @@ -103,12 +104,21 @@ export const AppInfo: FC = ({ href={getAppHref(docket.href)} target="_blank" rel="noreferrer" - onClick={() => addRecentApp(docket.desk)} - > + onClick={() => addRecentApp(docket.desk)}> Open App )} - {installStatus !== 'installed' && ( + {(treaty?.vips && treaty?.vips.length > 0) && ( + + Not Listed + + ) || + installStatus !== 'installed' && ( @@ -117,9 +127,7 @@ export const AppInfo: FC = ({ Installing... - ) : ( - 'Get App' - )} + ) : buttonText} diff --git a/ui/src/gear/docket/types.ts b/ui/src/gear/docket/types.ts index 4c56a6fd..2f119dfd 100644 --- a/ui/src/gear/docket/types.ts +++ b/ui/src/gear/docket/types.ts @@ -50,6 +50,7 @@ export interface SuspendChad { export interface Treaty extends Docket { ship: string; desk: string; + vips: [ship: string]; cass: Cass; hash: string; } From aaeba9190ea39305483339723c6968caaf7afcfd Mon Sep 17 00:00:00 2001 From: ryjm Date: Fri, 18 Aug 2023 18:56:32 -0600 Subject: [PATCH 2/3] treaty: don't show whitelisted ships --- desk/app/treaty.hoon | 36 ++++++++++++++++++++--------------- desk/lib/treaty.hoon | 9 +-------- desk/sur/treaty.hoon | 7 ++++++- ui/src/components/AppInfo.tsx | 4 ++-- ui/src/gear/docket/types.ts | 2 +- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index a6206b85..e260dc68 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -6,7 +6,7 @@ +$ card card:agent:gall +$ state-0 $: treaties=(map [=ship =desk] treaty) - sovereign=(map desk treaty) + sovereign=(map desk pact) entente=alliance =allies:ally direct=(set [=ship =desk]) @@ -45,8 +45,8 @@ %noun =+ ;;([%add =desk] q.vase) =/ =docket:docket ~(get-docket so:cc desk) - =/ =treaty (treaty-from-docket:cc desk docket) - =. sovereign (~(put by sovereign) desk treaty) + =/ =pact (pact-from-docket:cc desk docket) + =. sovereign (~(put by sovereign) desk pact) `this == :: @@ -75,10 +75,10 @@ ?. =(our.bowl ship) `this =* so ~(. so:cc desk) =/ =docket:docket get-docket:so - =/ =treaty (treaty-from-docket:cc desk docket) - =. sovereign (~(put by sovereign) desk treaty) + =/ =pact (pact-from-docket:cc desk docket) + =. sovereign (~(put by sovereign) desk pact) :_ this - ?^ vips.treaty + ?^ crew.pact [warp give]:so [publish warp give]:so :: @@ -100,7 +100,12 @@ =/ =ship (slav %p i.t.path) =* desk i.t.t.path ?: =(our.bowl ship) - :_(this (fact-init:io (treaty:cg:cc (~(got by sovereign) desk)))^~) + =/ =pact (~(got by sovereign) desk) + =. signed.treaty.pact + ?~ crew.pact %& + ?: (~(has in crew.pact) our.bowl) %| + (~(has in crew.pact) src.bowl) + :_(this (fact-init:io (treaty:cg:cc treaty.pact desk))^~) ?^ treat=(~(get by treaties) [ship desk]) :_ this (fact-init:io (treaty:cg:cc u.treat))^~ @@ -140,8 +145,8 @@ =/ allied %- ~(gas by *(map [^ship desk] treaty)) %+ skim ~(tap by treaties) - |= [ref=[^ship desk] =treaty] - (~(has in alliance) ref) + |= [[=^ship =desk] =treaty] + (~(has in alliance) [ship desk]) ``(treaty-update:cg:ca:cc %ini allied) :: [%x %treaty @ @ ~] @@ -255,12 +260,11 @@ =* cage r.u.riot ?. =(%docket-0 p.cage) `this =+ !<(=docket:docket q.cage) - =/ =treaty (treaty-from-docket:cc desk docket) + =/ [=treaty =crew:clay] (pact-from-docket:cc desk docket) =. sovereign (~(put by sovereign) desk treaty) =* so ~(. so:cc desk) :_(this [warp give]:so) -- - :: ++ on-fail on-fail:def ++ on-leave on-leave:def @@ -269,17 +273,19 @@ ++ io ~(. agentio bowl) ++ pass pass:io :: -++ treaty-from-docket +++ pact-from-docket |= [=desk =docket:docket] + ^+ pact =+ .^(=cass:clay %cw (scry:io desk /desk/docket)) =+ .^(hash=@uv %cz (scry:io desk ~)) - =- [our.bowl desk - da+da.cass hash docket] + =; buds + :_ buds + [our.bowl desk %| da+da.cass hash docket] =, clay =/ perms .^([r=dict w=dict] %cp (scry:io desk /)) =/ =_who:*real who.rul.r.perms =+ mod=mod.rul.r.perms - ?: ?=(%black mod) ~ - =- ?~ - (sy ~[our.bowl]) - + ?: ?=(%black mod) (sy ~[our.bowl]) ^- crew =; crews ?~ ships=p.who crews diff --git a/desk/lib/treaty.hoon b/desk/lib/treaty.hoon index 5d2d9054..58ca7320 100644 --- a/desk/lib/treaty.hoon +++ b/desk/lib/treaty.hoon @@ -16,17 +16,10 @@ %- pairs :~ ship+s+(scot %p ship.t) desk+s+desk.t - vips+(vips `crew:clay`vips.t) + signed+b+signed.t cass+(case case.t) hash+s+(scot %uv hash.t) == - ++ vips - |= v=crew:clay - :- %a - %+ turn ~(tap in v) - |= =^ship - ^- json - s+(scot %p ship) :: ++ case |= c=^case diff --git a/desk/sur/treaty.hoon b/desk/sur/treaty.hoon index e31e61bb..a5a65320 100644 --- a/desk/sur/treaty.hoon +++ b/desk/sur/treaty.hoon @@ -1,5 +1,6 @@ /- docket |% ++$ pact [=treaty =crew:clay] ++ treaty =< treaty |% @@ -8,7 +9,11 @@ :: Includes the docket itself, plus provenance generated by clay :: +$ treaty - [=ship =desk vips=crew:clay =case hash=@uv =docket:docket] + [=ship =desk signed=? =case hash=@uv =docket:docket] + :: + :: %pact: A treaty plus the ships it applies to. + :: + :: :: :: $update:treaty: Diff of treaty state :: diff --git a/ui/src/components/AppInfo.tsx b/ui/src/components/AppInfo.tsx index dff833a8..5f1a06a3 100644 --- a/ui/src/components/AppInfo.tsx +++ b/ui/src/components/AppInfo.tsx @@ -82,7 +82,7 @@ export const AppInfo: FC = ({ }, [publisher, desk]); const installing = installStatus === 'installing'; - const buttonText = treaty?.vips && treaty.vips.includes(window.ship) ? 'VIP' : 'Get App'; + const buttonText = treaty?.signed ? 'Get Whitelisted App' : 'Get App'; if (!docket) { // TODO: maybe replace spinner with skeletons @@ -108,7 +108,7 @@ export const AppInfo: FC = ({ Open App )} - {(treaty?.vips && treaty?.vips.length > 0) && ( + {!treaty?.signed && ( Date: Sun, 20 Aug 2023 02:36:26 -0400 Subject: [PATCH 3/3] treaty: update treaty version this exposes a gall bug that triggers a kick-rewatch loop on the subscriber sides. gall does not register the mark conversion failure from treaty-0 to treaty-1 as an error and does not send a watch-nack, so the subscriber will keep trying to watch the publisher's treaty even though it immediately gets kicked. --- desk/app/treaty.hoon | 29 ++++++++++++++++++----------- desk/mar/treaty-1.hoon | 14 ++++++++++++++ ui/src/components/AppInfo.tsx | 26 ++++++++++++++++++++------ 3 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 desk/mar/treaty-1.hoon diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index e260dc68..ff4d3307 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -103,9 +103,10 @@ =/ =pact (~(got by sovereign) desk) =. signed.treaty.pact ?~ crew.pact %& - ?: (~(has in crew.pact) our.bowl) %| - (~(has in crew.pact) src.bowl) - :_(this (fact-init:io (treaty:cg:cc treaty.pact desk))^~) + ?: (~(has in `crew:clay`crew.pact) our.bowl) %| + (~(has in `crew:clay`crew.pact) src.bowl) + :_ this + (fact-init:io (treaty:cg:cc treaty.pact))^~ ?^ treat=(~(get by treaties) [ship desk]) :_ this (fact-init:io (treaty:cg:cc u.treat))^~ @@ -218,9 +219,15 @@ %kick :_ this ?: =(our.bowl ship) ~ + :: XX this triggers a kick-rewatch loop if the + :: treaty on the other side is a treaty-0 ~[watch:tr] :: %watch-ack + :: XX this should not trigger a kick-rewatch loop + :: but it does - gall does not register the mark + :: conversion attempt as a failure and does not send + :: a nack ?~ p.sign `this =: treaties (~(del by treaties) ship desk) direct (~(del in direct) ship desk) @@ -229,7 +236,7 @@ [gone:tr this] :: %fact - ?. =(%treaty-0 p.cage.sign) `this + ?. =(%treaty-1 p.cage.sign) `this =+ !<(=treaty q.cage.sign) ?> =([ship desk] [ship desk]:treaty) =. treaties (~(put by treaties) [ship desk]:treaty treaty) @@ -261,7 +268,7 @@ ?. =(%docket-0 p.cage) `this =+ !<(=docket:docket q.cage) =/ [=treaty =crew:clay] (pact-from-docket:cc desk docket) - =. sovereign (~(put by sovereign) desk treaty) + =. sovereign (~(put by sovereign) desk [treaty crew]) =* so ~(. so:cc desk) :_(this [warp give]:so) -- @@ -275,7 +282,7 @@ :: ++ pact-from-docket |= [=desk =docket:docket] - ^+ pact + ^- pact =+ .^(=cass:clay %cw (scry:io desk /desk/docket)) =+ .^(hash=@uv %cz (scry:io desk ~)) =; buds @@ -306,7 +313,7 @@ |% ++ ally-update |=(=update:ally ally-update-0+!>(update)) ++ alliance-update |=(=update:alliance alliance-update-0+!>(update)) - ++ treaty |=(t=^treaty treaty-0+!>(t)) + ++ treaty |=(t=^treaty treaty-1+!>(t)) ++ treaty-update |=(u=update:^treaty treaty-update-0+!>(u)) -- :: +ca: Card construction @@ -323,7 +330,7 @@ ++ pass ~(. ^pass path) ++ path /treaty/(scot %p ship)/[desk] ++ dock [ship dap.bowl] - ++ watch (watch:pass dock path) + ++ watch [%pass path %agent dock %watch-as %treaty-1 path] ++ watching (~(has by wex.bowl) [path dock]) ++ safe-watch `(unit card)`?:(|(watching =(our.bowl ship)) ~ `watch) ++ leave (leave:pass dock) @@ -356,9 +363,9 @@ :: are handled in this core, not as "normal"/foreign treaties. :: ^- (list card) - =/ t=treaty (~(got by sovereign) desk) - :~ (fact:io (treaty-update:cg %add t) /treaties ~) - (fact:io (treaty:cg t) path ~) + =/ =pact (~(got by sovereign) desk) + :~ (fact:io (treaty-update:cg %add treaty.pact) /treaties ~) + (fact:io (treaty:cg treaty.pact) path ~) == ++ publish (poke-our:pass %hood kiln-permission+!>([desk / &])) diff --git a/desk/mar/treaty-1.hoon b/desk/mar/treaty-1.hoon new file mode 100644 index 00000000..4a6eef3b --- /dev/null +++ b/desk/mar/treaty-1.hoon @@ -0,0 +1,14 @@ +/- *treaty +/+ treat=treaty +|_ tret=treaty +++ grow + |% + ++ noun tret + ++ json (treaty:enjs:treat tret) + -- +++ grab + |% + ++ noun treaty + -- +++ grad %noun +-- diff --git a/ui/src/components/AppInfo.tsx b/ui/src/components/AppInfo.tsx index 5f1a06a3..635e1af3 100644 --- a/ui/src/components/AppInfo.tsx +++ b/ui/src/components/AppInfo.tsx @@ -16,6 +16,7 @@ import { import { getAppHref, getAppName } from '@/logic/utils'; import { addRecentApp } from '../nav/search/Home'; import { TreatyMeta } from './TreatyMeta'; +import { Attribute } from './Attribute'; type InstallStatus = 'uninstalled' | 'installing' | 'installed'; @@ -40,6 +41,15 @@ function getInstallStatus(docket: App): InstallStatus { return 'uninstalled'; } +function PermissionStatus({ treaty }: { treaty: Treaty }) { + return ( +
+ + {treaty?.signed ? 'Granted' : 'Not Granted'} + +
+ ); +} function getRemoteDesk(docket: App, pike?: Pike, treatyInfoShip?: string) { if (pike && pike.sync) { return [pike.sync.ship, pike.sync.desk]; @@ -94,7 +104,7 @@ export const AppInfo: FC = ({ } return ( -
+
{installStatus === 'installed' && ( @@ -111,10 +121,8 @@ export const AppInfo: FC = ({ {!treaty?.signed && ( + style={{ pointerEvents: 'none' }} + disabled> Not Listed ) || @@ -150,7 +158,7 @@ export const AppInfo: FC = ({ - @@ -166,6 +174,12 @@ export const AppInfo: FC = ({
+ {treaty && ( + <> +
+ + + )} {pike ? ( <>