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


closed as off-topic by David Richerby, Evil, Yuval Filmus, Thomas Klimpel, Luke Mathieson Feb 12 at 23:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – David Richerby, Evil, Thomas Klimpel, Luke Mathieson
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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 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 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 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 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 at 10:00