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

treaty: add desk permissions check #215

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all 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
67 changes: 48 additions & 19 deletions desk/app/treaty.hoon
Original file line number Diff line number Diff line change
@@ -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,9 +75,11 @@
?. =(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
?^ crew.pact
[warp give]:so
[publish warp give]:so
::
%del
@@ -98,7 +100,13 @@
=/ =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: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))^~
@@ -138,8 +146,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 @ @ ~]
@@ -211,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)
@@ -222,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)
@@ -253,12 +267,11 @@
=* cage r.u.riot
?. =(%docket-0 p.cage) `this
=+ !<(=docket:docket q.cage)
=/ =treaty (treaty-from-docket:cc desk docket)
=. sovereign (~(put by sovereign) desk treaty)
=/ [=treaty =crew:clay] (pact-from-docket:cc desk docket)
=. sovereign (~(put by sovereign) desk [treaty crew])
=* so ~(. so:cc desk)
:_(this [warp give]:so)
--

::
++ on-fail on-fail:def
++ on-leave on-leave:def
@@ -267,11 +280,27 @@
++ 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])
^- 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
@@ -284,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
@@ -301,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)
@@ -334,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 / &]))
1 change: 1 addition & 0 deletions desk/lib/treaty.hoon
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
%- pairs
:~ ship+s+(scot %p ship.t)
desk+s+desk.t
signed+b+signed.t
cass+(case case.t)
hash+s+(scot %uv hash.t)
==
14 changes: 14 additions & 0 deletions desk/mar/treaty-1.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/- *treaty
/+ treat=treaty
|_ tret=treaty
++ grow
|%
++ noun tret
++ json (treaty:enjs:treat tret)
--
++ grab
|%
++ noun treaty
--
++ grad %noun
--
7 changes: 6 additions & 1 deletion desk/sur/treaty.hoon
Original file line number Diff line number Diff line change
@@ -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 =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
::
38 changes: 30 additions & 8 deletions ui/src/components/AppInfo.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="mt-5 space-y-5 sm:mt-8 sm:space-y-8">
<Attribute title="Desk Permission Status" attr="signed" className="break-all">
{treaty?.signed ? 'Granted' : 'Not Granted'}
</Attribute>
</div>
);
}
function getRemoteDesk(docket: App, pike?: Pike, treatyInfoShip?: string) {
if (pike && pike.sync) {
return [pike.sync.ship, pike.sync.desk];
@@ -82,6 +92,7 @@ export const AppInfo: FC<AppInfoProps> = ({
}, [publisher, desk]);

const installing = installStatus === 'installing';
const buttonText = treaty?.signed ? 'Get Whitelisted App' : 'Get App';

if (!docket) {
// TODO: maybe replace spinner with skeletons
@@ -93,7 +104,7 @@ export const AppInfo: FC<AppInfoProps> = ({
}

return (
<div className={cn('text-black', className)}>
<div className={cn('text-black', className)} style={{ overflowY: 'auto', maxHeight: '100vh' }}>
<DocketHeader docket={docket}>
<div className="col-span-2 flex items-center space-x-4 md:col-span-1">
{installStatus === 'installed' && (
@@ -103,12 +114,19 @@ export const AppInfo: FC<AppInfoProps> = ({
href={getAppHref(docket.href)}
target="_blank"
rel="noreferrer"
onClick={() => addRecentApp(docket.desk)}
>
onClick={() => addRecentApp(docket.desk)}>
Open App
</PillButton>
)}
{installStatus !== 'installed' && (
{!treaty?.signed && (
<PillButton
variant="secondary"
style={{ pointerEvents: 'none' }}
disabled>
Not Listed
</PillButton>
) ||
installStatus !== 'installed' && (
<Dialog.Root>
<DialogTrigger asChild>
<PillButton variant="alt-primary" disabled={installing}>
@@ -117,9 +135,7 @@ export const AppInfo: FC<AppInfoProps> = ({
<Spinner />
<span className="sr-only">Installing...</span>
</>
) : (
'Get App'
)}
) : buttonText}
</PillButton>
</DialogTrigger>
<Dialog.Portal>
@@ -142,7 +158,7 @@ export const AppInfo: FC<AppInfoProps> = ({
<Button variant="secondary">Cancel</Button>
</DialogClose>
<DialogClose asChild>
<Button onClick={installApp}>
<Button onClick={installApp} variant='alt-secondary'>
Get &ldquo;{getAppName(docket)}&rdquo;
</Button>
</DialogClose>
@@ -158,6 +174,12 @@ export const AppInfo: FC<AppInfoProps> = ({
</div>
</DocketHeader>
<div className="space-y-6">
{treaty && (
<>
<hr className="-mx-5 border-gray-50 sm:-mx-8" />
<PermissionStatus treaty={treaty} />
</>
)}
{pike ? (
<>
<hr className="-mx-5 border-gray-50 sm:-mx-8" />
1 change: 1 addition & 0 deletions ui/src/gear/docket/types.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ export interface SuspendChad {
export interface Treaty extends Docket {
ship: string;
desk: string;
signed: boolean;
cass: Cass;
hash: string;
}