def handle_add(self, action, data):
        '''Add someone to a group

:param action: The button that was clicked.
:param dict data: The form data.'''
        admin = self.siteInfo.site_admins[0]
        groupInfo = createObject('groupserver.GroupInfo', self.context,
                                 data['groupId'])
        adder = Adder(self.context, groupInfo, admin)
        toAddr = sanitise_address(data['email'])
        fromAddr = self.siteInfo.get_support_email()
        msg, userInfo, status = adder.add(toAddr, data)

        r = {'status': 257,
             'message': 'Not processed'}

        if status == ADD_NEW_USER:
            notifier = NotifyAdd(groupInfo.groupObj, self.request)
            fromAddr = sanitise_address(self.siteInfo.get_support_email())
            passwd = self.get_password_reset(userInfo, toAddr)
            notifier.notify(self.loggedInUser, userInfo, fromAddr, toAddr,
                            passwd)
            r['status'] = 0
            m = 'Created a new profile for {0} and added {0} to {1}'
            r['message'] = m.format(userInfo.name, groupInfo.name)
            r['user'] = user_info(self.siteInfo, userInfo)
            r['user']['email'] = email_info(self.siteInfo, userInfo)
            r['user']['groups'] = groups(self.siteInfo, userInfo)
        elif status == ADD_OLD_USER:
            notifier = NotifyJoin(groupInfo.groupObj, self.request)
            notifier.notify(userInfo)
            r['status'] = 1
            r['message'] = 'Added {0} to {1}'.format(userInfo.name, groupInfo.name)
            r['user'] = user_info(self.siteInfo, userInfo)
            r['user']['email'] = email_info(self.siteInfo, userInfo)
            r['user']['groups'] = groups(self.siteInfo, userInfo)
        elif status == ADD_EXISTING_MEMBER:
            r['status'] = 256
            r['message'] = '{0} is alredy a member of {1}'.format(userInfo.name, groupInfo.name)
            r['user'] = user_info(self.siteInfo, userInfo)
            r['user']['email'] = email_info(self.siteInfo, userInfo)
            r['user']['groups'] = groups(self.siteInfo, userInfo)
        else:
            r['status'] = 257
            r['message'] = 'An unknown event occurred.'

        if status in (ADD_NEW_USER, ADD_OLD_USER):
            adminNotifier = NotifyAdmin(groupInfo.groupObj, self.request)
            for adminInfo in groupInfo.group_admins:
                adminNotifier.notify(adminInfo, userInfo)

        retval = to_json(r)
        return retval
    def handle_prefer(self, action, data):
        '''Prefer an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif (e in self.emailUser.preferred):
            msg = 'The address <{0}> is already preferred'.format(
                data['email'])
            raise AddressPreferred(msg)
        elif (e in self.emailUser.unverified):
            msg = 'The address <{0}> is unverified'.format(data['email'])
            raise AddressUnverified(msg)

        msg = self.prefer(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo),
        }
        retval = to_json(r)
        return retval
    def handle_delete(self, action, data):
        '''Delete an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif ((len(self.emailUser.preferred) == 1)
              and (e in self.emailUser.preferred)):
            msg = 'Not deleting the only preferred address <{0}>'.format(
                data['email'])
            raise RemovingOnlyPreferred(msg)

        msg = self.delete(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo),
        }
        retval = to_json(r)
        return retval
    def handle_prefer(self, action, data):
        '''Prefer an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif (e in self.emailUser.preferred):
            msg = 'The address <{0}> is already preferred'.format(data['email'])
            raise AddressPreferred(msg)
        elif (e in self.emailUser.unverified):
            msg = 'The address <{0}> is unverified'.format(data['email'])
            raise AddressUnverified(msg)

        msg = self.prefer(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo), }
        retval = to_json(r)
        return retval
    def handle_add(self, action, data):
        '''Add an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        if data['email'] in self.emailUser:
            m = '{0} ({1}) already has the email address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressExists(msg)

        msg = self.add(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo), }
        retval = to_json(r)
        return retval
Esempio n. 6
0
    def handle_get_groups(self, action, data):
        '''The form action for the list of members and their groups

:param action: The button that was clicked.
:param dict data: The form data.'''
        usergroups = []
        for userId in self.siteMembers.memberIds:
            userInfo = createObject('groupserver.UserFromId',
                                    self.context, userId)
            r = user_info(self.siteInfo, userInfo)
            r['email'] = email_info(self.siteInfo, userInfo)
            # So the list of groups is cached
            r['groups'] = [group.getId() for group in self.groups
                           if user_member_of_group(userInfo, group)]
            usergroups.append(r)

        retval = to_json(usergroups)
        return retval
Esempio n. 7
0
    def handle_add(self, action, data):
        '''Add an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        if data['email'] in self.emailUser:
            m = '{0} ({1}) already has the email address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressExists(msg)

        msg = self.add(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo),
        }
        retval = to_json(r)
        return retval
Esempio n. 8
0
    def handle_search(self, action, data):
        '''The form action for the *simple* list

:param action: The button that was clicked.
:param dict data: The form data.'''
        if '@' in data['user']:  # It is an email address
            email = parseaddr(data['user'])[1]
            userId = self.query.find_uids_by_email(email)
        else:  # userId
            userId = data['user']
        r = {}
        if userId:
            userInfo = createObject('groupserver.UserFromId',
                                    self.context, userId)
            if not userInfo.anonymous:
                r = user_info(self.siteInfo, userInfo)
                r['groups'] = groups(self.siteInfo, userInfo)
                r['email'] = email_info(self.siteInfo, userInfo)
        retval = to_json(r)
        return retval
Esempio n. 9
0
    def handle_search(self, action, data):
        '''The form action for the *simple* list

:param action: The button that was clicked.
:param dict data: The form data.'''
        if '@' in data['user']:  # It is an email address
            email = parseaddr(data['user'])[1]
            userId = self.query.find_uids_by_email(email)
        else:  # userId
            userId = data['user']
        r = {}
        if userId:
            userInfo = createObject('groupserver.UserFromId', self.context,
                                    userId)
            if not userInfo.anonymous:
                r = user_info(self.siteInfo, userInfo)
                r['groups'] = groups(self.siteInfo, userInfo)
                r['email'] = email_info(self.siteInfo, userInfo)
        retval = to_json(r)
        return retval
    def handle_delete(self, action, data):
        '''Delete an email address

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif ((len(self.emailUser.preferred) == 1) and (e in self.emailUser.preferred)):
            msg = 'Not deleting the only preferred address <{0}>'.format(data['email'])
            raise RemovingOnlyPreferred(msg)

        msg = self.delete(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo), }
        retval = to_json(r)
        return retval
    def handle_resend(self, action, data):
        '''Resend an email address verification message

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif (e in self.emailUser.verified):
            m = '{0} ({1}) has already verified the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressVerified(msg)

        msg = self.resend(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo), }
        retval = to_json(r)
        return retval
    def handle_resend(self, action, data):
        '''Resend an email address verification message

:param action: The button that was clicked.
:param dict data: The form data.'''
        e = data['email'].lower()
        if (e not in self.emailUser):
            m = '{0} ({1}) lacks the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressMissing(msg)
        elif (e in self.emailUser.verified):
            m = '{0} ({1}) has already verified the address <{2}>'
            msg = m.format(self.userInfo.name, self.userInfo.id, data['email'])
            raise AddressVerified(msg)

        msg = self.resend(data['email'])

        r = {
            'status': 0,
            'message': msg,
            'email': email_info(self.siteInfo, self.userInfo),
        }
        retval = to_json(r)
        return retval
 def __call__(self):
     self.request.response.setHeader(b'Content-Type', b'application/json')
     r = email_info(self.siteInfo, self.userInfo)
     retval = to_json(r)
     return retval
 def __call__(self):
     self.request.response.setHeader(b'Content-Type', b'application/json')
     r = email_info(self.siteInfo, self.userInfo)
     retval = to_json(r)
     return retval