Skip to content

Commit

Permalink
fix-uni-test-and-code-optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
r350178982 committed Jul 2, 2024
1 parent 8346741 commit 5987b11
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
16 changes: 8 additions & 8 deletions frontend/src/components/dialog/clean-trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class CleanTrash extends React.Component {
submitBtnDisabled: true
});
seafileAPI.deleteRepoTrash(repoID, inputValue.value).then((res) => {
if (this.props.trashType === 0) {
this.props.refreshTrash2();
}
if (this.props.trashType === 1) {
this.props.refreshTrash();
}
this.props.toggleDialog();
toaster.success(gettext('Clean succeeded.'));
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
this.setState({
Expand All @@ -52,14 +60,6 @@ class CleanTrash extends React.Component {
});
});

if (this.props.trashType === 0){
this.props.refreshTrash2();
}
if (this.props.trashType === 1){
this.props.refreshTrash();
}
this.props.toggleDialog();
toaster.success(gettext('Clean succeeded.'));
};

render() {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/dialog/select-trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ class SelectTrash extends React.Component {
formSubmit = ()=>{
const inputValue = this.state.inputValue;
if (inputValue.value === 1){
this.OldTrash();
this.listOldTrash();
}
if (inputValue.value === 0){
this.NewTrash();
this.listNewTrash();
}
this.props.changeTrash(this.state.inputValue.value);
};

OldTrash = ()=>{
listOldTrash = ()=>{
this.props.refreshTrash();
this.props.toggleDialog();
};
NewTrash = () => {

listNewTrash = () => {
this.props.refreshTrash2();
this.props.toggleDialog();
};

render() {
return (
<Modal isOpen={true} centered={true} toggle={this.props.toggleDialog}>
<ModalHeader toggle={this.props.toggleDialog}>{gettext('Old Trash')}</ModalHeader>
<ModalHeader toggle={this.props.toggleDialog}>{gettext('Select trash')}</ModalHeader>
<ModalBody>
<React.Fragment>
<p>{gettext('Select Trash')}</p>
<CreatableSelect
defaultValue={this.options[this.props.trashType]}
options={this.options}
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/repo-folder-trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ class RepoFolderTrash extends React.Component {
</a>
<div className="d-flex justify-content-between align-items-center op-bar">
<p className="m-0 text-truncate d-flex"><span className="mr-1">{gettext('Current path: ')}</span>{showFolder ? this.renderFolderPath() : <span className="text-truncate" title={repoFolderName}>{repoFolderName}</span>}</p>

<button className="btn btn-secondary clean flex-shrink-0 ml-4"
onClick={this.getOldTrash}>{gettext('Select Trash')}</button>
{(path == '/' && enableClean && !showFolder && isRepoAdmin) &&
<button className="btn btn-secondary clean flex-shrink-0 ml-4" onClick={this.cleanTrash}>{gettext('Clean')}</button>

}
<div className="d-flex">
<button className="btn btn-secondary clean flex-shrink-0 ml-4"
onClick={this.getOldTrash}>{gettext('Select trash')}</button>
{(path == '/' && enableClean && !showFolder && isRepoAdmin) &&
<button className="btn btn-secondary clean flex-shrink-0 ml-4" onClick={this.cleanTrash}>{gettext('Clean')}</button>
}
</div>
</div>
<Content
data={this.state}
Expand Down
5 changes: 1 addition & 4 deletions seahub/api2/endpoints/repo_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@ def delete(self, request, repo_id, format=None):
return api_error(status.HTTP_403_FORBIDDEN, error_msg)

try:
from seahub.utils import SeafEventsSession, seafevents_api
seafile_api.clean_up_repo_history(repo_id, keep_days)
org_id = None if not request.user.org else request.user.org.org_id
clean_up_repo_trash.send(sender=None, org_id=org_id,
operator=username, repo_id=repo_id, repo_name=repo.name,
repo_owner=repo_owner, days=keep_days)
session = SeafEventsSession()
seafevents_api.clean_up_repo_trash(session, repo_id, keep_days)
session.close()

except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
Expand Down
7 changes: 6 additions & 1 deletion seahub/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ def clean_up_repo_trash_cb(sender, **kwargs):

from .utils import SeafEventsSession
session = SeafEventsSession()
seafevents_api.save_user_activity(session, record)
try:
seafevents_api.save_user_activity(session, record)
seafevents_api.clean_up_repo_trash(session, repo_id, days)
except Exception as e:
logger.error(e)

session.close()

def repo_restored_cb(sender, **kwargs):
Expand Down

0 comments on commit 5987b11

Please sign in to comment.