Exemplo n.º 1
0
    def save(self,
             groupname,
             display_name,
             owner,
             group_type,
             needs_sponsor=0,
             user_can_remove=1,
             prerequisite='',
             url='',
             mailing_list='',
             mailing_list_url='',
             invite_only=0,
             irc_channel='',
             irc_network='',
             joinmsg='',
             apply_rules="None"):
        '''Edit a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_edit_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            try:
                owner = People.by_username(owner)
                group.display_name = display_name
                group.owner = owner
                group.group_type = group_type
                group.needs_sponsor = bool(needs_sponsor)
                group.user_can_remove = bool(user_can_remove)
                if prerequisite:
                    prerequisite = Groups.by_name(prerequisite)
                    group.prerequisite = prerequisite
                else:
                    group.prerequisite = None
                group.url = url
                group.mailing_list = mailing_list
                group.mailing_list_url = mailing_list_url
                group.invite_only = invite_only
                group.irc_channel = irc_channel
                group.irc_network = irc_network
                group.joinmsg = joinmsg
                group.apply_rules = apply_rules
                # Log here
                session.flush()
            except:
                turbogears.flash(_('The group details could not be saved.'))
            else:
                Log(author_id=person.id,
                    description='%s edited group %s' %
                    (person.username, group.name))
                turbogears.flash(_('The group details have been saved.'))
                turbogears.redirect('/group/view/%s' % group.name)
            return dict(group=group)
Exemplo n.º 2
0
Arquivo: group.py Projeto: chepioq/fas
    def view(self, groupname, order_by='username'):
        '''View group'''
        sort_map = { 'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
            }
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # Also return information on who is not sponsored
        unsponsored = PersonRoles.query.join('group').join('member',
            aliased=True).outerjoin('sponsor', aliased=True).filter(
            and_(Groups.name==groupname,
                PersonRoles.role_status=='unapproved')).order_by(sort_map[order_by])
        unsponsored.json_props = {'PersonRoles': ['member']}
        members = PersonRoles.query.join('group').join('member', aliased=True).filter(
            People.username.like('%')
            ).outerjoin('sponsor', aliased=True).filter(
            Groups.name==groupname,
            ).order_by(sort_map[order_by])
        return dict(group=group, sponsor_queue=unsponsored,
            members=list(members))
Exemplo n.º 3
0
    def members(self, groupname, search=u'a*', role_type=None,
                order_by='username'):
        '''View group'''
        sort_map = { 'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
            }
        if not isinstance(search, unicode) and isinstance(search, basestring):
            search = unicode(search, 'utf-8', 'replace')

        re_search = search.translate({ord(u'*'): ur'%'}).lower()

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # return all members of this group that fit the search criteria
        members = PersonRoles.query.join('group').join('member', aliased=True).filter(
            People.username.like(re_search)
            ).outerjoin('sponsor', aliased=True).filter(
            Groups.name==groupname,
            ).order_by(sort_map[order_by])
        if role_type:
            members = members.filter(PersonRoles.role_type==role_type)
        group.json_props = {'PersonRoles': ['member']}
        return dict(group=group, members=members, search=search)
Exemplo n.º 4
0
    def invite(self, groupname, language):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)
        person = person.filter_private()

        subject = _('Invitation to join the Fedora Team!', language)
        text = _('''
%(fullname)s <%(user)s@%(hostname)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).  %(fullname)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!'''
        % {'fullname': person.human_name,
               'user': person.username,
           'hostname': config.get('email_host')}, language)

        return dict(person=person, group=group, invite_subject=subject,
                    invite_text=text, selected_language=language)
Exemplo n.º 5
0
Arquivo: group.py Projeto: ccoss/fas
    def invite(self, groupname):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        person = person.filter_private()
        return dict(person=person, group=group)
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def invite(self, groupname):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        person = person.filter_private()
        return dict(person=person, group=group)
Exemplo n.º 8
0
Arquivo: group.py Projeto: chepioq/fas
    def members(self, groupname, search=u'a*', role_type=None,
                order_by='username'):
        '''View group'''
        sort_map = { 'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
            }
        if not isinstance(search, unicode) and isinstance(search, basestring):
            search = unicode(search, 'utf-8', 'replace')

        re_search = search.translate({ord(u'*'): ur'%'}).lower()

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # return all members of this group that fit the search criteria
        members = PersonRoles.query.join('group').join('member', aliased=True).filter(
            People.username.like(re_search)
            ).outerjoin('sponsor', aliased=True).filter(
            Groups.name==groupname,
            ).order_by(sort_map[order_by])
        if role_type:
            members = members.filter(PersonRoles.role_type==role_type)
        group.json_props = {'PersonRoles': ['member']}
        return dict(group=group, members=members, search=search)
Exemplo n.º 9
0
    def application_screen(self, groupname, targetname=None):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if not targetname:
            targetname = username
            target = person
        else:
            target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if username != targetname or group.apply_rules is None or len(
                group.apply_rules) < 1:
            turbogears.redirect('/group/apply/%s/%s' %
                                (group.name, target.username))

        if group in target.memberships:
            turbogears.flash('You are already a member of %s!' % group.name)
            turbogears.redirect('/group/view/%s' % group.name)

        if not can_apply_group(person, group, target):
            turbogears.flash(_('%(user)s can not apply to %(group)s.') % \
                {'user': target.username, 'group': group.name })
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            return dict(group=group)
Exemplo n.º 10
0
    def view(self, groupname, order_by='username'):
        '''View group'''
        sort_map = {
            'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
        }
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # Also return information on who is not sponsored
        unsponsored = PersonRoles.query.join('group').join(
            'member', aliased=True).outerjoin('sponsor', aliased=True).filter(
                and_(Groups.name == groupname,
                     PersonRoles.role_status == 'unapproved')).order_by(
                         sort_map[order_by])
        unsponsored.json_props = {'PersonRoles': ['member']}
        return dict(group=group, sponsor_queue=unsponsored)
Exemplo n.º 11
0
Arquivo: group.py Projeto: 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)
Exemplo n.º 12
0
Arquivo: group.py Projeto: chepioq/fas
    def invite(self, groupname, language):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)
        person = person.filter_private()

        subject = _('Invitation to join the Fedora Team!', language)
        text = _('''
%(fullname)s <%(user)s@%(hostname)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).  %(fullname)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!'''
        % {'fullname': person.human_name, 
               'user': person.username,
           'hostname': config.get('email_host')}, language)

        return dict(person=person, group=group, invite_subject=subject,
                    invite_text=text, selected_language=language)
Exemplo n.º 13
0
    def save(self, groupname, display_name, owner, group_type,
             needs_sponsor=0, user_can_remove=1, prerequisite='',
             url='', mailing_list='', mailing_list_url='', invite_only=0,
             irc_channel='', irc_network='', joinmsg='', apply_rules="None"):
        '''Edit a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        changed = []
        #TODO: check any mandatory fields
        if not group_type:
            turbogears.flash(_("Group type cannot by empty!"))
            turbogears.redirect('/group/edit/%s' % group.name)

        if not can_edit_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            owner = People.by_username(owner)

            if prerequisite:
                prerequisite = Groups.by_name(prerequisite)

            try:
                for field, _validator in GroupSave().fields.items():
                    if field in ['groupname']:
                        continue

                    if getattr(group, field) != locals()[field]:
                        setattr(group, field, locals()[field])
                        changed.append(field)

                session.flush()
            except:
                turbogears.flash(_('The group details could not be saved.'))
            else:
                Log(author_id=person.id, description='%s edited group %s' %
                    (person.username, group.name))
                fas.fedmsgshim.send_message(topic="group.update", msg={
                    'agent': person.username,
                    'group': group.name,
                    'fields': changed,
                })
                turbogears.flash(_('The group details have been saved.'))
                turbogears.redirect('/group/view/%s' % group.name)
            return dict(group=group)
Exemplo n.º 14
0
    def save(self, groupname, display_name, owner, group_type,
             needs_sponsor=0, user_can_remove=1, prerequisite='',
             url='', mailing_list='', mailing_list_url='', invite_only=0,
             irc_channel='', irc_network='', joinmsg='', apply_rules="None"):
        '''Edit a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        changed = []
        #TODO: check any mandatory fields
        if not group_type:
            turbogears.flash(_("Group type cannot by empty!"))
            turbogears.redirect('/group/edit/%s' % group.name)

        if not can_edit_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            owner = People.by_username(owner)

            if prerequisite:
                prerequisite = Groups.by_name(prerequisite)

            try:
                for field, _validator in GroupSave().fields.items():
                    if field in ['groupname']:
                        continue

                    if getattr(group, field) != locals()[field]:
                        setattr(group, field, locals()[field])
                        changed.append(field)

                session.flush()
            except:
                turbogears.flash(_('The group details could not be saved.'))
            else:
                Log(author_id=person.id, description='%s edited group %s' %
                    (person.username, group.name))
                fas.fedmsgshim.send_message(topic="group.update", msg={
                    'agent': person.username,
                    'group': group.name,
                    'fields': changed,
                })
                turbogears.flash(_('The group details have been saved.'))
                turbogears.redirect('/group/view/%s' % group.name)
            return dict(group=group)
Exemplo n.º 15
0
Arquivo: group.py Projeto: Affix/fas
    def save(self, groupname, display_name, owner, group_type, 
             needs_sponsor=0, user_can_remove=1, prerequisite='', 
             url='', mailing_list='', mailing_list_url='', invite_only=0,
             irc_channel='', irc_network='', joinmsg='', apply_rules="None"):
        '''Edit a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_edit_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        else:
            try:
                owner = People.by_username(owner)
                group.display_name = display_name
                group.owner = owner
                group.group_type = group_type
                group.needs_sponsor = bool(needs_sponsor)
                group.user_can_remove = bool(user_can_remove)
                if prerequisite:
                    prerequisite = Groups.by_name(prerequisite)
                    group.prerequisite = prerequisite
                else:
                    group.prerequisite = None
                group.url = url
                group.mailing_list = mailing_list
                group.mailing_list_url = mailing_list_url
                if invite_only: 
                    group.invite_only = True
                else:
                    group.invite_only = False
                group.irc_channel = irc_channel
                group.irc_network = irc_network
                group.joinmsg = joinmsg
                group.apply_rules = apply_rules
                # Log here
                session.flush()
            except:
                turbogears.flash(_('The group details could not be saved.'))
            else:
                Log(author_id=person.id, description='%s edited group %s' %
                    (person.username, group.name))
                turbogears.flash(_('The group details have been saved.'))
                turbogears.redirect('/group/view/%s' % group.name)
            return dict(group=group)
Exemplo n.º 16
0
 def group_by_name(self, groupname):
     try:
         group = Groups.by_name(groupname)
         group.json_props = {
                 'Groups': ('approved_roles', 'unapproved_roles')}
         return dict(success=True, group=group)
     except InvalidRequestError:
         return dict(success=False)
Exemplo n.º 17
0
 def validate_python(self, value, state):
     # pylint: disable-msg=C0111
     try:
         # Just make sure the group already exists
         # pylint: disable-msg=W0612
         group = Groups.by_name(value)
     except InvalidRequestError:
         raise validators.Invalid(
             self.message('no_group', state, group=value), value, state)
Exemplo n.º 18
0
 def validate_python(self, value, state):
     # pylint: disable-msg=C0111
     try:
         # Just make sure the group already exists
         # pylint: disable-msg=W0612
         group = Groups.by_name(value)
     except InvalidRequestError:
         raise validators.Invalid(self.message('no_group', state, group=value),
                 value, state)
Exemplo n.º 19
0
 def group_by_name(self, groupname):
     try:
         group = Groups.by_name(groupname)
         group.json_props = {
             'Groups': ('approved_roles', 'unapproved_roles')
         }
         return dict(success=True, group=group)
     except InvalidRequestError:
         return dict(success=False)
Exemplo n.º 20
0
Arquivo: group.py Projeto: chepioq/fas
    def edit(self, groupname):
        '''Display edit group form'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_admin_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        return dict(group=group)
Exemplo n.º 21
0
    def edit(self, groupname):
        '''Display edit group form'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_admin_group(person, group):
            turbogears.flash(_("You cannot edit '%s'.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
        return dict(group=group)
Exemplo n.º 22
0
    def view(self, groupname, order_by='username'):
        '''View group'''
        sort_map = { 'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
            }
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # Also return information on who is not sponsored
        unsponsored = PersonRoles.query.join('group').join('member',
            aliased=True).outerjoin('sponsor', aliased=True).filter(
            and_(Groups.name==groupname,
                PersonRoles.role_status=='unapproved')).options(
                    eagerload('member')).order_by(sort_map[order_by])

        # Filter out privacy sensitive information
        unsponsored = list(unsponsored)
        for person in unsponsored:
            person.member.filter_private()


        # This is a really, really slow query in some cases, and we only
        # render it in this view if there are < 10 members. This is a rare case
        # where it makes sense to perform a count query first.
        # However, for consistency, we should probably count in the template.
        # So instead of sending list(members) back to the template, let's
        # send the members query object, then in the template, we can check
        # if we need to convert it to a list or not.
        members = PersonRoles.query.join('group').join('member', aliased=True).filter(
            People.username.like('%')
            ).outerjoin('sponsor', aliased=True).filter(
            Groups.name==groupname,
            ).order_by(sort_map[order_by])
        # At the present time members is only PersonRoles info
        # so we don't have to filter that.
        return dict(group=group, sponsor_queue=unsponsored, members=members)
Exemplo n.º 23
0
    def view(self, groupname, order_by='username'):
        '''View group'''
        sort_map = { 'username': '******',
            'creation': 'person_roles_creation',
            'approval': 'person_roles_approval',
            'role_status': 'person_roles_role_status',
            'role_type': 'person_roles_role_type',
            'sponsor': 'people_2.username',
            }
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        group = Groups.by_name(groupname)

        if not can_view_group(person, group):
            turbogears.flash(_("You cannot view '%s'") % group.name)
            turbogears.redirect('/group/list')
            return dict()

        # Also return information on who is not sponsored
        unsponsored = PersonRoles.query.join('group').join('member',
            aliased=True).outerjoin('sponsor', aliased=True).filter(
            and_(Groups.name==groupname,
                PersonRoles.role_status=='unapproved')).options(
                    eagerload('member')).order_by(sort_map[order_by])

        # Filter out privacy sensitive information
        unsponsored = list(unsponsored)
        for person in unsponsored:
            person.member.filter_private()


        # This is a really, really slow query in some cases, and we only
        # render it in this view if there are < 10 members. This is a rare case
        # where it makes sense to perform a count query first.
        # However, for consistency, we should probably count in the template.
        # So instead of sending list(members) back to the template, let's
        # send the members query object, then in the template, we can check
        # if we need to convert it to a list or not.
        members = PersonRoles.query.join('group').join('member', aliased=True).filter(
            People.username.like('%')
            ).outerjoin('sponsor', aliased=True).filter(
            Groups.name==groupname,
            ).order_by(sort_map[order_by])
        # At the present time members is only PersonRoles info
        # so we don't have to filter that.
        return dict(group=group, sponsor_queue=unsponsored, members=members)
Exemplo n.º 24
0
    def downgrade(self, groupname, targetname):
        '''Upgrade user in group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_downgrade_user(person, group):
            turbogears.flash(_("You cannot downgrade '%s'") % target.username)
            turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            return dict()
        else:
            try:
                target.downgrade(group, person)
            except fas.DowngradeError, e:
                turbogears.flash(_('%(name)s could not be downgraded in %(group)s: %(error)s') % \
                    {'name': target.username, 'group': group.name, 'error': e})
                turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            else:
Exemplo n.º 25
0
Arquivo: group.py Projeto: chepioq/fas
    def downgrade(self, groupname, targetname):
        '''Upgrade user in group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_downgrade_user(person, group):
            turbogears.flash(_("You cannot downgrade '%s'") % target.username)
            turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            return dict()
        else:
            try:
                target.downgrade(group, person)
            except fas.DowngradeError, e:
                turbogears.flash(_('%(name)s could not be downgraded in %(group)s: %(error)s') % \
                    {'name': target.username, 'group': group.name, 'error': e})
                turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            else:
Exemplo n.º 26
0
Arquivo: group.py Projeto: chepioq/fas
    def sponsor(self, groupname, targetname):
        '''Sponsor user'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_sponsor_user(person, group):
            turbogears.flash(_("You cannot sponsor '%s'") % target.username)
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            try:
                target.sponsor(group, person)
            except fas.SponsorError, e:
                turbogears.flash(_("%(user)s could not be sponsored in %(group)s: %(error)s") % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect('/group/view/%s' % group.name)
            else:
Exemplo n.º 27
0
    def sponsor(self, groupname, targetname):
        '''Sponsor user'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_sponsor_user(person, group):
            turbogears.flash(_("You cannot sponsor '%s'") % target.username)
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            try:
                target.sponsor(group, person)
            except fas.SponsorError, e:
                turbogears.flash(_("%(user)s could not be sponsored in %(group)s: %(error)s") % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect('/group/view/%s' % group.name)
            else:
Exemplo n.º 28
0
    def type_list(self, grptype='pkgdb'):
        """ Return the list of all group of the given type.
        """
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        groups = []
        results = Groups.by_type(grptype)
        if self.jsonRequest():
            if len(results) == 1 \
                    and results[0].name == grptype \
                    and can_view_group(person, results[0]):
                turbogears.redirect('/group/view/%s' % (results[0].name))
                return dict()

        for group in results:
            if can_view_group(person, group):
                groups.append(group)
        if not len(groups):
            turbogears.flash(_("No Groups found of type '%s'") % grptype)
        return dict(groups=groups, search=grptype)
Exemplo n.º 29
0
    def type_list(self, grptype='pkgdb'):
        """ Return the list of all group of the given type.
        """
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        groups = []
        results = Groups.by_type(grptype)
        if self.jsonRequest():
            if len(results) == 1 \
                    and results[0].name == grptype \
                    and can_view_group(person, results[0]):
                turbogears.redirect('/group/view/%s' % (results[0].name))
                return dict()

        for group in results:
            if can_view_group(person, group):
                groups.append(group)
        if not len(groups):
            turbogears.flash(_("No Groups found of type '%s'") % grptype)
        return dict(groups=groups, search=grptype)
Exemplo n.º 30
0
Arquivo: group.py Projeto: chepioq/fas
    def remove(self, groupname, targetname):
        '''Remove user from group'''
        # TODO: Add confirmation?
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_remove_user(person, group, target):
            turbogears.flash(_("You cannot remove '%(user)s' from '%(group)s'.") % \
                {'user': target.username, 'group': group.name})
            turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            return dict()
        else:
            try:
                target.remove(group, target)
            except fas.RemoveError, e:
                turbogears.flash(_("%(user)s could not be removed from %(group)s: %(error)s") % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            else:
Exemplo n.º 31
0
    def remove(self, groupname, targetname):
        '''Remove user from group'''
        # TODO: Add confirmation?
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_remove_user(person, group, target):
            turbogears.flash(_("You cannot remove '%(user)s' from '%(group)s'.") % \
                {'user': target.username, 'group': group.name})
            turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            return dict()
        else:
            try:
                target.remove(group, target)
            except fas.RemoveError, e:
                turbogears.flash(_("%(user)s could not be removed from %(group)s: %(error)s") % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
            else:
Exemplo n.º 32
0
Arquivo: group.py Projeto: chepioq/fas
    def apply(self, groupname, targetname=None):
        '''Apply to a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if not targetname:
            target = person
        else:
            target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_apply_group(person, group, target):
            turbogears.flash(_('%(user)s can not apply to %(group)s.') % \
                {'user': target.username, 'group': group.name })
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            try:
                target.apply(group, person)
            except fas.ApplyError, e:
                turbogears.flash(_('%(user)s could not apply to %(group)s: %(error)s') % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect('/group/view/%s' % group.name)
            else:
Exemplo n.º 33
0
    def apply(self, groupname, targetname=None):
        '''Apply to a group'''
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if not targetname:
            target = person
        else:
            target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if not can_apply_group(person, group, target):
            turbogears.flash(_('%(user)s can not apply to %(group)s.') % \
                {'user': target.username, 'group': group.name })
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            try:
                target.apply(group, person)
            except fas.ApplyError, e:
                turbogears.flash(_('%(user)s could not apply to %(group)s: %(error)s') % \
                    {'user': target.username, 'group': group.name, 'error': e})
                turbogears.redirect('/group/view/%s' % group.name)
            else:
Exemplo n.º 34
0
Arquivo: group.py Projeto: chepioq/fas
    def application_screen(self, groupname, targetname=None):
        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if not targetname:
            targetname = username
            target = person
        else:
            target = People.by_username(targetname)
        group = Groups.by_name(groupname)

        if username != targetname or group.apply_rules is None or len(group.apply_rules) < 1:
            turbogears.redirect('/group/apply/%s/%s' % (group.name, target.username))

        if group in target.memberships:
            turbogears.flash('You are already a member of %s!' % group.name)
            turbogears.redirect('/group/view/%s' % group.name)

        if not can_apply_group(person, group, target):
            turbogears.flash(_('%(user)s can not apply to %(group)s.') % \
                {'user': target.username, 'group': group.name })
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
        else:
            return dict(group=group)
Exemplo n.º 35
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.º 36
0
    def create(self, name, display_name, owner, group_type, invite_only=0,
               needs_sponsor=0, user_can_remove=1, prerequisite='',
               joinmsg='', apply_rules='None'):
        '''Create a group'''

        groupname = name
        person = People.by_username(turbogears.identity.current.user_name)
        person_owner = People.by_username(owner)

        if not can_create_group(person):
            turbogears.flash(_('Only FAS administrators can create groups.'))
            turbogears.redirect('/')
        try:
            owner = People.by_username(owner)
            group = Groups()
            group.name = name
            group.display_name = display_name
            group.owner_id = person_owner.id
            group.group_type = group_type
            group.needs_sponsor = bool(needs_sponsor)
            if invite_only:
                group.invite_only = True
            else:
                group.invite_only = False
            group.user_can_remove = bool(user_can_remove)
            if prerequisite:
                prerequisite = Groups.by_name(prerequisite)
                group.prerequisite = prerequisite
            group.joinmsg = joinmsg
            group.apply_rules = apply_rules
            # Log group creation
            Log(author_id=person.id, description='%s created group %s' %
                (person.username, group.name))
            session.flush()
        except TypeError:
            turbogears.flash(_("The group: '%s' could not be created.") % groupname)
            return dict()
        else:
            try:
                owner.apply(group, person) # Apply...
                session.flush()
                owner.sponsor(group, person)
                owner.upgrade(group, person)
                owner.upgrade(group, person)
            except KeyError:
                turbogears.flash(_("The group: '%(group)s' has been created, but '%(user)s' could not be added as a group administrator.") % {'group': group.name, 'user': owner.username})
            else:
                fas.fedmsgshim.send_message(topic="group.create", msg={
                    'agent': person.username,
                    'group': group.name,
                })
                turbogears.flash(_("The group: '%s' has been created.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
Exemplo n.º 37
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.º 38
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()
Exemplo n.º 39
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.º 40
0
Arquivo: group.py Projeto: chepioq/fas
    def create(self, name, display_name, owner, group_type, invite_only=0,
               needs_sponsor=0, user_can_remove=1, prerequisite='', 
               joinmsg='', apply_rules='None'):
        '''Create a group'''

        groupname = name
        person = People.by_username(turbogears.identity.current.user_name)
        person_owner = People.by_username(owner)

        if not can_create_group(person):
            turbogears.flash(_('Only FAS administrators can create groups.'))
            turbogears.redirect('/')
        try:
            owner = People.by_username(owner)
            group = Groups()
            group.name = name
            group.display_name = display_name
            group.owner_id = person_owner.id
            group.group_type = group_type
            group.needs_sponsor = bool(needs_sponsor)
            if invite_only:
                group.invite_only = True
            else:
                group.invite_only = False
            group.user_can_remove = bool(user_can_remove)
            if prerequisite:
                prerequisite = Groups.by_name(prerequisite)
                group.prerequisite = prerequisite
            group.joinmsg = joinmsg
            group.apply_rules = apply_rules
            # Log group creation
            Log(author_id=person.id, description='%s created group %s' %
                (person.username, group.name))
            session.flush()
        except TypeError:
            turbogears.flash(_("The group: '%s' could not be created.") % groupname)
            return dict()
        else:
            try:
                owner.apply(group, person) # Apply...
                session.flush()
                owner.sponsor(group, person)
                owner.upgrade(group, person)
                owner.upgrade(group, person)
            except KeyError:
                turbogears.flash(_("The group: '%(group)s' has been created, but '%(user)s' could not be added as a group administrator.") % {'group': group.name, 'user': owner.username})
            else:
                fas.fedmsgshim.send_message(topic="group.create", msg={
                    'agent': { 'username': person.username, },
                    'group': { 'name': group.name, },
                })
                turbogears.flash(_("The group: '%s' has been created.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()