Beispiel #1
0
 def on_get(self, request, response):
     """/domains/<domain>/owners"""
     if self._domain is None:
         not_found(response)
         return
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #2
0
 def on_put(self, request, response):
     """Set or replace the addresses's user."""
     if self._user:
         self._user.unlink(self._address)
     # Process post data and check for an existing user.
     fields = CREATION_FIELDS.copy()
     fields['user_id'] = int
     fields['_optional'] = fields['_optional'] + (
         'user_id', 'email', 'is_server_owner')
     try:
         validator = Validator(**fields)
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     user_manager = getUtility(IUserManager)
     if 'user_id' in arguments:
         raw_uid = arguments['user_id']
         user_id = UUID(int=raw_uid)
         user = user_manager.get_user_by_id(user_id)
         if user is None:
             not_found(response, b'No user with ID {}'.format(raw_uid))
             return
         okay(response)
     else:
         user = create_user(arguments, request, response)
         if user is None:
             return
     user.link(self._address)
Beispiel #3
0
 def on_get(self, request, response):
     """Return a single domain end-point."""
     domain = getUtility(IDomainManager).get(self._domain)
     if domain is None:
         not_found(response)
     else:
         okay(response, self._resource_as_json(domain))
Beispiel #4
0
 def on_get(self, request, response):
     """/<api>/system"""
     resource = dict(
         mailman_version=system.mailman_version,
         python_version=system.python_version,
         self_link=path_to('system'),
         )
     okay(response, etag(resource))
 def on_get(self, request, response):
     """Get a header match."""
     try:
         header_match = self.header_matches[self._position]
     except IndexError:
         not_found(response, "No header match at this position: {}".format(self._position))
     else:
         okay(response, etag(self._resource_as_dict(header_match)))
Beispiel #6
0
 def on_get(self, request, response):
     """Get all the archiver statuses."""
     archiver_set = IListArchiverSet(self._mlist)
     resource = {
         archiver.name: archiver.is_enabled
         for archiver in archiver_set.archivers
         if archiver.system_archiver.is_enabled
     }
     okay(response, etag(resource))
Beispiel #7
0
 def on_get(self, request, response):
     """/<api>/system/versions"""
     resource = dict(
         mailman_version=system.mailman_version,
         python_version=system.python_version,
         api_version=self.api.version,
         self_link=self.api.path_to('system/versions'),
     )
     okay(response, etag(resource))
 def on_get(self, request, response):
     """Get a header match."""
     try:
         header_match = self.header_matches[self._position]
     except IndexError:
         not_found(response, 'No header match at this position: {}'.format(
                   self._position))
     else:
         okay(response, etag(self._resource_as_dict(header_match)))
Beispiel #9
0
 def on_get(self, request, response):
     template = getUtility(ITemplateManager).raw(self._template, None)
     if template is None:
         not_found(response)
     else:
         resource = dict(uri=template.uri)
         resource['self_link'] = self.api.path_to('uris/{}'.format(
             self._template))
         okay(response, etag(resource))
Beispiel #10
0
 def on_get(self, request, response):
     # Get the pended record associated with this token, if it exists in
     # the pending table.
     try:
         resource = self._resource_as_dict(self._token)
     except LookupError:
         not_found(response)
         return
     okay(response, etag(resource))
Beispiel #11
0
 def on_get(self, request, response):
     # Get the pended record associated with this token, if it exists in
     # the pending table.
     try:
         resource = self._resource_as_dict(self._token)
         assert resource is not None, resource
     except LookupError:
         not_found(response)
         return
     okay(response, etag(resource))
 def on_get(self, request, response):
     try:
         request_id = int(self._request_id)
     except ValueError:
         bad_request(response)
         return
     resource = self._make_resource(request_id)
     if resource is None:
         not_found(response)
     else:
         okay(response, etag(resource))
 def on_get(self, request, response):
     try:
         request_id = int(self._request_id)
     except ValueError:
         not_found(response)
         return
     resource = self._make_resource(request_id)
     if resource is None:
         not_found(response)
     else:
         okay(response, etag(resource))
Beispiel #14
0
 def on_get(self, request, response):
     """Get a banned email."""
     if self.ban_manager.is_banned(self._email):
         resource = dict(
             email=self._email,
             self_link=self._location(self._email),
             )
         if self._mlist is not None:
             resource['list_id'] = self._mlist.list_id
         okay(response, etag(resource))
     else:
         not_found(response, 'Email is not banned: {}'.format(self._email))
Beispiel #15
0
 def on_get(self, request, response):
     """Get a banned email."""
     if self.ban_manager.is_banned(self._email):
         resource = dict(
             email=self._email,
             self_link=self._location(self._email),
             )
         if self._mlist is not None:
             resource['list_id'] = self._mlist.list_id
         okay(response, etag(resource))
     else:
         not_found(response, 'Email is not banned: {}'.format(self._email))
Beispiel #16
0
 def on_get(self, request, response):
     try:
         request_id = int(self._request_id)
     except ValueError:
         bad_request(response)
         return
     resource = self._make_resource(request_id, MEMBERSHIP_CHANGE_REQUESTS)
     if resource is None:
         not_found(response)
     else:
         # Remove unnecessary keys.
         del resource['key']
         okay(response, etag(resource))
Beispiel #17
0
 def on_get(self, request, response):
     try:
         request_id = int(self._request_id)
     except ValueError:
         bad_request(response)
         return
     resource = self._make_resource(request_id, MEMBERSHIP_CHANGE_REQUESTS)
     if resource is None:
         not_found(response)
     else:
         # Remove unnecessary keys.
         del resource['key']
         okay(response, etag(resource))
Beispiel #18
0
 def on_post(self, request, response):
     """Find a member"""
     service = getUtility(ISubscriptionService)
     validator = Validator(list_id=str,
                           subscriber=str,
                           role=enum_validator(MemberRole),
                           _optional=('list_id', 'subscriber', 'role'))
     try:
         members = service.find_members(**validator(request))
     except ValueError as error:
         bad_request(response, str(error))
     else:
         resource = _FoundMembers(members, self.api_version)
         okay(response, etag(resource._make_collection(request)))
Beispiel #19
0
 def on_post(self, request, response):
     """Find a member"""
     service = getUtility(ISubscriptionService)
     validator = Validator(
         list_id=unicode,
         subscriber=unicode,
         role=enum_validator(MemberRole),
         _optional=('list_id', 'subscriber', 'role'))
     try:
         members = service.find_members(**validator(request))
     except ValueError as error:
         bad_request(response, str(error))
     else:
         resource = _FoundMembers(members)._make_collection(request)
         okay(response, etag(resource))
Beispiel #20
0
 def on_get(self, request, response):
     if self._section is None:
         resource = dict(sections=sorted(section.name
                                         for section in config))
         okay(response, etag(resource))
         return
     missing = object()
     section = getattr(config, self._section, missing)
     if section is missing:
         not_found(response)
         return
     # Sections don't have .keys(), .values(), or .items() but we can
     # iterate over them.
     resource = {key: section[key] for key in section}
     okay(response, etag(resource))
Beispiel #21
0
 def on_get(self, request, response):
     if self._section is None:
         resource = dict(
             sections=sorted(section.name for section in config))
         okay(response, etag(resource))
         return
     missing = object()
     section = getattr(config, self._section, missing)
     if section is missing:
         not_found(response)
         return
     # Sections don't have .keys(), .values(), or .items() but we can
     # iterate over them.
     resource = {key: section[key] for key in section}
     okay(response, etag(resource))
Beispiel #22
0
 def on_delete(self, request, response):
     """Delete the members of the named mailing list."""
     status = {}
     try:
         validator = Validator(emails=list_of_strings_validator)
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     emails = arguments.pop('emails')
     success, fail = getUtility(ISubscriptionService).unsubscribe_members(
         self._mlist.list_id, emails)
     # There should be no email in both sets.
     assert success.isdisjoint(fail), (success, fail)
     status.update({email: True for email in success})
     status.update({email: False for email in fail})
     okay(response, etag(status))
Beispiel #23
0
 def on_get(self, request, response):
     """Get a mailing list configuration."""
     resource = {}
     if self._attribute is None:
         # Return all readable attributes.
         for attribute in ATTRIBUTES:
             value = ATTRIBUTES[attribute].get(self._mlist, attribute)
             resource[attribute] = value
     elif self._attribute not in ATTRIBUTES:
         bad_request(
             response, b'Unknown attribute: {}'.format(self._attribute))
         return
     else:
         attribute = self._attribute
         value = ATTRIBUTES[attribute].get(self._mlist, attribute)
         resource[attribute] = value
     okay(response, etag(resource))
 def on_get(self, request, response):
     validator = Validator(
         token_owner=enum_validator(TokenOwner),
         request_type=enum_validator(PendType),
         _optional=['token_owner', 'request_type'])
     try:
         data = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         token_owner = data.pop('token_owner', None)
         pend_type = data.pop('request_type', PendType.subscription)
         count = getUtility(IPendings).count(
             mlist=self._mlist,
             pend_type=pend_type.name,
             token_owner=token_owner)
         okay(response, etag(dict(count=count)))
Beispiel #25
0
 def on_get(self, request, response):
     resource = dict()
     for attr in PREFERENCES:
         # Handle this one specially.
         if attr == 'preferred_language':
             continue
         value = getattr(self._parent, attr, None)
         if value is not None:
             resource[attr] = value
     # Add the preferred language, if it's not missing.
     preferred_language = self._parent.preferred_language
     if preferred_language is not None:
         resource['preferred_language'] = preferred_language.code
     # Add the self link.
     resource['self_link'] = path_to(
         '{0}/preferences'.format(self._base_url))
     okay(response, etag(resource))
Beispiel #26
0
 def on_delete(self, request, response):
     """Delete the members of the named mailing list."""
     status = {}
     try:
         validator = Validator(emails=list_of_strings_validator)
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     emails = arguments.pop('emails')
     success, fail = getUtility(ISubscriptionService).unsubscribe_members(
         self._mlist.list_id, emails)
     # There should be no email in both sets.
     assert success.isdisjoint(fail), (success, fail)
     status.update({email: True for email in success})
     status.update({email: False for email in fail})
     okay(response, etag(status))
Beispiel #27
0
 def on_get(self, request, response):
     """Get a mailing list configuration."""
     resource = {}
     if self._attribute is None:
         # Return all readable attributes.
         for attribute in ATTRIBUTES:
             value = ATTRIBUTES[attribute].get(self._mlist, attribute)
             resource[attribute] = value
     elif self._attribute not in ATTRIBUTES:
         bad_request(
             response, b'Unknown attribute: {}'.format(self._attribute))
         return
     else:
         attribute = self._attribute
         value = ATTRIBUTES[attribute].get(self._mlist, attribute)
         resource[attribute] = value
     okay(response, etag(resource))
Beispiel #28
0
 def on_get(self, request, response):
     resource = dict()
     for attr in PREFERENCES:
         # Handle this one specially.
         if attr == 'preferred_language':
             continue
         value = getattr(self._parent, attr, None)
         if value is not None:
             resource[attr] = value
     # Add the preferred language, if it's not missing.
     preferred_language = self._parent.preferred_language
     if preferred_language is not None:
         resource['preferred_language'] = preferred_language.code
     # Add the self link.
     resource['self_link'] = self.api.path_to(
         '{}/preferences'.format(self._base_url))
     okay(response, etag(resource))
Beispiel #29
0
 def on_post(self, request, response):
     try:
         validator = Validator(send=as_boolean,
                               bump=as_boolean,
                               _optional=('send', 'bump'))
         values = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     if len(values) == 0:
         # There's nothing to do, but that's okay.
         okay(response)
         return
     if values.get('bump', False):
         bump_digest_number_and_volume(self._mlist)
     if values.get('send', False):
         maybe_send_digest_now(self._mlist, force=True)
     accepted(response)
Beispiel #30
0
 def on_post(self, request, response):
     try:
         validator = Validator(
             send=as_boolean,
             bump=as_boolean,
             _optional=('send', 'bump'))
         values = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     if len(values) == 0:
         # There's nothing to do, but that's okay.
         okay(response)
         return
     if values.get('bump', False):
         bump_digest_number_and_volume(self._mlist)
     if values.get('send', False):
         maybe_send_digest_now(self._mlist, force=True)
     accepted(response)
Beispiel #31
0
 def on_post(self, request, response):
     """Link a user to the address, and create it if needed."""
     if self._user:
         conflict(response)
         return
     # When creating a linked user by POSTing, the user either must already
     # exist, or it can be automatically created, if the auto_create flag
     # is given and true (if missing, it defaults to true).  However, in
     # this case we do not accept 'email' as a POST field.
     fields = CREATION_FIELDS.copy()
     del fields['email']
     fields['user_id'] = self.api.to_uuid
     fields['auto_create'] = as_boolean
     fields['_optional'] = fields['_optional'] + ('user_id', 'auto_create',
                                                  'is_server_owner')
     try:
         validator = Validator(**fields)
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     user_manager = getUtility(IUserManager)
     if 'user_id' in arguments:
         user_id = arguments['user_id']
         user = user_manager.get_user_by_id(user_id)
         if user is None:
             bad_request(
                 response, 'No user with ID {}'.format(
                     self.api.from_uuid(user_id)).encode())
             return
         okay(response)
     else:
         auto_create = arguments.pop('auto_create', True)
         if auto_create:
             # This sets the 201 or 400 status.
             user = create_user(self.api, arguments, response)
             if user is None:
                 return
         else:
             forbidden(response)
             return
     user.link(self._address)
Beispiel #32
0
 def on_get(self, request, response):
     """Get a mailing list configuration."""
     resource = {}
     if self._attribute is None:
         # This is a requst for all the mailing list's configuration
         # variables.  Return all readable attributes.
         for attribute in ATTRIBUTES:
             value = ATTRIBUTES[attribute].get(self._mlist, attribute)
             resource[attribute] = value
     elif self._attribute not in ATTRIBUTES:
         # This is a request for a specific, nonexistent attribute.
         not_found(
             response, 'Unknown attribute: {}'.format(self._attribute))
         return
     else:
         # This is a request for a specific attribute.
         attribute = self._attribute
         value = ATTRIBUTES[attribute].get(self._mlist, attribute)
         resource[attribute] = value
     okay(response, etag(resource))
Beispiel #33
0
 def on_post(self, request, response):
     """Link a user to the address, and create it if needed."""
     if self._user:
         conflict(response)
         return
     # When creating a linked user by POSTing, the user either must already
     # exist, or it can be automatically created, if the auto_create flag
     # is given and true (if missing, it defaults to true).  However, in
     # this case we do not accept 'email' as a POST field.
     fields = CREATION_FIELDS.copy()
     del fields['email']
     fields['user_id'] = int
     fields['auto_create'] = as_boolean
     fields['_optional'] = fields['_optional'] + (
         'user_id', 'auto_create', 'is_server_owner')
     try:
         validator = Validator(**fields)
         arguments = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
         return
     user_manager = getUtility(IUserManager)
     if 'user_id' in arguments:
         raw_uid = arguments['user_id']
         user_id = UUID(int=raw_uid)
         user = user_manager.get_user_by_id(user_id)
         if user is None:
             not_found(response, b'No user with ID {}'.format(raw_uid))
             return
         okay(response)
     else:
         auto_create = arguments.pop('auto_create', True)
         if auto_create:
             # This sets the 201 or 400 status.
             user = create_user(arguments, request, response)
             if user is None:
                 return
         else:
             forbidden(response)
             return
     user.link(self._address)
Beispiel #34
0
 def on_get(self, request, response):
     """Get a mailing list configuration."""
     resource = {}
     attributes = api_attributes(self.api)
     if self._attribute is None:
         # This is a request for all the mailing list's configuration
         # variables.  Return all readable attributes.
         for attribute, getter in attributes.items():
             value = getter.get(self._mlist, attribute)
             resource[attribute] = value
     elif self._attribute in attributes:
         # This is a request for a specific attribute.
         value = attributes[self._attribute].get(self._mlist,
                                                 self._attribute)
         resource[self._attribute] = value
     else:
         # This is a request for a specific, nonexistent attribute.
         not_found(response,
                   'Unknown attribute: {}'.format(self._attribute))
         return
     okay(response, etag(resource))
Beispiel #35
0
    def on_get(self, request, response):
        """/members"""
        validator = Validator(
            fields=list_of_strings_validator,
            count=int,
            page=int,
            _optional=['fields', 'count', 'page'],
        )
        try:
            data = validator(request)
        except ValueError as ex:
            bad_request(response, str(ex))
            return
        fields = data.get('fields', None)

        try:
            resource = self._make_collection(request, fields)
        except ValueError as ex:
            bad_request(response, str(ex))
            return
        okay(response, etag(resource))
Beispiel #36
0
 def _find(self, request, response):
     """Find a member"""
     service = getUtility(ISubscriptionService)
     validator = Validator(
         list_id=str,
         subscriber=str,
         role=enum_validator(MemberRole),
         # Allow pagination.
         page=int,
         count=int,
         _optional=('list_id', 'subscriber', 'role', 'page', 'count'))
     try:
         data = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         # Remove any optional pagination query elements; they will be
         # handled later.
         data.pop('page', None)
         data.pop('count', None)
         members = service.find_members(**data)
         resource = _FoundMembers(members, self.api)
         okay(response, etag(resource._make_collection(request)))
Beispiel #37
0
 def _find(self, request, response):
     """Find a member"""
     service = getUtility(ISubscriptionService)
     validator = Validator(
         list_id=str,
         subscriber=str,
         role=enum_validator(MemberRole),
         # Allow pagination.
         page=int,
         count=int,
         _optional=('list_id', 'subscriber', 'role', 'page', 'count'))
     try:
         data = validator(request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         # Remove any optional pagination query elements; they will be
         # handled later.
         data.pop('page', None)
         data.pop('count', None)
         members = service.find_members(**data)
         resource = _FoundMembers(members, self.api)
         okay(response, etag(resource._make_collection(request)))
Beispiel #38
0
 def on_get(self, request, response):
     resource = self._make_collection(request)
     resource['self_link'] = self.api.path_to(
         '{}/uris'.format(self._prefix))
     okay(response, etag(resource))
Beispiel #39
0
 def on_get(self, request, response):
     """/domains/<domain>/lists"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #40
0
 def on_get(self, request, response):
     resource = dict(chains=sorted(config.chains))
     okay(response, etag(resource))
Beispiel #41
0
 def on_get(self, request, response):
     resource = dict(pipelines=sorted(config.pipelines))
     okay(response, etag(resource))
Beispiel #42
0
 def on_get(self, request, response):
     """Get all the archiver statuses."""
     archiver_set = IListArchiverSet(self._mlist)
     resource = {archiver.name: archiver.is_enabled
                 for archiver in archiver_set.archivers}
     okay(response, etag(resource))
Beispiel #43
0
 def on_get(self, request, response):
     """/lists/listname/requests"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #44
0
 def on_get(self, request, response):
     """Return a single user end-point."""
     if self._user is None:
         not_found(response)
     else:
         okay(response, self._resource_as_json(self._user))
Beispiel #45
0
 def on_get(self, request, response):
     """/domains/<domain>/lists"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #46
0
 def on_get(self, request, response):
     """Return a single member end-point."""
     if self._member is None:
         not_found(response)
     else:
         okay(response, self._resource_as_json(self._member))
Beispiel #47
0
 def on_get(self, request, response):
     """/members"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #48
0
 def on_get(self, request, response):
     okay(response, etag(self._resource))
Beispiel #49
0
 def on_get(self, request, response):
     """Return a single address."""
     if self._address is None:
         not_found(response)
     else:
         okay(response, self._resource_as_json(self._address))
Beispiel #50
0
 def on_get(self, request, response):
     """/lists/listname/requests"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #51
0
 def on_get(self, request, response):
     """Return a single mailing list end-point."""
     if self._mlist is None:
         not_found(response)
     else:
         okay(response, self._resource_as_json(self._mlist))
Beispiel #52
0
 def on_get(self, request, response):
     resource = dict(
         next_digest_number=self._mlist.next_digest_number,
         volume=self._mlist.volume,
         )
     okay(response, etag(resource))
Beispiel #53
0
 def on_get(self, request, response):
     """roster/[members|owners|moderators]"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #54
0
 def on_get(self, request, response):
     """/addresses"""
     assert self._user is not None
     okay(response, etag(self._make_collection(request)))
Beispiel #55
0
 def on_get(self, request, response):
     resource = dict(
         next_digest_number=self._mlist.next_digest_number,
         volume=self._mlist.volume,
     )
     okay(response, etag(resource))
Beispiel #56
0
 def on_get(self, request, response):
     """roster/[members|owners|moderators]"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #57
0
 def on_get(self, request, response):
     okay(response, etag(self._resource))
Beispiel #58
0
 def on_get(self, request, response):
     resource = dict(pipelines=sorted(config.pipelines))
     okay(response, etag(resource))
Beispiel #59
0
 def on_get(self, request, response):
     """/owners"""
     resource = self._make_collection(request)
     okay(response, etag(resource))
Beispiel #60
0
 def on_get(self, request, response):
     resource = dict(chains=sorted(config.chains))
     okay(response, etag(resource))