Skip to content

Commit

Permalink
Merge pull request #575 from intuitem/567_show_filesize
Browse files Browse the repository at this point in the history
567: show evidences file size
  • Loading branch information
ab-smith authored Jul 19, 2024
2 parents 5fe56a4 + 8cf72c1 commit c98b0f8
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 11 deletions.
12 changes: 12 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,18 @@ def get_folder(self):
def filename(self):
return os.path.basename(self.attachment.name)

def get_size(self):
if not self.attachment:
return None
# get the attachment size with the correct unit
size = self.attachment.size
if size < 1024:
return f"{size} B"
elif size < 1024 * 1024:
return f"{size / 1024:.1f} KB"
else:
return f"{size / 1024 / 1024:.1f} MB"


class AppliedControl(NameDescriptionMixin, FolderMixin, PublishInRootFolderMixin):
class Status(models.TextChoices):
Expand Down
1 change: 1 addition & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ class RequirementNodeWriteSerializer(RequirementNodeReadSerializer):

class EvidenceReadSerializer(BaseModelSerializer):
attachment = serializers.CharField(source="filename")
size = serializers.CharField(source="get_size")
folder = FieldsRelatedField()
applied_controls = FieldsRelatedField(many=True)
requirement_assessments = FieldsRelatedField(many=True)
Expand Down
3 changes: 2 additions & 1 deletion frontend/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"ssoSettings": "إعدادات تسجيل الدخول الموحد",
"ssoSettingsDescription": "قم بتكوين إعدادات تسجيل الدخول الموحد هنا.",
"sso": "SSO",
"isSso": "هل هو SSO"
"isSso": "هل هو SSO",
"size": "الحجم"
}
3 changes: 2 additions & 1 deletion frontend/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Fortschreiten",
"back": "Zurückkehren",
"duplicate": "Duplikat",
"duplicateRiskAssessment": "Duplizieren Sie die Risikobewertung"
"duplicateRiskAssessment": "Duplizieren Sie die Risikobewertung",
"size": "Größe"
}
3 changes: 2 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,6 @@
"progress": "Progress",
"back": "Back",
"duplicate": "Duplicate",
"duplicateRiskAssessment": "Duplicate the risk assessment"
"duplicateRiskAssessment": "Duplicate the risk assessment",
"size": "Size"
}
3 changes: 2 additions & 1 deletion frontend/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Progresión",
"back": "Devolver",
"duplicate": "Duplicar",
"duplicateRiskAssessment": "Duplicar la evaluación de riesgo"
"duplicateRiskAssessment": "Duplicar la evaluación de riesgo",
"size": "Tamaño"
}
3 changes: 2 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Progression",
"back": "Retour",
"duplicate": "Dupliquer",
"duplicateRiskAssessment": "Dupliquer l’évaluation de risque"
"duplicateRiskAssessment": "Dupliquer l’évaluation de risque",
"size": "Taille"
}
3 changes: 2 additions & 1 deletion frontend/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Progressione",
"back": "Ritorno",
"duplicate": "Duplicare",
"duplicateRiskAssessment": "Duplicare la valutazione del rischio"
"duplicateRiskAssessment": "Duplicare la valutazione del rischio",
"size": "Dimensione"
}
3 changes: 2 additions & 1 deletion frontend/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Progressie",
"back": "Opbrengst",
"duplicate": "Duplicaat",
"duplicateRiskAssessment": "Dupliceer de risicobeoordeling"
"duplicateRiskAssessment": "Dupliceer de risicobeoordeling",
"size": "Grootte"
}
3 changes: 2 additions & 1 deletion frontend/messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,6 @@
"progress": "Postęp",
"back": "Powrót",
"duplicate": "Duplikować",
"duplicateRiskAssessment": "Powielić ocenę ryzyka"
"duplicateRiskAssessment": "Powielić ocenę ryzyka",
"size": "Rozmiar"
}
3 changes: 2 additions & 1 deletion frontend/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,6 @@
"progress": "Progressão",
"back": "Retornar",
"duplicate": "Duplicado",
"duplicateRiskAssessment": "Duplicar a avaliação de risco"
"duplicateRiskAssessment": "Duplicar a avaliação de risco",
"size": "Tamanho"
}
4 changes: 2 additions & 2 deletions frontend/src/lib/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ export const listViewFields: ListViewFieldsConfig = {
breadcrumb_link_disabled: true
},
evidences: {
head: ['name', 'file', 'description'],
body: ['name', 'attachment', 'description'],
head: ['name', 'file', 'size', 'description'],
body: ['name', 'attachment', 'size', 'description'],
filters: {
folder: { ...DOMAIN_FILTER_FROM_META, alwaysDisplay: true } // This filter should also be displayed even without alwaysDisplay
}
Expand Down

0 comments on commit c98b0f8

Please sign in to comment.