mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 17:02:47 +00:00
fix export file access log (#6944)
* fix * update * optimize export log * update * update * update * fomrat-update --------- Co-authored-by: 孙永强 <11704063+s-yongqiang@user.noreply.gitee.com> Co-authored-by: r350178982 <32759763+r350178982@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import { orgAdminAPI } from '../../utils/org-admin-api';
|
|||||||
import { userAPI } from '../../utils/user-api';
|
import { userAPI } from '../../utils/user-api';
|
||||||
import toaster from '../../components/toast';
|
import toaster from '../../components/toast';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
|
import SeahubIODialog from '../dialog/seahub-io-dialog';
|
||||||
|
|
||||||
|
|
||||||
class OrgLogsExportExcelDialog extends React.Component {
|
class OrgLogsExportExcelDialog extends React.Component {
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ class OrgLogsExportExcelDialog extends React.Component {
|
|||||||
endDateStr: '',
|
endDateStr: '',
|
||||||
errMsg: '',
|
errMsg: '',
|
||||||
taskId: '',
|
taskId: '',
|
||||||
|
isShowIODialog: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,34 +41,51 @@ class OrgLogsExportExcelDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
queryIOStatus = (task_id, logType) => {
|
||||||
|
userAPI.queryIOStatus(task_id).then(res => {
|
||||||
|
if (res.data.is_finished === true) {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
location.href = siteRoot + 'api/v2.1/org/admin/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.queryIOStatus(task_id, logType);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
toaster.danger(gettext('Failed to export. Please check whether the size of table attachments exceeds the limit.'));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
orgAdminExportLogs = (logType) => {
|
orgAdminExportLogs = (logType) => {
|
||||||
let { startDateStr, endDateStr } = this.state;
|
let { startDateStr, endDateStr } = this.state;
|
||||||
let task_id = '';
|
let task_id = '';
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: true
|
||||||
|
}, () => {
|
||||||
orgAdminAPI.orgAdminExportLogsExcel(orgID, startDateStr, endDateStr, logType).then(res => {
|
orgAdminAPI.orgAdminExportLogsExcel(orgID, startDateStr, endDateStr, logType).then(res => {
|
||||||
task_id = res.data.task_id;
|
task_id = res.data.task_id;
|
||||||
this.setState({
|
this.setState({
|
||||||
taskId: task_id
|
taskId: task_id
|
||||||
});
|
});
|
||||||
this.props.toggle();
|
|
||||||
return userAPI.queryIOStatus(task_id);
|
return userAPI.queryIOStatus(task_id);
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.data.is_finished === true) {
|
if (res.data.is_finished === true) {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
location.href = siteRoot + 'api/v2.1/org/admin/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
location.href = siteRoot + 'api/v2.1/org/admin/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
||||||
} else {
|
} else {
|
||||||
this.timer = setInterval(() => {
|
this.queryIOStatus(task_id, logType);
|
||||||
userAPI.queryIOStatus(task_id).then(res => {
|
|
||||||
if (res.data.is_finished === true) {
|
|
||||||
clearInterval(this.timer);
|
|
||||||
location.href = siteRoot + 'api/v2.1/org/admin/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
|
||||||
}
|
|
||||||
}).catch(err => {
|
|
||||||
clearInterval(this.timer);
|
|
||||||
toaster.danger(gettext('Failed to export. Please check whether the size of table attachments exceeds the limit.'));
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.props.toggle();
|
|
||||||
if (error.response && error.response.status === 500) {
|
if (error.response && error.response.status === 500) {
|
||||||
const error_msg = error.response.data ? error.response.data['error_msg'] : null;
|
const error_msg = error.response.data ? error.response.data['error_msg'] : null;
|
||||||
if (error_msg && error_msg !== 'Internal Server Error') {
|
if (error_msg && error_msg !== 'Internal Server Error') {
|
||||||
@@ -77,7 +97,10 @@ class OrgLogsExportExcelDialog extends React.Component {
|
|||||||
let errMessage = Utils.getErrorMsg(error);
|
let errMessage = Utils.getErrorMsg(error);
|
||||||
toaster.danger(errMessage);
|
toaster.danger(errMessage);
|
||||||
}
|
}
|
||||||
|
this.props.toggle();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
isValidDateStr = () => {
|
isValidDateStr = () => {
|
||||||
@@ -111,8 +134,17 @@ class OrgLogsExportExcelDialog extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onExportToggle = (e) => {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: !this.state.isShowIODialog,
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
{!this.state.isShowIODialog &&
|
||||||
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
|
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
|
||||||
<ModalHeader toggle={this.props.toggle}>{gettext('Choose date')}</ModalHeader>
|
<ModalHeader toggle={this.props.toggle}>{gettext('Choose date')}</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
@@ -143,7 +175,13 @@ class OrgLogsExportExcelDialog extends React.Component {
|
|||||||
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
|
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
|
||||||
<Button color="primary" onClick={this.downloadExcel}>{gettext('Submit')}</Button>
|
<Button color="primary" onClick={this.downloadExcel}>{gettext('Submit')}</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Modal>
|
</Modal>}
|
||||||
|
{this.state.isShowIODialog &&
|
||||||
|
<SeahubIODialog
|
||||||
|
toggle={this.onExportToggle}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
frontend/src/components/dialog/seahub-io-dialog.js
Normal file
39
frontend/src/components/dialog/seahub-io-dialog.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Modal, ModalBody, ModalHeader } from 'reactstrap';
|
||||||
|
import { gettext } from '../../utils/constants';
|
||||||
|
import Loading from '../loading';
|
||||||
|
|
||||||
|
import '../../css/seahub-io-dialog.css';
|
||||||
|
|
||||||
|
|
||||||
|
const propTypes = {
|
||||||
|
toggle: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
class SeahubIODialog extends React.Component {
|
||||||
|
|
||||||
|
toggle = () => {
|
||||||
|
this.props.toggle();
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal className='seahub-io-dialog' isOpen={true} toggle={this.toggle}>
|
||||||
|
<ModalHeader toggle={this.toggle}>
|
||||||
|
{gettext('Exporting')}
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<>
|
||||||
|
<Loading/>
|
||||||
|
<div className="seahub-io-dialog-parsing-text">{gettext('Exporting...')}</div>
|
||||||
|
</>
|
||||||
|
</ModalBody>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SeahubIODialog.propTypes = propTypes;
|
||||||
|
|
||||||
|
export default SeahubIODialog;
|
@@ -7,6 +7,7 @@ import { systemAdminAPI } from '../../../utils/system-admin-api';
|
|||||||
import { userAPI } from '../../../utils/user-api';
|
import { userAPI } from '../../../utils/user-api';
|
||||||
import toaster from '../../../components/toast';
|
import toaster from '../../../components/toast';
|
||||||
import { Utils } from '../../../utils/utils';
|
import { Utils } from '../../../utils/utils';
|
||||||
|
import SeahubIODialog from '../../dialog/seahub-io-dialog';
|
||||||
|
|
||||||
class LogsExportExcelDialog extends React.Component {
|
class LogsExportExcelDialog extends React.Component {
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ class LogsExportExcelDialog extends React.Component {
|
|||||||
endDateStr: '',
|
endDateStr: '',
|
||||||
errMsg: '',
|
errMsg: '',
|
||||||
taskId: '',
|
taskId: '',
|
||||||
|
isShowIODialog: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,34 +43,51 @@ class LogsExportExcelDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
queryIOStatus = (task_id, logType) => {
|
||||||
|
userAPI.queryIOStatus(task_id).then(res => {
|
||||||
|
if (res.data.is_finished === true) {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
location.href = siteRoot + 'sys/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.queryIOStatus(task_id, logType);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
toaster.danger(gettext('Failed to export. Please check whether the size of table attachments exceeds the limit.'));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
sysExportLogs = (logType) => {
|
sysExportLogs = (logType) => {
|
||||||
let { startDateStr, endDateStr } = this.state;
|
let { startDateStr, endDateStr } = this.state;
|
||||||
let task_id = '';
|
let task_id = '';
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: true
|
||||||
|
}, () => {
|
||||||
systemAdminAPI.sysAdminExportLogsExcel(startDateStr, endDateStr, logType).then(res => {
|
systemAdminAPI.sysAdminExportLogsExcel(startDateStr, endDateStr, logType).then(res => {
|
||||||
task_id = res.data.task_id;
|
task_id = res.data.task_id;
|
||||||
this.setState({
|
this.setState({
|
||||||
taskId: task_id
|
taskId: task_id,
|
||||||
});
|
});
|
||||||
this.props.toggle();
|
|
||||||
return userAPI.queryIOStatus(task_id);
|
return userAPI.queryIOStatus(task_id);
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.data.is_finished === true) {
|
if (res.data.is_finished === true) {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false,
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
location.href = siteRoot + 'sys/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
location.href = siteRoot + 'sys/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
||||||
} else {
|
} else {
|
||||||
this.timer = setInterval(() => {
|
this.queryIOStatus(task_id, logType);
|
||||||
userAPI.queryIOStatus(task_id).then(res => {
|
|
||||||
if (res.data.is_finished === true) {
|
|
||||||
clearInterval(this.timer);
|
|
||||||
location.href = siteRoot + 'sys/log/export-excel/?task_id=' + task_id + '&log_type=' + logType;
|
|
||||||
}
|
|
||||||
}).catch(err => {
|
|
||||||
clearInterval(this.timer);
|
|
||||||
toaster.danger(gettext('Failed to export. Please check whether the size of table attachments exceeds the limit.'));
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.props.toggle();
|
|
||||||
if (error.response && error.response.status === 500) {
|
if (error.response && error.response.status === 500) {
|
||||||
const error_msg = error.response.data ? error.response.data['error_msg'] : null;
|
const error_msg = error.response.data ? error.response.data['error_msg'] : null;
|
||||||
if (error_msg && error_msg !== 'Internal Server Error') {
|
if (error_msg && error_msg !== 'Internal Server Error') {
|
||||||
@@ -80,6 +99,11 @@ class LogsExportExcelDialog extends React.Component {
|
|||||||
let errMessage = Utils.getErrorMsg(error);
|
let errMessage = Utils.getErrorMsg(error);
|
||||||
toaster.danger(errMessage);
|
toaster.danger(errMessage);
|
||||||
}
|
}
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: false
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,8 +138,17 @@ class LogsExportExcelDialog extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onExportToggle = (e) => {
|
||||||
|
this.setState({
|
||||||
|
isShowIODialog: !this.state.isShowIODialog,
|
||||||
|
});
|
||||||
|
this.props.toggle();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
{!this.state.isShowIODialog &&
|
||||||
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
|
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
|
||||||
<ModalHeader toggle={this.props.toggle}>{gettext('Choose date')}</ModalHeader>
|
<ModalHeader toggle={this.props.toggle}>{gettext('Choose date')}</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
@@ -146,7 +179,15 @@ class LogsExportExcelDialog extends React.Component {
|
|||||||
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
|
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
|
||||||
<Button color="primary" onClick={this.downloadExcel}>{gettext('Submit')}</Button>
|
<Button color="primary" onClick={this.downloadExcel}>{gettext('Submit')}</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
|
|
||||||
</Modal>
|
</Modal>
|
||||||
|
}
|
||||||
|
{this.state.isShowIODialog &&
|
||||||
|
<SeahubIODialog
|
||||||
|
toggle={this.onExportToggle}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
frontend/src/css/seahub-io-dialog.css
Normal file
12
frontend/src/css/seahub-io-dialog.css
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
.seahub-io-dialog .modal-body {
|
||||||
|
height: 142px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.seahub-io-dialog .modal-body .seahub-io-dialog-parsing-text {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 14px;
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
from datetime import datetime
|
||||||
from django.http import FileResponse
|
from django.http import FileResponse
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
@@ -16,6 +17,8 @@ from seahub.api2.throttling import UserRateThrottle
|
|||||||
from seahub.api2.utils import api_error
|
from seahub.api2.utils import api_error
|
||||||
from seahub.auth.decorators import login_required
|
from seahub.auth.decorators import login_required
|
||||||
from seahub.base.decorators import sys_staff_required
|
from seahub.base.decorators import sys_staff_required
|
||||||
|
from seahub.settings import ADMIN_LOGS_EXPORT_MAX_DAYS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SysLogsExport(APIView):
|
class SysLogsExport(APIView):
|
||||||
@@ -32,6 +35,15 @@ class SysLogsExport(APIView):
|
|||||||
error_msg = 'Failed to export excel, invalid start or end date.'
|
error_msg = 'Failed to export excel, invalid start or end date.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
|
start_date = datetime.strptime(start, '%Y-%m-%d')
|
||||||
|
end_date = datetime.strptime(end, '%Y-%m-%d')
|
||||||
|
if start_date > end_date:
|
||||||
|
error_msg = 'invalid start or end date'
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
if (end_date - start_date).days > ADMIN_LOGS_EXPORT_MAX_DAYS:
|
||||||
|
error_msg = 'Failed to export excel, only can export logs within %s days' % ADMIN_LOGS_EXPORT_MAX_DAYS
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
task_id = export_logs_to_excel(start, end, log_type)
|
task_id = export_logs_to_excel(start, end, log_type)
|
||||||
res_data = {'task_id': task_id}
|
res_data = {'task_id': task_id}
|
||||||
return Response(res_data)
|
return Response(res_data)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
from datetime import datetime
|
||||||
from django.http import FileResponse
|
from django.http import FileResponse
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@@ -17,6 +18,7 @@ from seahub.api2.utils import api_error
|
|||||||
from seahub.auth.decorators import login_required
|
from seahub.auth.decorators import login_required
|
||||||
from seahub.organizations.api.permissions import IsOrgAdmin
|
from seahub.organizations.api.permissions import IsOrgAdmin
|
||||||
from seahub.organizations.decorators import org_staff_required
|
from seahub.organizations.decorators import org_staff_required
|
||||||
|
from seahub.settings import ADMIN_LOGS_EXPORT_MAX_DAYS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +37,15 @@ class OrgLogsExport(APIView):
|
|||||||
if not check_time_period_valid(start, end):
|
if not check_time_period_valid(start, end):
|
||||||
error_msg = 'Failed to export excel, invalid start or end date.'
|
error_msg = 'Failed to export excel, invalid start or end date.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
|
start_date = datetime.strptime(start, '%Y-%m-%d')
|
||||||
|
end_date = datetime.strptime(end, '%Y-%m-%d')
|
||||||
|
if start_date > end_date:
|
||||||
|
error_msg = 'invalid start or end date'
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
if (end_date - start_date).days > ADMIN_LOGS_EXPORT_MAX_DAYS:
|
||||||
|
error_msg = 'Failed to export excel, only can export logs within %s days' % ADMIN_LOGS_EXPORT_MAX_DAYS
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
task_id = export_logs_to_excel(start, end, log_type, org_id)
|
task_id = export_logs_to_excel(start, end, log_type, org_id)
|
||||||
res_data = {'task_id': task_id}
|
res_data = {'task_id': task_id}
|
||||||
return Response(res_data)
|
return Response(res_data)
|
||||||
|
@@ -494,6 +494,9 @@ ENABLE_SEAFILE_DOCS = False
|
|||||||
|
|
||||||
ENABLE_CONVERT_TO_TEAM_ACCOUNT = False
|
ENABLE_CONVERT_TO_TEAM_ACCOUNT = False
|
||||||
|
|
||||||
|
|
||||||
|
ADMIN_LOGS_EXPORT_MAX_DAYS = 180
|
||||||
|
|
||||||
# File preview
|
# File preview
|
||||||
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
|
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
|
||||||
FILE_ENCODING_LIST = ['auto', 'utf-8', 'gbk', 'ISO-8859-1', 'ISO-8859-5']
|
FILE_ENCODING_LIST = ['auto', 'utf-8', 'gbk', 'ISO-8859-1', 'ISO-8859-5']
|
||||||
|
Reference in New Issue
Block a user