shrub/pkg/arvo/lib/group.hoon

124 lines
2.3 KiB
Plaintext
Raw Normal View History

/- *group, *metadata-store
/+ store=group-store, resource
2020-06-24 03:28:57 +03:00
::
2020-05-21 07:30:02 +03:00
|_ =bowl:gall
+$ card card:agent:gall
2020-05-21 07:30:02 +03:00
++ scry-for
|* [=mold =path]
.^ mold
%gx
(scot %p our.bowl)
%group-store
(scot %da now.bowl)
(snoc `^path`path %noun)
==
++ scry-tag
|= [rid=resource =tag]
^- (unit (set ship))
=/ group
(scry-group rid)
?~ group
~
`(~(gut by tags.u.group) tag ~)
2020-05-21 07:30:02 +03:00
::
++ scry-group-path
|= =path
%+ scry-for
(unit group)
[%groups path]
::
++ scry-group
|= rid=resource
2020-05-21 07:30:02 +03:00
%- scry-group-path
(en-path:resource rid)
2020-05-25 08:52:54 +03:00
::
++ members
|= rid=resource
2020-05-25 08:52:54 +03:00
%- members-from-path
(en-path:resource rid)
2020-05-21 07:30:02 +03:00
::
++ members-from-path
|= =group-path
^- (set ship)
=- members:(fall - *group)
(scry-group-path group-path)
::
2020-07-02 05:17:28 +03:00
++ is-member
2021-01-12 07:26:19 +03:00
|= [=ship group=resource]
2020-05-21 07:30:02 +03:00
^- ?
=- (~(has in -) ship)
2021-01-12 07:26:19 +03:00
(members group)
::
++ is-admin
2021-01-12 07:26:19 +03:00
|= [=ship group=resource]
^- ?
2021-01-12 07:26:19 +03:00
=/ tags tags:(fall (scry-group group) *^group)
=/ admins=(set ^ship) (~(gut by tags) %admin ~)
(~(has in admins) ship)
2020-05-27 07:32:43 +03:00
:: +role-for-ship: get role for user
2020-05-21 07:30:02 +03:00
::
2020-05-27 07:32:43 +03:00
:: Returns ~ if no such group exists or user is not
:: a member of the group. Returns [~ ~] if the user
:: is a member with no additional role.
2020-05-21 07:30:02 +03:00
++ role-for-ship
|= [rid=resource =ship]
2020-05-27 07:32:43 +03:00
^- (unit (unit role-tag))
2020-05-21 07:30:02 +03:00
=/ grp=(unit group)
(scry-group rid)
2020-05-21 07:30:02 +03:00
?~ grp ~
=* group u.grp
=* policy policy.group
2020-05-27 09:19:29 +03:00
=* tags tags.group
2020-05-21 07:30:02 +03:00
=/ admins=(set ^ship)
2020-05-27 09:19:29 +03:00
(~(gut by tags) %admin ~)
2020-05-21 07:30:02 +03:00
?: (~(has in admins) ship)
2020-05-27 07:32:43 +03:00
``%admin
2020-05-21 07:30:02 +03:00
=/ mods
2020-05-27 09:19:29 +03:00
(~(gut by tags) %moderator ~)
2020-05-21 07:30:02 +03:00
?: (~(has in mods) ship)
2020-05-27 07:32:43 +03:00
``%moderator
2020-05-21 07:30:02 +03:00
=/ janitors
2020-05-27 09:19:29 +03:00
(~(gut by tags) %janitor ~)
2020-05-21 07:30:02 +03:00
?: (~(has in janitors) ship)
2020-05-27 07:32:43 +03:00
``%janitor
2020-05-21 07:30:02 +03:00
?: (~(has in members.group) ship)
2020-05-27 07:32:43 +03:00
[~ ~]
2020-05-21 07:30:02 +03:00
~
::
2020-05-25 08:52:54 +03:00
++ can-join-from-path
2020-05-21 07:30:02 +03:00
|= [=path =ship]
%+ scry-for
?
%+ welp
[%groups path]
/join/[(scot %p ship)]
2020-05-25 08:52:54 +03:00
::
++ can-join
|= [rid=resource =ship]
2020-05-25 08:52:54 +03:00
%+ can-join-from-path
(en-path:resource rid)
2020-05-25 08:52:54 +03:00
ship
::
2021-01-26 05:42:44 +03:00
++ get-tagged-ships
|= [rid=resource =tag]
^- (set ship)
=/ grp=(unit group)
(scry-group rid)
?~ grp ~
(~(get ju tags.u.grp) tag)
::
2020-05-25 08:52:54 +03:00
++ is-managed-path
|= =path
2020-05-27 07:32:43 +03:00
^- ?
=/ group=(unit group)
(scry-group-path path)
?~ group %.n
!hidden.u.group
::
2020-05-25 08:52:54 +03:00
++ is-managed
|= rid=resource
2020-05-25 08:52:54 +03:00
%- is-managed-path
(en-path:resource rid)
2020-05-27 07:32:43 +03:00
::
2020-05-21 07:30:02 +03:00
--