本文整理汇总了Python中fas.model.People类的典型用法代码示例。如果您正苦于以下问题:Python People类的具体用法?Python People怎么用?Python People使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了People类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reject
def reject(self, person_name):
"""Reject a user's FPCA.
This method will remove a user from the FPCA group and any other groups
that they are in that require the FPCA. It is used when a person has
to fulfill some more legal requirements before having a valid FPCA.
Arguments
:person_name: Name of the person to reject.
"""
show = {}
show["show_postal_address"] = config.get("show_postal_address")
exc = None
user = People.by_username(turbogears.identity.current.user_name)
if not is_admin(user):
# Only admins can use this
turbogears.flash(_("You are not allowed to reject FPCAs."))
exc = "NotAuthorized"
else:
# Unapprove the cla and all dependent groups
person = People.by_username(person_name)
for role in person.roles:
if self._cla_dependent(role.group):
role.role_status = "unapproved"
try:
session.flush()
except DBAPIError, error:
turbogears.flash(
_("Error removing cla and dependent groups" " for %(person)s\n Error was: %(error)s")
% {"person": person_name, "error": str(error)}
)
exc = "DBAPIError"
示例2: save
def save(self, targetname, yubikey_enabled, yubikey_prefix):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not can_edit_user(person, target):
ff.error(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/yubikey')
return dict()
new_configs = {'enabled': yubikey_enabled, 'prefix': yubikey_prefix}
cur_configs = Configs.query.filter_by(person_id=target.id, application='yubikey').all()
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='yubikey', attribute=config, value=new_configs[config])
target.configs.append(c)
mail_subject=_('Fedora Yubikey changed for %s' % target)
mail_text=_('''
You have changed your Yubikey on your Fedora account %s. If you did not make
this change, please contact [email protected]''' % target)
email='%[email protected]' % target
send_mail(email, mail_subject, mail_text)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/yubikey/')
return dict()
示例3: save
def save(self, targetname, bugzilla_email):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not can_edit_user(person, target):
turbogears.flash(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/bugzilla')
return dict()
new_configs = {'bugzilla_email': bugzilla_email}
cur_configs = Configs.query.filter_by(person_id=target.id, application='bugzilla').all()
if bugzilla_email == None:
session.delete(cur_configs[0])
turbogears.flash(_("Bugzilla specific email removed! This means your bugzilla email must be set to: %s" % target.email))
turbogears.redirect('/bugzilla/')
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='bugzilla', attribute=config, value=new_configs[config])
target.configs.append(c)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/bugzilla/')
return dict()
示例4: edit
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='yubikey').all())
return dict(admin=admin, person=person, configs=configs,target=target)
示例5: reject
def reject(self, person_name):
'''Reject a user's FPCA.
This method will remove a user from the FPCA group and any other groups
that they are in that require the FPCA. It is used when a person has
to fulfill some more legal requirements before having a valid FPCA.
Arguments
:person_name: Name of the person to reject.
'''
show = {}
show['show_postal_address'] = config.get('show_postal_address')
exc = None
user = People.by_username(turbogears.identity.current.user_name)
if not is_admin(user):
# Only admins can use this
turbogears.flash(_('You are not allowed to reject FPCAs.'))
exc = 'NotAuthorized'
else:
# Unapprove the cla and all dependent groups
person = People.by_username(person_name)
for role in person.roles:
if self._cla_dependent(role.group):
role.role_status = 'unapproved'
try:
session.flush()
except SQLError, error:
turbogears.flash(_('Error removing cla and dependent groups' \
' for %(person)s\n Error was: %(error)s') %
{'person': person_name, 'error': str(error)})
exc = 'sqlalchemy.SQLError'
示例6: save
def save(self, targetname, asterisk_enabled, asterisk_pass):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not cla_done(target):
turbogears.flash(_('You must sign the CLA to have access to this service.'))
turbogears.redirect('/user/view/%s' % target.username)
return dict()
if not can_edit_user(person, target):
turbogears.flash(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/asterisk')
return dict()
new_configs = {'enabled': asterisk_enabled, 'pass': asterisk_pass}
cur_configs = Configs.query.filter_by(person_id=target.id, application='asterisk').all()
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='asterisk', attribute=config, value=new_configs[config])
target.configs.append(c)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/asterisk/')
return dict()
示例7: edit
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
if not cla_done(target):
turbogears.flash(_('You must sign the CLA to have access to this service.'))
turbogears.redirect('/user/view/%s' % target.username)
return dict()
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='asterisk').all())
return dict(admin=admin, person=person, configs=configs,target=target)
示例8: create
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()
示例9: edit
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=person.id, application='bugzilla').all())
if 'bugzilla_email' in configs:
email = configs['bugzilla_email']
else:
email = target.email
return dict(admin=admin, person=person, email=email, target=target)
示例10: dump
def dump(self):
dump_list = []
person = People.by_username(identity.current.user_name)
if identity.in_group(admin_group) or \
identity.in_group(system_group):
yubikey_attrs = {}
for attr in Configs.query.filter_by(application='yubikey').all():
if attr.person_id not in yubikey_attrs:
yubikey_attrs[attr.person_id] = {}
yubikey_attrs[attr.person_id][attr.attribute] = attr.value
for user_id in yubikey_attrs:
if yubikey_attrs[user_id]['enabled'] == u'1':
dump_list.append('%s:%s' % (People.by_id(user_id).username, yubikey_attrs[user_id]['prefix']))
return '\n'.join(dump_list)
return '# Sorry, must be in an admin group to get these'
示例11: genkey
def genkey(self):
username = turbogears.identity.current.user_name
person = People.by_username(username)
created = time.strftime("%Y-%m-%dT%H:%M:%S")
hexctr = "%012x" % person.id
publicname = hex2modhex(hexctr)
internalname = gethexrand(12)
aeskey = gethexrand(32)
lockcode = gethexrand(12)
try:
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
session.add(new_ykksm)
session.flush()
except IntegrityError:
session.rollback()
old_ykksm = session.query(Ykksm).filter_by(serialnr=person.id).all()[0]
session.delete(old_ykksm)
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
old_ykksm = new_ykksm
session.flush()
try:
old_ykval = session.query(Ykval).filter_by(yk_publicname=publicname).all()[0]
session.delete(old_ykval)
session.flush()
except IndexError:
# No old record? Maybe they never used their key
pass
string = "%s %s %s" % (publicname, internalname, aeskey)
return dict(key=string)
示例12: otp_verify
def otp_verify(uid, otp):
import sys, os, re
import urllib2
target = People.by_id(uid)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='yubikey').all())
if not otp.startswith(configs['prefix']):
raise AuthException('Unauthorized/Invalid OTP')
server_prefix = 'http://localhost/yk-val/verify?id='
auth_regex = re.compile('^status=(?P<rc>\w{2})')
server_url = server_prefix + client_id + "&otp=" + otp
fh = urllib2.urlopen(server_url)
for line in fh:
match = auth_regex.search(line.strip('\n'))
if match:
if match.group('rc') == 'OK':
return
else:
raise AuthException(line.split('=')[1])
break
turbogears.redirect('/yubikey/')
return dict()
示例13: home
def home(self):
user_name = turbogears.identity.current.user_name
person = People.by_username(user_name)
(cla_done, undeprecated_cla) = undeprecated_cla_done(person)
person = person.filter_private()
return dict(person=person, memberships=person['memberships'], cla=undeprecated_cla)
示例14: otp_validate
def otp_validate(user_name, otp):
client_id = '1'
target = People.by_username(user_name)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='yubikey').all())
if not otp.startswith(configs['prefix']):
return False
server_prefix = config.get('yubi_server_prefix', 'http://localhost/yk-val/verify?id=')
auth_regex = re.compile('^status=(?P<rc>\w{2})')
server_url = server_prefix + client_id + "&otp=" + otp
fh = urllib2.urlopen(server_url)
for line in fh:
match = auth_regex.search(line.strip('\n'))
if match:
if match.group('rc') == 'OK':
return True
else:
return False
break
return False
示例15: invite
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)[email protected]%(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)