✨(backend) add computed link reach and role to document API
On a document, we need to display the status of the link (reach and role) taking into account the ancestors link reach/role as well as the current document.
This commit is contained in:
committed by
Anthony LC
parent
1c34305393
commit
c1fc1bd52f
@@ -493,6 +493,7 @@ class Document(MP_Node, BaseModel):
|
||||
"""Initialize cache property."""
|
||||
super().__init__(*args, **kwargs)
|
||||
self._ancestors_link_definition = None
|
||||
self._computed_link_definition = None
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Write content to object storage only if _content has changed."""
|
||||
@@ -716,6 +717,11 @@ class Document(MP_Node, BaseModel):
|
||||
|
||||
return paths_links_mapping
|
||||
|
||||
@property
|
||||
def link_definition(self):
|
||||
"""Returns link reach/role as a definition in dictionary format."""
|
||||
return {"link_reach": self.link_reach, "link_role": self.link_role}
|
||||
|
||||
@property
|
||||
def ancestors_link_definition(self):
|
||||
"""Link defintion equivalent to all document's ancestors."""
|
||||
@@ -746,6 +752,28 @@ class Document(MP_Node, BaseModel):
|
||||
"""Link role equivalent to all document's ancestors."""
|
||||
return self.ancestors_link_definition["link_role"]
|
||||
|
||||
@property
|
||||
def computed_link_definition(self):
|
||||
"""
|
||||
Link reach/role on the document, combining inherited ancestors' link
|
||||
definitions and the document's own link definition.
|
||||
"""
|
||||
if getattr(self, "_computed_link_definition", None) is None:
|
||||
self._computed_link_definition = get_equivalent_link_definition(
|
||||
[self.ancestors_link_definition, self.link_definition]
|
||||
)
|
||||
return self._computed_link_definition
|
||||
|
||||
@property
|
||||
def computed_link_reach(self):
|
||||
"""Actual link reach on the document."""
|
||||
return self.computed_link_definition["link_reach"]
|
||||
|
||||
@property
|
||||
def computed_link_role(self):
|
||||
"""Actual link role on the document."""
|
||||
return self.computed_link_definition["link_role"]
|
||||
|
||||
def get_abilities(self, user):
|
||||
"""
|
||||
Compute and return abilities for a given user on the document.
|
||||
|
||||
Reference in New Issue
Block a user