예제 #1
0
파일: membership.py 프로젝트: pchengi/COG
def cancelMembership(user, group, admin=None):

    # cancel all requests for that project
    project = getProjectForGroup(group)
    cancelMembershipRequests(user, project)

    if group in user.groups.all():

        # first remove user from that group
        user.groups.remove(group)
        print "Removed user=%s from group=%s" % (user.username, group.name)

        # if user is not part of the project any more, remove from all project management bodies
        project = getProjectForGroup(group)
        if not project.hasUser(user):
            # Management Bodies
            objs = ManagementBodyMember.objects.filter(user=user).filter(
                managementBody__project=project)
            for obj in objs:
                print 'Deleting ManagementBodyMember for project=%s user=%s managementBody=%s' % (
                    project, user, obj.managementBody.title)
                obj.delete()
            # Organization Roles
            objs = OrganizationalRoleMember.objects.filter(user=user).filter(
                organizationalRole__project=project)
            for obj in objs:
                print 'Deleting OrganizationalRoleMember for project=%s user=%s organizationalRole=%s' % (
                    project, user, obj.organizationalRole.title)
                obj.delete()
            # Communication Means
            objs = CommunicationMeansMember.objects.filter(user=user).filter(
                communicationMeans__project=project)
            for obj in objs:
                print 'Deleting CommunicationMeansMember for project=%s user=%s communicationMeans=%s' % (
                    project, user, obj.communicationMeans.title)
                obj.delete()

        # log event
        if admin is not None:
            event = LoggedEvent.objects.create(
                user=admin,
                project=project,
                title="Membership canceled",
                description="Administrator: %s removed user: %s from group: %s"
                % (admin, user, group.name))
            event.save()

        return RESULT_SUCCESS

    else:
        print "User=%s not found in group=%s" % (user.username, group.name)
        return RESULT_NOT_FOUND
예제 #2
0
def cancelMembership(user, group, admin=None):
     
    # cancel all requests for that project
    project = getProjectForGroup(group)
    cancelMembershipRequests(user, project)
    
    if group in user.groups.all():
           
        # first remove user from that group
        user.groups.remove(group)
        print "Removed user=%s from group=%s" % (user.username, group.name)
        
        # if user is not part of the project any more, remove from all project management bodies
        project = getProjectForGroup(group)
        if not project.hasUser(user):
            # Management Bodies
            objs = ManagementBodyMember.objects.filter(user=user).filter(managementBody__project=project)
            for obj in objs:
                print 'Deleting ManagementBodyMember for project=%s user=%s managementBody=%s' % (project, user, obj.managementBody.title)
                obj.delete()
            # Organization Roles
            objs = OrganizationalRoleMember.objects.filter(user=user).filter(organizationalRole__project=project)
            for obj in objs:
                print 'Deleting OrganizationalRoleMember for project=%s user=%s organizationalRole=%s' % (project, user, obj.organizationalRole.title)
                obj.delete()
            # Communication Means
            objs = CommunicationMeansMember.objects.filter(user=user).filter(communicationMeans__project=project)
            for obj in objs:
                print 'Deleting CommunicationMeansMember for project=%s user=%s communicationMeans=%s' % (project, user, obj.communicationMeans.title)
                obj.delete()
            
        # log event
        if admin is not None:
            event = LoggedEvent.objects.create(user=admin, project=project, 
                                               title="Membership canceled", 
                                               description="Administrator: %s removed user: %s from group: %s" % (admin, user, group.name))
            event.save()

            
        return RESULT_SUCCESS
    
    else:
        print "User=%s not found in group=%s" % (user.username, group.name)
        return RESULT_NOT_FOUND
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
def addMembership(user, group, admin=None):
    
    project = getProjectForGroup(group)
    
    if not group in user.groups.all():
        user.groups.add(group)
        print "Enrolled user=%s in group=%s" % (user.username, group.name)
        cancelMembershipRequests(user, project)
        # log event
        if admin is not None:
            event = LoggedEvent.objects.create(user=admin, project=project, 
                                               title="Membership added", 
                                               description="Administrator: %s added user: %s to group: %s" % (admin, user, group.name))
            event.save()
        return RESULT_SUCCESS
    
    else:
        print "User=%s is already enrolled in group=%s" % (user.username, group.name)
        cancelMembershipRequests(user, project)
        return RESULT_DUPLICATE
예제 #6
0
파일: membership.py 프로젝트: pchengi/COG
def addMembership(user, group, admin=None):

    project = getProjectForGroup(group)

    if not group in user.groups.all():
        user.groups.add(group)
        print "Enrolled user=%s in group=%s" % (user.username, group.name)
        cancelMembershipRequests(user, project)
        # log event
        if admin is not None:
            event = LoggedEvent.objects.create(
                user=admin,
                project=project,
                title="Membership added",
                description="Administrator: %s added user: %s to group: %s" %
                (admin, user, group.name))
            event.save()
        return RESULT_SUCCESS

    else:
        print "User=%s is already enrolled in group=%s" % (user.username,
                                                           group.name)
        cancelMembershipRequests(user, project)
        return RESULT_DUPLICATE
예제 #7
0
from django.contrib.auth.models import User, Permission, Group
from cog.models import Project, getProjectForGroup

# loop over users
for user in User.objects.all():
    
    print 'Processing user=%s' % user
    
    # FIXME
    #if user.last_name=='Cinquini':
    
    for ugroup in user.groups.all():        

        if '_users' in ugroup.name:
            try:
                project = getProjectForGroup(ugroup)
                # remove 'user' group
                user.groups.remove( ugroup )
                # add 'contributor' group
                cgroup = project.getContributorGroup()
                print '\tUser %s: changing group %s to %s' % (user, ugroup, cgroup)
                user.groups.add( cgroup )
                user.save()
            except Project.DoesNotExist:
                pass # old project ?
                        
    # delete obsolete Permission objects
    for permission in user.user_permissions.all():
        if 'Admin Permission' in permission.name or 'User Permission' in permission.name:
            print '\tUser: %s deleting permission: %s' % (user, permission)
            user.user_permissions.remove(permission)
예제 #8
0
from django.contrib.auth.models import User, Permission, Group
from cog.models import Project, getProjectForGroup

# loop over users
for user in User.objects.all():

    print 'Processing user=%s' % user

    # FIXME
    #if user.last_name=='Cinquini':

    for ugroup in user.groups.all():

        if '_users' in ugroup.name:
            try:
                project = getProjectForGroup(ugroup)
                # remove 'user' group
                user.groups.remove(ugroup)
                # add 'contributor' group
                cgroup = project.getContributorGroup()
                print '\tUser %s: changing group %s to %s' % (user, ugroup,
                                                              cgroup)
                user.groups.add(cgroup)
                user.save()
            except Project.DoesNotExist:
                pass  # old project ?

    # delete obsolete Permission objects
    for permission in user.user_permissions.all():
        if 'Admin Permission' in permission.name or 'User Permission' in permission.name:
            print '\tUser: %s deleting permission: %s' % (user, permission)