mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
appsv2: simplify code to hydrate url/additional_urls with app settings
This commit is contained in:
parent
fa26574b51
commit
8ca756dbd3
1 changed files with 8 additions and 11 deletions
|
@ -17,7 +17,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import os
|
||||
import re
|
||||
import copy
|
||||
import shutil
|
||||
import random
|
||||
|
@ -562,17 +561,15 @@ class PermissionsResource(AppResource):
|
|||
|
||||
super().__init__({"permissions": properties}, *args, **kwargs)
|
||||
|
||||
from yunohost.app import _get_app_settings, _hydrate_app_template
|
||||
|
||||
settings = _get_app_settings(self.app)
|
||||
for perm, infos in self.permissions.items():
|
||||
if infos.get("url"):
|
||||
for variable in re.findall(r"(__[A-Z0-9_]+__)", infos.get("url", "")):
|
||||
infos["url"] = infos["url"].replace(
|
||||
variable, self.get_setting(variable.lower().replace("__",""))
|
||||
)
|
||||
for i in range(0, len(infos.get("additional_urls", []))):
|
||||
for variable in re.findall(r"(__[A-Z0-9_]+__)", infos.get("additional_urls", [])[i]):
|
||||
infos["additional_urls"][i] = infos["additional_urls"][i].replace(
|
||||
variable, self.get_setting(variable.lower().replace("__",""))
|
||||
)
|
||||
if infos.get("url") and "__" in infos.get("url"):
|
||||
infos["url"] = _hydrate_app_template(infos["url"], settings)
|
||||
|
||||
if infos.get("additional_urls"):
|
||||
infos["additional_urls"] = [_hydrate_app_template(url) for url in infos["additional_urls"]]
|
||||
|
||||
def provision_or_update(self, context: Dict = {}):
|
||||
from yunohost.permission import (
|
||||
|
|
Loading…
Add table
Reference in a new issue