Exemplo n.º 1
0
 def testIsDeveloper(self):
     with test_utils.EnvContext(SERVER_SOFTWARE='Google App Engine/1.7.6'):
         self.assertFalse(users.IsDeveloper())
         with test_utils.EnvContext(USER_IS_ADMIN='1'):
             self.assertTrue(users.IsDeveloper())
     with test_utils.EnvContext(SERVER_SOFTWARE='Development/1.0'):
         self.assertTrue(users.IsDeveloper())
Exemplo n.º 2
0
    def get(self):  # pylint: disable=g-bad-name
        """This endpoint is only for setting up data for system tests."""
        if not users.IsDeveloper():
            self.response.out.write('Not authorized.')
            return

        # For system tests, we pretend the app runs under "/crisismap".
        config.Set('root_path', '/crisismap')

        # Because there is no user logged in during system testing, we can't use
        # the usual access-controlled API (Map, CatalogEntry); we have to use
        # admin-level APIs (Config, MapModel, CatalogEntryModel, etc.) below.

        # Allow testing of behaviour controlled by flags in the ClientConfig.
        maps.ClientConfig.Create('google-test',
                                 allowed_referer_domains=['google.com'],
                                 hide_footer=True,
                                 hide_share_button=True,
                                 hide_my_location_button=True,
                                 allow_embed_map_callback=True).put()

        # Allow tests of the tabbed UI.
        maps.ClientConfig.Create('google-test-tab',
                                 allowed_referer_domains=['google.com'],
                                 use_tab_panel=True).put()

        # Add the godzilla test map to the datastore with map ID '1'.
        self.PutTestMap('1', 'godzilla.json')

        # Add the test_maproot test map to the datastore with map ID '2'
        self.PutTestMap('2', 'test_maproot.json')

        # Add the gas_stations (with crowd reports) test map with map ID '3'.
        self.PutTestMap('3', 'gas_stations.json')

        # Add a catalog entry with label 'godzilla' pointing at our test map.
        config.Set('primary_domain', 'gmail.com')
        model.CatalogEntryModel.Put('test1',
                                    'gmail.com',
                                    'godzilla',
                                    model.Map.Get('1'),
                                    is_listed=True)
        model.CatalogEntry.FlushCaches('gmail.com')

        self.response.out.write('Test data written.')
Exemplo n.º 3
0
 def CheckAccess(self):
     """Ensures this page is only accessible to developers."""
     if not users.IsDeveloper():
         raise base_handler.Error(404, 'Not found.')
Exemplo n.º 4
0
def GetConfig(request, map_object=None, catalog_entry=None, xsrf_token=''):
  dev_mode = request.get('dev') and users.IsDeveloper()
  map_picker_items = GetMapPickerItems(
      catalog_entry and catalog_entry.domain or
      config.Get('primary_domain'), request.root_path)

  # Fill the cm_config dictionary.
  root = request.root_path
  xsrf_qs = '?xsrf_token=' + xsrf_token  # needed for all POST URLs
  result = {
      'dev_mode': dev_mode,
      'langs': base_handler.ALL_LANGUAGES,
      # Each endpoint that the JS client code uses gets an entry in config.
      'js_root': root + '/.js',
      'json_proxy_url': root + '/.jsonp',
      'kmlify_url': request.host_url + root + '/.kmlify',
      'login_url': users.GetLoginUrl(request.url),
      'logout_url': users.GetLogoutUrl(request.url),
      'map_picker_items': map_picker_items,
      'protect_url': root + '/.protect',
      'report_query_url': root + '/.api/reports',
      'report_post_url': root + '/.api/reports' + xsrf_qs,
      'vote_post_url': root + '/.api/votes' + xsrf_qs,
      'static_content_url': root + '/.static',
      'user_email': users.GetCurrent() and users.GetCurrent().email,
      'wms_configure_url': root + '/.wms/configure',
      'wms_tiles_url': root + '/.wms/tiles'
  }

  # Add settings from the selected client config, if any.
  result.update(GetClientConfig(request.get('client'),
                                request.headers.get('referer'), dev_mode))

  # Add the MapRoot data and other map-specific information.
  if catalog_entry:  # published map
    map_root = result['map_root'] = catalog_entry.map_root
    result['label'] = catalog_entry.label
    result['publisher_name'] = catalog_entry.publisher_name
    key = catalog_entry.map_version_key
  elif map_object:  # draft map
    map_root = result['map_root'] = map_object.map_root
    result['map_list_url'] = root + '/.maps'
    result['diff_url'] = root + '/.diff/' + map_object.id + xsrf_qs
    result['save_url'] = root + '/.api/maps/' + map_object.id + xsrf_qs
    result['share_url'] = root + '/.share/' + map_object.id + xsrf_qs
    result['api_maps_url'] = root + '/.api/maps'
    result['legend_url'] = root + '/.legend'
    result['wms_query_url'] = root + '/.wms/query'
    result['enable_editing'] = map_object.CheckAccess(perms.Role.MAP_EDITOR)
    result['draft_mode'] = True
    key = map_object.current_version_key

  # Parameters that depend on the MapRoot, for both published and draft maps.
  ui_region = request.get('gl')
  if map_object or catalog_entry:
    result['lang'] = base_handler.SelectLanguageForRequest(request, map_root)
    ui_region = map_root.get('region', ui_region)
    cache_key, sources = metadata.CacheSourceAddresses(key, result['map_root'])
    result['metadata'] = {s: METADATA_CACHE.Get(s) for s in sources}
    result['metadata_url'] = root + '/.metadata?ck=' + cache_key
    metadata.ActivateSources(sources)

  # Construct the URL for the Maps JavaScript API.
  api_url_params = {
      'sensor': 'false',
      'libraries': 'places,search,visualization,weather',
      'client': GetMapsApiClientId(request.host),
      'language': request.lang
  }
  if ui_region:
    api_url_params['region'] = ui_region
  result['maps_api_url'] = (MAPS_API_BASE_URL + '?' +
                            urllib.urlencode(api_url_params))

  maproot_url = request.get('maproot_url', '')
  if dev_mode or maproot_url.startswith(request.root_url + '/'):
    # It's always okay to fetch MapRoot JSON from a URL if it's from this app.
    # In developer mode only, allow MapRoot JSON from arbitrary URLs.
    result['maproot_url'] = maproot_url

  if dev_mode:
    # In developer mode only, allow query params to override the result.
    # Developers can also specify map_root directly as a query param.
    for name in (
        ClientConfig.properties().keys() + ['map_root', 'use_tab_panel']):
      value = request.get(name)
      if value:
        result[name] = json.loads(value)

  return result