1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 10:26:17 +00:00

Merge pull request #2652 from haiwen/file-audit

get file audit event type/device
This commit is contained in:
Daniel Pan
2018-12-17 18:15:23 +08:00
committed by GitHub
2 changed files with 45 additions and 2 deletions

View File

@@ -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')

View File

@@ -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] == ''