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)
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))
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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:
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:
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)
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:
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:
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)
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()
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()
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()
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()
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()
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()