diff --git a/nc_py_api/apps.py b/nc_py_api/apps.py index 25a47126..c4b7a5c0 100644 --- a/nc_py_api/apps.py +++ b/nc_py_api/apps.py @@ -38,7 +38,6 @@ def disable(self, app_name: str) -> None: :param app_name: id of the application. .. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode.""" - if not app_name: raise ValueError("`app_name` parameter can not be empty") self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{app_name}") @@ -49,7 +48,6 @@ def enable(self, app_name: str) -> None: :param app_name: id of the application. .. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode.""" - if not app_name: raise ValueError("`app_name` parameter can not be empty") self._session.ocs(method="POST", path=f"{ENDPOINT}/{app_name}") @@ -59,7 +57,6 @@ def get_list(self, enabled: Optional[bool] = None) -> list[str]: :param enabled: filter to list all/only enabled/only disabled applications. """ - params = None if enabled is not None: params = {"filter": "enabled" if enabled else "disabled"} @@ -71,7 +68,6 @@ def is_installed(self, app_name: str) -> bool: :param app_name: id of the application. """ - if not app_name: raise ValueError("`app_name` parameter can not be empty") return app_name in self.get_list() @@ -81,7 +77,6 @@ def is_enabled(self, app_name: str) -> bool: :param app_name: id of the application. """ - if not app_name: raise ValueError("`app_name` parameter can not be empty") return app_name in self.get_list(enabled=True) @@ -91,19 +86,16 @@ def is_disabled(self, app_name: str) -> bool: :param app_name: id of the application. """ - if not app_name: raise ValueError("`app_name` parameter can not be empty") return app_name in self.get_list(enabled=False) def ex_app_get_list(self) -> list[str]: """Gets the list of the external applications IDs installed on the server.""" - require_capabilities("app_ecosystem_v2", self._session.capabilities) return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 0}) def ex_app_get_info(self) -> list[ExAppInfo]: """Gets information of the external applications installed on the server.""" - require_capabilities("app_ecosystem_v2", self._session.capabilities) return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 1}) diff --git a/nc_py_api/files.py b/nc_py_api/files.py index 453f5a76..16ddf13e 100644 --- a/nc_py_api/files.py +++ b/nc_py_api/files.py @@ -71,7 +71,6 @@ def listdir(self, path: Union[str, FsNode] = "", depth: int = 1, exclude_self=Tr :param exclude_self: boolean value indicating whether the `path` itself should be excluded from the list or not. Default = **True**. """ - if exclude_self and not depth: raise ValueError("Wrong input parameters, query will return nothing.") properties = PROPFIND_PROPERTIES @@ -83,14 +82,12 @@ def by_id(self, file_id: Union[int, str, FsNode]) -> Optional[FsNode]: :param file_id: can be full file ID with Nextcloud instance ID or only clear file ID. """ - file_id = file_id.file_id if isinstance(file_id, FsNode) else file_id result = self.find(req=["eq", "fileid", file_id]) return result[0] if result else None def by_path(self, path: Union[str, FsNode]) -> Optional[FsNode]: """Returns :py:class:`~nc_py_api.files_defs.FsNode` by exact path if any.""" - path = path.user_path if isinstance(path, FsNode) else path result = self.listdir(path, depth=0, exclude_self=False) return result[0] if result else None @@ -101,7 +98,6 @@ def find(self, req: list, path: Union[str, FsNode] = "") -> list[FsNode]: :param req: list of conditions to search for. Detailed description here... :param path: path where to search from. Default = **""**. """ - # `req` possible keys: "name", "mime", "last_modified", "size", "favorite", "fileid" path = path.user_path if isinstance(path, FsNode) else path root = ElementTree.Element( @@ -129,7 +125,6 @@ def download(self, path: Union[str, FsNode]) -> bytes: :param path: path to download file. """ - path = path.user_path if isinstance(path, FsNode) else path response = self._session.dav("GET", self._dav_get_obj_path(self._session.user, path)) check_error(response.status_code, f"download: user={self._session.user}, path={path}") @@ -143,7 +138,6 @@ def download2stream(self, path: Union[str, FsNode], fp, **kwargs) -> None: The object must implement the ``file.write`` method and be able to write binary data. :param kwargs: **chunk_size** an int value specifying chunk size to write. Default = **4Mb** """ - path = path.user_path if isinstance(path, FsNode) else path if isinstance(fp, (str, Path)): with builtins.open(fp, "wb") as f: @@ -159,7 +153,6 @@ def upload(self, path: Union[str, FsNode], content: Union[bytes, str]) -> FsNode :param path: file's upload path. :param content: content to create the file. If it is a string, it will be encoded into bytes using UTF-8. """ - path = path.user_path if isinstance(path, FsNode) else path full_path = self._dav_get_obj_path(self._session.user, path) response = self._session.dav("PUT", full_path, data=content) @@ -174,7 +167,6 @@ def upload_stream(self, path: Union[str, FsNode], fp, **kwargs) -> FsNode: The object must implement the ``file.read`` method providing data with str or bytes type. :param kwargs: **chunk_size** an int value specifying chunk size to read. Default = **4Mb** """ - path = path.user_path if isinstance(path, FsNode) else path if isinstance(fp, (str, Path)): with builtins.open(fp, "rb") as f: @@ -189,7 +181,6 @@ def mkdir(self, path: Union[str, FsNode]) -> FsNode: :param path: path of the directory to be created. """ - path = path.user_path if isinstance(path, FsNode) else path full_path = self._dav_get_obj_path(self._session.user, path) response = self._session.dav("MKCOL", full_path) @@ -204,7 +195,6 @@ def makedirs(self, path: Union[str, FsNode], exist_ok=False) -> Optional[FsNode] :param exist_ok: ignore error if any of pathname components already exists. :returns: `FsNode` if directory was created or ``None`` if it was already created. """ - _path = "" path = path.user_path if isinstance(path, FsNode) else path result = None @@ -226,7 +216,6 @@ def delete(self, path: Union[str, FsNode], not_fail=False) -> None: :param path: path to delete. :param not_fail: if set to ``True`` and the object is not found, it does not raise an exception. """ - path = path.user_path if isinstance(path, FsNode) else path response = self._session.dav("DELETE", self._dav_get_obj_path(self._session.user, path)) if response.status_code == 404 and not_fail: @@ -241,7 +230,6 @@ def move(self, path_src: Union[str, FsNode], path_dest: Union[str, FsNode], over :param overwrite: if ``True`` and the destination object already exists, it gets overwritten. Default = **False**. """ - path_src = path_src.user_path if isinstance(path_src, FsNode) else path_src full_dest_path = self._dav_get_obj_path( self._session.user, path_dest.user_path if isinstance(path_dest, FsNode) else path_dest @@ -264,7 +252,6 @@ def copy(self, path_src: Union[str, FsNode], path_dest: Union[str, FsNode], over :param overwrite: if ``True`` and the destination object already exists, it gets overwritten. Default = **False**. """ - path_src = path_src.user_path if isinstance(path_src, FsNode) else path_src full_dest_path = self._dav_get_obj_path( self._session.user, path_dest.user_path if isinstance(path_dest, FsNode) else path_dest @@ -281,7 +268,6 @@ def copy(self, path_src: Union[str, FsNode], path_dest: Union[str, FsNode], over def listfav(self) -> list[FsNode]: """Returns a list of the current user's favorite files.""" - root = ElementTree.Element( "oc:filter-files", attrib={"xmlns:d": "DAV:", "xmlns:oc": "http://owncloud.org/ns", "xmlns:nc": "http://nextcloud.org/ns"}, @@ -301,7 +287,6 @@ def setfav(self, path: Union[str, FsNode], value: Union[int, bool]) -> None: :param path: path to the object to set the state. :param value: value to set for the ``favourite`` state. """ - path = path.user_path if isinstance(path, FsNode) else path root = ElementTree.Element( "d:propertyupdate", diff --git a/nc_py_api/files_defs.py b/nc_py_api/files_defs.py index 01f0c387..1cee2d0e 100644 --- a/nc_py_api/files_defs.py +++ b/nc_py_api/files_defs.py @@ -39,7 +39,6 @@ def last_modified(self) -> datetime: """Time when the object was last modified. .. note:: ETag if more preferable way to check if the object was changed.""" - return self._last_modified @last_modified.setter @@ -77,7 +76,6 @@ def __init__(self, full_path: str, **kwargs): @property def is_dir(self) -> bool: """Returns ``True`` for the directories, ``False`` otherwise.""" - return self.full_path.endswith("/") def __str__(self): @@ -95,61 +93,51 @@ def __eq__(self, other): def has_extra(self) -> bool: """Flag indicating whether this ``FsNode`` was obtained by the `mkdir` or `upload` methods and does not contain extended information.""" - return bool(self.info.permissions) @property def name(self) -> str: """Returns last ``pathname`` component.""" - return self.full_path.rstrip("/").rsplit("/", maxsplit=1)[-1] @property def user(self) -> str: """Returns user ID extracted from the `full_path`.""" - return self.full_path.lstrip("/").split("/", maxsplit=2)[1] @property def user_path(self) -> str: """Returns path relative to the user's root directory.""" - return self.full_path.lstrip("/").split("/", maxsplit=2)[-1] @property def is_shared(self) -> bool: """Check if a file or folder is shared.""" - return self.info.permissions.find("S") != -1 @property def is_shareable(self) -> bool: """Check if a file or folder can be shared.""" - return self.info.permissions.find("R") != -1 @property def is_mounted(self) -> bool: """Check if a file or folder is mounted.""" - return self.info.permissions.find("M") != -1 @property def is_readable(self) -> bool: """Check if the file or folder is readable.""" - return self.info.permissions.find("G") != -1 @property def is_deletable(self) -> bool: """Check if a file or folder can be deleted.""" - return self.info.permissions.find("D") != -1 @property def is_updatable(self) -> bool: """Check if file/directory is writable.""" - if self.is_dir: return self.info.permissions.find("NV") != -1 return self.info.permissions.find("W") != -1 @@ -157,7 +145,6 @@ def is_updatable(self) -> bool: @property def is_creatable(self) -> bool: """Check whether new files or folders can be created inside this folder.""" - if not self.is_dir: return False return self.info.permissions.find("CK") != -1 @@ -233,7 +220,6 @@ def share_type(self) -> ShareType: @property def permissions(self) -> SharePermissions: """Recipient permissions.""" - return SharePermissions(int(self.raw_data["permissions"])) @property diff --git a/nc_py_api/files_sharing.py b/nc_py_api/files_sharing.py index 20a9e971..0a83cf42 100644 --- a/nc_py_api/files_sharing.py +++ b/nc_py_api/files_sharing.py @@ -18,14 +18,12 @@ def __init__(self, session: NcSessionBasic): @property def available(self) -> bool: """Returns True if the Nextcloud instance supports this feature, False otherwise.""" - return not check_capabilities("files_sharing", self._session.capabilities) def get_list( self, shared_with_me=False, reshares=False, subfiles=False, path: Union[str, FsNode] = "" ) -> list[Share]: """Returns lists of shares.""" - require_capabilities("files_sharing", self._session.capabilities) path = path.user_path if isinstance(path, FsNode) else path params = { @@ -65,7 +63,6 @@ def create( * ``note`` - string with note, if any. default = ``""`` * ``label`` - string with label, if any. default = ``""`` """ - require_capabilities("files_sharing", self._session.capabilities) path = path.user_path if isinstance(path, FsNode) else path params = { @@ -94,6 +91,5 @@ def delete(self, share_id: Union[int, Share]) -> None: :param share_id: The Share object or an ID of the share. """ - share_id = share_id.share_id if isinstance(share_id, Share) else share_id self._session.ocs(method="DELETE", path=f"{ENDPOINT_BASE}/shares/{share_id}") diff --git a/nc_py_api/nextcloud.py b/nc_py_api/nextcloud.py index a66ffce8..89e2366e 100644 --- a/nc_py_api/nextcloud.py +++ b/nc_py_api/nextcloud.py @@ -36,20 +36,17 @@ def _init_api(self, session: NcSessionBasic): @property def capabilities(self) -> dict: """Returns the capabilities of the Nextcloud instance.""" - return self._session.capabilities @property def srv_version(self) -> ServerVersion: """Returns dictionary with the server version.""" - return self._session.nc_version def check_capabilities(self, capabilities: Union[str, list[str]]) -> list[str]: """Returns the list with missing capabilities if any. :param capabilities: one or more features to check for.""" - return check_capabilities(capabilities, self.capabilities) def update_server_info(self) -> None: @@ -57,13 +54,11 @@ def update_server_info(self) -> None: *In normal cases, it is called automatically and there is no need to call it manually.* """ - self._session.update_server_info() @property def theme(self) -> Optional[ThemingInfo]: """Returns Theme information.""" - return get_parsed_theme(self.capabilities["theming"]) if "theming" in self.capabilities else None @@ -76,14 +71,12 @@ class Nextcloud(NextcloudBasic): def __init__(self, **kwargs): """:param dsdada: ddsdsds""" - self._session = NcSession(**kwargs) self._init_api(self._session) @property def user(self) -> str: """Returns current user name.""" - return self._session.user @@ -114,7 +107,6 @@ def log(self, log_lvl: LogLvl, content: str) -> None: :param log_lvl: level of the log, content belongs to. :param content: string to write into the log. """ - if self.check_capabilities("app_ecosystem_v2"): return if int(log_lvl) < self.capabilities["app_ecosystem_v2"].get("loglevel", 0): @@ -125,14 +117,12 @@ def log(self, log_lvl: LogLvl, content: str) -> None: def users_list(self) -> list[str]: """Returns list of users on the Nextcloud instance. **Available** only for ``System`` applications.""" - return self._session.ocs("GET", path=f"{APP_V2_BASIC_URL}/users", params={"format": "json"}) def scope_allowed(self, scope: ApiScope) -> bool: """Check if API scope is avalaible for application. Useful for applications which declare ``Optional`` scopes, to check if they are allowed for them.""" - if self.check_capabilities("app_ecosystem_v2"): return False return scope in self.capabilities["app_ecosystem_v2"]["scopes"] @@ -143,7 +133,6 @@ def user(self) -> str: *System Applications* can set it and impersonate the user. For normal applications, it is set automatically. """ - return self._session.user @user.setter @@ -155,7 +144,6 @@ def user(self, value: str): @property def app_cfg(self) -> AppConfig: """Returns deploy config, with AppEcosystem version, Application version and name.""" - return self._session.cfg def request_sign_check(self, request: Request) -> bool: @@ -165,7 +153,6 @@ def request_sign_check(self, request: Request) -> bool: .. note:: In most cases ``nc: Annotated[NextcloudApp, Depends(nc_app)]`` should be used. """ - try: self._session.sign_check(request) except ValueError as e: diff --git a/nc_py_api/preferences.py b/nc_py_api/preferences.py index d008dfa9..652387e0 100644 --- a/nc_py_api/preferences.py +++ b/nc_py_api/preferences.py @@ -13,17 +13,14 @@ def __init__(self, session: NcSessionBasic): @property def available(self) -> bool: """Returns True if the Nextcloud instance supports this feature, False otherwise.""" - return not check_capabilities("provisioning_api", self._session.capabilities) def set_value(self, app_name: str, key: str, value: str) -> None: """Sets the value for the key for the specific application.""" - require_capabilities("provisioning_api", self._session.capabilities) self._session.ocs(method="POST", path=f"{ENDPOINT}/{app_name}/{key}", params={"configValue": value}) def delete(self, app_name: str, key: str) -> None: """Removes a key and its value for a specific application.""" - require_capabilities("provisioning_api", self._session.capabilities) self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{app_name}/{key}") diff --git a/nc_py_api/theming.py b/nc_py_api/theming.py index 81a305b4..dacbe830 100644 --- a/nc_py_api/theming.py +++ b/nc_py_api/theming.py @@ -27,7 +27,6 @@ class ThemingInfo(TypedDict): def convert_str_color(theming_capability: dict, key: str) -> tuple[int, int, int]: """Returns a tuple of integers representing the RGB color for the specified theme key.""" - if key not in theming_capability: return 0, 0, 0 value = theming_capability[key] diff --git a/nc_py_api/ui_files_actions_menu.py b/nc_py_api/ui_files_actions_menu.py index dcf354fe..2be9197d 100644 --- a/nc_py_api/ui_files_actions_menu.py +++ b/nc_py_api/ui_files_actions_menu.py @@ -33,7 +33,6 @@ def __init__(self, session: NcSessionApp): def register(self, name: str, display_name: str, callback_url: str, **kwargs) -> None: """Registers the files a dropdown menu element.""" - require_capabilities("app_ecosystem_v2", self._session.capabilities) params = { "fileActionMenuParams": { @@ -51,7 +50,6 @@ def register(self, name: str, display_name: str, callback_url: str, **kwargs) -> def unregister(self, name: str, not_fail=True) -> None: """Removes files dropdown menu element.""" - require_capabilities("app_ecosystem_v2", self._session.capabilities) params = {"fileActionMenuName": name} try: diff --git a/nc_py_api/users.py b/nc_py_api/users.py index a026e5ce..16acb98b 100644 --- a/nc_py_api/users.py +++ b/nc_py_api/users.py @@ -44,7 +44,6 @@ def get_list( :param limit: limits the number of results. :param offset: offset of results. """ - data = kwargs_to_dict(["search", "limit", "offset"], search=mask, limit=limit, offset=offset) response_data = self._session.ocs(method="GET", path=ENDPOINT, params=data) return response_data["users"] if response_data else {} @@ -54,7 +53,6 @@ def get_details(self, user_id: str = "") -> dict: :param user_id: the identifier of the user about which information is to be returned. """ - if not user_id: user_id = self._session.user if not user_id: @@ -77,7 +75,6 @@ def create(self, user_id: str, **kwargs) -> None: * ``quota`` - quota for the user, if needed. * ``language`` - default language for the user. """ - password = kwargs.get("password", None) email = kwargs.get("email", None) if not password and not email: @@ -93,7 +90,6 @@ def delete(self, user_id: str) -> None: :param user_id: id of the user. """ - self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{user_id}") def enable(self, user_id: str) -> None: @@ -101,7 +97,6 @@ def enable(self, user_id: str) -> None: :param user_id: id of the user. """ - self._session.ocs(method="PUT", path=f"{ENDPOINT}/{user_id}/enable") def disable(self, user_id: str) -> None: @@ -109,7 +104,6 @@ def disable(self, user_id: str) -> None: :param user_id: id of the user. """ - self._session.ocs(method="PUT", path=f"{ENDPOINT}/{user_id}/disable") def resend_welcome_email(self, user_id: str) -> None: @@ -117,12 +111,10 @@ def resend_welcome_email(self, user_id: str) -> None: :param user_id: id of the user. """ - self._session.ocs(method="POST", path=f"{ENDPOINT}/{user_id}/welcome") def editable_fields(self) -> list[str]: """Returns user fields that avalaible for edit.""" - return self._session.ocs(method="GET", path=f"{ENDPOINT_BASE}/user/fields") def edit(self, user_id: str, **kwargs) -> None: @@ -131,7 +123,6 @@ def edit(self, user_id: str, **kwargs) -> None: :param user_id: id of the user. :param kwargs: dictionary where keys are values from ``editable_fields`` method, and values to set. """ - for k, v in kwargs.items(): self._session.ocs(method="PUT", path=f"{ENDPOINT}/{user_id}", params={"key": k, "value": v}) @@ -141,7 +132,6 @@ def add_to_group(self, user_id: str, group_id: str) -> None: :param user_id: ID of the user. :param group_id: the destination group to which add user to. """ - self._session.ocs(method="POST", path=f"{ENDPOINT}/{user_id}/groups", params={"groupid": group_id}) def remove_from_group(self, user_id: str, group_id: str) -> None: @@ -150,7 +140,6 @@ def remove_from_group(self, user_id: str, group_id: str) -> None: :param user_id: ID of the user. :param group_id: group from which remove user. """ - self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{user_id}/groups", params={"groupid": group_id}) def promote_to_subadmin(self, user_id: str, group_id: str) -> None: @@ -159,7 +148,6 @@ def promote_to_subadmin(self, user_id: str, group_id: str) -> None: :param user_id: ID of the user. :param group_id: group where user should become administrator. """ - self._session.ocs(method="POST", path=f"{ENDPOINT}/{user_id}/subadmins", params={"groupid": group_id}) def demote_from_subadmin(self, user_id: str, group_id: str) -> None: @@ -168,5 +156,4 @@ def demote_from_subadmin(self, user_id: str, group_id: str) -> None: :param user_id: ID of the user. :param group_id: group where user should be removed from administrators. """ - self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{user_id}/subadmins", params={"groupid": group_id}) diff --git a/nc_py_api/users_groups.py b/nc_py_api/users_groups.py index b08c29a7..ecbc0da4 100644 --- a/nc_py_api/users_groups.py +++ b/nc_py_api/users_groups.py @@ -27,7 +27,6 @@ def get_list( :param limit: limits the number of results. :param offset: offset of results. """ - data = kwargs_to_dict(["search", "limit", "offset"], search=mask, limit=limit, offset=offset) response_data = self._session.ocs(method="GET", path=ENDPOINT, params=data) return response_data["groups"] if response_data else [] @@ -41,7 +40,6 @@ def get_details( :param limit: limits the number of results. :param offset: offset of results. """ - data = kwargs_to_dict(["search", "limit", "offset"], search=mask, limit=limit, offset=offset) response_data = self._session.ocs(method="GET", path=f"{ENDPOINT}/details", params=data) return [GroupDetails(i) for i in response_data["groups"]] if response_data else [] @@ -52,7 +50,6 @@ def create(self, group_id: str, display_name: Optional[str] = None) -> None: :param group_id: the ID of group to be created. :param display_name: display name for a created group. """ - params = {"groupid": group_id} if display_name is not None: params["displayname"] = display_name @@ -64,7 +61,6 @@ def edit(self, group_id: str, display_name: str) -> None: :param group_id: the ID of group to edit info. :param display_name: new group display name. """ - params = {"key": "displayname", "value": display_name} self._session.ocs(method="PUT", path=f"{ENDPOINT}/{group_id}", params=params) @@ -73,7 +69,6 @@ def delete(self, group_id: str) -> None: :param group_id: the ID of group to remove. """ - self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{group_id}") def get_members(self, group_id: str) -> list[str]: @@ -81,7 +76,6 @@ def get_members(self, group_id: str) -> list[str]: :param group_id: Group ID to get the list of members. """ - response_data = self._session.ocs(method="GET", path=f"{ENDPOINT}/{group_id}") return response_data["users"] if response_data else {} @@ -90,5 +84,4 @@ def get_subadmins(self, group_id: str) -> list[str]: :param group_id: group ID to get the list of subadmins. """ - return self._session.ocs(method="GET", path=f"{ENDPOINT}/{group_id}/subadmins") diff --git a/nc_py_api/users_notifications.py b/nc_py_api/users_notifications.py index 2fb471d5..3c49e028 100644 --- a/nc_py_api/users_notifications.py +++ b/nc_py_api/users_notifications.py @@ -18,7 +18,6 @@ def __init__(self, session: NcSessionBasic): @property def available(self) -> bool: """Returns True if the Nextcloud instance supports this feature, False otherwise.""" - return not check_capabilities("notifications", self._session.capabilities) def create( @@ -30,7 +29,6 @@ def create( link: str = "", ) -> str: """Create a Notification for the current user and returns it's ObjectID.""" - if not isinstance(self._session, NcSessionApp): raise NotImplementedError("Sending notifications is only supported for `App` mode.") if not subject: @@ -59,13 +57,11 @@ def create( def get_all(self) -> list[Notification]: """Gets all notifications for a current user.""" - require_capabilities("notifications", self._session.capabilities) return [Notification(i) for i in self._session.ocs(method="GET", path=ENDPOINT)] def get_one(self, notification_id: int) -> Notification: """Gets a single notification for a current user.""" - require_capabilities("notifications", self._session.capabilities) return Notification(self._session.ocs(method="GET", path=f"{ENDPOINT}/{notification_id}")) @@ -73,7 +69,6 @@ def by_object_id(self, object_id: str) -> Optional[Notification]: """Returns Notification if any by its object ID. .. note:: this method is a temporary workaround until `create` can return `notification_id`.""" - for i in self.get_all(): if i.object_id == object_id: return i @@ -81,18 +76,15 @@ def by_object_id(self, object_id: str) -> Optional[Notification]: def delete(self, notification_id: int) -> None: """Deletes a notification for the current user.""" - require_capabilities("notifications", self._session.capabilities) self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{notification_id}") def delete_all(self) -> None: """Deletes all notifications for the current user.""" - require_capabilities("notifications", self._session.capabilities) self._session.ocs(method="DELETE", path=ENDPOINT) def exists(self, notification_ids: list[int]) -> list[int]: """Checks the existence of notifications for the current user.""" - require_capabilities("notifications", self._session.capabilities) return self._session.ocs(method="POST", path=f"{ENDPOINT}/exists", json={"ids": notification_ids}) diff --git a/nc_py_api/users_status.py b/nc_py_api/users_status.py index b9ae7c83..c60a75b1 100644 --- a/nc_py_api/users_status.py +++ b/nc_py_api/users_status.py @@ -19,7 +19,6 @@ def __init__(self, session: NcSessionBasic): @property def available(self) -> bool: """Returns True if the Nextcloud instance supports this feature, False otherwise.""" - return not check_capabilities("user_status", self._session.capabilities) def get_list(self, limit: Optional[int] = None, offset: Optional[int] = None) -> list[UserStatus]: @@ -28,7 +27,6 @@ def get_list(self, limit: Optional[int] = None, offset: Optional[int] = None) -> :param limit: limits the number of results. :param offset: offset of results. """ - require_capabilities("user_status", self._session.capabilities) data = kwargs_to_dict(["limit", "offset"], limit=limit, offset=offset) result = self._session.ocs(method="GET", path=f"{ENDPOINT}/statuses", params=data) @@ -36,7 +34,6 @@ def get_list(self, limit: Optional[int] = None, offset: Optional[int] = None) -> def get_current(self) -> CurrentUserStatus: """Returns the current user status.""" - require_capabilities("user_status", self._session.capabilities) return CurrentUserStatus(self._session.ocs(method="GET", path=f"{ENDPOINT}/user_status")) @@ -45,7 +42,6 @@ def get(self, user_id: str) -> Optional[UserStatus]: :param user_id: User ID for getting status. """ - require_capabilities("user_status", self._session.capabilities) try: return UserStatus(self._session.ocs(method="GET", path=f"{ENDPOINT}/statuses/{user_id}")) @@ -54,7 +50,6 @@ def get(self, user_id: str) -> Optional[UserStatus]: def get_predefined(self) -> list[PredefinedStatus]: """Returns a list of predefined statuses available for installation on this Nextcloud instance.""" - if self._session.nc_version["major"] < 27: return [] require_capabilities("user_status", self._session.capabilities) @@ -67,7 +62,6 @@ def set_predefined(self, status_id: str, clear_at: int = 0) -> None: :param status_id: ``predefined`` status ID. :param clear_at: *optional* time in seconds before the status is cleared. """ - if self._session.nc_version["major"] < 27: return require_capabilities("user_status", self._session.capabilities) @@ -78,7 +72,6 @@ def set_predefined(self, status_id: str, clear_at: int = 0) -> None: def set_status_type(self, value: Literal["online", "away", "dnd", "invisible", "offline"]) -> None: """Sets the status type for the current user.""" - self._session.ocs(method="PUT", path=f"{ENDPOINT}/user_status/status", params={"statusType": value}) def set_status(self, message: Optional[str] = None, clear_at: int = 0, status_icon: str = "") -> None: @@ -88,7 +81,6 @@ def set_status(self, message: Optional[str] = None, clear_at: int = 0, status_ic :param clear_at: Unix Timestamp, representing the time to clear the status. :param status_icon: The icon picked by the user (must be one emoji) """ - require_capabilities("user_status", self._session.capabilities) if message is None: self._session.ocs(method="DELETE", path=f"{ENDPOINT}/user_status/message") @@ -107,7 +99,6 @@ def get_backup_status(self, user_id: str = "") -> Optional[UserStatus]: :param user_id: User ID for getting status. """ - require_capabilities("user_status", self._session.capabilities) user_id = user_id if user_id else self._session.user if not user_id: @@ -119,7 +110,6 @@ def restore_backup_status(self, status_id: str) -> Optional[CurrentUserStatus]: :param status_id: backup status ID. """ - require_capabilities("user_status", self._session.capabilities) require_capabilities("restore", self._session.capabilities["user_status"]) result = self._session.ocs(method="DELETE", path=f"{ENDPOINT}/user_status/revert/{status_id}") diff --git a/nc_py_api/users_weather.py b/nc_py_api/users_weather.py index d58b98d0..03df4a3b 100644 --- a/nc_py_api/users_weather.py +++ b/nc_py_api/users_weather.py @@ -18,12 +18,10 @@ def __init__(self, session: NcSessionBasic): @property def available(self) -> bool: """Returns True if the Nextcloud instance supports this feature, False otherwise.""" - return not check_capabilities("weather_status", self._session.capabilities) def get_location(self) -> WeatherLocation: """Returns the current location set on the Nextcloud server for the user.""" - require_capabilities("weather_status", self._session.capabilities) return WeatherLocation(self._session.ocs(method="GET", path=f"{ENDPOINT}/location")) @@ -36,7 +34,6 @@ def set_location( :param longitude: east–west position of a point on the surface of the Earth. :param address: city, index(*optional*) and country, e.g. "Paris, 75007, France" """ - require_capabilities("weather_status", self._session.capabilities) params: dict[str, Union[str, float]] = {} if latitude is not None and longitude is not None: @@ -50,26 +47,22 @@ def set_location( def get_forecast(self) -> list[dict]: """Get forecast for the current location.""" - require_capabilities("weather_status", self._session.capabilities) return self._session.ocs(method="GET", path=f"{ENDPOINT}/forecast") def get_favorites(self) -> list[str]: """Returns favorites addresses list.""" - require_capabilities("weather_status", self._session.capabilities) return self._session.ocs(method="GET", path=f"{ENDPOINT}/favorites") def set_favorites(self, favorites: list[str]) -> bool: """Sets favorites addresses list.""" - require_capabilities("weather_status", self._session.capabilities) result = self._session.ocs(method="PUT", path=f"{ENDPOINT}/favorites", json={"favorites": favorites}) return result.get("success", False) def set_mode(self, mode: WeatherLocationMode) -> bool: """Change the weather status mode.""" - if int(mode) == WeatherLocationMode.UNKNOWN.value: raise ValueError("This mode can not be set") require_capabilities("weather_status", self._session.capabilities) diff --git a/pyproject.toml b/pyproject.toml index f1435568..16cda4a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,7 @@ preview = true [tool.ruff] line-length = 120 target-version = "py39" -select = ["A", "B", "C", "D200", "D212", "D400", "E", "F", "UP", "Q", "W"] +select = ["A", "B", "C", "D200", "D202", "D212", "D400", "E", "F", "UP", "Q", "W"] #extend-ignore = ["D203"] [tool.ruff.per-file-ignores]