urbit/pkg/arvo/lib/group.hoon

94 lines
1.8 KiB
Plaintext
Raw Normal View History

2021-01-28 09:13:57 +03:00
/- *group
/+ 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]
2021-01-28 09:13:57 +03:00
=. path
(snoc path %noun)
2020-05-21 07:30:02 +03:00
.^ mold
%gx
(scot %p our.bowl)
%group-store
(scot %da now.bowl)
2021-01-28 09:13:57 +03:00
path
2020-05-21 07:30:02 +03:00
==
++ 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
|= rid=resource
2021-01-28 09:13:57 +03:00
%+ scry-for ,(unit group)
`path`groups+(en-path:resource rid)
2020-05-25 08:52:54 +03:00
::
++ members
|= rid=resource
2021-01-28 09:13:57 +03:00
=; =group
members.group
(fall (scry-group rid) *group)
2020-05-21 07:30:02 +03:00
::
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
|= [rid=resource =ship]
2021-01-28 09:13:57 +03:00
%+ scry-for ,?
^- path
:- %groups
(weld (en-path:resource rid) /join/(scot %p ship))
::
2021-01-28 09:13:57 +03:00
++ is-managed
|= rid=resource
2020-05-27 07:32:43 +03:00
=/ group=(unit group)
2021-01-28 09:13:57 +03:00
(scry-group rid)
2020-05-27 07:32:43 +03:00
?~ group %.n
!hidden.u.group
::
2020-05-21 07:30:02 +03:00
--