# HG changeset patch # User Goffi # Date 1596293244 -7200 # Node ID d0575e9abf7d7087ad3bc4723505203026deb7a6 # Parent 991ff12241e0d904a039bd0a74c4e7df9994cf1f pages (files/list): use new `FISAffiliationsGet` to get `directory_affiliation` diff -r 991ff12241e0 -r d0575e9abf7d libervia/pages/files/list/page_meta.py --- a/libervia/pages/files/list/page_meta.py Sat Aug 01 16:47:24 2020 +0200 +++ b/libervia/pages/files/list/page_meta.py Sat Aug 01 16:47:24 2020 +0200 @@ -30,6 +30,9 @@ service, path_elts = data["service"], data["path"] path = Path('/', *path_elts) profile = self.getProfile(request) or C.SERVICE_PROFILE + session_data = self.host.getSessionData( + request, session_iface.ISATSession + ) try: files_data = await self.host.bridgeCall( @@ -82,9 +85,6 @@ ) else: filename = os.path.basename(thumb_path) - session_data = self.host.getSessionData( - request, session_iface.ISATSession - ) file_data["thumb_url"] = os.path.join( session_data.cache_dir, filename ) @@ -112,26 +112,28 @@ ) # parent dir affiliation - # for the moment the only way to get affiliation of current directory is to check - # it from parent's list # TODO: some caching? What if affiliation changes? - if path.parent != path: - try: - parent_files_data = await self.host.bridgeCall( - "FISList", service.full(), str(path.parent), {}, profile) - except BridgeException as e: - if e.condition == 'item-not-found': - pass - else: - raise e - else: - directory_data = next(f for f in parent_files_data if f['name'] == path.name) - template_data['directory_affiliation'] = directory_data.get('affiliation') + affiliations = await self.host.bridgeCall( + "FISAffiliationsGet", service.full(), "", str(path), profile + ) + directory_affiliation = affiliations.get(session_data.jid.userhost()) + if directory_affiliation == "owner": + # we need to transtype dict items to str because with some bridges (D-Bus) + # we have a specific type which can't be exposed + self.exposeToScripts( + request, + affiliations={str(e): str(a) for e, a in affiliations.items()} + ) + template_data["directory_affiliation"] = directory_affiliation template_data["files_data"] = files_data template_data["path"] = path - # we make the service and path accessible from scripts - self.exposeToScripts(request, files_service=service.full(), files_path=str(path)) + self.exposeToScripts( + request, + directory_affiliation=str(directory_affiliation), + files_service=service.full(), + files_path=str(path), + ) if path_elts: template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1])