def post(self, request, project): """ Create a rule Create a new rule for the given project. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ serializer = RuleSerializer( context={'project': project}, data=request.DATA, ) if serializer.is_valid(): rule = serializer.save(rule=Rule()) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, project): """ Create a rule Create a new rule for the given project. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ serializer = RuleSerializer( context={'project': project}, data=request.DATA, ) if serializer.is_valid(): rule = serializer.save(rule=Rule()) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, project, rule_id): """ Update a rule Update various attributes for the given rule. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ rule = Rule.objects.get( project=project, id=rule_id, ) serializer = RuleSerializer({ 'actionMatch': rule.data.get('action_match', 'all'), }, context={'project': project}, data=request.DATA, partial=True) if serializer.is_valid(): rule = serializer.save(rule=rule) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, project): """ Create a rule Create a new rule for the given project. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ serializer = RuleSerializer(context={"project": project}, data=request.data) if serializer.is_valid(): rule = serializer.save(rule=Rule()) self.create_audit_entry( request=request, organization=project.organization, target_object=rule.id, event=AuditLogEntryEvent.RULE_ADD, data=rule.get_audit_log_data(), ) alert_rule_created.send_robust( user=request.user, project=project, rule=rule, sender=self ) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, project, rule_id): """ Update a rule Update various attributes for the given rule. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ rule = Rule.objects.get( project=project, id=rule_id, ) serializer = RuleSerializer( { 'actionMatch': rule.data.get('action_match', 'all'), }, context={'project': project}, data=request.DATA, partial=True) if serializer.is_valid(): rule = serializer.save(rule=rule) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, project): """ Create a rule Create a new rule for the given project. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ serializer = RuleSerializer( context={'project': project}, data=request.DATA, ) if serializer.is_valid(): rule = serializer.save(rule=Rule()) self.create_audit_entry( request=request, organization=project.organization, target_object=rule.id, event=AuditLogEntryEvent.RULE_ADD, data=rule.get_audit_log_data(), ) alert_rule_created.send(project=project, rule=rule, sender=self) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, project, rule_id): """ Update a rule Update various attributes for the given rule. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ rule = Rule.objects.get( project=project, id=rule_id, ) serializer = RuleSerializer( { 'actionMatch': rule.data.get('action_match') or Rule.DEFAULT_ACTION_MATCH, 'frequency': rule.data.get('frequency') or Rule.DEFAULT_FREQUENCY, }, context={'project': project}, data=request.DATA, partial=True) if serializer.is_valid(): rule = serializer.save(rule=rule) self.create_audit_entry( request=request, organization=project.organization, target_object=rule.id, event=AuditLogEntryEvent.RULE_EDIT, data=rule.get_audit_log_data(), ) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, project, rule_id): """ Update a rule Update various attributes for the given rule. {method} {path} {{ "name": "My rule name", "conditions": [], "actions": [], "actionMatch": "all" }} """ rule = Rule.objects.get( project=project, id=rule_id, ) serializer = RuleSerializer( { 'actionMatch': rule.data.get('action_match') or Rule.DEFAULT_ACTION_MATCH, 'frequency': rule.data.get('frequency') or Rule.DEFAULT_FREQUENCY, }, context={'project': project}, data=request.DATA, partial=True ) if serializer.is_valid(): rule = serializer.save(rule=rule) self.create_audit_entry( request=request, organization=project.organization, target_object=rule.id, event=AuditLogEntryEvent.RULE_EDIT, data=rule.get_audit_log_data(), ) return Response(serialize(rule, request.user)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)