diff --git a/frontend/src/pages/my-libs/mylib-repo-menu.js b/frontend/src/pages/my-libs/mylib-repo-menu.js index 11b4755c8d..ea94fc1533 100644 --- a/frontend/src/pages/my-libs/mylib-repo-menu.js +++ b/frontend/src/pages/my-libs/mylib-repo-menu.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap'; -import { gettext, isPro, folderPermEnabled, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured } from '../../utils/constants'; +import { gettext, isPro, folderPermEnabled, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured, enableRepoAutoDel } from '../../utils/constants'; import { Utils } from '../../utils/utils'; const propTypes = { @@ -80,7 +80,7 @@ class MylibRepoMenu extends React.Component { if (this.props.isPC && enableRepoSnapshotLabel) { operations.push('Label Current State'); } - if (isPro) { + if (enableRepoAutoDel) { operations.push('Old Files Auto Delete'); } return operations; diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 7aa092940a..fab1e8cd69 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -20,6 +20,7 @@ export const serviceURL = window.app.config.serviceURL; export const appAvatarURL = window.app.config.avatarURL; export const faviconPath = window.app.config.faviconPath; export const loginBGPath = window.app.config.loginBGPath; +export const enableRepoAutoDel = window.app.config.enableRepoAutoDel; //pageOptions export const trashReposExpireDays = window.app.pageOptions.trashReposExpireDays; diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index 46bda2a51a..b4b0cf7dfb 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -32,7 +32,7 @@ from seahub.utils import get_site_name, get_service_url from seahub.avatar.templatetags.avatar_tags import api_avatar_url -from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, is_pro_version +from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, is_pro_version, ENABLE_REPO_AUTO_DEL try: from seahub.settings import MULTI_TENANCY @@ -154,6 +154,7 @@ def base(request): 'terms_of_service_link': TERMS_OF_SERVICE_LINK, 'side_nav_footer_custom_html': SIDE_NAV_FOOTER_CUSTOM_HTML, 'about_dialog_custom_html': ABOUT_DIALOG_CUSTOM_HTML, + 'enable_repo_auto_del': ENABLE_REPO_AUTO_DEL, } if request.user.is_staff: diff --git a/seahub/repo_auto_delete/management/commands/scan_repo_auto_delete.py b/seahub/repo_auto_delete/management/commands/scan_repo_auto_delete.py index 8e802a659c..6e923bfc8c 100644 --- a/seahub/repo_auto_delete/management/commands/scan_repo_auto_delete.py +++ b/seahub/repo_auto_delete/management/commands/scan_repo_auto_delete.py @@ -20,23 +20,22 @@ def iterate_and_del_files_recursively(repo_id, path, days): dirents = seafile_api.list_dir_by_path(repo_id, path) + del_dirents = list() for dirent in dirents: if stat.S_ISDIR(dirent.mode): - iterate_and_del_files_recursively(repo_id, - os.path.join(path, dirent.obj_name), - days) - continue - - mtime = dirent.mtime - cur_time = int(time.time()) - time_delta = days * 24 * 60 * 60 - if cur_time - time_delta > mtime: - file_full_path = os.path.join(path, dirent.obj_name) - seafile_api.del_file(repo_id, path, - json.dumps([dirent.obj_name]), - 'seafevents') - logger.info('{} of {} deleted at {}.'.format(file_full_path, repo_id, cur_time)) + iterate_and_del_files_recursively(repo_id, os.path.join(path, dirent.obj_name), days) + else: + mtime = dirent.mtime + cur_time = int(time.time()) + time_delta = days * 24 * 60 * 60 + if cur_time - time_delta > mtime: + del_dirents.append(dirent.obj_name) + if del_dirents: + try: + seafile_api.del_file(repo_id, path, json.dumps(del_dirents), 'seafevents') + except Exception as e: + logger.error('Failed to delete files in repo: %s, path: %s, error: %s' % (repo_id, path, e)) class Command(BaseCommand): diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html index 9b3e0da619..897dd8fd6a 100644 --- a/seahub/templates/base_for_react.html +++ b/seahub/templates/base_for_react.html @@ -47,6 +47,7 @@ isDocs: '{{ is_docs }}', lang: '{{ LANGUAGE_CODE }}', fileServerRoot: '{{ FILE_SERVER_ROOT }}', + enableRepoAutoDel: {% if enable_repo_auto_del %} true {% else %} false {% endif %}, useGoFileserver: {% if USE_GO_FILESERVER %} true {% else %} false {% endif %}, serviceURL: '{{ service_url }}', seafileVersion: '{{ seafile_version }}', diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index b065d0bdeb..70d8468c1c 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1171,6 +1171,21 @@ if EVENTS_CONFIG_FILE: HAS_FILE_SEARCH = check_search_enabled() +# repo auto delete related +ENABLE_REPO_AUTO_DEL = False +if EVENTS_CONFIG_FILE: + def check_repo_auto_del_enabled(): + enabled = False + if hasattr(seafevents, 'is_repo_auto_del_enabled'): + enabled = seafevents.is_repo_auto_del_enabled(EVENTS_CONFIG_FILE) + if enabled: + logging.debug('search: enabled') + else: + logging.debug('search: not enabled') + return enabled + + ENABLE_REPO_AUTO_DEL = check_repo_auto_del_enabled() + def is_user_password_strong(password): """Return ``True`` if user's password is STRONG, otherwise ``False``.