From 05bc4996a832fa9be7f20e2c5c5f8794001d91e0 Mon Sep 17 00:00:00 2001 From: Steve Johnson Date: Sat, 14 Jan 2017 11:08:24 -0800 Subject: [PATCH] Rename and invert new config option --- beetsplug/web/__init__.py | 12 ++++++------ docs/plugins/web.rst | 4 ++-- test/test_web.py | 14 +++++++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 1344b898d..4d5dcba54 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -37,10 +37,10 @@ def _rep(obj, expand=False): out = dict(obj) if isinstance(obj, beets.library.Item): - if app.config.get('EXCLUDE_PATHS_FROM_ITEMS', True): - del out['path'] - else: + if app.config.get('INCLUDE_PATHS', False): out['path'] = out['path'].decode('utf-8') + else: + del out['path'] # Get the size (in bytes) of the backing file. This is useful # for the Tomahawk resolver API. @@ -320,7 +320,7 @@ class WebPlugin(BeetsPlugin): 'host': u'127.0.0.1', 'port': 8337, 'cors': '', - 'exclude_paths_from_items': True, + 'include_paths': False, }) def commands(self): @@ -339,8 +339,8 @@ class WebPlugin(BeetsPlugin): # Normalizes json output app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False - app.config['EXCLUDE_PATHS_FROM_ITEMS'] = ( - self.config.get('exclude_paths_from_items', True)) + app.config['INCLUDE_PATHS'] = ( + self.config.get('include_paths', False)) # Enable CORS if required. if self.config['cors']: diff --git a/docs/plugins/web.rst b/docs/plugins/web.rst index ef5769a2c..54c507cf0 100644 --- a/docs/plugins/web.rst +++ b/docs/plugins/web.rst @@ -63,8 +63,8 @@ configuration file. The available options are: Default: 8337. - **cors**: The CORS allowed origin (see :ref:`web-cors`, below). Default: CORS is disabled. -- **exclude_paths_from_items**: The 'path' key of items is filtered out of JSON - responses for security reasons. Default: true. +- **include_paths**: If true, includes paths in item objects. + Default: false. Implementation -------------- diff --git a/test/test_web.py b/test/test_web.py index d64341f3f..871fd1b09 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -28,17 +28,25 @@ class WebPluginTest(_common.LibTestCase): web.app.config['TESTING'] = True web.app.config['lib'] = self.lib - web.app.config['EXCLUDE_PATHS_FROM_ITEMS'] = True + web.app.config['INCLUDE_PATHS'] = False self.client = web.app.test_client() - def test_config_exclude_paths_from_items(self): - web.app.config['EXCLUDE_PATHS_FROM_ITEMS'] = False + def test_config_include_paths_true(self): + web.app.config['INCLUDE_PATHS'] = True response = self.client.get('/item/1') response.json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(response.json['path'], u'/path_1') + def test_config_include_paths_false(self): + web.app.config['INCLUDE_PATHS'] = False + response = self.client.get('/item/1') + response.json = json.loads(response.data.decode('utf-8')) + + self.assertEqual(response.status_code, 200) + self.assertNotIn('path', response.json) + def test_get_all_items(self): response = self.client.get('/item/') response.json = json.loads(response.data.decode('utf-8'))