From 818dc2ebe3219523ca0712905fff3802820cf3ef Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:26:52 +0300 Subject: [PATCH] added `enabled_state` property for NextcloudApp (#268) Reference: https://github.com/cloud-py-api/app_api/pull/318 _Required functionality when wrapping external service as ExApp_ Signed-off-by: Alexander Piskun --- CHANGELOG.md | 5 +++-- nc_py_api/nextcloud.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fae782e6..7c15b5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,14 @@ All notable changes to this project will be documented in this file. -## [0.14.0 - 2024-05-31] +## [0.14.0 - 2024-07-0X] ### Added - `LoginFlowV2` implementation by @blvdek #255 -- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+) #252 - `files.get_tags` function to get all tags assigned to the file or directory. #260 +- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+) #252 +- NextcloudApp: `enabled_state` property to check if current ExApp is disabled or enabled. ## [0.13.0 - 2024-04-28] diff --git a/nc_py_api/nextcloud.py b/nc_py_api/nextcloud.py index f33b91a8..889b7c51 100644 --- a/nc_py_api/nextcloud.py +++ b/nc_py_api/nextcloud.py @@ -1,5 +1,6 @@ """Nextcloud class providing access to all API endpoints.""" +import contextlib import typing from abc import ABC @@ -333,6 +334,13 @@ def __init__(self, **kwargs): self.events_listener = EventsListenerAPI(self._session) self.occ_commands = OccCommandsAPI(self._session) + @property + def enabled_state(self) -> bool: + """Returns ``True`` if ExApp is enabled, ``False`` otherwise.""" + with contextlib.suppress(Exception): + return bool(self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state")) + return False + def log(self, log_lvl: LogLvl, content: str) -> None: """Writes log to the Nextcloud log file.""" if self.check_capabilities("app_api"): @@ -456,6 +464,13 @@ def __init__(self, **kwargs): self.events_listener = AsyncEventsListenerAPI(self._session) self.occ_commands = AsyncOccCommandsAPI(self._session) + @property + async def enabled_state(self) -> bool: + """Returns ``True`` if ExApp is enabled, ``False`` otherwise.""" + with contextlib.suppress(Exception): + return bool(await self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state")) + return False + async def log(self, log_lvl: LogLvl, content: str) -> None: """Writes log to the Nextcloud log file.""" if await self.check_capabilities("app_api"):