def post(self): req = request.get_json(True) require_fields(req, ("options", "name", "type")) schema = get_configuration_schema_for_destination_type(req["type"]) if schema is None: abort(400) config = ConfigurationContainer(req["options"], schema) if not config.is_valid(): abort(400) destination = models.NotificationDestination( org=self.current_org, name=req["name"], type=req["type"], options=config, user=self.current_user, ) try: models.db.session.add(destination) models.db.session.commit() except IntegrityError as e: if "name" in str(e): abort( 400, message="Alert Destination with the name {} already exists." .format(req["name"]), ) abort(500) return destination.to_dict(all=True)
def post(self): req = request.get_json(True) require_fields(req, ('options', 'name', 'type')) schema = get_configuration_schema_for_destination_type(req['type']) if schema is None: abort(400) config = ConfigurationContainer(req['options'], schema) if not config.is_valid(): abort(400) destination = models.NotificationDestination(org=self.current_org, name=req['name'], type=req['type'], options=config, user=self.current_user) models.db.session.add(destination) models.db.session.commit() return destination.to_dict(all=True)