Skip to content

Commit

Permalink
dropped "system" flag for ExApps (#271)
Browse files Browse the repository at this point in the history
We are making ExApps more like usual PHP Apps for Nextcloud.

Now any ExApp is allowed to impersonate any user, no need "system" flag
for this.

Reference: nextcloud/app_api#323

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Jul 12, 2024
1 parent 4f2bbf6 commit 000819d
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 68 deletions.
2 changes: 1 addition & 1 deletion docs/NextcloudApp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ After launching your application, execute the following command in the Nextcloud
.. code-block:: shell
php occ app_api:app:register YOUR_APP_ID manual_install --json-info \
"{\"id\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"scopes\":[\"ALL\"],\"port\":SELECTED_PORT,\"system\":0}" \
"{\"id\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"scopes\":[\"ALL\"],\"port\":SELECTED_PORT}" \
--force-scopes --wait-finish
You can see how **nc_py_api** registers in ``scripts/dev_register.sh``.
Expand Down
2 changes: 0 additions & 2 deletions docs/NextcloudSysApp.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Have a great time with Python and Nextcloud!
NextcloudApp
NextcloudTalkBot
NextcloudTalkBotTransformers
NextcloudSysApp
NextcloudUiApp
Options
reference/index.rst
Expand Down
24 changes: 12 additions & 12 deletions examples/as_app/talk_bot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ help:
@echo " build-push build image and upload to ghcr.io"
@echo " "
@echo " run install TalkBot for Nextcloud Last"
@echo " run27 install TalkBot for Nextcloud 27"
@echo " run28 install TalkBot for Nextcloud 28"
@echo " "
@echo " For development of this example use PyCharm run configurations. Development is always set for last Nextcloud."
@echo " First run 'TalkBot' and then 'make registerXX', after that you can use/debug/develop it and easy test."
@echo " "
@echo " register perform registration of running 'TalkBot' into the 'manual_install' deploy daemon."
@echo " register27 perform registration of running 'TalkBot' into the 'manual_install' deploy daemon."
@echo " register28 perform registration of running 'TalkBot' into the 'manual_install' deploy daemon."

.PHONY: build-push
build-push:
Expand All @@ -29,22 +29,22 @@ run:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/talk_bot/appinfo/info.xml

.PHONY: run27
run27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot --force-scopes \
.PHONY: run28
run28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register talk_bot --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/talk_bot/appinfo/info.xml

.PHONY: register
register:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
"{\"id\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":[\"TALK\", \"TALK_BOT\"],\"system\":0}" \
"{\"id\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":[\"TALK\", \"TALK_BOT\"]}" \
--force-scopes --wait-finish

.PHONY: register27
register27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
"{\"id\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":[\"TALK\", \"TALK_BOT\"],\"system\":0}" \
.PHONY: register28
register28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister talk_bot --force || true
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
"{\"id\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":[\"TALK\", \"TALK_BOT\"]}" \
--force-scopes --wait-finish
3 changes: 1 addition & 2 deletions examples/as_app/talk_bot/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<bugs>https://github.com/cloud-py-api/nc_py_api/issues</bugs>
<repository type="git">https://github.com/cloud-py-api/nc_py_api</repository>
<dependencies>
<nextcloud min-version="27" max-version="29"/>
<nextcloud min-version="28" max-version="30"/>
</dependencies>
<external-app>
<docker-install>
Expand All @@ -28,6 +28,5 @@
<value>TALK</value>
<value>TALK_BOT</value>
</scopes>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/talk_bot/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nc_py_api[app]>=0.10.0
nc_py_api[app]>=0.14.0
24 changes: 12 additions & 12 deletions examples/as_app/talk_bot_ai/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ help:
@echo " build-push build image and upload to ghcr.io"
@echo " "
@echo " run install TalkBotAI for Nextcloud Last"
@echo " run27 install TalkBotAI for Nextcloud 27"
@echo " run28 install TalkBotAI for Nextcloud 28"
@echo " "
@echo " For development of this example use PyCharm run configurations. Development is always set for last Nextcloud."
@echo " First run 'TalkBotAI' and then 'make registerXX', after that you can use/debug/develop it and easy test."
@echo " "
@echo " register perform registration of running 'TalkBotAI' into the 'manual_install' deploy daemon."
@echo " register27 perform registration of running 'TalkBotAI' into the 'manual_install' deploy daemon."
@echo " register28 perform registration of running 'TalkBotAI' into the 'manual_install' deploy daemon."

.PHONY: build-push
build-push:
Expand All @@ -29,22 +29,22 @@ run:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot_ai --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/talk_bot_ai/appinfo/info.xml

.PHONY: run27
run27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot_ai --force-scopes \
.PHONY: run28
run28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register talk_bot_ai --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/talk_bot_ai/appinfo/info.xml

.PHONY: register
register:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
"{\"id\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":[\"TALK\", \"TALK_BOT\"],\"system\":0}" \
"{\"id\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":[\"TALK\", \"TALK_BOT\"]}" \
--force-scopes --wait-finish

.PHONY: register27
register27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
"{\"id\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":[\"TALK\", \"TALK_BOT\"],\"system\":0}" \
.PHONY: register28
register28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
"{\"id\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":[\"TALK\", \"TALK_BOT\"]}" \
--force-scopes --wait-finish
3 changes: 1 addition & 2 deletions examples/as_app/talk_bot_ai/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<bugs>https://github.com/cloud-py-api/nc_py_api/issues</bugs>
<repository type="git">https://github.com/cloud-py-api/nc_py_api</repository>
<dependencies>
<nextcloud min-version="27" max-version="29"/>
<nextcloud min-version="28" max-version="30"/>
</dependencies>
<external-app>
<docker-install>
Expand All @@ -28,6 +28,5 @@
<value>TALK</value>
<value>TALK_BOT</value>
</scopes>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/talk_bot_ai/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nc_py_api[app]>=0.10.0
nc_py_api[app]>=0.14.0
transformers>=4.33
torch
torchvision
Expand Down
19 changes: 2 additions & 17 deletions examples/as_app/to_gif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ help:
@echo " "
@echo " build-push build image and upload to ghcr.io"
@echo " "
@echo " run27 install ToGif for Nextcloud 27"
@echo " run28 install ToGif for Nextcloud 28"
@echo " run install ToGif for Nextcloud Last"
@echo " "
@echo " For development of this example use PyCharm run configurations. Development is always set for last Nextcloud."
@echo " First run 'ToGif' and then 'make registerXX', after that you can use/debug/develop it and easy test."
@echo " "
@echo " register27 perform registration of running 'to_gif' into the 'manual_install' deploy daemon."
@echo " register28 perform registration of running 'to_gif' into the 'manual_install' deploy daemon."
@echo " register perform registration of running 'to_gif' into the 'manual_install' deploy daemon."

Expand All @@ -25,12 +23,6 @@ build-push:
docker login ghcr.io
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/cloud-py-api/to_gif:latest .

.PHONY: run27
run27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register to_gif --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/to_gif/appinfo/info.xml

.PHONY: run28
run28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
Expand All @@ -43,23 +35,16 @@ run:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register to_gif --force-scopes \
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/to_gif/appinfo/info.xml

.PHONY: register27
register27:
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
"{\"id\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":[\"FILES\", \"NOTIFICATIONS\"],\"system\":0}" \
--force-scopes --wait-finish

.PHONY: register28
register28:
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
"{\"id\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":[\"FILES\", \"NOTIFICATIONS\"],\"system\":0}" \
"{\"id\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":[\"FILES\", \"NOTIFICATIONS\"]}" \
--force-scopes --wait-finish

.PHONY: register
register:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
"{\"id\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":[\"FILES\", \"NOTIFICATIONS\"],\"system\":0}" \
"{\"id\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":[\"FILES\", \"NOTIFICATIONS\"]}" \
--force-scopes --wait-finish
3 changes: 1 addition & 2 deletions examples/as_app/to_gif/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<bugs>https://github.com/cloud-py-api/nc_py_api/issues</bugs>
<repository type="git">https://github.com/cloud-py-api/nc_py_api</repository>
<dependencies>
<nextcloud min-version="27" max-version="29"/>
<nextcloud min-version="28" max-version="30"/>
</dependencies>
<external-app>
<docker-install>
Expand All @@ -28,6 +28,5 @@
<value>FILES</value>
<value>NOTIFICATIONS</value>
</scopes>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/to_gif/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nc_py_api[app]>=0.10.0
nc_py_api[app]>=0.14.0
pygifsicle
imageio
opencv-python
Expand Down
4 changes: 2 additions & 2 deletions nc_py_api/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ def _create_adapter(self, dav: bool = False) -> AsyncClient | Client:

@property
def ae_url(self) -> str:
"""Return base url for the App Ecosystem endpoints."""
"""Return base url for the AppAPI endpoints."""
return "/ocs/v1.php/apps/app_api/api/v1"

@property
def ae_url_v2(self) -> str:
"""Return base url for the App Ecosystem endpoints(version 2)."""
"""Return base url for the AppAPI endpoints(version 2)."""
return "/ocs/v1.php/apps/app_api/api/v2"


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.14.0"
__version__ = "0.15.0.dev0"
4 changes: 2 additions & 2 deletions nc_py_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def last_check_time(self) -> datetime.datetime:

@property
def system(self) -> bool:
"""Flag indicating if the application is a system application."""
return bool(self._raw_data["system"])
"""**DEPRECATED** Flag indicating if the application is a system application."""
return True

def __repr__(self):
return f"<{self.__class__.__name__} id={self.app_id}, ver={self.version}>"
Expand Down
8 changes: 4 additions & 4 deletions nc_py_api/nextcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ def log(self, log_lvl: LogLvl, content: str) -> None:
self._session.ocs("POST", f"{self._session.ae_url}/log", json={"level": int(log_lvl), "message": content})

def users_list(self) -> list[str]:
"""Returns list of users on the Nextcloud instance. **Available** only for ``System`` applications."""
"""Returns list of users on the Nextcloud instance."""
return self._session.ocs("GET", f"{self._session.ae_url}/users")

@property
def user(self) -> str:
"""Property containing the current user ID.
**System Applications** can change user ID they impersonate with **set_user** method.
**ExApps** can change user ID they impersonate with **set_user** method.
"""
return self._session.user

Expand Down Expand Up @@ -480,14 +480,14 @@ async def log(self, log_lvl: LogLvl, content: str) -> None:
await self._session.ocs("POST", f"{self._session.ae_url}/log", json={"level": int(log_lvl), "message": content})

async def users_list(self) -> list[str]:
"""Returns list of users on the Nextcloud instance. **Available** only for ``System`` applications."""
"""Returns list of users on the Nextcloud instance."""
return await self._session.ocs("GET", f"{self._session.ae_url}/users")

@property
async def user(self) -> str:
"""Property containing the current user ID.
**System Applications** can change user ID they impersonate with **set_user** method.
**ExApps** can change user ID they impersonate with **set_user** method.
"""
return await self._session.user

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci_register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

php occ app_api:daemon:register manual_install "Manual Install" manual-install http "$4" 0
php occ app_api:app:register "$1" manual_install --json-info \
"{\"appid\":\"$1\",\"name\":\"$1\",\"daemon_config_name\":\"manual_install\",\"version\":\"$2\",\"secret\":\"$3\",\"scopes\":[\"ALL\"],\"port\":$5,\"system_app\":1}" \
"{\"appid\":\"$1\",\"name\":\"$1\",\"daemon_config_name\":\"manual_install\",\"version\":\"$2\",\"secret\":\"$3\",\"scopes\":[\"ALL\"],\"port\":$5}" \
--force-scopes --wait-finish
2 changes: 1 addition & 1 deletion scripts/dev_register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ echo "unregistering nc_py_api as an app for $1 container"
docker exec "$1" sudo -u www-data php occ app_api:app:unregister nc_py_api --silent --force || true
echo "registering nc_py_api as an app for $1 container"
docker exec "$1" sudo -u www-data php occ app_api:app:register nc_py_api manual_install --json-info \
"{\"id\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"scopes\":[\"ALL\"],\"port\":9009,\"system_app\":1}" \
"{\"id\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"scopes\":[\"ALL\"],\"port\":9009}" \
--force-scopes --wait-finish
echo "nc_py_api for $1 is ready to use"
3 changes: 0 additions & 3 deletions tests/actual_tests/apps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ def _test_ex_app_get_list(ex_apps: list[ExAppInfo], enabled_ex_apps: list[ExAppI
assert isinstance(app.version, str)
assert isinstance(app.enabled, bool)
assert isinstance(app.last_check_time, datetime.datetime)
assert isinstance(app.system, bool)
if app.app_id == "nc_py_api":
assert app.system is True
assert str(app).find("id=") != -1 and str(app).find("ver=") != -1


Expand Down

0 comments on commit 000819d

Please sign in to comment.