def rights_can_SHOW(self, user): if not has_property(self, self.MetaRights.linked_unit_property): # Check if at least one of unit match for accred in user.accreditation_set.filter(end_date=None): if hasattr(self, 'MetaData') and hasattr( self.MetaData, 'costcenterlinked' ) and self.MetaData.costcenterlinked and accred.unit.costcenter_set.first( ): setattr(self, 'costcenter', accred.unit.costcenter_set.first()) try: set_property(self, self.MetaRights.linked_unit_property, accred.unit) if self.rights_can_SHOW(user): return True except: pass return hasattr(self.MetaRightsUnit, 'world_ro') and self.MetaRightsUnit.world_ro return (hasattr(self.MetaRightsUnit, 'world_ro') and self.MetaRightsUnit.world_ro) or ( self.MetaRightsUnit.unit_ro_access and self.rights_in_linked_unit(user) ) or self.rights_in_linked_unit(user, self.MetaRightsUnit.access)
def people_in_linked_unit(self, access=None): if not self.MetaRights.linked_unit_property or not has_property(self, self.MetaRights.linked_unit_property): return False unit = get_property(self, self.MetaRights.linked_unit_property) return self.people_in_unit(unit, access)
def rights_can_EDIT(self, user): # Peut toujours afficher, de manière générique if not has_property(self, self.MetaRights.linked_unit_property): return True if not get_property(self, self.MetaRights.linked_unit_property): # Pas d'unité. L'user doit être l'user try: return not self.unit_blank_user or self.unit_blank_user == user or self.rights_in_root_unit(user, self.MetaRightsUnit.access) except: return True # Pas d'unité, ni d'users return self.rights_in_linked_unit(user, self.MetaRightsUnit.access)
def rights_can_EDIT(self, user): # Peut toujours afficher, de manière générique if not has_property(self, self.MetaRights.linked_unit_property): return True if not get_property(self, self.MetaRights.linked_unit_property): # Pas d'unité. L'user doit être l'user try: return not self.unit_blank_user or self.unit_blank_user == user except: return True # Pas d'unité, ni d'users return self.rights_in_linked_unit(user, self.MetaRightsUnit.access)
def rights_can_SHOW(self, user): if not has_property(self, self.MetaRights.linked_unit_property): # Check if at least one of unit match for accred in user.accreditation_set.filter(end_date=None): if hasattr(self, 'MetaData') and hasattr(self.MetaData, 'costcenterlinked') and self.MetaData.costcenterlinked and accred.unit.costcenter_set.first(): setattr(self, 'costcenter', accred.unit.costcenter_set.first()) try: set_property(self, self.MetaRights.linked_unit_property, accred.unit) if self.rights_can_SHOW(user): return True except: pass return hasattr(self.MetaRightsUnit, 'world_ro') and self.MetaRightsUnit.world_ro return (hasattr(self.MetaRightsUnit, 'world_ro') and self.MetaRightsUnit.world_ro) or (self.MetaRightsUnit.unit_ro_access and self.rights_in_linked_unit(user)) or self.rights_in_linked_unit(user, self.MetaRightsUnit.access)
def rights_in_linked_unit(self, user, access=None): if not self.MetaRights.linked_unit_property or not has_property(self, self.MetaRights.linked_unit_property): return False unit = get_property(self, self.MetaRights.linked_unit_property) if not unit: e = Exception("Tried to test right in unit without an unit") raise e return False if type(access) is list: for acc in access: if self.rights_in_unit(user, unit, acc): return True return False return self.rights_in_unit(user, unit, access)