Multi-platform: support multiple files per version #201
@ -733,16 +733,26 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
|
||||
@property
|
||||
def permissions_with_reasons(self) -> List[dict]:
|
||||
"""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]})
|
||||
"""Returns permissions with reasons, slugs, and names to be shown in templates.
|
||||
|
||||
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
|
||||
|
||||
# FIXME make dependent on File or platform
|
||||
|
Loading…
Reference in New Issue
Block a user