Exemplo n.º 1
0
        def helper(currentUid, ModifiedUid, appList):
                
                appPerms=[]
                for app in appList:
                    obj = importModule('apps.'+app+'.permissions')
                    mperms=obj.getPermissionsForUser(ModifiedUid)
                    cperms=obj.getGrantablePermissions(currentUid)
                    if mperms != None and cperms != None:
                        for perm in mperms:
		                    for cperm in cperms:
			                    if perm['id'] == cperm['id']:
			    	                cperm['value'] = perm['value']
                        appPerms.append(cperms)
                return appPerms
Exemplo n.º 2
0
    def change_view(self, request, object_id, extra_context=None):
        """ this allows the extra context needed to display app permissions 
            Template=change_form.html
        """
        def helper(currentUid, ModifiedUid, appList):
                
                appPerms=[]
                for app in appList:
                    obj = importModule('apps.'+app+'.permissions')
                    mperms=obj.getPermissionsForUser(ModifiedUid)
                    cperms=obj.getGrantablePermissions(currentUid)
                    if mperms != None and cperms != None:
                        for perm in mperms:
		                    for cperm in cperms:
			                    if perm['id'] == cperm['id']:
			    	                cperm['value'] = perm['value']
                        appPerms.append(cperms)
                return appPerms

        if request.method == 'POST':
            #from django.template.defaultfilters import slugify #doing this will not exactly work
            #users there manycase where two strings return the same slugified string!
            appList=[]
            if request.user.is_admin: # get all installed apps
                from hipercic.apps.appConfig import ACTIVE_APPS #import all ACTIVE_APPS apps
                appList = ACTIVE_APPS
            else:
                #get only the apps the user has permissions to
                apps = request.user.apps_managed.all()
                for app in apps:
                    appList.append(app.name)
            for app in appList:
                perm_dict = helper(request.user.id, object_id, [app]) #for each app get a perm dict
                for ls in perm_dict:
                  for perm in ls: #for every perm update all values
                    #find the key from the request with the correct id...
                    #print "old: ", perm['value']                    
                    perm['value'] = request.POST.__getitem__(perm['id'])
                    #print "new: ", perm['value']               
                    #update the value of the dictionary with the value from the request
                    obj = importModule('apps.'+app+'.permissions')
                    test = obj.updatePermissions(object_id, ls)    
            return super(UserAdmin, self).change_view(request, object_id, extra_context)
        #if request.path contains user... we know permissions for the user object must be loaded.
        
        else: #method is get generate user permissions

            
            appPerms=[]
            #Modify extra context to pass information to the template
            if request.user.is_admin: # get all installed apps
                from hipercic.apps.appConfig import ACTIVE_APPS #import all ACTIVE_APPS apps
                appPerms = helper(request.user.id, object_id, ACTIVE_APPS)
            else:
                #get only the apps the user has permissions to
                apps = request.user.apps_managed.all()
                appList=[]
                for app in apps:
                    appList.append(app.name)
                appPerms = helper(request.user.id, object_id, appList)
               
                #import permissions from only a few apps
                #pass a dictionary of dictionaries of permissions to the templates
        #pass a dictionary of dictionary permissions to the template
            if extra_context == None:
                return super(UserAdmin, self).change_view(request, object_id, {'appPerms':appPerms})
            else:
                extra_context.update({'appPerms':appPerms})
                return super(UserAdmin, self).change_view(request, object_id, extra_context)