Exemplo n.º 1
0
 def testPost_WithKey_UpdatesNamespacedValues(self):
   namespaced_stored_object.Set('foo', 'XXXinternalYYY')
   namespaced_stored_object.SetExternal('foo', 'XXXYYY')
   self.testapp.post('/edit_site_config', {
       'key': 'foo',
       'external_value': '{"x": "y"}',
       'internal_value': '{"x": "yz"}',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual({'x': 'yz'}, namespaced_stored_object.Get('foo'))
   self.assertEqual({'x': 'y'}, namespaced_stored_object.GetExternal('foo'))
Exemplo n.º 2
0
  def get(self):
    """Renders the UI with the form."""
    key = self.request.get('key')
    if not key:
      self.RenderHtml('edit_site_config.html', {})
      return

    value = stored_object.Get(key)
    external_value = namespaced_stored_object.GetExternal(key)
    internal_value = namespaced_stored_object.Get(key)
    self.RenderHtml('edit_site_config.html', {
        'key': key,
        'value': _FormatJson(value),
        'external_value': _FormatJson(external_value),
        'internal_value': _FormatJson(internal_value),
    })
Exemplo n.º 3
0
  def post(self):
    """Accepts posted values, makes changes, and shows the form again."""
    key = self.request.get('key')

    if not utils.IsInternalUser():
      self.RenderHtml('edit_site_config.html', {
          'error': 'Only internal users can post to this end-point.'
      })
      return

    if not key:
      self.RenderHtml('edit_site_config.html', {})
      return

    new_value_json = self.request.get('value').strip()
    new_external_value_json = self.request.get('external_value').strip()
    new_internal_value_json = self.request.get('internal_value').strip()

    template_params = {
        'key': key,
        'value': new_value_json,
        'external_value': new_external_value_json,
        'internal_value': new_internal_value_json,
    }

    try:
      new_value = json.loads(new_value_json or 'null')
      new_external_value = json.loads(new_external_value_json or 'null')
      new_internal_value = json.loads(new_internal_value_json or 'null')
    except ValueError:
      template_params['error'] = 'Invalid JSON in at least one field.'
      self.RenderHtml('edit_site_config.html', template_params)
      return

    old_value = stored_object.Get(key)
    old_external_value = namespaced_stored_object.GetExternal(key)
    old_internal_value = namespaced_stored_object.Get(key)

    stored_object.Set(key, new_value)
    namespaced_stored_object.SetExternal(key, new_external_value)
    namespaced_stored_object.Set(key, new_internal_value)

    _SendNotificationEmail(
        key, old_value, old_external_value, old_internal_value,
        new_value, new_external_value, new_internal_value)

    self.RenderHtml('edit_site_config.html', template_params)
 def testGetExternal_InternalUser_ExternalVersionReturned(self):
     self.SetCurrentUser('*****@*****.**')
     stored_object.Set('internal_only__foo', [1, 2, 3])
     stored_object.Set('externally_visible__foo', [4, 5, 6])
     self.assertEqual([4, 5, 6],
                      namespaced_stored_object.GetExternal('foo'))