Exemplo n.º 1
0
Arquivo: fpca.py Projeto: ccoss/fas
    def send(self, human_name, telephone, country_code, postal_address=None,
        confirm=False, agree=False):
        '''Send FPCA'''

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if standard_cla_done(person):
            turbogears.flash(_('You have already completed the FPCA.'))
            turbogears.redirect('/fpca/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the FPCA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(_(
                'You must confirm that your personal information is accurate.'
            ))
            turbogears.redirect('/fpca/')

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect('/fpca/')
            return dict()

        # Heuristics to detect bad data
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1':
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the FPCA, we must have your ' + \
                    'name telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/fpca/')

        blacklist = config.get('country_blacklist', [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(_('To complete the FPCA, a valid country code' + \
            'must be specified.  Please select one now.'))
            turbogears.redirect('/fpca/')
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(_('Telephone numbers can only consist of ' + \
                'numbers, "-", "+", "(", ")", or " ".  Please reenter using' +\
                'only those characters.'))
            turbogears.redirect('/fpca/')

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person) # Apply for the new group
            session.flush()
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
            return dict()

        try:
            # Everything is correct.
            person.sponsor(group, person) # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(_("You are already a part of the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
        except:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')

        date_time = datetime.utcnow()
        Log(author_id = person.id, description = 'Completed FPCA',
            changetime = date_time)
        cla_subject = \
            'Fedora ICLA completed for %(human_name)s (%(username)s)' % \
            {'username': person.username, 'human_name': person.human_name}
        cla_text = '''
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    https://admin.fedoraproject.org/accounts/fpca/reject/%(username)s

=== FPCA ===

''' % {'username': person.username,
'email': person.email,
'date': date_time.ctime(),}
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(dict(person=person),
                    'fas.templates.fpca.fpca').render(method='text',
                    encoding=None)

        send_mail(config.get('legal_cla_email'), cla_subject, cla_text)

        turbogears.flash(_("You have successfully completed the FPCA.  You " + \
                            "are now in the '%s' group.") % group.name)
        turbogears.redirect('/user/view/%s' % person.username)
        return dict()
Exemplo n.º 2
0
    def send(self, human_name, telephone, country_code, postal_address=None, confirm=False, agree=False):
        """Send FPCA"""

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show["show_postal_address"] = config.get("show_postal_address")

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if standard_cla_done(person):
            turbogears.flash(_("You have already completed the FPCA."))
            turbogears.redirect("/fpca/")
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the FPCA."))
            turbogears.redirect("/user/view/%s" % person.username)
        if not confirm:
            turbogears.flash(_("You must confirm that your personal information is accurate."))
            turbogears.redirect("/fpca/")

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect("/fpca/")
            return dict()

        # Heuristics to detect bad data
        if show["show_postal_address"]:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == "O1":
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect("/fpca/")
            else:
                if not person.country_code or not person.human_name or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect("/fpca/")
        else:
            if not person.telephone or not person.human_name or not person.country_code:
                turbogears.flash(
                    _(
                        "To complete the FPCA, we must have your "
                        + "name telephone number, and country.  Please ensure they "
                        + "have been filled out."
                    )
                )
                turbogears.redirect("/fpca/")

        blacklist = config.get("country_blacklist", [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(
                _("To complete the FPCA, a valid country code" + " must be specified. Please select one now.")
            )
            turbogears.redirect("/fpca/")
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(
                _(
                    "Telephone numbers can only consist of"
                    + ' numbers, "-", "+", "(", ")", or " ". Please reenter using'
                    + " only those characters."
                )
            )
            turbogears.redirect("/fpca/")

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person)  # Apply for the new group
            session.flush()

            fas.fedmsgshim.send_message(
                topic="group.member.apply", msg={"agent": person.username, "user": person.username, "group": group.name}
            )
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(_("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect("/fpca/")
            return dict()

        if config.get("antispam.cla.autoaccept", True):
            self.accept_fpca(group, person)
            turbogears.redirect("/user/view/%s" % person.username)
            return dict()
        else:
            r = submit_to_spamcheck("fedora.fas.cla_sign", {"user": person.filter_private("systems", True)})
            try:
                log.info("Spam response: %s" % r.text)
                response = r.json()
                result = response["result"]
            except:
                log.error("Spam checking failed: %s" % repr(ex))
                result = "checking"

            # Result is either accepted or checking
            if result == "accepted":
                self.accept_fpca(group, person)
                turbogears.redirect("/user/view/%s" % person.username)
                return dict()
            else:
                turbogears.flash(
                    _(
                        "We are processing your FPCA application, "
                        + "please watch for an email from us with the status."
                    )
                )
                turbogears.redirect("/user/view/%s" % person.username)
                return dict()
Exemplo n.º 3
0
    def send(self, human_name, telephone, country_code, postal_address=None,
        confirm=False, agree=False):
        '''Send FPCA'''

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if standard_cla_done(person):
            turbogears.flash(_('You have already completed the FPCA.'))
            turbogears.redirect('/fpca/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the FPCA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(_(
                'You must confirm that your personal information is accurate.'
            ))
            turbogears.redirect('/fpca/')

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect('/fpca/')
            return dict()

        # Heuristics to detect bad data
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1':
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the FPCA, we must have your ' + \
                    'name telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/fpca/')

        blacklist = config.get('country_blacklist', [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(_('To complete the FPCA, a valid country code' + \
            ' must be specified. Please select one now.'))
            turbogears.redirect('/fpca/')
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(_('Telephone numbers can only consist of' + \
                ' numbers, "-", "+", "(", ")", or " ". Please reenter using' +\
                ' only those characters.'))
            turbogears.redirect('/fpca/')

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person) # Apply for the new group
            session.flush()

            fas.fedmsgshim.send_message(topic="group.member.apply", msg={
                'agent': person.username,
                'user': person.username,
                'group': group.name,
            })
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
            return dict()

        try:
            # Everything is correct.
            person.sponsor(group, person) # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(_("You are already a part of the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
        except:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')

        date_time = datetime.utcnow()
        Log(author_id = person.id, description = 'Completed FPCA',
            changetime = date_time)
        cla_subject = \
            'Fedora ICLA completed for %(human_name)s (%(username)s)' % \
            {'username': person.username, 'human_name': person.human_name}
        cla_text = '''
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    https://admin.fedoraproject.org/accounts/fpca/reject/%(username)s

=== FPCA ===

''' % {'username': person.username,
'email': person.email,
'date': date_time.ctime(),}
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(dict(person=person),
                    'fas.templates.fpca.fpca').render(method='text',
                    encoding=None)

        send_mail(config.get('legal_cla_email'), cla_subject, cla_text)

        fas.fedmsgshim.send_message(topic="group.member.sponsor", msg={
            'agent': person.username,
            'user': person.username,
            'group': group.name,
        })

        turbogears.flash(_("You have successfully completed the FPCA.  You " + \
                            "are now in the '%s' group.") % group.name)
        turbogears.redirect('/user/view/%s' % person.username)
        return dict()
Exemplo n.º 4
0
    def send(self,
             human_name,
             telephone,
             country_code,
             postal_address=None,
             confirm=False,
             agree=False):
        '''Send FPCA'''

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if standard_cla_done(person):
            turbogears.flash(_('You have already completed the FPCA.'))
            turbogears.redirect('/fpca/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the FPCA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(
                _('You must confirm that your personal information is accurate.'
                  ))
            turbogears.redirect('/fpca/')

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect('/fpca/')
            return dict()

        # Heuristics to detect bad data
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1':
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the FPCA, we must have your ' + \
                    'name telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/fpca/')

        blacklist = config.get('country_blacklist', [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(_('To complete the FPCA, a valid country code' + \
            ' must be specified. Please select one now.'))
            turbogears.redirect('/fpca/')
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(_('Telephone numbers can only consist of' + \
                ' numbers, "-", "+", "(", ")", or " ". Please reenter using' +\
                ' only those characters.'))
            turbogears.redirect('/fpca/')

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person)  # Apply for the new group
            session.flush()

            fas.fedmsgshim.send_message(topic="group.member.apply",
                                        msg={
                                            'agent': person.username,
                                            'user': person.username,
                                            'group': group.name,
                                        })
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(
                _("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect('/fpca/')
            return dict()

        if config.get('antispam.cla.autoaccept', True):
            self.accept_fpca(group, person)
            turbogears.redirect('/user/view/%s' % person.username)
            return dict()
        else:
            r = submit_to_spamcheck(
                'fedora.fas.cla_sign',
                {'user': person.filter_private('systems', True)})
            try:
                log.info('Spam response: %s' % r.text)
                response = r.json()
                result = response['result']
            except:
                log.error('Spam checking failed: %s' % repr(ex))
                result = 'checking'

            # Result is either accepted or checking
            if result == 'accepted':
                self.accept_fpca(group, person)
                turbogears.redirect('/user/view/%s' % person.username)
                return dict()
            else:
                turbogears.flash(_('We are processing your FPCA application, ' + \
                                   'please watch for an email from us with the status.'))
                turbogears.redirect('/user/view/%s' % person.username)
                return dict()