Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        """
        Saves the action. If new, checks it against current passed policies. Note: Only meant for internal use.
        """
        if self.shouldCreate():
            if self.data is None:
                self.data = DataStore.objects.create()

            #runs only if they have propose permission
            if self.initiator.has_perm(self._meta.app_label + '.add_' +
                                       self.action_codename):
                if hasattr(self, 'proposal'):
                    self.proposal.status = Proposal.PROPOSED
                else:
                    self.proposal = Proposal.objects.create(
                        status=Proposal.PROPOSED)
                super(ConstitutionAction, self).save(*args, **kwargs)

                if not self.is_bundled:
                    govern_action(self, is_first_evaluation=True)
            else:
                self.proposal = Proposal.objects.create(status=Proposal.FAILED)
                super(ConstitutionAction, self).save(*args, **kwargs)
        else:
            if not self.pk:  # Runs only when object is new
                self.proposal = Proposal.objects.create(status=Proposal.FAILED)
            super(ConstitutionAction, self).save(*args, **kwargs)
Exemplo n.º 2
0
    def save(self, *args, **kwargs):
        if not self.pk:
            action = self
            if action.initiator.has_perm(action._meta.app_label + '.add_' +
                                         action._meta.verbose_name):
                govern_action(action, is_first_evaluation=True)

        super(ConstitutionActionBundle, self).save(*args, **kwargs)
Exemplo n.º 3
0
    def save(self, *args, **kwargs):
        if not self.pk:
            action = self
            if action.initiator.has_perm(action._meta.app_label + '.add_' +
                                         action.action_codename):
                govern_action(action, is_first_evaluation=True)

        super(PlatformActionBundle, self).save(*args, **kwargs)
Exemplo n.º 4
0
def consider_proposed_actions():
    platform_actions = PlatformAction.objects.filter(
        proposal__status=Proposal.PROPOSED, is_bundled=False)
    logger.info(f"{platform_actions.count()} proposed PlatformActions")
    for action in platform_actions:
        govern_action(action, is_first_evaluation=False)
    """bundle_actions = PlatformActionBundle.objects.filter(proposal__status=Proposal.PROPOSED)
    for action in bundle_actions:
        govern_action(action, is_first_evaluation=False)"""

    constitution_actions = ConstitutionAction.objects.filter(
        proposal__status=Proposal.PROPOSED, is_bundled=False)
    logger.info(f"{constitution_actions.count()} proposed ConstitutionActions")
    for action in constitution_actions:
        govern_action(action, is_first_evaluation=False)

    clean_up_logs()
    logger.info('finished task')
Exemplo n.º 5
0
def consider_proposed_actions():
    # import PK modules inside the task so we get code updates.
    from policyengine.views import govern_action
    from policyengine.models import ConstitutionAction, PlatformAction, Proposal

    platform_actions = PlatformAction.objects.filter(
        proposal__status=Proposal.PROPOSED, is_bundled=False)
    logger.debug(f"{platform_actions.count()} proposed PlatformActions")
    for action in platform_actions:
        govern_action(action, is_first_evaluation=False)
    """bundle_actions = PlatformActionBundle.objects.filter(proposal__status=Proposal.PROPOSED)
    for action in bundle_actions:
        govern_action(action, is_first_evaluation=False)"""

    constitution_actions = ConstitutionAction.objects.filter(
        proposal__status=Proposal.PROPOSED, is_bundled=False)
    logger.debug(
        f"{constitution_actions.count()} proposed ConstitutionActions")
    for action in constitution_actions:
        govern_action(action, is_first_evaluation=False)

    clean_up_logs()
    logger.debug("finished task")