mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
appsv2: fix permission provisioning for fulldomain apps + fix apps not properly getting removed after failed resources init
This commit is contained in:
parent
0e787acb5d
commit
476908bdc2
2 changed files with 40 additions and 17 deletions
47
src/app.py
47
src/app.py
|
@ -1074,10 +1074,14 @@ def app_install(
|
||||||
if packaging_format >= 2:
|
if packaging_format >= 2:
|
||||||
from yunohost.utils.resources import AppResourceManager
|
from yunohost.utils.resources import AppResourceManager
|
||||||
|
|
||||||
AppResourceManager(app_instance_name, wanted=manifest, current={}).apply(
|
try:
|
||||||
rollback_and_raise_exception_if_failure=True,
|
AppResourceManager(app_instance_name, wanted=manifest, current={}).apply(
|
||||||
operation_logger=operation_logger,
|
rollback_and_raise_exception_if_failure=True,
|
||||||
)
|
operation_logger=operation_logger,
|
||||||
|
)
|
||||||
|
except (KeyboardInterrupt, EOFError, Exception) as e:
|
||||||
|
shutil.rmtree(app_setting_path)
|
||||||
|
raise e
|
||||||
else:
|
else:
|
||||||
# Initialize the main permission for the app
|
# Initialize the main permission for the app
|
||||||
# The permission is initialized with no url associated, and with tile disabled
|
# The permission is initialized with no url associated, and with tile disabled
|
||||||
|
@ -2651,22 +2655,31 @@ def _guess_webapp_path_requirement(app_folder: str) -> str:
|
||||||
if len(domain_questions) == 1 and len(path_questions) == 1:
|
if len(domain_questions) == 1 and len(path_questions) == 1:
|
||||||
return "domain_and_path"
|
return "domain_and_path"
|
||||||
if len(domain_questions) == 1 and len(path_questions) == 0:
|
if len(domain_questions) == 1 and len(path_questions) == 0:
|
||||||
# This is likely to be a full-domain app...
|
|
||||||
|
|
||||||
# Confirm that this is a full-domain app This should cover most cases
|
if manifest.get("packaging_format", 0) < 2:
|
||||||
# ... though anyway the proper solution is to implement some mechanism
|
|
||||||
# in the manifest for app to declare that they require a full domain
|
|
||||||
# (among other thing) so that we can dynamically check/display this
|
|
||||||
# requirement on the webadmin form and not miserably fail at submit time
|
|
||||||
|
|
||||||
# Full-domain apps typically declare something like path_url="/" or path=/
|
# This is likely to be a full-domain app...
|
||||||
# and use ynh_webpath_register or yunohost_app_checkurl inside the install script
|
|
||||||
install_script_content = read_file(os.path.join(app_folder, "scripts/install"))
|
|
||||||
|
|
||||||
if re.search(
|
# Confirm that this is a full-domain app This should cover most cases
|
||||||
r"\npath(_url)?=[\"']?/[\"']?", install_script_content
|
# ... though anyway the proper solution is to implement some mechanism
|
||||||
) and re.search(r"ynh_webpath_register", install_script_content):
|
# in the manifest for app to declare that they require a full domain
|
||||||
return "full_domain"
|
# (among other thing) so that we can dynamically check/display this
|
||||||
|
# requirement on the webadmin form and not miserably fail at submit time
|
||||||
|
|
||||||
|
# Full-domain apps typically declare something like path_url="/" or path=/
|
||||||
|
# and use ynh_webpath_register or yunohost_app_checkurl inside the install script
|
||||||
|
install_script_content = read_file(os.path.join(app_folder, "scripts/install"))
|
||||||
|
|
||||||
|
if re.search(
|
||||||
|
r"\npath(_url)?=[\"']?/[\"']?", install_script_content
|
||||||
|
) and re.search(r"ynh_webpath_register", install_script_content):
|
||||||
|
return "full_domain"
|
||||||
|
|
||||||
|
else:
|
||||||
|
# For packaging v2 apps, check if there's a permission with url being a string
|
||||||
|
perm_resource = manifest.get("resources", {}).get("permissions")
|
||||||
|
if perm_resource is not None and isinstance(perm_resource.get("main", {}).get("url"), str):
|
||||||
|
return "full_domain"
|
||||||
|
|
||||||
return "?"
|
return "?"
|
||||||
|
|
||||||
|
|
|
@ -320,6 +320,16 @@ class PermissionsResource(AppResource):
|
||||||
# Delete legacy is_public setting if not already done
|
# Delete legacy is_public setting if not already done
|
||||||
self.delete_setting("is_public")
|
self.delete_setting("is_public")
|
||||||
|
|
||||||
|
# Detect that we're using a full-domain app,
|
||||||
|
# in which case we probably need to automagically
|
||||||
|
# define the "path" setting with "/"
|
||||||
|
if (
|
||||||
|
isinstance(self.permissions["main"]["url"], str)
|
||||||
|
and self.get_setting("domain")
|
||||||
|
and not self.get_setting("path")
|
||||||
|
):
|
||||||
|
self.set_setting("path", "/")
|
||||||
|
|
||||||
existing_perms = user_permission_list(short=True, apps=[self.app])[
|
existing_perms = user_permission_list(short=True, apps=[self.app])[
|
||||||
"permissions"
|
"permissions"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue