diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 0e023fa369..6cad04ac1c 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -666,13 +666,20 @@ if EVENTS_CONFIG_FILE: return events if events else None def generate_file_audit_event_type(e): - return { + + event_type_dict = { 'file-download-web': ('web', ''), 'file-download-share-link': ('share-link',''), 'file-download-api': ('API', e.device), 'repo-download-sync': ('download-sync', e.device), 'repo-upload-sync': ('upload-sync', e.device), - }[e.etype] + 'seadrive-download-file': ('seadrive-download', e.device), + } + + if not event_type_dict.has_key(e.etype): + event_type_dict[e.etype] = (e.etype, e.device if e.device else '') + + return event_type_dict[e.etype] def get_file_audit_events_by_path(email, org_id, repo_id, file_path, start, limit): """Return file audit events list by file path. (If no file audit, return 'None') diff --git a/tests/seahub/utils/test_generate_file_audit_event_type.py b/tests/seahub/utils/test_generate_file_audit_event_type.py new file mode 100644 index 0000000000..9227cbebd0 --- /dev/null +++ b/tests/seahub/utils/test_generate_file_audit_event_type.py @@ -0,0 +1,36 @@ +from seahub.test_utils import BaseTestCase +from seahub.utils import generate_file_audit_event_type + +class Events(): + + def __init__(self, etype, device): + self.etype = etype + self.device = device + + +class GenerateFileAuditEventTypeTest(BaseTestCase): + + def test_generate_file_audit_event_type(self): + + event_type_device = { + 'file-download-web': '', + 'file-download-share-link': '', + 'file-download-api': 'file-download-api-device', + 'repo-download-sync': 'repo-download-sync-device', + 'repo-upload-sync': 'repo-upload-sync-device', + 'seadrive-download-file': 'seadrive-download-file-device', + 'unknow-type-has-device': 'has-device', + 'unknow-type-no-device': '', + } + + for key,value in event_type_device.items(): + + e = Events(key, value) + + assert generate_file_audit_event_type(e)[1] == value + + if e.etype == 'unknow-type-has-device': + assert generate_file_audit_event_type(e)[1] == 'has-device' + + if e.etype == 'unknow-type-no-device': + assert generate_file_audit_event_type(e)[1] == ''