Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: fafc918b by Prashant Sharma at 2020-02-09T18:06:54+00:00 Allow action to be None for Header Filters. Currently, the REST API does not allow header filter action to be None since it uses enum_validator. However, it should be possible for the action to be None in which case `config.antispam.jump_chain` is used as the action. - - - - - a76a1e64 by Abhilash Raj at 2020-02-09T18:06:54+00:00 Merge branch 'allow_none_action' into 'master' Allow None action for header filter Closes #671 See merge request mailman/mailman!598 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/header_matches.py - src/mailman/rest/tests/test_header_matches.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -15,6 +15,7 @@ Here is a history of user visible changes to Mailman. Bugs ---- +* Allow ``action`` for header matches to be None in REST interface. (Closes #671) * It is now possible to add the list posting address with nonmember role, e.g. to give it a moderaction of discard. (Closes #633) * The issue of posting a message without a To: header to a fully personalized ===================================== src/mailman/rest/header_matches.py ===================================== @@ -96,7 +96,7 @@ class HeaderMatch(_HeaderMatchBase): header=lowercase, pattern=GetterSetter(regexp_validator), position=int, - action=enum_validator(Action), + action=enum_validator(Action, allow_blank=True), tag=lowercase, ) if is_optional: @@ -109,9 +109,12 @@ class HeaderMatch(_HeaderMatchBase): validator = Validator(**kws) try: arguments = validator(request) - action = arguments.pop('action', None) - if action is not None: + missing = object() + action = arguments.pop('action', missing) + if action is not missing and action is not None: arguments['chain'] = action.name + elif action is not missing and action is None: + arguments['chain'] = action for key, value in arguments.items(): setattr(header_match, key, value) except ValueError as error: @@ -147,7 +150,7 @@ class HeaderMatches(_HeaderMatchBase, CollectionMixin): validator = Validator( header=str, pattern=GetterSetter(regexp_validator), - action=enum_validator(Action), + action=enum_validator(Action, allow_blank=True), tag=str, _optional=('action', 'tag') ) ===================================== src/mailman/rest/tests/test_header_matches.py ===================================== @@ -119,6 +119,52 @@ class TestHeaderMatches(unittest.TestCase): for match in header_matches], [('header-1', '^Yes', 'hold', 'tag1')]) + def test_add_header_match_with_no_action(self): + _, resp = call_api('http://localhost:9001/3.0/lists/ant.example.com' + '/header-matches', { + 'header': 'header-1', + 'pattern': '^Yes', + 'action': '', + 'tag': 'tag1', + }, + method='POST') + self.assertEqual(resp.status_code, 201) + header_matches = IHeaderMatchList(self._mlist) + self.assertEqual( + [(match.header, match.pattern, match.chain, match.tag) + for match in header_matches], + [('header-1', '^Yes', None, 'tag1')]) + + def test_update_header_match_with_action(self): + header_matches = IHeaderMatchList(self._mlist) + with transaction(): + header_matches.append('header-1', '^Yes', 'hold', 'tag1') + _, resp = call_api('http://localhost:9001/3.0/lists/ant.example.com' + '/header-matches/0', { + 'action': '' + }, + method='PATCH') + self.assertEqual(resp.status_code, 204) + self.assertEqual( + [(match.header, match.pattern, match.chain, match.tag) + for match in header_matches], + [('header-1', '^Yes', None, 'tag1')]) + + def test_update_header_match_with_no_action(self): + header_matches = IHeaderMatchList(self._mlist) + with transaction(): + header_matches.append('header-1', '^Yes', 'hold', 'tag1') + _, resp = call_api('http://localhost:9001/3.0/lists/ant.example.com' + '/header-matches/0', { + 'pattern': '^No' + }, + method='PATCH') + self.assertEqual(resp.status_code, 204) + self.assertEqual( + [(match.header, match.pattern, match.chain, match.tag) + for match in header_matches], + [('header-1', '^No', 'hold', 'tag1')]) + def test_get_header_match_by_tag(self): header_matches = IHeaderMatchList(self._mlist) with transaction(): View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/3af7ed0b5b98efb3a4203b8d7a81bea5f20bda46...a76a1e64ae9d86c1ec94f8e2c66742e0778f0355 -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/3af7ed0b5b98efb3a4203b8d7a81bea5f20bda46...a76a1e64ae9d86c1ec94f8e2c66742e0778f0355 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org