diff --git a/plinth/frontpage.py b/plinth/frontpage.py index f3383a07f..397ba05d1 100644 --- a/plinth/frontpage.py +++ b/plinth/frontpage.py @@ -42,6 +42,8 @@ def add_shortcut(shortcut_id, name, short_description="", login_required=False, shortcuts[shortcut_id] = { 'id': shortcut_id, + 'name': name, + 'short_description': short_description, 'label': label, 'url': url, 'icon': icon, diff --git a/plinth/modules/api/__init__.py b/plinth/modules/api/__init__.py new file mode 100644 index 000000000..ce84efe13 --- /dev/null +++ b/plinth/modules/api/__init__.py @@ -0,0 +1,22 @@ +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +""" +Plinth module for api for android app. +""" + +version = 1 \ No newline at end of file diff --git a/plinth/modules/api/test/__init__.py b/plinth/modules/api/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plinth/modules/api/test/test_get_apps.py b/plinth/modules/api/test/test_get_apps.py new file mode 100644 index 000000000..2b84f0a76 --- /dev/null +++ b/plinth/modules/api/test/test_get_apps.py @@ -0,0 +1,43 @@ +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +""" +Test get apps for api module. +""" + +import unittest + +from plinth.modules.api.views import get_app_payload + + +class TestApi(unittest.TestCase): + apps = [{ + 'name': 'someName', + 'short_description': 'someDescription', + 'icon': 'someIconURl', + 'label': 'someLabel' + }] + + expected = [{ + 'name': 'someName', + 'short_description': 'someDescription', + 'icon_url': 'static/theme/icons/someIconURl.svg' + }] + + def test_get_app_payload(self): + apps = get_app_payload(self.apps) + self.assertEquals(apps, self.expected) \ No newline at end of file diff --git a/plinth/modules/api/urls.py b/plinth/modules/api/urls.py new file mode 100644 index 000000000..26f03d8bd --- /dev/null +++ b/plinth/modules/api/urls.py @@ -0,0 +1,30 @@ +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +""" +URLs for the plinth api for android app. +""" + +from django.conf.urls import url +from stronghold.decorators import public + +from plinth.modules.api.views import get_apps, get_access_info + +urlpatterns = [ + url(r'^api/(?P[0-9]+)/services/?$', public(get_apps)), + url(r'^api/(?P[0-9]+)/accessInfo/?$', public(get_access_info)) +] \ No newline at end of file diff --git a/plinth/modules/api/views.py b/plinth/modules/api/views.py new file mode 100644 index 000000000..b7076d401 --- /dev/null +++ b/plinth/modules/api/views.py @@ -0,0 +1,52 @@ +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +""" +Plinth module for api for android app. +""" + +from django.http import HttpResponse + +from plinth.modules.names import get_domain, get_domain_types +from plinth import frontpage +import json + + +def get_apps(request, **kwargs): + shortcuts = frontpage.get_shortcuts() + + response = {'services': get_app_payload(shortcuts)} + return HttpResponse(json.dumps(response), content_type="application/json") + + +def get_app_payload(enabled_apps): + service_apps = [] + for app in enabled_apps: + app['icon_url'] = 'static/theme/icons/' + app['icon'] + '.svg' + app_required_fields = dict((key, app[key]) for key in ('name', 'short_description', 'icon_url')) + apps = {key: str(value) for key, value in app_required_fields.items()} + service_apps.append(apps) + + return service_apps + + +def get_access_info(request, **kwargs): + domain_types = get_domain_types() + response = {} + for domain_type in domain_types: + response[domain_type] = get_domain(domain_type) + return HttpResponse(json.dumps(response), content_type="application/json") \ No newline at end of file