const replyInsertPermission = await deep.insert({
type_id: Rule,
out: { data: [
{
type_id: RuleSubject,
to: { data: {
type_id: Selector,
out: { data: [
{
type_id: SelectorInclude,
to_id: usersId,
out: { data: {
type_id: SelectorTree,
to_id: await deep.id('@deep-foundation/core', 'joinTree'),
}, },
},
] },
}, },
},
{
type_id: RuleObject,
to: { data: {
type_id: Selector,
out: { data: [
{
type_id: SelectorInclude,
to_id: Reply,
out: { data: {
type_id: SelectorTree,
to_id: containTree,
}, },
},
{
type_id: SelectorFilter,
to: { data: {
type_id: BoolExp,
object: { data: {
value: {
// only if upper exists current user or join current user
to: {
_or: [
{
_by_item: { group_id: { _eq: messagingTree }, root_id: { _eq: 'X-Deep-User-Id' } },
},
{
_by_item: { group_id: { _eq: messagingTree }, path_item: { out: { type_id: { _eq: Join }, to_id: { _eq: 'X-Deep-User-Id' } } } },
},
],
},
from: {
out: {
type_id: { _eq: Author },
to_id: { _eq: 'X-Deep-User-Id' },
},
},
},
}, },
}, },
},
], },
}, },
},
{
type_id: RuleAction,
to: { data: {
type_id: Selector,
out: { data: [
{
type_id: SelectorInclude,
to_id: AllowInsert,
out: { data: {
type_id: SelectorTree,
to_id: containTree,
}, },
},
], },
}, },
},
], },
});