Skip to content

Commit 818dc2e

Browse files
authored
added enabled_state property for NextcloudApp (#268)
Reference: nextcloud/app_api#318 _Required functionality when wrapping external service as ExApp_ Signed-off-by: Alexander Piskun <[email protected]>
1 parent a7ecfa7 commit 818dc2e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.14.0 - 2024-05-31]
5+
## [0.14.0 - 2024-07-0X]
66

77
### Added
88

99
- `LoginFlowV2` implementation by @blvdek #255
10-
- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+) #252
1110
- `files.get_tags` function to get all tags assigned to the file or directory. #260
11+
- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+) #252
12+
- NextcloudApp: `enabled_state` property to check if current ExApp is disabled or enabled.
1213

1314
## [0.13.0 - 2024-04-28]
1415

nc_py_api/nextcloud.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Nextcloud class providing access to all API endpoints."""
22

3+
import contextlib
34
import typing
45
from abc import ABC
56

@@ -333,6 +334,13 @@ def __init__(self, **kwargs):
333334
self.events_listener = EventsListenerAPI(self._session)
334335
self.occ_commands = OccCommandsAPI(self._session)
335336

337+
@property
338+
def enabled_state(self) -> bool:
339+
"""Returns ``True`` if ExApp is enabled, ``False`` otherwise."""
340+
with contextlib.suppress(Exception):
341+
return bool(self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state"))
342+
return False
343+
336344
def log(self, log_lvl: LogLvl, content: str) -> None:
337345
"""Writes log to the Nextcloud log file."""
338346
if self.check_capabilities("app_api"):
@@ -456,6 +464,13 @@ def __init__(self, **kwargs):
456464
self.events_listener = AsyncEventsListenerAPI(self._session)
457465
self.occ_commands = AsyncOccCommandsAPI(self._session)
458466

467+
@property
468+
async def enabled_state(self) -> bool:
469+
"""Returns ``True`` if ExApp is enabled, ``False`` otherwise."""
470+
with contextlib.suppress(Exception):
471+
return bool(await self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state"))
472+
return False
473+
459474
async def log(self, log_lvl: LogLvl, content: str) -> None:
460475
"""Writes log to the Nextcloud log file."""
461476
if await self.check_capabilities("app_api"):

0 commit comments

Comments
 (0)