appsv2: fix permission provisioning for fulldomain apps + fix apps not properly getting removed after failed resources init

This commit is contained in:
Alexandre Aubin 2023-02-03 20:27:52 +01:00
parent 0e787acb5d
commit 476908bdc2
2 changed files with 40 additions and 17 deletions

View file

@ -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
try:
AppResourceManager(app_instance_name, wanted=manifest, current={}).apply( AppResourceManager(app_instance_name, wanted=manifest, current={}).apply(
rollback_and_raise_exception_if_failure=True, rollback_and_raise_exception_if_failure=True,
operation_logger=operation_logger, 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,6 +2655,9 @@ 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:
if manifest.get("packaging_format", 0) < 2:
# This is likely to be a full-domain app... # This is likely to be a full-domain app...
# Confirm that this is a full-domain app This should cover most cases # Confirm that this is a full-domain app This should cover most cases
@ -2668,6 +2675,12 @@ def _guess_webapp_path_requirement(app_folder: str) -> str:
) and re.search(r"ynh_webpath_register", install_script_content): ) and re.search(r"ynh_webpath_register", install_script_content):
return "full_domain" 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 "?"

View file

@ -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"
] ]