diff sat/plugins/plugin_misc_identity.py @ 3326:9e1ba1e1179f

plugin identity: added "filename" metadata for avatar
author Goffi <goffi@goffi.org>
date Sun, 02 Aug 2020 17:40:07 +0200
parents 27d4b71e264a
children 203a491fcd86
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_identity.py	Sat Aug 01 16:25:50 2020 +0200
+++ b/sat/plugins/plugin_misc_identity.py	Sun Aug 02 17:40:07 2020 +0200
@@ -145,6 +145,9 @@
                         cache_uid = value['cache_uid']
                         if not cache_uid:
                             raise ValueError
+                        filename = value['filename']
+                        if not filename:
+                            raise ValueError
                     except (ValueError, KeyError):
                         log.warning(
                             f"invalid data for {entity} avatar, it will be deleted: "
@@ -464,6 +467,7 @@
             raise ValueError(f"There is no file at {file_path} to use as avatar")
         avatar_data = {
             'path': file_path,
+            'filename': file_path.name,
             'media_type': image.guess_type(file_path),
         }
         media_type = avatar_data['media_type']
@@ -499,6 +503,7 @@
 
             return {
                 "path": path,
+                "filename": path.name,
                 "media_type": media_type,
                 "cache_uid": cache_uid,
             }
@@ -509,7 +514,7 @@
     async def avatarUpdateDataFilter(self, client, entity, data):
         if not isinstance(data, dict):
             raise ValueError(f"Invalid data type ({type(data)}), a dict is expected")
-        mandatory_keys = {'path', 'cache_uid'}
+        mandatory_keys = {'path', 'filename', 'cache_uid'}
         if not data.keys() >= mandatory_keys:
             raise ValueError(f"missing avatar data keys: {mandatory_keys - data.keys()}")
         return data