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())
def get_queryset(self): """ Filter identities by current user """ user = self.request.user idents = Identity.shared_with_user(user) if user.is_admin(): 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.get(username=target_username) idents = Identity.shared_with_user(user) return idents.filter(only_current_provider())
def test_identity_permissions(self, user, identity_id, is_leader=False): identity_kwargs = {} if type(identity_id) == int: identity_kwargs = {'id': identity_id} else: identity_kwargs = {'uuid': identity_id} return Identity.shared_with_user( user, is_leader=is_leader).filter(**identity_kwargs).exists()
def get_queryset(self): """ Filter providers by current user """ user = self.request.user if (type(user) == AnonymousUser): return Identity.objects.none() identity_list = Identity.shared_with_user(user) return identity_list
def allocation_source_overage_enforcement(allocation_source): all_user_instances = {} for user in allocation_source.all_users: all_user_instances[user.username] = [] #TODO: determine how this will work with project-sharing (i.e. that we aren't issue-ing multiple suspend/stop/etc. for shared instances for identity in Identity.shared_with_user(user): affected_instances = allocation_source_overage_enforcement_for( allocation_source, user, identity) user_instances = all_user_instances[user.username] user_instances.extend(affected_instances) all_user_instances[user.username] = user_instances return all_user_instances
def allocation_source_overage_enforcement(allocation_source): all_user_instances = {} for user in allocation_source.all_users: all_user_instances[user.username] = [] #TODO: determine how this will work with project-sharing (i.e. that we aren't issue-ing multiple suspend/stop/etc. for shared instances for identity in Identity.shared_with_user(user): affected_instances = allocation_source_overage_enforcement_for( allocation_source, user, identity) user_instances = all_user_instances[user.username] user_instances.extend(affected_instances) all_user_instances[user.username] = user_instances return all_user_instances
def get_is_leader(self, identity): """ Returns true/false if the user requesting the object is the leader. """ user = None if self.context: if 'request' in self.context: user = self.context['request'].user elif 'user' in self.context: user = self.context['user'] if user == identity.created_by: return True return Identity.shared_with_user(user, is_leader=True).filter(id=identity.id).exists()
def get_is_leader(self, identity): """ Returns true/false if the user requesting the object is the leader. """ user = None if self.context: if 'request' in self.context: user = self.context['request'].user elif 'user' in self.context: user = self.context['user'] if user == identity.created_by: return True return Identity.shared_with_user( user, is_leader=True).filter(id=identity.id).exists()