def serviceAuthorizations(request):
    authentication = platform_manager.authenticate(request)
    if 'error' in authentication:
        return HttpResponse(authentication['response'])

    user = authentication['user']

    return_v = defaultdict(
        lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str))))
    applications = application_manager.getApplications()
    for application in applications:
        scopes = application_manager.getApplicationScopes(application)
        return_v[application._id]['name'] = application.name
        return_v[application._id]['owner'] = application.user.get_full_name()
        return_v[application._id]['description'] = application.description
        connectors = set()

        for scope in scopes:
            return_v[application._id]['scopes'][
                scope.scope]['description'] = scope.description
            connector = scope.connector
            connectors.add(connector)
            return_v[application._id]['scopes'][
                scope.scope]['status'] = getAuthorizationStatus(
                    user, application, scope)
            return_v[application._id]['scopes'][
                scope.scope]['connector'] = connector.name
        for connector in connectors:
            uri = createUri(user, application, connector)
            return_v[application._id]['connectors'][
                connector.name]['grant_uri'] = uri['grant_uri']
            return_v[application._id]['connectors'][
                connector.name]['revoke_uri'] = uri['revoke_uri']

    return HttpResponse(json.dumps({'service': dict(return_v)}))
def serviceAuthorizations(request):
	authentication = platform_manager.authenticate(request)
        if 'error' in authentication:
                return HttpResponse(authentication['response'])

	user = authentication['user']

	return_v = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str))))
	applications = application_manager.getApplications()
	for application in applications:
		scopes = application_manager.getApplicationScopes(application)
		return_v[application._id]['name'] = application.name
		return_v[application._id]['owner'] = application.user.get_full_name()
		return_v[application._id]['description'] = application.description
		connectors = set()		

		for scope in scopes:
			return_v[application._id]['scopes'][scope.scope]['description'] = scope.description
			connector = scope.connector
			connectors.add(connector)
			return_v[application._id]['scopes'][scope.scope]['status'] = getAuthorizationStatus(user, application, scope)
			return_v[application._id]['scopes'][scope.scope]['connector'] = connector.name
		for connector in connectors:
			uri = createUri(user, application, connector)
			return_v[application._id]['connectors'][connector.name]['grant_uri'] = uri['grant_uri']
			return_v[application._id]['connectors'][connector.name]['revoke_uri'] = uri['revoke_uri']
			


	return HttpResponse(json.dumps({'service': dict(return_v)}))
def researcher(request):
	roles = []
	try: roles = [x.role for x in UserRole.objects.get(user=request.user).roles.all()]
	except: pass

	values = {}
	applications = application_manager.getApplications()
	for application in applications:
		if not application.connector_type == 'data_viewer': continue
		values[application.name] = {}
		values[application.name]['uri'] = application.url
		values[application.name]['description'] = application.description
		application_scopes = application_manager.getApplicationScopes(application)
		values[application.name]['scopes'] = {}
		for scope in application_scopes:
			if not 'researcher' in scope.scope: continue
			auth = authorization_manager.authorization_manager.getAuthorization(request.user, scope, application)
			auth = [x for x in auth if x.access_token.expire > time.time()]

			values[application.name]['scopes'][scope.scope] = {}
			values[application.name]['scopes'][scope.scope]['authorized'] = 1 if len(auth)>0 else 0
			values[application.name]['scopes'][scope.scope]['authorization'] = auth
			values[application.name]['scopes'][scope.scope]['description'] = scope.description
			values[application.name]['scopes'][scope.scope]['description_extra'] = scope.description_extra
			values[application.name]['scopes'][scope.scope]['auth_url'] = authorization_manager.authorization_manager.buildAuthUrl(scope.connector, application)



	if not 'researcher' in roles:
		return render_to_response('researcher.html', {'authorized': False}, context_instance=RequestContext(request))
	return render_to_response('researcher.html', {'authorized': True, 'application_values': values}, context_instance=RequestContext(request))
def userStatus(request):
	authentication = platform_manager.authenticate(request)
	if 'error' in authentication:
		return HttpResponse(authentication['response'])



	user = authentication['user']
	response = {}
	response['applications'] = {}
	applications = application_manager.getApplications()
	if len(InformedConsent.objects.filter(user=user).all()) == 0:
		return HttpResponse(json.dumps({'error':'not enrolled'}))
	
	for application in applications:
		response['applications'][application.name] = {}
		response['applications'][application.name]['description'] = application.description
		response['applications'][application.name]['uri'] = application.url
		application_scopes = application_manager.getApplicationScopes(application)
		response['applications'][application.name]['scopes'] = {}
		for scope in application_scopes:
			if 'researcher' in scope.scope: continue
			auth = authorization_manager.authorization_manager.getAuthorization(user, scope, application)
			response['applications'][application.name]['scopes'][scope.scope] = {}
			response['applications'][application.name]['scopes'][scope.scope]['authorized'] = 1 if len(auth)>0 else 0 
			response['applications'][application.name]['scopes'][scope.scope]['description'] = scope.description
			response['applications'][application.name]['scopes'][scope.scope]['description_extra'] = scope.description_extra
			response['applications'][application.name]['scopes'][scope.scope]['auth_url'] = authorization_manager.authorization_manager.buildAuthUrl(scope.connector, application)
		

	return HttpResponse(json.dumps(response))
def researcher(request):
    roles = []
    try:
        roles = [x.role for x in UserRole.objects.get(user=request.user).roles.all()]
    except:
        pass

    values = {}
    applications = application_manager.getApplications()
    for application in applications:
        if not application.connector_type == "data_viewer":
            continue
        values[application.name] = {}
        values[application.name]["uri"] = application.url
        values[application.name]["description"] = application.description
        application_scopes = application_manager.getApplicationScopes(application)
        values[application.name]["scopes"] = {}
        for scope in application_scopes:
            if not "researcher" in scope.scope:
                continue
            auth = authorization_manager.authorization_manager.getAuthorization(request.user, scope, application)
            auth = [x for x in auth if x.access_token.expire > time.time()]

            values[application.name]["scopes"][scope.scope] = {}
            values[application.name]["scopes"][scope.scope]["authorized"] = 1 if len(auth) > 0 else 0
            values[application.name]["scopes"][scope.scope]["authorization"] = auth
            values[application.name]["scopes"][scope.scope]["description"] = scope.description
            values[application.name]["scopes"][scope.scope]["description_extra"] = scope.description_extra
            values[application.name]["scopes"][scope.scope][
                "auth_url"
            ] = authorization_manager.authorization_manager.buildAuthUrl(scope.connector, application)

    if not "researcher" in roles:
        return render_to_response("researcher.html", {"authorized": False}, context_instance=RequestContext(request))
    return render_to_response(
        "researcher.html", {"authorized": True, "application_values": values}, context_instance=RequestContext(request)
    )
Exemple #6
0
def userStatus(request):
    authentication = platform_manager.authenticate(request)
    if 'error' in authentication:
        return HttpResponse(authentication['response'])

    user = authentication['user']
    response = {}
    response['applications'] = {}
    applications = application_manager.getApplications()
    if len(InformedConsent.objects.filter(user=user).all()) == 0:
        return HttpResponse(json.dumps({'error': 'not enrolled'}))

    for application in applications:
        response['applications'][application.name] = {}
        response['applications'][
            application.name]['description'] = application.description
        response['applications'][application.name]['uri'] = application.url
        application_scopes = application_manager.getApplicationScopes(
            application)
        response['applications'][application.name]['scopes'] = {}
        for scope in application_scopes:
            if 'researcher' in scope.scope: continue
            auth = authorization_manager.authorization_manager.getAuthorization(
                user, scope, application)
            response['applications'][application.name]['scopes'][
                scope.scope] = {}
            response['applications'][application.name]['scopes'][
                scope.scope]['authorized'] = 1 if len(auth) > 0 else 0
            response['applications'][application.name]['scopes'][
                scope.scope]['description'] = scope.description
            response['applications'][application.name]['scopes'][
                scope.scope]['description_extra'] = scope.description_extra
            response['applications'][application.name]['scopes'][scope.scope][
                'auth_url'] = authorization_manager.authorization_manager.buildAuthUrl(
                    scope.connector, application)

    return HttpResponse(json.dumps(response))