Multi-platform: support multiple files per version #201

Merged
Oleg-Komarov merged 43 commits from multi-os into main 2024-07-09 16:27:46 +02:00
Showing only changes of commit 9f8a984bc1 - Show all commits

View File

@ -733,16 +733,26 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
@property @property
def permissions_with_reasons(self) -> List[dict]: def permissions_with_reasons(self) -> List[dict]:
"""Returns permissions with reasons, slugs, and names to be shown in templates.""" """Returns permissions with reasons, slugs, and names to be shown in templates.
# FIXME? is it ok to check just the first file?
file = self.files.all()[0]
if 'permissions' not in file.metadata:
return []
permissions = []
all_permission_names = {p.slug: p.name for p in VersionPermission.objects.all()}
for slug, reason in file.metadata['permissions'].items():
permissions.append({'slug': slug, 'reason': reason, 'name': all_permission_names[slug]})
It might make sense to not aggregate at the Version level, and query directly from File.
If we ever restructure multi-platform UI, this method should be revisited.
Normally we can expect that all files have the same permissions, but checking all files,
just in case.
"""
slug2reason = {}
for file in self.files.all():
if 'permissions' in file.metadata:
slug2reason.update(file.metadata['permissions'])
if not slug2reason:
return []
all_permission_names = {p.slug: p.name for p in VersionPermission.objects.all()}
permissions = []
for slug, reason in slug2reason.items():
permissions.append({'slug': slug, 'reason': reason, 'name': all_permission_names[slug]})
return permissions return permissions
# FIXME make dependent on File or platform # FIXME make dependent on File or platform