11"""Nextcloud API for working with applications."""
22
3- from typing import Optional , TypedDict
3+ from dataclasses import dataclass
4+ from typing import Optional
45
56from ._session import NcSessionBasic
67from .misc import require_capabilities
78
89ENDPOINT = "/ocs/v1.php/cloud/apps"
910
1011
11- class ExAppInfo (TypedDict ):
12+ @dataclass
13+ class ExAppInfo :
1214 """Information about the External Application."""
1315
14- id : str
16+ app_id : str
1517 """`ID` of the application"""
1618 name : str
1719 """Display name"""
@@ -24,6 +26,14 @@ class ExAppInfo(TypedDict):
2426 system : bool
2527 """Flag indicating if the application is a system application"""
2628
29+ def __init__ (self , raw_data : dict ):
30+ self .app_id = raw_data ["id" ]
31+ self .name = raw_data ["name" ]
32+ self .version = raw_data ["version" ]
33+ self .enabled = bool (raw_data ["enabled" ])
34+ self .last_check_time = raw_data ["last_check_time" ]
35+ self .system = raw_data ["system" ]
36+
2737
2838class AppAPI :
2939 """The class provides the application management API on the Nextcloud server."""
@@ -78,12 +88,25 @@ def is_disabled(self, app_id: str) -> bool:
7888 raise ValueError ("`app_id` parameter can not be empty" )
7989 return app_id in self .get_list (enabled = False )
8090
81- def ex_app_get_list (self ) -> list [str ]:
82- """Gets the list of the external applications IDs installed on the server."""
83- require_capabilities ("app_ecosystem_v2" , self ._session .capabilities )
84- return self ._session .ocs (method = "GET" , path = f"{ self ._session .ae_url } /ex-app/all" , params = {"extended" : 0 })
91+ def ex_app_get_list (self , enabled : bool = False ) -> list [ExAppInfo ]:
92+ """Gets information of the enabled external applications installed on the server.
8593
86- def ex_app_get_info (self ) -> list [ExAppInfo ]:
87- """Gets information of the external applications installed on the server."""
94+ :param enabled: Flag indicating whether to return only enabled applications or all applications.
95+ Default = **False**.
96+ """
8897 require_capabilities ("app_ecosystem_v2" , self ._session .capabilities )
89- return self ._session .ocs (method = "GET" , path = f"{ self ._session .ae_url } /ex-app/all" , params = {"extended" : 1 })
98+ url_param = "enabled" if enabled else "all"
99+ r = self ._session .ocs (method = "GET" , path = f"{ self ._session .ae_url } /ex-app/{ url_param } " )
100+ return [ExAppInfo (i ) for i in r ]
101+
102+ def ex_app_is_enabled (self , app_id : str ) -> bool :
103+ """Returns ``True`` if specified external application is enabled."""
104+ if not app_id :
105+ raise ValueError ("`app_id` parameter can not be empty" )
106+ return app_id in [i .app_id for i in self .ex_app_get_list (True )]
107+
108+ def ex_app_is_disabled (self , app_id : str ) -> bool :
109+ """Returns ``True`` if specified external application is disabled."""
110+ if not app_id :
111+ raise ValueError ("`app_id` parameter can not be empty" )
112+ return app_id in [i .app_id for i in self .ex_app_get_list (True ) if not i .enabled ]
0 commit comments