def _get_response_data(self, logs): user_list = [] for log in logs: user_list.append(log.username) name_dict = get_user_name_dict(user_list) contact_email_dict = get_user_contact_email_dict(user_list) data = [] for log in logs: email = log.username data.append({ 'login_time': datetime_to_isoformat_timestr(log.login_date), 'login_ip': log.login_ip, 'login_success': log.login_success, 'email': email, 'name': name_dict[email], 'contact_email': contact_email_dict[email], }) return data
def get(self, request): """List organization file access in logs """ if not EVENTS_ENABLED: error_msg = "Events not enabled." return api_error(status.HTTP_404_NOT_FOUND, error_msg) # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '25')) except ValueError: page = 1 per_page = 25 user_selected = request.GET.get('email', None) repo_selected = request.GET.get('repo_id', None) start = per_page * (page - 1) limit = per_page org_id = request.user.org.org_id events = get_file_audit_events(user_selected, org_id, repo_selected, start, limit) event_list = [] if not events: return Response({ 'log_list': event_list, 'page': page, 'page_next': False, }) ev_user_list = [] repo_id_list = [] for ev in events: ev_user_list.append(ev.user) repo_id_list.append(ev.repo_id) ev_user_name_dict = get_user_name_dict(ev_user_list) ev_user_contact_email_dict = get_user_contact_email_dict(ev_user_list) ev_repo_dict = get_repo_dict(repo_id_list) for ev in events: event = {} event['type'] = ev.etype event['device'] = ev.device event['file_name'] = os.path.basename(ev.file_path) event['file_path'] = ev.file_path event['ip'] = ev.ip event['user_email'] = ev.user event['user_name'] = ev_user_name_dict[ev.user] event['user_contact_email'] = ev_user_contact_email_dict[ev.user] event['time'] = datetime_to_isoformat_timestr(ev.timestamp) event['repo_id'] = ev.repo_id event['repo_name'] = ev_repo_dict[ev.repo_id].name if ev_repo_dict[ ev.repo_id] else '' event_list.append(event) page_next = True if len(events) == per_page else False return Response({ 'log_list': event_list, 'page': page, 'page_next': page_next, })
def get(self, request): """List organization permission audit in logs """ if not EVENTS_ENABLED: error_msg = "Events not enabled." return api_error(status.HTTP_404_NOT_FOUND, error_msg) # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '25')) except ValueError: page = 1 per_page = 25 user_selected = request.GET.get('email', None) repo_selected = request.GET.get('repo_id', None) start = per_page * (page - 1) limit = per_page org_id = request.user.org.org_id events = get_perm_audit_events(user_selected, org_id, repo_selected, start, limit) event_list = [] if not events: return Response({ 'log_list': event_list, 'page': page, 'page_next': False }) ev_user_list = [] repo_id_list = [] group_id_list = [] for ev in events: ev_user_list.append(ev.from_user) repo_id_list.append(ev.repo_id) if '@' in ev.to: ev_user_list.append(ev.to) if ev.to.isdigit(): group_id_list.append(ev.to) ev_user_name_dict = get_user_name_dict(ev_user_list) ev_user_contact_email_dict = get_user_contact_email_dict(ev_user_list) ev_repo_dict = get_repo_dict(repo_id_list) ev_group_dict = get_group_dict(group_id_list) for ev in events: event = {} event['from_user_email'] = ev.from_user event['from_user_name'] = ev_user_name_dict[ev.from_user] event['from_user_contact_email'] = ev_user_contact_email_dict[ ev.from_user] if ev.to.isdigit(): event['to_group_name'] = ev_group_dict[ ev.to].group_name if ev_group_dict[ev.to] else '' event['to_group_id'] = ev.to elif ev.to == 'all': pass else: event['to_user_email'] = ev.to event['to_user_name'] = ev_user_name_dict[ev.to] event['to_user_contact_email'] = ev_user_contact_email_dict[ ev.to] event['type'] = update_log_perm_audit_type(ev) event['permission'] = ev.permission event['repo_name'] = ev_repo_dict[ev.repo_id].name if ev_repo_dict[ ev.repo_id] else '' event['repo_id'] = ev.repo_id event['folder_name'] = os.path.basename(ev.file_path) event['folder_path'] = ev.file_path event['time'] = datetime_to_isoformat_timestr(ev.timestamp) event_list.append(event) page_next = True if len(events) == per_page else False return Response({ 'log_list': event_list, 'page': page, 'page_next': page_next, })
def get(self, request): # check the date format, should be like '2015-10-10' start = request.GET.get('start', None) end = request.GET.get('end', None) if not check_time_period_valid(start, end): error_msg = 'start or end date invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: events = get_log_events_by_type_and_time('file_audit', start, end) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) result = [] if events: # get name/contact_email dict for events user/repo_owner ev_user_list = [] ev_repo_owner_list = [] for ev in events: repo_id = ev.repo_id repo = seafile_api.get_repo(repo_id) if repo: ev.repo_name = repo.name ev.repo_owner = seafile_api.get_repo_owner(repo_id) or \ seafile_api.get_org_repo_owner(repo_id) else: ev.repo_name = '' ev.repo_owner = '' ev_user_list.append(ev.user) ev_repo_owner_list.append(ev.repo_owner) ev_user_name_dict = get_user_name_dict(ev_user_list) ev_user_contact_email_dict = get_user_contact_email_dict(ev_user_list) ev_repo_owner_name_dict = get_user_name_dict(ev_repo_owner_list) ev_repo_owner_contact_email_dict = get_user_contact_email_dict(ev_repo_owner_list) for ev in events: result.append({ 'repo_id': ev.repo_id, 'repo_name': ev.repo_name, 'repo_owner_email': ev.repo_owner, 'repo_owner_name': ev_repo_owner_name_dict[ev.repo_owner], 'repo_owner_contact_email': ev_repo_owner_contact_email_dict[ev.repo_owner], 'time': datetime_to_isoformat_timestr(ev.timestamp), 'ip': ev.ip, 'file_path': ev.file_path, 'etype': ev.etype, 'user_email': ev.user, 'user_name': ev_user_name_dict[ev.user], 'user_contact_email': ev_user_contact_email_dict[ev.user], }) return Response(result)
def get(self, request): # check the date format, should be like '2015-10-10' start = request.GET.get('start', None) end = request.GET.get('end', None) if not check_time_period_valid(start, end): error_msg = 'start or end date invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: events = get_log_events_by_type_and_time('file_audit', start, end) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) result = [] if events: # get name/contact_email dict for events user/repo_owner ev_user_list = [] ev_repo_owner_list = [] for ev in events: repo_id = ev.repo_id repo = seafile_api.get_repo(repo_id) if repo: ev.repo_name = repo.name ev.repo_owner = seafile_api.get_repo_owner(repo_id) or \ seafile_api.get_org_repo_owner(repo_id) else: ev.repo_name = '' ev.repo_owner = '' ev_user_list.append(ev.user) ev_repo_owner_list.append(ev.repo_owner) ev_user_name_dict = get_user_name_dict(ev_user_list) ev_user_contact_email_dict = get_user_contact_email_dict( ev_user_list) ev_repo_owner_name_dict = get_user_name_dict(ev_repo_owner_list) ev_repo_owner_contact_email_dict = get_user_contact_email_dict( ev_repo_owner_list) for ev in events: result.append({ 'repo_id': ev.repo_id, 'repo_name': ev.repo_name, 'repo_owner_email': ev.repo_owner, 'repo_owner_name': ev_repo_owner_name_dict[ev.repo_owner], 'repo_owner_contact_email': ev_repo_owner_contact_email_dict[ev.repo_owner], 'time': datetime_to_isoformat_timestr(ev.timestamp), 'ip': ev.ip, 'file_path': ev.file_path, 'etype': ev.etype, 'user_email': ev.user, 'user_name': ev_user_name_dict[ev.user], 'user_contact_email': ev_user_contact_email_dict[ev.user], }) return Response(result)