def get(self, request, provider_uuid, identity_uuid, format=None):
     """
     Return the credential information for this identity
     """
     # Sanity checks:
     # User is authenticated
     user = request.user
     try:
         # User is a member of a group ( TODO: loop through all instead)
         group = user.group_set.get(name=user.username)
         # NOTE: Provider_uuid no longer needed.
         # Group has access to the identity on an active,
         # currently-running provider
         identity = group.identities.get(only_current_provider(),
                                         provider__active=True,
                                         uuid=identity_uuid)
         # All other members of the identity are visible
         id_members = CoreIdentityMembership.objects.filter(
             identity__uuid=identity_uuid)
     except ObjectDoesNotExist as odne:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             '%s does not exist.' % odne.message.split()[0])
     id_list = [id_member.identity for id_member in id_members[:1]]
     serializer = IdentitySerializer(id_list, many=True)
     serialized_data = serializer.data
     return Response(serialized_data)
Beispiel #2
0
 def get(self, request):
     query = request.GET
     user = request.user
     providers = []
     records = CoreMaintenanceRecord.objects.none()
     active_records = query.get('active', 'false').lower() == "true"
     if user and type(user) != AnonymousUser:
         groups = user.group_set.all()
         for group in groups:
             provider_ids = group.identities.filter(
                 only_current_provider(),
                 provider__active=True).values_list('provider',
                                                    flat=True)
             providers = Provider.objects.filter(id__in=provider_ids)
             for p in providers:
                 if active_records:
                     records |= CoreMaintenanceRecord.active(p)
                 else:
                     records |= CoreMaintenanceRecord.objects.filter(
                         provider=p)
     if active_records:
         global_records = CoreMaintenanceRecord.active()
     else:
         global_records = CoreMaintenanceRecord.objects.filter(
             provider=None)
     records |= global_records
     return Response(MaintenanceRecordSerializer(records, many=True).data)
Beispiel #3
0
def get_identity_list(user, provider=None):
    """
    Given the (request) user
    return all identities on all active providers
    """
    try:
        group = Group.objects.get(name=user.username)
        if provider:
            identity_list = group.identities.filter(
                provider=provider,
                #Active providers only
                provider__active=True)
        else:
            identity_list = group.identities.filter(
                #Non-end dated providers as search base
                only_current_provider(),
                #Active providers only
                provider__active=True)
        return identity_list
    except Group.DoesNotExist:
        logger.warn("Group %s DoesNotExist" % user.username)
        return None
    except CoreIdentity.DoesNotExist:
        logger.warn("Identity %s DoesNotExist" % identity_uuid)
        return None
Beispiel #4
0
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.identities.filter(
            only_current_provider(),
            provider__active=True).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
Beispiel #5
0
 def get_queryset(self):
     """
     Filter providers by current user
     """
     user = self.request.user
     group = Group.objects.get(name=user.username)
     provider_ids = group.identities.filter(only_current_provider(), provider__active=True).values_list('provider', flat=True)
     return Provider.objects.filter(id__in=provider_ids)
Beispiel #6
0
 def get_queryset(self):
     """
     Filter identities by current user
     """
     user = self.request.user
     group = Group.objects.get(name=user.username)
     identities = group.identities.filter(only_current_provider(), provider__active=True)
     return identities
 def setUp(self):
     # Have group name match the users name
     self.group = GroupWithDataFactory.create(name="test")
     #TODO: Create IDENTITIES to use 'self.providers'
     user = self.group.leaders.first()
     provider_ids = self.group.identities.filter(only_current_provider(), provider__active=True).values_list('provider', flat=True)
     self.providers = Provider.objects.filter(id__in=provider_ids)
     self.provider_data = ProviderSerializer(self.providers, many=True).data
     self.client = APIClient()
     self.client.force_authenticate(user=user)
Beispiel #8
0
 def get(self, request):
     """
     Authentication Required, list of Providers on your account.
     """
     username = request.user.username
     group = Group.objects.get(name=username)
     try:
         provider_ids = group.identities.filter(only_current_provider(), provider__active=True).values_list('provider', flat=True)
         providers = CoreProvider.objects.filter(id__in=provider_ids).order_by('id')
     except CoreProvider.DoesNotExist:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             "The provider does not exist.")
     serialized_data = ProviderSerializer(providers, many=True).data
     return Response(serialized_data)
Beispiel #9
0
    def get_queryset(self):
        """
        Filter identities by user
        """
        user = self.request.user
        idents = Identity.shared_with_user(user)

        if 'all_users' in self.request.GET:
            idents = Identity.objects.all()
        if 'username' in self.request.GET:
            target_username = self.request.GET.get('username')
            user = AtmosphereUser.objects.filter(username=target_username).first()
            idents = Identity.shared_with_user(user)

        return idents.filter(only_current_provider())
Beispiel #10
0
 def get(self, request, provider_uuid):
     """
     Authentication Required, return specific provider.
     """
     username = request.user.username
     group = Group.objects.get(name=username)
     try:
         provider_ids = group.identities.filter(only_current_provider(), provider__active=True).values_list('provider', flat=True)
         provider = CoreProvider.objects.get(uuid=provider_uuid,
                                         id__in=provider_ids)
     except CoreProvider.DoesNotExist:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             "The provider does not exist.")
     serialized_data = ProviderSerializer(provider).data
     return Response(serialized_data)
Beispiel #11
0
    def get_queryset(self):
        """
        Filter providers by current user
        """
        user = self.request.user
        # Anonymous access: Show ONLY the providers that are:
        # publically available, active, and non-end dated
        if (type(user) == AnonymousUser):
            return Provider.objects.filter(
                only_current(), active=True, public=True)

        group = Group.objects.get(name=user.username)
        provider_ids = group.identities.filter(
            only_current_provider(),
            provider__active=True).values_list('provider', flat=True)
        return Provider.objects.filter(id__in=provider_ids)
Beispiel #12
0
    def get_queryset(self):
        """
        Filter projects by current user
        """
        request_user = self.request.user
        # Switch based on user's ClassType
        if isinstance(request_user, AnonymousUser):
            provider_ids = Provider.objects.filter(only_current(), active=True).values_list('id',flat=True)
        else:
            group = Group.objects.get(name=request_user.username)
            provider_ids = group.identities.filter(
                only_current_provider(),
                provider__active=True).values_list('provider', flat=True)

        # Switch based on query
        if 'archived' in self.request.QUERY_PARAMS:
            return Size.objects.filter(
                provider__id__in=provider_ids)
        else:
            return Size.objects.filter(
                only_current(), provider__id__in=provider_ids)
Beispiel #13
0
def get_provider(user, provider_uuid):
    """
    Given the (request) user and a provider uuid,
    return None or an Active provider
    """
    try:
        group = Group.objects.get(name=user.username)
    except Group.DoesNotExist:
        logger.warn("Group %s DoesNotExist" % user.username)
        return None

    try:
        provider_ids = group.identities.filter(
            only_current_provider(),
            provider__active=True).values_list('provider', flat=True)
        provider = Provider.objects.filter(
            id__in=provider_ids).get(uuid=provider_uuid)
        return provider
    except Provider.DoesNotExist:
        logger.warn("Provider %s DoesNotExist for User:%s in Group:%s"
            % (provider_uuid, user, group))
        return None
Beispiel #14
0
 def current_identities(self):
     return Identity.shared_with_group(self).filter(only_current_provider())
 def current_identities(self):
     identity_ids = self.identity_memberships.filter(
             only_active_memberships()).values_list('identity',flat=True)
     return Identity.objects.filter(only_current_provider(), only_active_provider(), id__in=identity_ids)