1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 13:24:52 +00:00

delete repo index (#5884)

* delete repo index

* fix index permission
This commit is contained in:
JoinTyang
2024-01-09 18:23:11 +08:00
committed by GitHub
parent 52a58124ed
commit 61ffe21ff4
4 changed files with 39 additions and 15 deletions

View File

@@ -4,7 +4,7 @@ import isHotkey from 'is-hotkey';
import classnames from 'classnames';
import MediaQuery from 'react-responsive';
import { seafileAPI } from '../../utils/seafile-api';
import { gettext, siteRoot } from '../../utils/constants';
import { gettext, siteRoot, username } from '../../utils/constants';
import SearchResultItem from './search-result-item';
import { Utils } from '../../utils/utils';
import { isMac } from '../../utils/extra-attributes';
@@ -35,6 +35,7 @@ export default class AISearch extends Component {
placeholder: PropTypes.string,
onSearchedClick: PropTypes.func.isRequired,
repoName: PropTypes.string,
currentRepoInfo: PropTypes.object,
};
constructor(props) {
@@ -66,6 +67,8 @@ export default class AISearch extends Component {
this.indexStateTimer = null;
this.timer = null;
this.isChineseInput = false;
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
this.isAdmin = props.currentRepoInfo.is_admin;
}
componentDidMount() {
@@ -517,7 +520,7 @@ export default class AISearch extends Component {
this.setState({ indexState: INDEX_STATE.RUNNING });
seafileAPI.createLibraryIndex(this.props.repoID).then(res => {
const taskId = res.data.task_id;
toaster.notify(gettext('Indexing the library. Semantic search will be available within a few minutes.'))
toaster.notify(gettext('Indexing the library. Semantic search will be available within a few minutes.'));
this.queryIndexTaskStatus(taskId);
}).catch(error => {
const errorMsg = Utils.getErrorMsg(error);
@@ -526,9 +529,19 @@ export default class AISearch extends Component {
});
};
onDeleteIndex = () => {
seafileAPI.deleteLibraryIndex(this.props.repoID).then(res => {
toaster.notify(gettext('Successfully turned off'));
this.setState({ indexState: INDEX_STATE.UNCREATED });
}).catch(error => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
};
renderSwitch = () => {
const { indexState } = this.state;
if (indexState === INDEX_STATE.FINISHED || indexState === INDEX_STATE.RUNNING) {
if (indexState === INDEX_STATE.RUNNING) {
return (
<Switch
checked={true}
@@ -539,6 +552,17 @@ export default class AISearch extends Component {
disabled
/>
);
} else if (indexState === INDEX_STATE.FINISHED) {
return (
<Switch
checked={true}
placeholder={gettext('Turn off semantic search for this library')}
className="w-100 mt-1"
size="small"
onChange={this.onDeleteIndex}
textPosition='right'
/>
);
} else if (indexState === '' || indexState === INDEX_STATE.UNCREATED) {
return (
<Switch
@@ -603,7 +627,7 @@ export default class AISearch extends Component {
onScroll={this.onResultListScroll}
ref={this.searchContainer}
>
{isCloseShow && this.renderSwitch()}
{isCloseShow && (this.isRepoOwner || this.isAdmin) && this.renderSwitch()}
{this.renderSearchResult()}
</div>
</div>

View File

@@ -13,7 +13,8 @@ const propTypes = {
repoName: PropTypes.string,
isLibView: PropTypes.bool,
onSearchedClick: PropTypes.func.isRequired,
searchPlaceholder: PropTypes.string
searchPlaceholder: PropTypes.string,
currentRepoInfo: PropTypes.object,
};
class CommonToolbar extends React.Component {
@@ -30,6 +31,7 @@ class CommonToolbar extends React.Component {
placeholder={placeholder}
onSearchedClick={this.props.onSearchedClick}
repoName={repoName}
currentRepoInfo={this.props.currentRepoInfo}
/>
);
} else {

View File

@@ -142,6 +142,7 @@ class LibContentToolbar extends React.Component {
isLibView={true}
repoID={this.props.repoID}
repoName={this.props.repoName}
currentRepoInfo={this.props.currentRepoInfo}
onSearchedClick={this.props.onSearchedClick}
searchPlaceholder={gettext('Search files')}
/>

View File

@@ -14,8 +14,7 @@ from seahub.api2.throttling import UserRateThrottle
from seahub.api2.authentication import TokenAuthentication, SeafileAiAuthentication
from seahub.api2.utils import api_error
from seahub.views import check_folder_permission
from seahub.utils.repo import parse_repo_perm, is_valid_repo_id_format
from seahub.utils.repo import is_valid_repo_id_format, is_repo_admin
from seahub.ai.utils import create_library_sdoc_index, search, update_library_sdoc_index, \
delete_library_index, query_task_status, query_library_index_state, question_answering_search_in_library,\
get_file_download_token, get_search_repos, RELATED_REPOS_PREFIX, RELATED_REPOS_CACHE_TIMEOUT, SEARCH_REPOS_LIMIT, \
@@ -43,10 +42,7 @@ class LibrarySdocIndexes(APIView):
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
parent_dir = '/'
# permission check
if parse_repo_perm(check_folder_permission(request, repo_id, parent_dir)).can_download is False:
if not is_repo_admin(request.user.username, repo_id):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
@@ -216,10 +212,7 @@ class LibrarySdocIndex(APIView):
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
parent_dir = '/'
# permission check
if parse_repo_perm(check_folder_permission(request, repo_id, parent_dir)).can_download is False:
if not is_repo_admin(request.user.username, repo_id):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
@@ -244,6 +237,10 @@ class LibrarySdocIndex(APIView):
if not repo_id:
return api_error(status.HTTP_400_BAD_REQUEST, 'repo_id invalid')
if not is_repo_admin(request.user.username, repo_id):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
try:
resp = delete_library_index(repo_id)
if resp.status_code == 500: