Skip to content

Refactoring + Talk api(first small part) #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
cd ..
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33, 50]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -290,7 +290,7 @@ jobs:
cd ..
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33, 50]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -429,7 +429,7 @@ jobs:
cd ..
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33, 50]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -549,7 +549,7 @@ jobs:
cd ..
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33, 50]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -795,7 +795,7 @@ jobs:
cd ..
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"protocol\":\"http\",\"port\":$APP_PORT,\"system_app\":1}" \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33, 50]},\"protocol\":\"http\",\"port\":$APP_PORT,\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

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

## [0.0.32 - 2023-08-2x]
## [0.0.40 - 2023-08-22]

### Added

- Basic APIs for Nextcloud Talk(Part 1)

### Changed

- `require_capabilities`/`check_capabilities` can accept value with `dot`: like `files_sharing.api_enabled` and check for sub-values.
- Refactored all API(except `Files`) again.

### Fixed

- `options.NPA_NC_CERT` bug, when setting throw `.env` file.

## [0.0.31 - 2023-08-17]

Expand Down
12 changes: 6 additions & 6 deletions docs/reference/Apps.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
Applications Management
-----------------------

.. autoclass:: nc_py_api.apps.apps.AppsAPI
.. autoclass:: nc_py_api.apps._AppsAPI
:members:

.. autoclass:: nc_py_api.apps.apps.ExAppInfo
.. autoclass:: nc_py_api.apps.ExAppInfo
:members:

Preferences
^^^^^^^^^^^

.. autoclass:: nc_py_api.apps.preferences_ex.CfgRecord
.. autoclass:: nc_py_api._preferences_ex.CfgRecord
:members:
:undoc-members:

User specific
"""""""""""""

.. autoclass:: nc_py_api.apps.preferences.PreferencesAPI
.. autoclass:: nc_py_api._preferences.PreferencesAPI
:members:

.. autoclass:: nc_py_api.apps.preferences_ex.PreferencesExAPI
.. autoclass:: nc_py_api._preferences_ex.PreferencesExAPI
:members:
:inherited-members:

Non-user specific
"""""""""""""""""

.. autoclass:: nc_py_api.apps.preferences_ex.AppConfigExAPI
.. autoclass:: nc_py_api._preferences_ex.AppConfigExAPI
:members:
:inherited-members:
50 changes: 50 additions & 0 deletions docs/reference/Talk.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Talk API
--------

.. autoclass:: nc_py_api.talk.Conversation
:members:
:inherited-members:

.. autoclass:: nc_py_api.talk._TalkAPI
:members:

.. autoclass:: nc_py_api.talk.ConversationType
:members:

.. autoclass:: nc_py_api.talk.ParticipantType
:members:

.. autoclass:: nc_py_api.talk.AttendeePermissions
:members:

.. autoclass:: nc_py_api.talk.InCallFlags
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.ListableScope
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.NotificationLevel
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.WebinarLobbyStates
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.SipEnabledStatus
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.CallRecordingStatus
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.BreakoutRoomMode
:members:
:undoc-members:

.. autoclass:: nc_py_api.talk.BreakoutRoomStatus
:members:
:undoc-members:
6 changes: 3 additions & 3 deletions docs/reference/Users/Notifications.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Notifications
-------------

.. autoclass:: nc_py_api.users.notifications._NotificationsAPI
.. autoclass:: nc_py_api.notifications._NotificationsAPI
:members:

.. autoclass:: nc_py_api.users.notifications.Notification
.. autoclass:: nc_py_api.notifications.Notification
:members:

.. autoclass:: nc_py_api.users.notifications.NotificationInfo
.. autoclass:: nc_py_api.notifications.NotificationInfo
:members:
2 changes: 1 addition & 1 deletion docs/reference/Users/Users.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
User Management
---------------

.. autoclass:: nc_py_api.users.users.UsersAPI
.. autoclass:: nc_py_api.users._UsersAPI
:members:
4 changes: 2 additions & 2 deletions docs/reference/Users/UsersGroups.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
User Groups Management
----------------------

.. autoclass:: nc_py_api.users.groups._UserGroupsAPI
.. autoclass:: nc_py_api.users_groups._UsersGroupsAPI
:members:

.. autoclass:: nc_py_api.users.groups.GroupDetails
.. autoclass:: nc_py_api.users_groups.GroupDetails
:members:
11 changes: 6 additions & 5 deletions docs/reference/Users/UsersStatus.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
User Status
-----------

.. autoclass:: nc_py_api.users.status._UserStatusAPI
.. autoclass:: nc_py_api.user_status._UserStatusAPI
:members:

.. autoclass:: nc_py_api.users.status.CurrentUserStatus
.. autoclass:: nc_py_api.user_status.CurrentUserStatus
:members:

.. autoclass:: nc_py_api.users.status.UserStatus
.. autoclass:: nc_py_api.user_status.UserStatus
:members:
:inherited-members:

.. autoclass:: nc_py_api.users.status.PredefinedStatus
.. autoclass:: nc_py_api.user_status.PredefinedStatus
:members:

.. autoclass:: nc_py_api.users.status.ClearAt
.. autoclass:: nc_py_api.user_status.ClearAt
:members:
6 changes: 3 additions & 3 deletions docs/reference/Users/WeatherStatus.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Weather Status
--------------

.. autoclass:: nc_py_api.users.weather._WeatherStatusAPI
.. autoclass:: nc_py_api.weather_status._WeatherStatusAPI
:members:

.. autoclass:: nc_py_api.users.weather.WeatherLocation
.. autoclass:: nc_py_api.weather_status.WeatherLocation
:members:

.. autoclass:: nc_py_api.users.weather.WeatherLocationMode
.. autoclass:: nc_py_api.weather_status.WeatherLocationMode
:members:
1 change: 1 addition & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Reference
Users/index.rst
ExApp
Exceptions
Talk
Session
19 changes: 15 additions & 4 deletions nc_py_api/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@

from random import choice
from string import ascii_lowercase, ascii_uppercase, digits
from typing import Union
from typing import Callable, Union

from ._exceptions import NextcloudMissingCapabilities


def kwargs_to_dict(keys: list[str], **kwargs) -> dict:
"""Creates dictionary from ``kwargs`` by keys, the value of each is not ``None``."""
return {k: kwargs[k] for k in keys if kwargs[k] is not None}
def __check_for_none(v):
return v is not None


def kwargs_to_params(keys: list[str], filter_func: Callable = __check_for_none, **kwargs) -> dict:
"""Returns dictionary from ``kwargs`` by keys. By default, only pairs with ``not None`` values returned."""
return {k: kwargs[k] for k in keys if filter_func(kwargs[k])}


def clear_from_params_empty(keys: list[str], params: dict) -> None:
"""Removes key:values pairs from ``params`` which values are empty."""
for key in keys:
if key in params and not params[key]:
params.pop(key)


def require_capabilities(capabilities: Union[str, list[str]], srv_capabilities: dict) -> None:
Expand Down
4 changes: 2 additions & 2 deletions nc_py_api/apps/preferences.py → nc_py_api/_preferences.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Nextcloud API for working with classics app's storage with user's context (table oc_preferences)."""

from .._misc import check_capabilities, require_capabilities
from .._session import NcSessionBasic
from ._misc import check_capabilities, require_capabilities
from ._session import NcSessionBasic


class PreferencesAPI:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Nextcloud API for working with apps V2's storage w/wo user context(table oc_appconfig_ex/oc_preferences_ex)."""
from dataclasses import dataclass
from typing import Optional, Union
import dataclasses
import typing

from .._exceptions import NextcloudExceptionNotFound
from .._misc import require_capabilities
from .._session import NcSessionBasic
from ._exceptions import NextcloudExceptionNotFound
from ._misc import require_capabilities
from ._session import NcSessionBasic


@dataclass
@dataclasses.dataclass
class CfgRecord:
"""A representation of a single key-value pair returned from the **get_values** method."""

Expand All @@ -25,7 +25,7 @@ class _BasicAppCfgPref:
def __init__(self, session: NcSessionBasic):
self._session = session

def get_value(self, key: str, default=None) -> Optional[str]:
def get_value(self, key: str, default=None) -> typing.Optional[str]:
"""Returns the value of the key, if found, or the specified default value."""
if not key:
raise ValueError("`key` parameter can not be empty")
Expand All @@ -48,7 +48,7 @@ def get_values(self, keys: list[str]) -> list[CfgRecord]:
)
return [CfgRecord(i) for i in results]

def delete(self, keys: Union[str, list[str]], not_fail=True) -> None:
def delete(self, keys: typing.Union[str, list[str]], not_fail=True) -> None:
"""Deletes config/preference entries by the provided keys."""
if isinstance(keys, str):
keys = [keys]
Expand Down Expand Up @@ -85,7 +85,7 @@ class AppConfigExAPI(_BasicAppCfgPref):

_url_suffix = "ex-app/config"

def set_value(self, key: str, value: str, sensitive: Optional[bool] = None) -> None:
def set_value(self, key: str, value: str, sensitive: typing.Optional[bool] = None) -> None:
"""Sets a value and if specified the sensitive flag for a key.

.. note:: A sensitive flag ensures key values are truncated in Nextcloud logs.
Expand Down
2 changes: 1 addition & 1 deletion nc_py_api/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of nc_py_api."""

__version__ = "0.0.32.dev0"
__version__ = "0.0.40.dev0"
14 changes: 7 additions & 7 deletions nc_py_api/apps/apps.py → nc_py_api/apps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Nextcloud API for working with applications."""

from dataclasses import dataclass
from typing import Optional
import dataclasses
import typing

from .._misc import require_capabilities
from .._session import NcSessionBasic
from ._misc import require_capabilities
from ._session import NcSessionBasic


@dataclass
@dataclasses.dataclass
class ExAppInfo:
"""Information about the External Application."""

Expand All @@ -33,7 +33,7 @@ def __init__(self, raw_data: dict):
self.system = raw_data["system"]


class AppsAPI:
class _AppsAPI:
"""The class provides the application management API on the Nextcloud server."""

_ep_base: str = "/ocs/v1.php/cloud/apps"
Expand All @@ -59,7 +59,7 @@ def enable(self, app_id: str) -> None:
raise ValueError("`app_id` parameter can not be empty")
self._session.ocs(method="POST", path=f"{self._ep_base}/{app_id}")

def get_list(self, enabled: Optional[bool] = None) -> list[str]:
def get_list(self, enabled: typing.Optional[bool] = None) -> list[str]:
"""Get the list of installed applications.

:param enabled: filter to list all/only enabled/only disabled applications.
Expand Down
1 change: 0 additions & 1 deletion nc_py_api/apps/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions nc_py_api/ex_app/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ class ApiScope(enum.IntEnum):
"""Allows access to APIs that provide Notifications."""
WEATHER_STATUS = 33
"""Allows access to APIs that provide Weather status."""
TALK = 50
"""Allows access to Talk API endpoints."""
Loading