~abompard/mailman/subpolicy

« back to all changes in this revision

Viewing changes to src/mailman/rest/domains.py

  • Committer: Barry Warsaw
  • Date: 2015-04-07 02:06:28 UTC
  • mfrom: (7313.2.6 lp1423756)
  • mto: This revision was merged to the branch mainline in revision 7323.
  • Revision ID: barry@list.org-20150407020628-fkwphij7to9lc8gy
 * Domains now have a list of owners, which are ``IUser`` objects, instead of
   the single ``contact_address`` they used to have.  ``IUser`` objects now
   also have a ``is_server_owner`` flag (defaulting to False) to indicate
   whether they have superuser privileges.  Give by Abhliash Raj, with fixes
   and refinements by Barry Warsaw.  (LP: #1423756)

 * Domains can now optionally be created with owners; domain owners can be
   added after the fact; domain owners can be deleted.  Also, users now have
   an ``is_server_owner`` flag as part of their representation, which defaults
   to False, and can be PUT and PATCH'd.  Given by Abhilash Raj, with fixes
   and refinements by Barry Warsaw.  (LP: #1423756)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    BadRequest, CollectionMixin, NotFound, bad_request, child, created, etag,
30
30
    no_content, not_found, okay, path_to)
31
31
from mailman.rest.lists import ListsForDomain
32
 
from mailman.rest.validator import Validator
 
32
from mailman.rest.users import OwnersForDomain
 
33
from mailman.rest.validator import Validator, list_of_strings_validator
33
34
from zope.component import getUtility
34
35
 
35
36
 
41
42
        """See `CollectionMixin`."""
42
43
        return dict(
43
44
            base_url=domain.base_url,
44
 
            contact_address=domain.contact_address,
45
45
            description=domain.description,
46
46
            mail_host=domain.mail_host,
47
47
            self_link=path_to('domains/{0}'.format(domain.mail_host)),
88
88
        else:
89
89
            return BadRequest(), []
90
90
 
 
91
    @child()
 
92
    def owners(self, request, segments):
 
93
        """/domains/<domain>/owners"""
 
94
        if len(segments) == 0:
 
95
            domain = getUtility(IDomainManager).get(self._domain)
 
96
            if domain is None:
 
97
                return NotFound()
 
98
            return OwnersForDomain(domain)
 
99
        else:
 
100
            return BadRequest(), []
 
101
 
91
102
 
92
103
class AllDomains(_DomainBase):
93
104
    """The domains."""
99
110
            validator = Validator(mail_host=str,
100
111
                                  description=str,
101
112
                                  base_url=str,
102
 
                                  contact_address=str,
103
 
                                  _optional=('description', 'base_url',
104
 
                                             'contact_address'))
105
 
            domain = domain_manager.add(**validator(request))
106
 
        except BadDomainSpecificationError:
107
 
            bad_request(response, b'Domain exists')
 
113
                                  owner=list_of_strings_validator,
 
114
                                  _optional=(
 
115
                                      'description', 'base_url', 'owner'))
 
116
            values = validator(request)
 
117
            # For consistency, owners are passed in as multiple `owner` keys,
 
118
            # but .add() requires an `owners` keyword.  Match impedence.
 
119
            owners = values.pop('owner', None)
 
120
            if owners is not None:
 
121
                values['owners'] = owners
 
122
            domain = domain_manager.add(**values)
 
123
        except BadDomainSpecificationError as error:
 
124
            bad_request(response, str(error))
108
125
        except ValueError as error:
109
126
            bad_request(response, str(error))
110
127
        else: