def delete(self, request, project_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response( "Project with UUID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST ) running_resources = project.has_running_resources() if running_resources: return Response( "Project %s has running resources. These resources " "MUST be transferred or deleted before deleting the project." % project.name, status=status.HTTP_409_CONFLICT ) project.delete_project() serialized_data = ProjectSerializer( project, context={ "request": request } ).data response = Response(serialized_data) return response
def put(self, request, project_uuid, application_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) application = Application.objects.filter(uuid=application_uuid) if not application: return Response( "application with UUID=%s not found in the database" % (application_uuid, ), status=status.HTTP_400_BAD_REQUEST) application = application[0] if application.private == True: #If the application is private, the user must be a member to have # access to the application inside their project. application = user.application_set.filter( provider_alias=instance_id) if not application: return Response( "Private Application with UUID=%s not accessible to user:%s" % (application_uuid, user.username), status=status.HTTP_400_BAD_REQUEST) application = application[0] project.add_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_uuid, application_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) application = Application.objects.filter(uuid=application_uuid) if not application: return Response("application with UUID=%s not found " "in the database" % (application_uuid,), status=status.HTTP_400_BAD_REQUEST) application = application[0] if application.private: # If the application is private, the user must be a member to have # access to the application inside their project. application = user.application_set.filter( provider_alias=instance_id) if not application: return Response( "Private Application with UUID=%s not " "accessible to user:%s" % (application_uuid, user.username), status=status.HTTP_400_BAD_REQUEST) application = application[0] project.add_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_id): """ """ user = request.user data = request.DATA group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] serializer = ProjectSerializer(project, data=data, context={"user":request.user}) if serializer.is_valid(): #If the default project was renamed if project.name == "Default" \ and serializer.object.name != "Default": #Create another one. group.projects.get_or_create(name="Default") serializer.save() response = Response( serializer.data, status=status.HTTP_201_CREATED) return response else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_default_identity(username, provider=None): """ Return the default identity given to the user-group for provider. """ try: from core.models.group import get_user_group group = get_user_group(username) identities = group.identities.all() if provider: if provider.is_active(): identities = identities.filter(provider=provider) return identities[0] else: logger.error("Provider provided for " "get_default_identity is inactive.") raise("Provider provided for get_default_identity " "is inactive.") else: default_provider = get_default_provider(username) default_identity = group.identities.filter( provider=default_provider)[0] logger.debug( "default_identity set to %s " % default_identity) return default_identity except Exception, e: logger.exception(e) return None
def get(self, request, project_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response( "Project with ID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST ) instances = project.instances.filter( only_current(), provider_machine__provider__active=True ) active_provider_uuids = [ap.uuid for ap in Provider.get_active()] instances = instances.filter( pk__in=[ i.id for i in instances if i.instance.provider_uuid() in active_provider_uuids ] ) serialized_data = InstanceSerializer( instances, many=True, context={ "request": request } ).data response = Response(serialized_data) return response
def get_default_identity(username, provider=None): """ Return the default identity given to the user-group for provider. """ try: from core.models.group import get_user_group group = get_user_group(username) identities = group.identities.all() if provider: if provider.is_active(): identities = identities.filter(provider=provider) return identities[0] else: logger.error("Provider provided for " "get_default_identity is inactive.") raise ("Provider provided for get_default_identity " "is inactive.") else: default_provider = get_default_provider(username) default_identity = group.identities.filter( provider=default_provider)[0] logger.debug("default_identity set to %s " % default_identity) return default_identity except Exception, e: logger.exception(e) return None
def get(self, request): user = request.user group = get_user_group(user.username) projects = group.projects.filter(Q(end_date=None) | Q(end_date__gt=timezone.now())) serialized_data = ProjectSerializer(projects, many=True, context={"request": request}).data response = Response(serialized_data) return response
def put(self, request, project_id): """ """ user = request.user data = request.DATA group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] serializer = ProjectSerializer(project, data=data, context={"user": request.user}) if serializer.is_valid(): #If the default project was renamed if project.name == "Default" \ and serializer.object.name != "Default": #Create another one. group.projects.get_or_create(name="Default") serializer.save() response = Response(serializer.data, status=status.HTTP_201_CREATED) return response else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_default_identity(username, provider=None): """ Return the default identity given to the user-group for provider. """ try: from core.models.group import get_user_group group = get_user_group(username) identities = group.identities.all() if provider: if provider.is_active(): identities = identities.filter(provider=provider) return identities[0] else: logger.error("Provider provided for " "get_default_identity is inactive.") raise "Inactive Provider provided for get_default_identity " else: default_provider = get_default_provider(username) default_identity = group.identities.filter( provider=default_provider) if not default_identity: logger.error("User %s has no identities on Provider %s" % (username, default_provider)) raise "No Identities on Provider %s for %s" % (default_provider,username) #Passing default_identity = default_identity[0] logger.debug( "default_identity set to %s " % default_identity) return default_identity except Exception as e: logger.exception(e) return None
def get_default_provider(username): """ Return default provider given """ try: from core.models.group import get_user_group group = get_user_group(username) provider = group.providers.filter( Q(end_date=None) | Q(end_date__gt=timezone.now()), active=True, type__name="OpenStack") if provider: provider = provider[0] else: logger.error("get_default_provider could not find " "a valid Provider") return None logger.debug( "default provider is %s " % provider) return provider except IndexError: logger.info("No provider found for %s" % username) return None except Exception, e: logger.exception(e) return None
def get_default_provider(username): """ Return default provider given """ try: from core.models.group import get_user_group from core.models.provider import Provider group = get_user_group(username) provider_ids = group.current_identities.values_list('provider', flat=True) provider = Provider.objects.filter(id__in=provider_ids, type__name="OpenStack") if provider: logger.debug("get_default_provider selected a new " "Provider for %s: %s" % (username, provider)) provider = provider[0] else: logger.error("get_default_provider could not find a new " "Provider for %s" % (username, )) return None return provider except Exception as e: logger.exception("get_default_provider encountered an error " "for %s" % (username, )) return None
def field_from_native(self, data, files, field_name, into): value = data.get(field_name) if value is None: return related_obj = self.root.object user = self.root.request_user group = get_user_group(user.username) # Retrieve the New Project(s) if type(value) == list: new_projects = value else: new_projects = [ value, ] # Remove related_obj from Old Project(s) old_projects = related_obj.get_projects(user) for old_proj in old_projects: related_obj.projects.remove(old_proj) # Add Project(s) to related_obj for project_id in new_projects: # Retrieve/Create the New Project #TODO: When projects can be shared, #change the qualifier here. new_project = Project.objects.get(id=project_id, owner=group) # Assign related_obj to New Project if not related_obj.projects.filter(id=project_id): related_obj.projects.add(new_project) # Modifications to how 'project' should be displayed here: into[field_name] = new_projects
def to_internal_value(self, data, files, field_name, into): value = data.get(field_name) if value is None: return related_obj = self.parent.instance user = self.parent.request_user group = get_user_group(user.username) # Retrieve the New Project(s) if type(value) == list: new_projects = value else: new_projects = [value, ] # Remove related_obj from Old Project(s) old_projects = related_obj.get_projects(user) for old_proj in old_projects: related_obj.projects.remove(old_proj) # Add Project(s) to related_obj for project_id in new_projects: # Retrieve/Create the New Project #TODO: When projects can be shared, #change the qualifier here. new_project = Project.objects.get(id=project_id, owner=group) # Assign related_obj to New Project if not related_obj.projects.filter(id=project_id): related_obj.projects.add(new_project) # Modifications to how 'project' should be displayed here: into[field_name] = new_projects
def get_default_provider(username): """ Return default provider given """ try: from core.models.group import get_user_group from core.models.provider import Provider group = get_user_group(username) provider_ids = group.current_identities.values_list( 'provider', flat=True) provider = Provider.objects.filter( id__in=provider_ids, type__name="OpenStack") if provider: logger.debug("get_default_provider selected a new " "Provider for %s: %s" % (username, provider)) provider = provider[0] else: logger.error("get_default_provider could not find a new " "Provider for %s" % (username,)) return None return provider except Exception as e: logger.exception("get_default_provider encountered an error " "for %s" % (username,)) return None
def get_default_provider(username): """ Return default provider given """ try: from core.models.group import get_user_group group = get_user_group(username) provider = group.providers.filter(Q(end_date=None) | Q(end_date__gt=timezone.now()), active=True, type__name="OpenStack") if provider: provider = provider[0] else: logger.error("get_default_provider could not find " "a valid Provider") return None logger.debug("default provider is %s " % provider) return provider except IndexError: logger.info("No provider found for %s" % username) return None except Exception, e: logger.exception(e) return None
def put(self, request, project_uuid, volume_id): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response( "Project with ID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST ) volume = user.volume_set().filter(instance_source__identifier=volume_id) if not volume: return Response( "volume with ID=%s not found in the database" % (volume_id, ), status=status.HTTP_400_BAD_REQUEST ) volume = volume[0] existing_projects = volume.projects.all() if existing_projects: for proj in existing_projects: proj.remove_object(volume) project.add_object(volume) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def get(self, request): user = request.user group = get_user_group(user.username) projects = group.projects.filter( Q(end_date=None) | Q(end_date__gt=timezone.now())) serialized_data = ProjectSerializer( projects, many=True, context={"request": request}).data response = Response(serialized_data) return response
def get_default_project(user): """ Return the 'default' project for 'User' """ from core.models.group import get_user_group group = get_user_group(user.username) project, created = group.projects.get_or_create(name="Default") if created: logger.info("Created new 'Default' project for user: %s" % user) return project
def get(self, request, project_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) volumes = project.volumes.filter(only_current(), provider__active=True) serialized_data = VolumeSerializer(volumes, many=True, context={"request": request}).data response = Response(serialized_data) return response
def get(self, request): """ """ user = request.user group = get_user_group(user.username) projects = group.projects.filter(only_current) serialized_data = ProjectSerializer(projects, many=True, context={"user":request.user}).data response = Response(serialized_data) return response
def to_representation(self, project_mgr): request_user = self.parent.request_user if type(request_user) == AnonymousUser: return None try: group = get_user_group(request_user.username) projects = project_mgr.filter(owner=group) # Modifications to how 'project' should be displayed here: return [p.uuid for p in projects] except Project.DoesNotExist: return None
def to_native(self, project_mgr): request_user = self.root.request_user if type(request_user) == AnonymousUser: return None try: group = get_user_group(request_user.username) projects = project_mgr.filter(owner=group) # Modifications to how 'project' should be displayed here: return [p.uuid for p in projects] except Project.DoesNotExist: return None
def to_representation(self, project_mgr): request_user = self.parent.request_user if isinstance(request_user, AnonymousUser): return None try: group = get_user_group(request_user.username) projects = project_mgr.filter(owner=group) # Modifications to how 'project' should be displayed here: return [p.uuid for p in projects] except Project.DoesNotExist: return None
def get(self, request, project_uuid): """ """ user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with UUID=%s " "does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) serialized_data = ProjectSerializer(project, context={"request": request}).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) # TODO: Check that you have permission! projects = group.projects.get(id=project_id) instances = projects.instances.filter(only_active()) serialized_data = InstanceSerializer(instances, many=True, context={"request": request}).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) #TODO: Check that you have permission! projects = group.projects.get(id=project_id) applications = projects.applications.filter(only_current) serialized_data = ApplicationSerializer(applications, many=True, context={"user":request.user}).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) #TODO: Check that you have permission! projects = group.projects.get(id=project_id) volumes = projects.volumes.all() serialized_data = VolumeSerializer(volumes, many=True, context={"user":request.user}).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) serialized_data = ProjectSerializer(project, context={"user":request.user}).data response = Response(serialized_data) return response
def get(self, request): """ """ user = request.user group = get_user_group(user.username) projects = group.projects.filter(only_current) serialized_data = ProjectSerializer(projects, many=True, context={ "user": request.user }).data response = Response(serialized_data) return response
def delete(self, request, project_uuid, instance_id): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) instance = project.instances.filter(provider_alias=instance_id) if not instance: error_str = ("instance with ID=%s does not exist in Project %s" % (instance_id, project.id),) return Response(error_str, status=status.HTTP_400_BAD_REQUEST) instance = instance[0] project.remove_object(instance) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with UUID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) data = request.data serializer = ProjectSerializer(project, data=data, context={"request": request}) if serializer.is_valid(): serializer.save() response = Response(serializer.data, status=status.HTTP_201_CREATED) return response else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) #TODO: Check that you have permission! projects = group.projects.get(id=project_id) instances = projects.instances.filter(only_current) serialized_data = InstanceSerializer(instances, many=True, context={ "user": request.user }).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) #TODO: Check that you have permission! projects = group.projects.get(id=project_id) applications = projects.applications.filter(only_active()) serialized_data = ApplicationSerializer(applications, many=True, context={ "request": request }).data response = Response(serialized_data) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) #TODO: Check that you have permission! projects = group.projects.get(id=project_id) volumes = projects.volumes.filter(only_active(), provider__active=True) serialized_data = VolumeSerializer(volumes, many=True, context={ "request": request }).data response = Response(serialized_data) return response
def delete(self, request, project_uuid, volume_id): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) volume = project.volumes.filter(identifier=volume_id) if not volume: error_str = ("volume with ID=%s does not exist in Project %s" % (volume_id, project.id),) return Response(error_str, status=status.HTTP_400_BAD_REQUEST) volume = volume[0] project.remove_object(volume) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def delete(self, request, project_id, application_uuid): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] application = project.applications.filter(provider_alias=application_uuid) if not application: error_str = ("application with ID=%s does not exist in Project %s" % (application_uuid, project.id),) return Response(error_str, status=status.HTTP_400_BAD_REQUEST) application = application[0] project.remove_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def get(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) serialized_data = ProjectSerializer(project, context={ "user": request.user }).data response = Response(serialized_data) return response
def put(self, request, project_id, instance_id): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] instance = user.instance_set.filter(provider_alias=instance_id) if not instance: return Response( "instance with ID=%s not found in the database" % (instance_id,), status=status.HTTP_400_BAD_REQUEST ) instance = instance[0] project.add_object(instance) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_id, volume_id): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] volume = user.volume_set.filter(alias=volume_id) if not volume: return Response( "volume with ID=%s not found in the database" % (volume_id,), status=status.HTTP_400_BAD_REQUEST ) volume = volume[0] project.add_object(volume) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def delete(self, request, project_uuid, instance_id): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) instance = project.instances.filter(provider_alias=instance_id) if not instance: error_str = "instance with ID=%s does not exist in Project %s"\ % (instance_id, project.id), return Response(error_str, status=status.HTTP_400_BAD_REQUEST) instance = instance[0] project.remove_object(instance) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_id, volume_id): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] volume = user.volume_set.filter(alias=volume_id) if not volume: return Response("volume with ID=%s not found in the database" % (volume_id, ), status=status.HTTP_400_BAD_REQUEST) volume = volume[0] project.add_object(volume) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def delete(self, request, project_id): """ """ user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] if project.name == "Default": return Response("The 'Default' project is reserved and cannot be deleted.", status=status.HTTP_409_CONFLICT) default_project = group.projects.get(name="Default") project.copy_objects(default_project) project.delete_project() serialized_data = ProjectSerializer(project, context={"request": request}).data response = Response(serialized_data) return response
def put(self, request, project_id, application_uuid): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] application = user.application_set.filter(uuid=application_uuid) if not application: return Response( "application with ID=%s not found in the database" % (application_uuid,), status=status.HTTP_400_BAD_REQUEST, ) application = application[0] project.add_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def delete(self, request, project_id, volume_id): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] volume = project.volumes.filter(alias=volume_id) if not volume: error_str = "volume with ID=%s does not exist in Project %s"\ % (volume_id, project.id), return Response(error_str, status=status.HTTP_400_BAD_REQUEST) volume = volume[0] project.remove_object(volume) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def delete(self, request, project_uuid, application_uuid): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_uuid) if not project: return Response("Project with ID=%s does not exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) application = project.applications.filter( provider_alias=application_uuid) if not application: error_str = "application with ID=%s does not exist in Project %s"\ % (application_uuid, project.id), return Response(error_str, status=status.HTTP_400_BAD_REQUEST) application = application[0] project.remove_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def put(self, request, project_id, instance_id): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] instance = user.instance_set.filter(provider_alias=instance_id) if not instance: return Response("instance with ID=%s not found in the database" % (instance_id, ), status=status.HTTP_400_BAD_REQUEST) instance = instance[0] project.add_object(instance) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def get(self, request, project_uuid): user = request.user group = get_user_group(user.username) project = get_group_project(group, project_uuid) if not project: return Response("Project with ID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST) # user = request.user # group = get_user_group(user.username) # TODO: Check that you have permission! # projects = get_group_project(group, project_uuid) applications = project.applications.filter(only_current()) serialized_data = ApplicationSerializer( applications, many=True, context={"request": request}).data response = Response(serialized_data) return response
def to_internal_value(self, data, files, field_name, into): value = data.get(field_name) if value is None: return related_obj = self.parent.instance user = self.parent.request_user group = get_user_group(user.username) # Retrieve the New Project(s) if isinstance(value, list): project_id = value[0] else: project_id = value new_project = Project.objects.get(id=project_id, owner=group) related_obj.project = new_project related_obj.save() # Modifications to how 'project' should be displayed here: into[field_name] = project_id
def put(self, request, project_id, application_uuid): user = request.user group = get_user_group(user.username) project = group.projects.filter(id=project_id) if not project: return Response("Project with ID=%s does not exist" % project_id, status=status.HTTP_400_BAD_REQUEST) project = project[0] application = user.application_set.filter(uuid=application_uuid) if not application: return Response( "application with ID=%s not found in the database" % (application_uuid, ), status=status.HTTP_400_BAD_REQUEST) application = application[0] project.add_object(application) response = Response(status=status.HTTP_204_NO_CONTENT) return response
def get_default_identity(username, provider=None): """ Return the default identity given to the user-group for provider. """ try: from core.models.group import get_user_group group = get_user_group(username) if not group or not group.current_identities.all().count(): if settings.AUTO_CREATE_NEW_ACCOUNTS: new_identities = create_new_accounts(username, provider=provider) if not new_identities: logger.error( "%s has no identities. Functionality will be severely limited." % username) return None return new_identities[0] else: return None identities = group.current_identities.all() if provider: if provider.is_active(): identities = identities.filter(provider=provider) return identities[0] else: logger.error("Provider provided for " "get_default_identity is inactive.") raise "Inactive Provider provided for get_default_identity " else: default_provider = get_default_provider(username) default_identity = group.current_identities.filter( provider=default_provider) if not default_identity: logger.error("User %s has no identities on Provider %s" % (username, default_provider)) raise Exception("No Identities on Provider %s for %s" % (default_provider, username)) #Passing default_identity = default_identity[0] logger.debug("default_identity set to %s " % default_identity) return default_identity except Exception as e: logger.exception(e) return None