urbit/pkg/landscape/lib/group-store.hoon

452 lines
9.1 KiB
Plaintext
Raw Normal View History

2020-05-15 01:50:04 +03:00
/- *group, sur=group-store
/+ resource
2020-05-15 01:50:04 +03:00
^?
=< [. sur]
=, sur
|%
::
++ dekebab
|= str=cord
^- cord
=- (fall - str)
%+ rush str
=/ name
%+ cook
|= part=tape
^- tape
?~ part part
:- (sub i.part 32)
t.part
(star low)
%+ cook
(cork (bake zing (list tape)) crip)
;~(plug (star low) (more hep name))
::
++ enkebab
|= str=cord
^- cord
~| str
=- (fall - str)
%+ rush str
=/ name
%+ cook
|= part=tape
^- tape
?~ part part
:- (add i.part 32)
t.part
;~(plug hig (star low))
%+ cook
|=(a=(list tape) (crip (zing (join "-" a))))
;~(plug (star low) (star name))
++ migrate-path-map
|* map=(map path *)
=/ keys=(list path)
(skim ~(tap in ~(key by map)) |=(=path =('~' (snag 0 path))))
|-
?~ keys
map
=* key i.keys
?> ?=(^ key)
=/ value
(~(got by map) key)
2020-06-24 03:28:57 +03:00
=. map
(~(put by map) t.key value)
=. map
(~(del by map) key)
$(keys t.keys, map (~(put by map) t.key value))
2020-05-15 01:50:04 +03:00
::
2020-05-21 07:30:02 +03:00
++ enjs
=, enjs:format
|%
++ frond
|= [p=@t q=json]
^- json
(frond:enjs:format (dekebab p) q)
++ pairs
|= a=(list [p=@t q=json])
^- json
%- pairs:enjs:format
%+ turn a
|= [p=@t q=json]
^- [@t json]
[(dekebab p) q]
2020-05-21 07:30:02 +03:00
::
++ update
|= =^update
^- json
%+ frond -.update
?- -.update
%add-group (add-group update)
%add-members (add-members update)
%add-tag (add-tag update)
%remove-members (remove-members update)
%remove-tag (remove-tag update)
%initial (initial update)
%initial-group (initial-group update)
%remove-group (remove-group update)
%change-policy (change-policy update)
2020-07-02 05:17:28 +03:00
%expose (expose update)
2020-05-21 07:30:02 +03:00
==
::
2020-05-21 07:30:02 +03:00
++ initial-group
|= =^update
?> ?=(%initial-group -.update)
%- pairs
:~ resource+(enjs:resource resource.update)
2020-05-21 07:30:02 +03:00
group+(group group.update)
==
::
++ initial
|= =^initial
?> ?=(%initial -.initial)
%- pairs
^- (list [@t json])
2020-05-21 07:30:02 +03:00
%+ turn
~(tap by groups.initial)
|= [rid=resource grp=^group]
2020-05-21 07:30:02 +03:00
^- [@t json]
:_ (group grp)
(enjs-path:resource rid)
2020-05-21 07:30:02 +03:00
::
++ group
|= =^group
^- json
%- pairs
:~ members+(set ship members.group)
policy+(policy policy.group)
2020-05-27 09:19:29 +03:00
tags+(tags tags.group)
hidden+b+hidden.group
2020-05-21 07:30:02 +03:00
==
::
++ rank
|= =rank:title
^- json
[%s rank]
2020-05-27 09:19:29 +03:00
++ tags
|= =^tags
2020-05-27 05:21:10 +03:00
^- json
2021-01-26 05:42:44 +03:00
%- pairs
%+ turn ~(tap by tags)
|= [=^tag ships=(^set ^ship)]
^- [@t json]
:_ (set ship ships)
?@ tag tag
;: (cury cat 3)
app.tag '\\'
tag.tag '\\'
(enjs-path:resource resource.tag)
==
2020-05-21 07:30:02 +03:00
::
++ set
|* [item=$-(* json) sit=(^set)]
^- json
:- %a
%+ turn
~(tap in sit)
item
::
2020-05-27 09:19:29 +03:00
++ tag
|= =^tag
^- json
?@ tag
(frond %tag s+tag)
%- pairs
:~ app+s+app.tag
tag+s+tag.tag
resource+s+(enjs-path:resource resource.tag)
2020-05-27 09:19:29 +03:00
==
2020-05-21 07:30:02 +03:00
::
++ policy
|= =^policy
%+ frond -.policy
%- pairs
?- -.policy
%invite
:~ pending+(set ship pending.policy)
==
%open
:~ banned+(set ship banned.policy)
ban-ranks+(set rank ban-ranks.policy)
2020-05-21 07:30:02 +03:00
==
==
++ policy-diff
|= =diff:^policy
%+ frond -.diff
|^
?- -.diff
%invite (invite +.diff)
%open (open +.diff)
%replace (policy +.diff)
2020-05-21 07:30:02 +03:00
==
++ open
|= =diff:open:^policy
%+ frond -.diff
?- -.diff
%allow-ranks (set rank ranks.diff)
%ban-ranks (set rank ranks.diff)
%allow-ships (set ship ships.diff)
%ban-ships (set ship ships.diff)
==
++ invite
|= =diff:invite:^policy
%+ frond -.diff
?- -.diff
%add-invites (set ship invitees.diff)
%remove-invites (set ship invitees.diff)
==
--
2020-05-21 07:30:02 +03:00
::
2020-07-02 05:17:28 +03:00
++ expose
2020-05-27 07:32:43 +03:00
|= =^update
^- json
2020-07-02 05:17:28 +03:00
?> ?=(%expose -.update)
(frond %resource (enjs:resource resource.update))
2020-05-27 07:32:43 +03:00
::
2020-05-21 07:30:02 +03:00
++ remove-group
|= =^update
^- json
?> ?=(%remove-group -.update)
(frond %resource (enjs:resource resource.update))
2020-05-21 07:30:02 +03:00
::
++ add-group
|= =action
^- json
?> ?=(%add-group -.action)
%- pairs
:~ resource+(enjs:resource resource.action)
2020-05-21 07:30:02 +03:00
policy+(policy policy.action)
2020-05-27 07:32:43 +03:00
hidden+b+hidden.action
2020-05-21 07:30:02 +03:00
==
::
++ add-members
|= =action
^- json
?> ?=(%add-members -.action)
%- pairs
:~ resource+(enjs:resource resource.action)
2020-05-21 07:30:02 +03:00
ships+(set ship ships.action)
==
::
++ remove-members
|= =action
^- json
?> ?=(%remove-members -.action)
%- pairs
:~ resource+(enjs:resource resource.action)
2020-05-21 07:30:02 +03:00
ships+(set ship ships.action)
==
::
++ add-tag
|= =action
^- json
?> ?=(%add-tag -.action)
%- pairs
^- (list [p=@t q=json])
:~ resource+(enjs:resource resource.action)
2020-05-27 09:19:29 +03:00
tag+(tag tag.action)
2020-05-21 07:30:02 +03:00
ships+(set ship ships.action)
==
::
++ remove-tag
|= =action
^- json
?> ?=(%remove-tag -.action)
%- pairs
:~ resource+(enjs:resource resource.action)
2020-05-27 09:19:29 +03:00
tag+(tag tag.action)
2020-05-21 07:30:02 +03:00
ships+(set ship ships.action)
==
::
++ change-policy
|= =action
^- json
?> ?=(%change-policy -.action)
%- pairs
:~ resource+(enjs:resource resource.action)
diff+(policy-diff diff.action)
2020-05-21 07:30:02 +03:00
==
--
++ dejs
=, dejs:format
|%
::
++ ruk-jon
|= [a=(map @t json) b=$-(@t @t)]
^+ a
=- (malt -)
|-
^- (list [@t json])
?~ a ~
:- [(b p.n.a) q.n.a]
%+ weld
$(a l.a)
$(a r.a)
::
++ of
|* wer=(pole [cord fist])
|= jon=json
?> ?=([%o [@ *] ~ ~] jon)
|-
?- wer
:: [[key=@t wit=*] t=*]
[[key=@t *] t=*]
=> .(wer [[* wit] *]=wer)
?: =(key.wer (enkebab p.n.p.jon))
[key.wer ~|(val+q.n.p.jon (wit.wer q.n.p.jon))]
?~ t.wer ~|(bad-key+p.n.p.jon !!)
((of t.wer) jon)
==
++ ot
|* wer=(pole [cord fist])
|= jon=json
~| jon
%- (ot-raw:dejs:format wer)
?> ?=(%o -.jon)
(ruk-jon p.jon enkebab)
::
++ update
^- $-(json ^update)
|= jon=json
^- ^update
%. jon
2020-05-21 07:30:02 +03:00
%- of
:~
add-group+add-group
add-members+add-members
remove-members+remove-members
add-tag+add-tag
remove-tag+remove-tag
change-policy+change-policy
remove-group+remove-group
2020-07-02 05:17:28 +03:00
expose+expose
2020-05-21 07:30:02 +03:00
==
++ rank
|= =json
^- rank:title
?> ?=(%s -.json)
?: =('czar' p.json) %czar
?: =('king' p.json) %king
?: =('duke' p.json) %duke
?: =('earl' p.json) %earl
?: =('pawn' p.json) %pawn
2020-05-26 02:50:29 +03:00
!!
2020-05-27 09:19:29 +03:00
++ tag
|= =json
^- ^tag
?> ?=(%o -.json)
?. (~(has by p.json) 'app')
=/ tag-json
(~(got by p.json) 'tag')
?> ?=(%s -.tag-json)
?: =('admin' p.tag-json) %admin
?: =('moderator' p.tag-json) %moderator
?: =('janitor' p.tag-json) %janitor
2020-05-27 09:19:29 +03:00
!!
%. json
%- ot
:~ app+so
resource+dejs-path:resource
tag+so
2020-05-27 09:19:29 +03:00
==
2020-05-21 07:30:02 +03:00
:: move to zuse also
++ oj
|* =fist
^- $-(json (jug cord _(fist *json)))
(om (as fist))
2020-05-27 09:19:29 +03:00
++ tags
^- $-(json ^tags)
*$-(json ^tags)
2020-05-21 07:30:02 +03:00
:: TODO: move to zuse
++ ship
(su ;~(pfix sig fed:ag))
++ policy
^- $-(json ^policy)
%- of
:~ invite+invite-policy
open+open-policy
==
++ invite-policy
%- ot
:~ pending+(as ship)
==
++ open-policy
%- ot
:~ ban-ranks+(as rank)
2020-05-21 07:30:02 +03:00
banned+(as ship)
==
++ open-policy-diff
2020-05-21 07:30:02 +03:00
%- of
:~ allow-ranks+(as rank)
2020-05-21 07:30:02 +03:00
allow-ships+(as ship)
ban-ranks+(as rank)
ban-ships+(as ship)
==
++ invite-policy-diff
%- of
:~ add-invites+(as ship)
remove-invites+(as ship)
==
++ policy-diff
^- $-(json diff:^policy)
%- of
:~ invite+invite-policy-diff
open+open-policy-diff
2020-05-21 07:30:02 +03:00
replace+policy
==
::
2020-05-21 07:30:02 +03:00
++ remove-group
|= =json
^- [resource ~]
2020-05-21 07:30:02 +03:00
?> ?=(%o -.json)
=/ rid=resource
(dejs:resource (~(got by p.json) 'resource'))
[rid ~]
2020-05-27 07:32:43 +03:00
::
2020-07-02 05:17:28 +03:00
++ expose
2020-05-27 07:32:43 +03:00
|= =json
^- [resource ~]
2020-05-27 07:32:43 +03:00
?> ?=(%o -.json)
=/ rid=resource
(dejs:resource (~(got by p.json) 'resource'))
[rid ~]
2020-05-27 07:32:43 +03:00
::
2020-05-21 07:30:02 +03:00
++ add-group
%- ot
:~ resource+dejs:resource
2020-05-21 07:30:02 +03:00
policy+policy
2020-05-27 07:32:43 +03:00
hidden+bo
2020-05-21 07:30:02 +03:00
==
++ add-members
%- ot
:~ resource+dejs:resource
2020-05-21 07:30:02 +03:00
ships+(as ship)
==
++ remove-members
^- $-(json [resource (set ^ship)])
2020-05-21 07:30:02 +03:00
%- ot
:~ resource+dejs:resource
2020-05-21 07:30:02 +03:00
ships+(as ship)
==
++ add-tag
%- ot
:~ resource+dejs:resource
2020-05-27 09:19:29 +03:00
tag+tag
2020-05-21 07:30:02 +03:00
ships+(as ship)
==
++ remove-tag
%- ot
:~ resource+dejs:resource
2020-05-27 09:19:29 +03:00
tag+tag
2020-05-21 07:30:02 +03:00
ships+(as ship)
==
++ change-policy
%- ot
:~ resource+dejs:resource
diff+policy-diff
2020-05-21 07:30:02 +03:00
==
--
2020-05-15 01:50:04 +03:00
--