def update_user_projects(user): ''' Function to update the user projects from across the federation. Will query all remote nodes (but NOT the current nodes, since that information should already be up-to-date) and save the updated information in the local database. ''' if user.is_authenticated(): # current user groups in local database ugroups = user.groups.all() # retrieve map of (project, groups) for this user (projTuples, grpTuples) = get_all_shared_user_info(user, includeCurrentSite=False) # add new memberships for remote projects remoteGroups = [] # updated list of remote groups for (project, roles) in projTuples: print 'Updating membership for user: %s project: %s roles: %s' % ( user.profile.openid(), project.short_name, roles) for role in roles: group = project.getGroup(role) remoteGroups.append(group) if not group in ugroups: print 'Adding group: %s to user: %s' % (group, user) user.groups.add(group) # persist changes to local database user.save() # remove old memberships for remote projects for group in user.groups.all(): try: project = getProjectForGroup(group) # do not change local projects if not project.isLocal(): if not group in remoteGroups: print 'Removing group: %s from user: %s' % (group, user) user.groups.remove(group) except ObjectDoesNotExist: print 'WARNING: cannot retrieve project for group=%s, removing obsolete group' % group user.groups.remove(group) # persist changes to local database user.save()
def update_user_projects(user): ''' Function to update the user projects from across the federation. Will query all remote nodes (but NOT the current nodes, since that information should already be up-to-date) and save the updated information in the local database. ''' if user.is_authenticated(): # current user groups in local database ugroups = user.groups.all() # retrieve map of (project, groups) for this user (projTuples, grpTuples) = get_all_shared_user_info(user, includeCurrentSite=False) # add new memberships for remote projects remoteGroups = [] # updated list of remote groups for (project, roles) in projTuples: print 'Updating membership for user: %s project: %s roles: %s' % (user.profile.openid(), project.short_name, roles) for role in roles: group = project.getGroup(role) remoteGroups.append(group) if not group in ugroups: print 'Adding group: %s to user: %s' % (group, user) user.groups.add(group) # persist changes to local database user.save() # remove old memberships for remote projects for group in user.groups.all(): try: project = getProjectForGroup(group) # do not change local projects if not project.isLocal(): if not group in remoteGroups: print 'Removing group: %s from user: %s' % (group, user) user.groups.remove( group ) except ObjectDoesNotExist: print 'WARNING: cannot retrieve project for group=%s, removing obsolete group' % group user.groups.remove( group ) # persist changes to local database user.save()
def user_detail(request, user_id): # load User object user = get_object_or_404(User, pk=user_id) # try loading user profile try: user_profile = UserProfile.objects.get(user=user) # create user profile if not existing already except: user_profile = UserProfile(user=user) user_profile.save() print "Created empty profile for user=%s" % user # retrieve map of (project, roles) for this user (projTuples, groupTuples) = get_all_shared_user_info(user) print "\nprojTuples=" print projTuples # sort projects, groups alphabetically projects = sorted(projTuples, key=lambda x: x[0].short_name) groups = sorted(groupTuples, key=lambda x: x[0]) return render(request, 'cog/account/user_detail.html', {'user_profile': user_profile, 'projects': projects, 'groups':groups, 'title': 'User Profile'})