Exemplo n.º 1
0
 def leave(self, list_id, email):
     """See `ISubscriptionService`."""
     mlist = getUtility(IListManager).get_by_list_id(list_id)
     if mlist is None:
         raise NoSuchListError(list_id)
     # XXX for now, no notification or user acknowledgment.
     delete_member(mlist, email, False, False)
Exemplo n.º 2
0
 def unsubscribe_members(self, store, list_id, emails):
     """See 'ISubscriptionService'."""
     success = set()
     fail = set()
     mlist = getUtility(IListManager).get_by_list_id(list_id)
     if mlist is None:
         raise NoSuchListError(list_id)
     # Start with a query on the matching list-id and role.
     q_member = store.query(Member).filter(Member.list_id == list_id,
                                           Member.role == MemberRole.member)
     # De-duplicate.
     for email in set(emails):
         unsubscribed = False
         # Join with a queries matching the email address and preferred
         # address of any subscribed user.
         q_address = q_member.join(
             Member._address).filter(Address.email == email)
         q_user = q_member.join(Member._user).join(
             User._preferred_address).filter(Address.email == email)
         members = q_address.union(q_user).all()
         for member in members:
             member.unsubscribe()
             unsubscribed = True
         (success if unsubscribed else fail).add(email)
     return success, fail
Exemplo n.º 3
0
 def join(self, list_id, subscriber,
          display_name=None,
          delivery_mode=DeliveryMode.regular,
          role=MemberRole.member):
     """See `ISubscriptionService`."""
     mlist = getUtility(IListManager).get_by_list_id(list_id)
     if mlist is None:
         raise NoSuchListError(list_id)
     # Is the subscriber an email address or user id?
     if isinstance(subscriber, str):
         if display_name is None:
             display_name, at, domain = subscriber.partition('@')
         # Because we want to keep the REST API simple, there is no
         # password or language given to us.  We'll use the system's
         # default language for the user's default language.  We'll set the
         # password to a system default.  This will have to get reset since
         # it can't be retrieved.  Note that none of these are used unless
         # the address is completely new to us.
         password = generate(int(config.passwords.password_length))
         return add_member(mlist, subscriber, display_name, password,
                           delivery_mode,
                           system_preferences.preferred_language, role)
     else:
         # We have to assume it's a UUID.
         assert isinstance(subscriber, UUID), 'Not a UUID'
         user = getUtility(IUserManager).get_user_by_id(subscriber)
         if user is None:
             raise MissingUserError(subscriber)
         return mlist.subscribe(user, role)