コード例 #1
0
    def static_rights_can(cls,
                          right,
                          user,
                          unit_to_link=None,
                          year_to_link=None):

        dummy = cls()

        if unit_to_link and hasattr(
                dummy.MetaRights, 'linked_unit_property'
        ) and dummy.MetaRights.linked_unit_property:
            if hasattr(dummy, 'MetaData') and hasattr(
                    dummy.MetaData,
                    'costcenterlinked') and dummy.MetaData.costcenterlinked:
                if unit_to_link.costcenter_set.first():
                    setattr(dummy, 'costcenter',
                            unit_to_link.costcenter_set.first())
                else:  # No costcenter, set a dummy one
                    from accounting_core.models import CostCenter
                    setattr(dummy, 'costcenter', CostCenter())
            set_property(dummy, dummy.MetaRights.linked_unit_property,
                         unit_to_link)

        if unit_to_link and hasattr(dummy, 'generic_set_dummy_unit'):
            dummy.generic_set_dummy_unit(unit_to_link)

        from accounting_core.utils import AccountingYearLinked

        if year_to_link and isinstance(dummy, AccountingYearLinked):
            dummy.accounting_year = year_to_link

        return dummy.rights_can(right, user)
コード例 #2
0
    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)
コード例 #3
0
ファイル: utils.py プロジェクト: AnomalRoil/truffe2
    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)
コード例 #4
0
ファイル: utils.py プロジェクト: AnomalRoil/truffe2
    def static_rights_can(cls, right, user, unit_to_link=None, year_to_link=None):

        dummy = cls()

        if unit_to_link and hasattr(dummy.MetaRights, 'linked_unit_property') and dummy.MetaRights.linked_unit_property:
            if hasattr(dummy, 'MetaData') and hasattr(dummy.MetaData, 'costcenterlinked') and dummy.MetaData.costcenterlinked:
                if unit_to_link.costcenter_set.first():
                    setattr(dummy, 'costcenter', unit_to_link.costcenter_set.first())
                else:  # No costcenter, set a dummy one
                    from accounting_core.models import CostCenter
                    setattr(dummy, 'costcenter', CostCenter())
            set_property(dummy, dummy.MetaRights.linked_unit_property, unit_to_link)

        if unit_to_link and hasattr(dummy, 'generic_set_dummy_unit'):
            dummy.generic_set_dummy_unit(unit_to_link)

        from accounting_core.utils import AccountingYearLinked

        if year_to_link and isinstance(dummy, AccountingYearLinked):
            dummy.accounting_year = year_to_link

        return dummy.rights_can(right, user)