def upgrade_internal_users_expiring_passwords(): """Set internal users to have expiring passwords.""" from qon.base import get_user_database from qon.ui import blocks user_db = get_user_database() for user_id, user in user_db.root.iteritems(): if blocks.util.is_internal_user(user): user.set_expiring_password(True)
def clean_email_db(): """Remove lingering entries in email db that don't map to current users.""" from base import get_user_database user_db = get_user_database() for email, user_id in user_db.email_db.root.iteritems(): user = user_db.get_user(user_id) if email not in user.email_list(): print "%s is no longer associated with %s, removing." % (email, user.display_name()) del user_db.email_db[email]
def upgradeFixInvitations(): """Remove any lingering invitations to users who are members of groups they are invited to.""" from base import get_group_database, get_user_database user_db = get_user_database() group_db = get_group_database() for user in user_db.root.values(): for g in group_db.users_groups(user): g.remove_invitation(user) group_db.invitations.remove_all_user_invitations(user, g)
def cleanup_invitations(): """Remove duplicate and redundant invitations from global list and individual groups.""" from base import get_group_database, get_user_database def user_name(user_or_email): if isinstance(user_or_email, HasEmail): return user_or_email.display_name() else: return user_or_email group_db = get_group_database() user_db = get_user_database() # sanity check and clean each group's invitation list for g in group_db.root.values(): for user_or_email in g.invited_users.keys(): user = user_db.resolve_user(user_or_email) if user: if g.is_member(user) or g.is_owner(user): print "%s is already a member of %s, removing invitation." % ( user_name(user), g.name) g.remove_invitation(user_or_email) # check and clean global list for (email, invites) in group_db.invitations.root.iteritems(): user = user_db.resolve_user(email) if user: for group_id in invites: g = group_db[group_id] if g.is_member(user) or g.is_owner(user): print "%s is a member of %s, removing global invitation." % ( user_name(user), g.name) group_db.invitations.remove_all_user_invitations(user, g) # remove duplicate group entries in global list for (email, invites) in group_db.invitations.root.iteritems(): invites = qon.util.unique_items(invites) group_db.invitations.root[email] = invites
def upgradeAddInvitations(): from base import get_group_database, get_user_database from persistent.mapping import PersistentMapping user_db = get_user_database() db = get_group_database() db.invitations = Invitations() for g in db.root.values(): g.invited_users = PersistentMapping(g.invited_users) for email in g.invited_users.keys(): db.invitations.add_invitation(email, g) # remove lingering invitations from when our code was dumb and left them for g in db.root.values(): for email in g.invited_users.keys(): try: user = user_db.get_user_by_email(email) except KeyError: pass else: if g.is_member(user): del g.invited_users[email] db.invitations.remove_all_user_invitations(user, g)
def fix_broken_user_data_caches(): """Scans all users to check if any of their user data caches are inaccurate, or worse, reference deleted groups.""" from qon.base import get_user_database, get_group_database user_db = get_user_database() group_db = get_group_database() i = 0 for user_id, user in user_db.root.iteritems(): i += 1 # print "%d) %s" % (i, user_id) # check/fix owned groups if hasattr(user, '_group_owned_groups'): real_owned_groups = [group_db[group] for group in group_db.root.keys() \ if group_db[group].is_owner(user)] if real_owned_groups != user._group_owned_groups: print "%s's _group_owned_groups isn't accurate" % user_id for g in user._group_owned_groups: if not group_db.has_key(g.get_user_id()): print "-%s's _group_owned_groups references deleted group %s" % (user_id, g.get_user_id()) # fix it! user._group_owned_groups = real_owned_groups # check/fix member groups if hasattr(user, '_group_member_groups'): real_member_groups = [group_db[group] for group in group_db.root.keys() \ if group_db[group].is_member(user, slow=True)] if real_member_groups != user._group_member_groups: print "%s's _group_member_groups isn't accurate" % user_id for g in user._group_member_groups: if not group_db.has_key(g.get_user_id()): print "-%s's _group_member_groups references deleted group %s" % (user_id, g.get_user_id()) # fix it user._group_member_groups = real_member_groups
def create_initial_groups(): """Create initial top-level groups if they don't already exist.""" from base import get_group_database, get_user_database import api # we want any groups we create in here to be active immediately save_min_sponsors = Group._min_sponsors Group._min_sponsors = 1 user_db = get_user_database() group_db = get_group_database() user_admin = user_db['admin'] def create_group(user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit=''): if not group_db.has_key(user_id): g = group_db.create_group(user_id=user_id, name=name, description=desc, owner=owner, no_pay=True) group_db.force_accept(g) if parent_id: group_db.join_group(g, group_db[parent_id], force=1) g = group_db[user_id] if join_pol: api.group_set_join_policy(user_admin, g, join_pol) if join_pol == 'open': # if membership is open, allow non-members to read api.group_set_other_perms(user_admin, g, 'ro') if memb_vis: api.group_set_membership_visible(user_admin, g, memb_vis) if desc: api.group_set_settings(user_admin, g, description=desc) if memb_edit: api.group_set_member_edit(user_admin, g, memb_edit) # set date of formation create = datetime(2004, 05, 10, 12, 0, 0) g.date = create groups = [ ('top', 'Top', 'This group contains the top-level groups.', user_admin, None, '', 'open', ''), ('regional', 'Regional', 'Contains groups with a regional focus.', user_admin, 'top', '', 'open', ''), ('orgs', 'Organizations', 'Contains categories of organizations.', user_admin, 'top', '', 'open', ''), ('community', 'Community', 'Contains groups that are focused or based on ned.com.', user_admin, 'top', '', 'open', ''), ('issues', 'Issues', 'Contains groups focused on particular issues.', user_admin, 'top', '', 'open', ''), ('general', 'General', 'Contains groups that don\'t belong in other categories.', user_admin, 'top', 'open', 'open', ''), ('general-other', 'General', 'Contains groups that don\'t belong in other categories.', user_admin, 'general', 'open', 'open', ''), ('help', 'Help', 'Contains site help.', user_admin, 'community', '', 'open', ''), ('community-general', 'Community - General', '', user_admin, 'community', 'open', 'open', 'member'), ('suggestions', 'Suggestions', 'For community suggestions.', user_admin, 'community-general', '', 'open', ''), ('public', 'Public sector', 'Groups operating in the public sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'), ('private', 'Private sector', 'Groups operating in the private sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'), ('social', 'Social sector', 'Groups operating in the social sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'), ('orgs-general', 'Organizations - General', "For organizations that don't fit in other categories.", user_admin, 'orgs', 'open', 'open', 'member'), ('issues-business', 'Business', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-cyf', 'Children - Youth - Families', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-education', 'Education', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-env', 'Environment - Conservation', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-health', 'Health Care', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-pol', 'Policy - Politics', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-religion', 'Religion', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-soc', 'Social Justice - Human Services', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-tech', 'Technology', '', user_admin, 'issues', 'open', 'open', 'member'), ('issues-general', 'Issues - General', '', user_admin, 'issues', 'open', 'open', 'member'), ('ned', '<ned> Network', '', user_admin, '', '', '', ''), ('ned-internal', 'Ned - Internal', '', user_admin, '', '', '', ''), ('sitedev', 'Site Development', '', user_admin, 'ned-internal', '', '', ''), ] for user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit in groups: create_group(user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit) # Help group g_help = group_db['help'] api.group_set_anon_read(user_admin, g_help, True) # ON groups g_on = group_db['ned'] group_db.join_group(g_on, group_db['private'], force=1) group_db.join_group(g_on, group_db['public'], force=1) group_db.join_group(g_on, group_db['social'], force=1) api.group_set_owners_by_user_id(user_admin, g_on, ['admin', 'jimc']) api.group_set_join_policy(user_admin, g_on, 'owner') api.group_set_invite_policy(user_admin, g_on, 'owner') api.group_set_membership_visible(user_admin, g_on, 'open') api.group_set_member_edit(user_admin, g_on, True) api.group_set_anon_read(user_admin, g_on, True) g_on_int = group_db['ned-internal'] api.group_set_owners_by_user_id(user_admin, g_on_int, ['admin', 'jimc']) api.group_set_join_policy(user_admin, g_on_int, 'owner') api.group_set_invite_policy(user_admin, g_on_int, 'owner') api.group_set_membership_visible(user_admin, g_on_int, 'member') api.group_set_member_edit(user_admin, g_on_int, True) api.group_set_anon_read(user_admin, g_on_int, False) g_sitedev = group_db['sitedev'] api.group_set_owners_by_user_id(user_admin, g_sitedev, ['admin', 'jimc']) Group._min_sponsors = save_min_sponsors