Sorry if my title or question is unclear. I lack the vocabulary to formulate it properly.

I've got a classical tree structure with several layers. I have to manage authorization for each user, as not every user has access to all elements, so each user has their own view of the same tree.

What is the best way to store this kind of tree?

Should I store all the tree and use booleans to know if each user has access to each element? Or should I only store an array of elements? Are there any alternatives?

In this case, readability is more important than pure performance.

tree structure

  • $\begingroup$ "[...] as not every user have access to all elements, so each user have his own tree." You mean each user has their own view of the tree? Or does every user have a different tree altogether (and modifying the contents of one does not modify the contents of the others)? $\endgroup$ – dkaeae Feb 12 '19 at 9:03
  • $\begingroup$ Also, be wary of mentioning programming languages or ressources such as "MongoDB" and "JavaScript" since discussing their use is off-topic here (though might be on topic, for example, on Stack Overflow). See also our FAQ. $\endgroup$ – dkaeae Feb 12 '19 at 9:07
  • $\begingroup$ @dkaeae the full tree with all categories, subcategories and item is common to all users, so every users will see the "bus category" for example, but each users will have different authorization, so it could be checked for user A but not for user B $\endgroup$ – Kepotx Feb 12 '19 at 9:12
  • $\begingroup$ Then this is probably better formulated as "each user has their own view of the same tree". You should consider editing the question to make this clear. $\endgroup$ – dkaeae Feb 12 '19 at 9:15
  • $\begingroup$ IMHO this question would be more suited for stackoverflow or software engineering than for this SE-site $\endgroup$ – dingalapadum Feb 12 '19 at 10:00