Ejemplo n.º 1
0
Archivo: group.py Proyecto: ccoss/fas
    def sendinvite(self, groupname, target):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if is_approved(person, group):
            invite_subject = _('Come join The Fedora Project!')
            invite_text = _('''
%(user)s <%(email)s> has invited you to join the Fedora
Project!  We are a community of users and developers who produce a
complete operating system from entirely free and open source software
(FOSS).  %(user)s thinks that you have knowledge and skills
that make you a great fit for the Fedora community, and that you might
be interested in contributing.

How could you team up with the Fedora community to use and develop your
skills?  Check out http://fedoraproject.org/join-fedora for some ideas.
Our community is more than just software developers -- we also have a
place for you whether you're an artist, a web site builder, a writer, or
a people person.  You'll grow and learn as you work on a team with other
very smart and talented people.

Fedora and FOSS are changing the world -- come be a part of it!''') % \
    {'user': person.username, 'email': person.email}

            send_mail(target, invite_subject, invite_text)

            turbogears.flash(_('Message sent to: %s') % target)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            turbogears.flash(_("You are not in the '%s' group.") % group.name)

        person = person.filter_private()
        return dict(target=target, person=person, group=group)
Ejemplo n.º 2
0
    def sendinvite(self, groupname, target):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if is_approved(person, group):
            invite_subject = _('Come join The Fedora Project!')
            invite_text = _('''
%(user)s <%(email)s> has invited you to join the Fedora
Project!  We are a community of users and developers who produce a
complete operating system from entirely free and open source software
(FOSS).  %(user)s thinks that you have knowledge and skills
that make you a great fit for the Fedora community, and that you might
be interested in contributing.

How could you team up with the Fedora community to use and develop your
skills?  Check out http://fedoraproject.org/join-fedora for some ideas.
Our community is more than just software developers -- we also have a
place for you whether you're an artist, a web site builder, a writer, or
a people person.  You'll grow and learn as you work on a team with other
very smart and talented people.

Fedora and FOSS are changing the world -- come be a part of it!''') % \
    {'user': person.username, 'email': person.email}

            send_mail(target, invite_subject, invite_text)

            turbogears.flash(_('Message sent to: %s') % target)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            turbogears.flash(_("You are not in the '%s' group.") % group.name)

        person = person.filter_private()
        return dict(target=target, person=person, group=group)
Ejemplo n.º 3
0
    def accept_fpca(self, group, person):
        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)
Ejemplo n.º 4
0
    def accept_fpca(self, group, person):
        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
        )
Ejemplo n.º 5
0
Archivo: group.py Proyecto: chepioq/fas
        'email': person.email,
        'url': sponsor_url,
        'group': group.name }

                join_subject = _('Application to the \'%(group)s\' group',
                        locale=locale) % {'user': target.username,
                                'group': group.name}
                join_text = _('''
Thank you for applying for the %(group)s group.  

%(joinmsg)s
''', locale=locale) % { 'user': person.username,
        'joinmsg': group.joinmsg,
        'group': group.name }

                send_mail(sponsors_addr, sponsor_subject, sponsors_text)
                send_mail(target.email, join_subject, join_text)

                Log(author_id=target.id, description='%s applied %s to %s' %
                    (person.username, target.username, group.name))

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

                turbogears.flash(_('%(user)s has applied to %(group)s!') % \
                    {'user': target.username, 'group': group.name})
                turbogears.redirect('/group/view/%s' % group.name)
            return dict()
Ejemplo n.º 6
0
Archivo: fpca.py Proyecto: 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()
Ejemplo n.º 7
0
class CLA(controllers.Controller):
    ''' Processes CLA workflow '''
    # Group name for people having signed the CLA
    CLAGROUPNAME = config.get('cla_standard_group')
    # Meta group for everyone who has satisfied the requirements of the CLA
    # (By signing or having a corporate signatue or, etc)
    CLAMETAGROUPNAME = config.get('cla_done_group')

    # Values legal in phone numbers
    PHONEDIGITS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+',
                   '-', ')', '(', ' ')

    def __init__(self):
        '''Create a CLA Controller.'''

    @identity.require(turbogears.identity.not_anonymous())
    @expose(template="fas.templates.cla.index")
    def index(self):
        '''Display the CLAs (and accept/do not accept buttons)'''
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        try:
            code_len = len(person.country_code)
        except TypeError:
            code_len = 0
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1' and not person.telephone:
                turbogears.flash(_('A telephone number is required to ' + \
                    'complete the CLA.  Please fill out below.'))
            elif not person.country_code or not person.human_name \
                or not contactInfo:
                turbogears.flash(_('A valid country and telephone number ' + \
                    'or postal address is required to complete the CLA.  ' + \
                    'Please fill them out below.'))
        else:
            if not person.telephone or code_len != 2 or \
                person.country_code == '  ':
                turbogears.flash(
                    _('A valid country and telephone number are' +
                      ' required to complete the CLA.  Please fill them ' +
                      'out below.'))
        cla = cla_done(person)
        person = person.filter_private()
        return dict(cla=cla,
                    person=person,
                    date=datetime.utcnow().ctime(),
                    show=show)

    def _cla_dependent(self, group):
        '''
        Check whether a group has the cla in its prerequisite chain.

        Arguments:
        :group: group to check

        Returns: True if the group requires the cla_group_name otherwise
        '''
        if group.name in (self.CLAGROUPNAME, self.CLAMETAGROUPNAME):
            return True
        if group.prerequisite_id:
            return self._cla_dependent(group.prerequisite)
        return False

    def json_request(self):
        ''' Helps define if json is being used for this request

        :returns: 1 or 0 depending on if request is json or not
        '''

        return 'tg_format' in cherrypy.request.params and \
                cherrypy.request.params['tg_format'] == 'json'

    @expose(template="fas.templates.error")
    def error(self, tg_errors=None):
        '''Show a friendly error message'''
        if not tg_errors:
            turbogears.redirect('/')
        return dict(tg_errors=tg_errors)

    @identity.require(turbogears.identity.not_anonymous())
    @expose(template="genshi-text:fas.templates.cla.cla",
            format="text",
            content_type='text/plain; charset=utf-8')
    def text(self):
        '''View CLA as text'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        person = person.filter_private()
        return dict(person=person, date=datetime.utcnow().ctime())

    @identity.require(turbogears.identity.not_anonymous())
    @expose(template="genshi-text:fas.templates.cla.cla",
            format="text",
            content_type='text/plain; charset=utf-8')
    def download(self):
        '''Download CLA'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        person = person.filter_private()
        return dict(person=person, date=datetime.utcnow().ctime())

    @identity.require(turbogears.identity.not_anonymous())
    @expose(template="fas.templates.user.view", allow_json=True)
    def reject(self, person_name):
        '''Reject a user's CLA.

        This method will remove a user from the CLA group and any other groups
        that they are in that require the CLA.  It is used when a person has
        to fulfill some more legal requirements before having a valid CLA.

        Arguments
        :person_name: Name of the person to reject.
        '''
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')
        exc = None
        user = People.by_username(turbogears.identity.current.user_name)
        if not is_admin(user):
            # Only admins can use this
            turbogears.flash(_('You are not allowed to reject CLAs.'))
            exc = 'NotAuthorized'
        else:
            # Unapprove the cla and all dependent groups
            person = People.by_username(person_name)
            for role in person.roles:
                if self._cla_dependent(role.group):
                    role.role_status = 'unapproved'
            try:
                session.flush()
            except SQLError, error:
                turbogears.flash(_('Error removing cla and dependent groups' \
                        ' for %(person)s\n Error was: %(error)s') %
                        {'person': person_name, 'error': str(error)})
                exc = 'sqlalchemy.SQLError'

        if not exc:
            # Send a message that the ICLA has been revoked
            date_time = datetime.utcnow()
            Log(author_id=user.id,
                description='Revoked %s CLA' % person.username,
                changetime=date_time)
            revoke_subject = _('Fedora ICLA Revoked')
            revoke_text = _('''
Hello %(human_name)s,

We're sorry to bother you but we had to reject your CLA for now because
information you provided has been deemed incorrect.  The most common cause
of this is people abbreviating their name like "B L Couper" instead of
providing their actual full name "Bill Lay Couper".  Other causes of this
include are using a country, or phone number that isn't accurate [1]_.
If you could edit your account [2]_ to fix any of these problems and resubmit
the CLA we would appreciate it.

.. [1]: Why does it matter that we have your real name and phone
        number?   It's because the CLA is a legal document and should we ever
        need to contact you about one of your contributions (as an example,
        because someone contacts *us* claiming that it was really they who
        own the copyright to the contribution) we might need to contact you
        for more information about what's going on.

.. [2]: Edit your account by logging in at this URL:
        %(editurl)s/accounts/user/edit/%(username)s

If you have questions about what specifically might be the problem with your
account, please contact us at [email protected].

Thanks!
    ''') % {
                'username': person.username,
                'human_name': person.human_name,
                'editurl': config.get('base_url_filter.base_url').rstrip('/')
            }

            send_mail(person.email, revoke_subject, revoke_text)

            # Yay, sweet success!
            turbogears.flash(_('CLA Successfully Removed.'))
        # and now we're done
        if request_format() == 'json':
            return_val = {}
            if exc:
                return_val['exc'] = exc
            return return_val
        else:
            turbogears.redirect('/user/view/%s' % person_name)
Ejemplo n.º 8
0
    def send(self,
             human_name,
             telephone,
             country_code,
             postal_address=None,
             confirm=False,
             agree=False):
        '''Send CLA'''

        # 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 cla_done(person):
            turbogears.flash(_('You have already completed the CLA.'))
            turbogears.redirect('/cla/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the CLA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(
                _('You must confirm that your personal information is accurate.'
                  ))
            turbogears.redirect('/cla/')

        # 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('/cla/')
            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('/cla/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/cla/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the CLA, we must have your ' + \
                    'name, telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/cla/')

        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 CLA, a valid country code ' + \
            'must be specified.  Please select one now.'))
            turbogears.redirect('/cla/')
        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('/cla/')

        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('/cla/')
            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('/cla/')
        except:
            turbogears.flash(
                _("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect('/cla/')

        date_time = datetime.utcnow()
        Log(author_id=person.id,
            description='Completed CLA',
            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:
    %(rejecturl)s/accounts/cla/reject/%(username)s

=== CLA ===

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

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

        turbogears.flash(_("You have successfully completed the CLA.  You " + \
                            "are now in the '%s' group.") % group.name)
        turbogears.redirect('/user/view/%s' % person.username)
        return dict()
Ejemplo n.º 9
0
        'email': person.email,
        'url': sponsor_url,
        'group': group.name }

                join_subject = _('Application to the \'%(group)s\' group',
                        locale=locale) % {'user': target.username,
                                'group': group.name}
                join_text = _('''
Thank you for applying for the %(group)s group.

%(joinmsg)s
''', locale=locale) % { 'user': person.username,
        'joinmsg': group.joinmsg,
        'group': group.name }

                send_mail(sponsors_addr, sponsor_subject, sponsors_text)
                send_mail(target.email, join_subject, join_text)

                Log(author_id=target.id, description='%s applied %s to %s' %
                    (person.username, target.username, group.name))

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

                turbogears.flash(_('%(user)s has applied to %(group)s!') % \
                    {'user': target.username, 'group': group.name})
                turbogears.redirect('/group/view/%s' % group.name)
            return dict()