Exemplo n.º 1
0
 def on_post(self, request, response):
     try:
         validator = Validator(action=enum_validator(Action))
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     requests = IListRequests(self._mlist)
     try:
         request_id = int(self._request_id)
     except ValueError:
         bad_request(response)
         return
     results = requests.get_request(request_id)
     if results is None:
         not_found(response)
         return
     key, data = results
     try:
         request_type = RequestType[data['_request_type']]
     except ValueError:
         bad_request(response)
         return
     if request_type is RequestType.subscription:
         handle_subscription(self._mlist, request_id, **arguments)
     elif request_type is RequestType.unsubscription:
         handle_unsubscription(self._mlist, request_id, **arguments)
     else:
         bad_request(response)
         return
     no_content(response)
Exemplo n.º 2
0
 def moderate(self, request):
     try:
         validator = Validator(action=enum_validator(Action))
         arguments = validator(request)
     except ValueError as error:
         return http.bad_request([], str(error))
     requests = IListRequests(self._mlist)
     try:
         request_id = int(self._request_id)
     except ValueError:
         return http.bad_request()
     results = requests.get_request(request_id)
     if results is None:
         return http.not_found()
     key, data = results
     try:
         request_type = RequestType(data['_request_type'])
     except ValueError:
         return http.bad_request()
     if request_type is RequestType.subscription:
         handle_subscription(self._mlist, request_id, **arguments)
     elif request_type is RequestType.unsubscription:
         handle_unsubscription(self._mlist, request_id, **arguments)
     else:
         return http.bad_request()
     return no_content()
Exemplo n.º 3
0
 def test_unsubscribe_defer(self):
     # When unsubscriptions must be approved by the moderator, but the
     # moderator defers this decision.
     user_manager = getUtility(IUserManager)
     anne = user_manager.create_address('*****@*****.**', 'Anne Person')
     token, token_owner, member = self._manager.register(
         anne, pre_verified=True, pre_confirmed=True, pre_approved=True)
     self.assertIsNone(token)
     self.assertEqual(member.address.email, '*****@*****.**')
     bart = user_manager.create_user('*****@*****.**', 'Bart User')
     address = set_preferred(bart)
     self._mlist.subscribe(address, MemberRole.moderator)
     # Now hold and handle an unsubscription request.
     token = hold_unsubscription(self._mlist, '*****@*****.**')
     handle_unsubscription(self._mlist, token, Action.defer)
     items = get_queue_messages('virgin', expected_count=2)
     # Find the moderator message.
     for item in items:
         if item.msg['to'] == '*****@*****.**':
             break
     else:
         raise AssertionError('No moderator email found')
     self.assertEqual(
         item.msgdata['recipients'], {'*****@*****.**'})
     self.assertEqual(
         item.msg['subject'],
         'New unsubscription request from Test by [email protected]')
Exemplo n.º 4
0
 def on_post(self, request, response):
     try:
         validator = Validator(action=enum_validator(Action))
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     requests = IListRequests(self._mlist)
     try:
         request_id = int(self._request_id)
     except ValueError:
         bad_request(response)
         return
     results = requests.get_request(request_id)
     if results is None:
         not_found(response)
         return
     key, data = results
     try:
         request_type = RequestType[data['_request_type']]
     except ValueError:
         bad_request(response)
         return
     if request_type is RequestType.subscription:
         handle_subscription(self._mlist, request_id, **arguments)
     elif request_type is RequestType.unsubscription:
         handle_unsubscription(self._mlist, request_id, **arguments)
     else:
         bad_request(response)
         return
     no_content(response)
Exemplo n.º 5
0
 def test_unsubscribe_defer(self):
     # When unsubscriptions must be approved by the moderator, but the
     # moderator defers this decision.
     token = hold_subscription(
         self._mlist,
         RequestRecord('*****@*****.**', 'Anne Person',
                       DeliveryMode.regular, 'en'))
     handle_subscription(self._mlist, token, Action.accept)
     # Now hold and handle an unsubscription request.
     token = hold_unsubscription(self._mlist, '*****@*****.**')
     handle_unsubscription(self._mlist, token, Action.defer)
Exemplo n.º 6
0
 def test_unsubscribe_defer(self):
     # When unsubscriptions must be approved by the moderator, but the
     # moderator defers this decision.
     anne = getUtility(IUserManager).create_address('*****@*****.**',
                                                    'Anne Person')
     token, token_owner, member = self._registrar.register(
         anne, pre_verified=True, pre_confirmed=True, pre_approved=True)
     self.assertIsNone(token)
     self.assertEqual(member.address.email, '*****@*****.**')
     # Now hold and handle an unsubscription request.
     token = hold_unsubscription(self._mlist, '*****@*****.**')
     handle_unsubscription(self._mlist, token, Action.defer)
Exemplo n.º 7
0
 def test_unsubscribe_defer(self):
     # When unsubscriptions must be approved by the moderator, but the
     # moderator defers this decision.
     anne = getUtility(IUserManager).create_address(
         '*****@*****.**', 'Anne Person')
     token, token_owner, member = self._registrar.register(
         anne, pre_verified=True, pre_confirmed=True, pre_approved=True)
     self.assertIsNone(token)
     self.assertEqual(member.address.email, '*****@*****.**')
     # Now hold and handle an unsubscription request.
     token = hold_unsubscription(self._mlist, '*****@*****.**')
     handle_unsubscription(self._mlist, token, Action.defer)