From d1b1cdd2e1afb6ee89c9a7fdfe2cba9baf9766e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?=
<11704063+s-yongqiang@user.noreply.gitee.com>
Date: Tue, 25 Mar 2025 11:44:13 +0800
Subject: [PATCH] optimize filter
---
.../src/pages/dashboard/log-user-selector.js | 15 +++-
.../sys-admin/logs-page/file-transfer-log.js | 77 ++++++++++++++++---
.../logs-page/share-permission-logs.js | 55 +++++++++----
frontend/src/utils/system-admin-api.js | 6 ++
seahub/api2/endpoints/admin/logs.py | 14 +++-
5 files changed, 136 insertions(+), 31 deletions(-)
diff --git a/frontend/src/pages/dashboard/log-user-selector.js b/frontend/src/pages/dashboard/log-user-selector.js
index e6e1617361..dc4f88a3e8 100644
--- a/frontend/src/pages/dashboard/log-user-selector.js
+++ b/frontend/src/pages/dashboard/log-user-selector.js
@@ -14,6 +14,7 @@ const propTypes = {
isOpen: PropTypes.bool.isRequired,
onToggle: PropTypes.func.isRequired,
searchUsersFunc: PropTypes.func.isRequired,
+ searchGroupsFunc: PropTypes.func
};
class LogUserSelector extends Component {
@@ -71,6 +72,15 @@ class LogUserSelector extends Component {
this.setState({
searchResults: users,
isLoading: false
+ }, () => {
+ if (this.props.searchGroupsFunc) {
+ this.props.searchGroupsFunc(value).then((res) => {
+ const groups = res.data.group_list || res.data.groups || [];
+ this.setState({
+ searchResults: [...users, ...groups]
+ });
+ });
+ }
});
}).catch((error) => {
this.setState({
@@ -132,7 +142,10 @@ class LogUserSelector extends Component {
) : (
displayItems.map((item, index) => {
- const isSelected = selectedItems.some(selected => selected.email === item.email);
+ const isSelected = selectedItems.some(selected =>
+ (item.email && selected.email === item.email) ||
+ (item.id && selected.id === item.id)
+ );
return (
{
- let { perPage, selectedFromUsers, selectedToUsers, selectedOperators, selectedRepos } = this.state;
+ let {
+ perPage,
+ selectedFromUsers,
+ selectedToUsers,
+ selectedToGroups,
+ selectedOperators,
+ selectedRepos
+ } = this.state;
+
const emails = {
from_emails: selectedFromUsers.map(user => user.email),
to_emails: selectedToUsers.map(user => user.email),
+ to_groups: selectedToGroups.map(group => group.to_group_id || group.id),
operator_emails: selectedOperators.map(user => user.email)
};
@@ -246,23 +256,51 @@ class FIleTransferLogs extends Component {
});
};
- handleToUserFilter = (user, shouldFetchData = true) => {
- const { selectedToUsers } = this.state;
- let newSelectedUsers;
+ handleToUserFilter = (item, shouldFetchData = true) => {
+ const { selectedToUsers, selectedToGroups } = this.state;
+ let newSelectedUsers = selectedToUsers;
+ let newSelectedGroups = selectedToGroups;
- if (user === null) {
+ if (item === null) {
newSelectedUsers = selectedToUsers;
+ newSelectedGroups = selectedToGroups;
} else {
- const isSelected = selectedToUsers.find(item => item.email === user.email);
- if (isSelected) {
- newSelectedUsers = selectedToUsers.filter(item => item.email !== user.email);
+ if (item.email) {
+ const isSelected = selectedToUsers.find(user => user.email === item.email);
+ if (isSelected) {
+ newSelectedUsers = selectedToUsers.filter(user => user.email !== item.email);
+ } else {
+ newSelectedUsers = [...selectedToUsers, item];
+ }
} else {
- newSelectedUsers = [...selectedToUsers, user];
+ const groupId = item.to_group_id || item.id;
+ const groupName = item.to_group_name || item.name;
+
+ const isSelected = selectedToGroups.find(group => {
+ const selectedGroupId = group.to_group_id || group.id;
+ return selectedGroupId === groupId;
+ });
+
+ if (isSelected) {
+ newSelectedGroups = selectedToGroups.filter(group => {
+ const selectedGroupId = group.to_group_id || group.id;
+ return selectedGroupId !== groupId;
+ });
+ } else {
+ const groupItem = {
+ id: groupId,
+ name: groupName,
+ to_group_id: groupId,
+ to_group_name: groupName
+ };
+ newSelectedGroups = [...selectedToGroups, groupItem];
+ }
}
}
this.setState({
selectedToUsers: newSelectedUsers,
+ selectedToGroups: newSelectedGroups,
currentPage: 1
}, () => {
if (shouldFetchData) {
@@ -339,6 +377,10 @@ class FIleTransferLogs extends Component {
return systemAdminAPI.sysAdminSearchUsers(value);
};
+ searchGroups = (value) => {
+ return systemAdminAPI.sysAdminSearchGroups(value);
+ };
+
searchRepos = (value) => {
return systemAdminAPI.sysAdminSearchRepos(value);
};
@@ -346,11 +388,23 @@ class FIleTransferLogs extends Component {
render() {
let {
logList, currentPage, perPage, hasNextPage,
- availableUsers, selectedFromUsers, selectedToUsers, selectedOperators,
+ availableUsers, selectedFromUsers,
+ selectedToUsers, selectedToGroups,
+ selectedOperators,
availableRepos, selectedRepos,
openSelector
} = this.state;
+ const selectedToItems = [
+ ...selectedToUsers,
+ ...selectedToGroups.map(group => ({
+ id: group.to_group_id || group.id,
+ name: group.to_group_name || group.name,
+ to_group_id: group.to_group_id || group.id,
+ to_group_name: group.to_group_name || group.name
+ }))
+ ];
+
return (
@@ -372,11 +426,12 @@ class FIleTransferLogs extends Component {
this.handleSelectorToggle('toUser')}
searchUsersFunc={this.searchUsers}
+ searchGroupsFunc={this.searchGroups}
/>
{
- let { perPage, selectedFromUsers, selectedToUsers, selectedRepos } = this.state;
- let fromEmails = selectedFromUsers.map(user => user.email);
- let toEmails = selectedToUsers.map(user => user.email);
+ let {
+ perPage,
+ selectedFromUsers,
+ selectedToUsers,
+ selectedToGroups,
+ selectedRepos
+ } = this.state;
+
const emails = {
- from_emails: fromEmails,
- to_emails: toEmails
+ from_emails: selectedFromUsers.map(user => user.email),
+ to_emails: selectedToUsers.map(user => user.email),
+ to_groups: selectedToGroups.map(group => group.id)
};
+
systemAdminAPI.sysAdminListSharePermissionLogs(
page,
perPage,
@@ -237,23 +245,35 @@ class SharePermissionLogs extends Component {
});
};
- handleToUserFilter = (user, shouldFetchData = true) => {
- const { selectedToUsers } = this.state;
- let newSelectedUsers;
+ handleToUserFilter = (item, shouldFetchData = true) => {
+ const { selectedToUsers, selectedToGroups } = this.state;
+ let newSelectedUsers = selectedToUsers;
+ let newSelectedGroups = selectedToGroups;
- if (user === null) {
+ if (item === null) {
newSelectedUsers = selectedToUsers;
+ newSelectedGroups = selectedToGroups;
} else {
- const isSelected = selectedToUsers.find(item => item.email === user.email);
- if (isSelected) {
- newSelectedUsers = selectedToUsers.filter(item => item.email !== user.email);
+ if (item.email) {
+ const isSelected = selectedToUsers.find(user => user.email === item.email);
+ if (isSelected) {
+ newSelectedUsers = selectedToUsers.filter(user => user.email !== item.email);
+ } else {
+ newSelectedUsers = [...selectedToUsers, item];
+ }
} else {
- newSelectedUsers = [...selectedToUsers, user];
+ const isSelected = selectedToGroups.find(group => group.id === item.id);
+ if (isSelected) {
+ newSelectedGroups = selectedToGroups.filter(group => group.id !== item.id);
+ } else {
+ newSelectedGroups = [...selectedToGroups, item];
+ }
}
}
this.setState({
selectedToUsers: newSelectedUsers,
+ selectedToGroups: newSelectedGroups,
currentPage: 1
}, () => {
if (shouldFetchData) {
@@ -308,11 +328,15 @@ class SharePermissionLogs extends Component {
return systemAdminAPI.sysAdminSearchRepos(value);
};
+ searchGroups = (value) => {
+ return systemAdminAPI.sysAdminSearchGroups(value);
+ };
+
render() {
let {
logList, currentPage, perPage, hasNextPage, isExportExcelDialogOpen,
availableUsers, selectedFromUsers, selectedToUsers,
- availableRepos, selectedRepos, openSelector
+ selectedToGroups, availableRepos, selectedRepos, openSelector
} = this.state;
return (
@@ -337,11 +361,12 @@ class SharePermissionLogs extends Component {
this.handleSelectorToggle('toUser')}
searchUsersFunc={this.searchUsers}
+ searchGroupsFunc={this.searchGroups}
/>
repo.id).join(',');
}
@@ -755,6 +758,9 @@ class SystemAdminAPI {
if (emails.operator_emails && emails.operator_emails.length) {
params.operator_emails = emails.operator_emails.join(',');
}
+ if (emails.to_groups && emails.to_groups.length) {
+ params.to_groups = emails.to_groups.join(',');
+ }
if (repos && repos.length) {
params.repos = repos.map(repo => repo.id).join(',');
}
diff --git a/seahub/api2/endpoints/admin/logs.py b/seahub/api2/endpoints/admin/logs.py
index be1f41c2fb..f3ca3f2c82 100644
--- a/seahub/api2/endpoints/admin/logs.py
+++ b/seahub/api2/endpoints/admin/logs.py
@@ -314,9 +314,13 @@ class AdminLogsSharePermissionLogs(APIView):
if not is_valid_email(user_selected):
error_msg = 'email %s invalid.' % user_selected
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
+
+ to_groups = request.GET.get('to_groups')
+ to_groups = to_groups.split(',') if to_groups else []
emails = {
'from_emails': from_emails,
- 'to_emails': to_emails
+ 'to_emails': to_emails,
+ 'to_groups': to_groups
}
repos = request.GET.get('repos', None)
@@ -489,7 +493,9 @@ class AdminLogsFileTransferLogs(APIView):
if not is_valid_email(user_selected):
error_msg = 'email %s invalid.' % user_selected
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
-
+ to_groups = request.GET.get('to_groups')
+ to_groups = to_groups.split(',') if to_groups else []
+ to_groups = [group_id + '@seafile_group' for group_id in to_groups]
repos = request.GET.get('repos', None)
if repos:
repos = repos.split(',')
@@ -501,8 +507,8 @@ class AdminLogsFileTransferLogs(APIView):
queryset = RepoTransfer.objects.all()
if from_emails:
queryset = queryset.by_from_user(from_emails)
- if to_emails:
- queryset = queryset.by_to_user(to_emails)
+ if to_emails or to_groups:
+ queryset = queryset.by_to_user(to_emails + to_groups)
if operator_emails:
queryset = queryset.by_operator(operator_emails)
if repos: