def _user_is_visible(user, admin_mode): if admin_mode or user.id == auth.current_user_id(): return True try: user_projects = set( (role.tenant.get('id') for role in user.list_roles())) user_projects.intersection_update(auth.current_user_project_ids()) return len(user_projects) > 0 except osc_exc.HttpException: return False
def _user_is_visible(user, admin_mode): if admin_mode or user.id == auth.current_user_id(): return True try: user_projects = set((role.tenant.get('id') for role in user.list_roles())) user_projects.intersection_update(auth.current_user_project_ids()) return len(user_projects) > 0 except osc_exc.HttpException: return False
def test_current_user_project_ids(self): tenants = [doubles.make(self.mox, doubles.Tenant, id='PID1'), doubles.make(self.mox, doubles.Tenant, id='PID2')] self.fake_client_set.identity_public.tenants.list() \ .AndReturn(tenants) self.mox.ReplayAll() with self.app.test_request_context(): self.install_fake_auth() ids = auth.current_user_project_ids() self.assertEquals(ids, set(('PID1', 'PID2')))
def _servers_for_user(): project_id = get_matcher_argument("project", "eq") if project_id is not None: projects = (project_id,) else: projects = get_matcher_argument("project", "in") result = [] for project_id in current_user_project_ids(): if projects is None or project_id in projects: cs = client_set_for_tenant(project_id) result.extend(cs.compute.servers.list()) return result
def test_current_user_project_ids(self): tenants = [ doubles.make(self.mox, doubles.Tenant, id='PID1'), doubles.make(self.mox, doubles.Tenant, id='PID2') ] self.fake_client_set.identity_public.tenants.list() \ .AndReturn(tenants) self.mox.ReplayAll() with self.app.test_request_context(): self.install_fake_auth() ids = auth.current_user_project_ids() self.assertEquals(ids, set(('PID1', 'PID2')))
def _role_is_visible(role): if role.tenant['name'] == app.config['SYSTENANT']: return False if not g.my_projects: return True return role.tenant['id'] in auth.current_user_project_ids()
def test_current_user_project_ids_no_auth(self): self.mox.ReplayAll() with self.app.test_request_context(): # we don't install fake auth, so user is not authenticated ids = auth.current_user_project_ids() self.assertEquals(ids, set())