Repository: Flexget/Flexget

Issue:
Tasks API should no return hidden tasks
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->
### Expected behaviour:
<!---
Please don't just say "it doesn't crash" or "it works". Explain what the expected result is.
--->
Tasks API should only return visible tasks
### Actual behaviour:
Return all tasks, including those starting with `-`



Discussion:

Resolving patch:
diff --git a/flexget/api/app.py b/flexget/api/app.py
--- a/flexget/api/app.py
+++ b/flexget/api/app.py
@@ -21,7 +21,7 @@
 from flexget.webserver import User
 from . import __path__
 
-__version__ = '1.4.2'
+__version__ = '1.4.3'
 
 log = logging.getLogger('api')
 
diff --git a/flexget/api/core/tasks.py b/flexget/api/core/tasks.py
--- a/flexget/api/core/tasks.py
+++ b/flexget/api/core/tasks.py
@@ -175,13 +175,14 @@ class TasksAPI(APIResource):
     def get(self, session=None):
         """ List all tasks """
 
+        active_tasks = {task: task_data for task, task_data in self.manager.user_config.get('tasks', {}).items()
+                        if not task.startswith('_')}
+
         args = tasks_parser.parse_args()
         if not args.get('include_config'):
-            return jsonify(list(self.manager.user_config.get('tasks', {})))
+            return jsonify(list(active_tasks))
 
-        tasks = []
-        for name, config in self.manager.user_config.get('tasks', {}).items():
-            tasks.append({'name': name, 'config': config})
+        tasks = [{'name': name, 'config': config} for name, config in active_tasks.items()]
         return jsonify(tasks)
 
     @api.validate(task_input_schema, description='New task object')


Test patch:
diff --git a/flexget/tests/api_tests/test_tasks_api.py b/flexget/tests/api_tests/test_tasks_api.py
--- a/flexget/tests/api_tests/test_tasks_api.py
+++ b/flexget/tests/api_tests/test_tasks_api.py
@@ -3,10 +3,11 @@
 
 import json
 
+from mock import patch
+
 from flexget.api.app import base_message
 from flexget.api.core.tasks import ObjectsContainer as OC
 from flexget.manager import Manager
-from mock import patch
 
 
 class TestTaskAPI(object):
@@ -266,3 +267,22 @@ def test_task_queue(self, api_client, schema_match, manager):
         assert not errors
 
         assert data == []
+
+
+class TestDisabledTasks(object):
+    config = """
+        tasks:
+          live_task:
+            mock:
+            - title: foo
+          _disabled_task:
+            mock:
+            - title: bar
+    """
+
+    def test_only_active_tasks_return(self, api_client):
+        rsp = api_client.get('/tasks/')
+        data = json.loads(rsp.get_data(as_text=True))
+
+        assert len(data) == 1
+        assert not data[0].get('name') == '_disabled_task'