Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        if self.shouldCreate():
            #runs only if they have propose permission
            if self.initiator.has_perm(self.app_name + '.add_' + self.action_codename):
                if hasattr(self, 'proposal'):
                    self.proposal.status = Proposal.PROPOSED
                else:
                    self.proposal = Proposal.objects.create(status=Proposal.PROPOSED, author=self.initiator)
                super(ConstitutionAction, self).save(*args, **kwargs)

                if not self.is_bundled:
                    action = self
                    #if they have execute permission, skip all policies
                    if action.initiator.has_perm(action.app_name + '.can_execute_' + action.action_codename):
                        action.execute()
                    else:
                        for policy in ConstitutionPolicy.objects.filter(community=self.community):
                          if filter_policy(policy, action):

                              initialize_policy(policy, action)

                              check_result = check_policy(policy, action)
                              if check_result == Proposal.PASSED:
                                  pass_policy(policy, action)
                              elif check_result == Proposal.FAILED:
                                  fail_policy(policy, action)
                              else:
                                  notify_policy(policy, action)
            else:
                self.proposal = Proposal.objects.create(status=Proposal.FAILED, author=self.initiator)
        else:
            if not self.pk: # Runs only when object is new
                self.proposal = Proposal.objects.create(status=Proposal.FAILED, author=self.initiator)
            super(ConstitutionAction, self).save(*args, **kwargs)
Exemplo n.º 2
0
    def save(self, *args, **kwargs):
        logger.info('entered save')
        if not self.pk:
            logger.info('is pk')
            #runs only if they have propose permission
            if self.initiator.has_perm(self.app_name + '.add_' +
                                       self.action_codename):
                logger.info('has propose permission')
                p = Proposal.objects.create(status=Proposal.PROPOSED,
                                            author=self.initiator)
                self.proposal = p

                super(PlatformAction, self).save(*args, **kwargs)

                if not self.is_bundled:
                    action = self
                    #if they have execute permission, skip all policies
                    if action.initiator.has_perm(action.app_name +
                                                 '.can_execute_' +
                                                 action.action_codename):
                        logger.info('has execute permission')
                        action.execute()
                    else:
                        for policy in PlatformPolicy.objects.filter(
                                community=self.community):

                            logger.info('save: policy checking')
                            if filter_policy(policy, action):

                                initialize_policy(policy, action)

                                check_result = check_policy(policy, action)
                                if check_result == Proposal.PASSED:
                                    logger.info('passed (save)')
                                    pass_policy(policy, action)
                                elif check_result == Proposal.FAILED:
                                    logger.info('failed (save)')
                                    fail_policy(policy, action)
                                else:
                                    logger.info('notify (save)')
                                    notify_policy(policy, action)
            else:
                logger.info('does not have propose permission')
                p = Proposal.objects.create(status=Proposal.FAILED,
                                            author=self.initiator)
                self.proposal = p
        else:
            super(PlatformAction, self).save(*args, **kwargs)
Exemplo n.º 3
0
def after_constitutionaction_bundle_save(sender, instance, **kwargs):
    action = instance
    if action.initiator.has_perm(action.app_name + '.add_' + action.action_codename):
        #if they have execute permission, skip all policies
        if action.initiator.has_perm(action.app_name + '.can_execute_' + action.action_codename):
            action.execute()
        else:
            for policy in ConstitutionPolicy.objects.filter(community=action.community):
                if filter_policy(policy, action):

                    initialize_policy(policy, action)

                    check_result = check_policy(policy, action)
                    if check_result == Proposal.PASSED:
                      pass_policy(policy, action)
                    elif check_result == Proposal.FAILED:
                      fail_policy(policy, action)
                    else:
                      notify_policy(policy, action)