mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
add office file editOnCloud and download (#3716)
* add office file editOnCloud and download * modify some details
This commit is contained in:
@@ -36,6 +36,7 @@ class GenerateShareLink extends React.Component {
|
||||
sendLinkEmails: '',
|
||||
sendLinkMessage: '',
|
||||
sendLinkErrorMessage: '',
|
||||
fileInfo: null,
|
||||
};
|
||||
this.permissions = {
|
||||
'can_edit': false,
|
||||
@@ -58,6 +59,12 @@ class GenerateShareLink extends React.Component {
|
||||
this.setState({isLoading: false});
|
||||
}
|
||||
});
|
||||
|
||||
seafileAPI.getFileInfo(repoID, path).then((res) => {
|
||||
if (res.data) {
|
||||
this.setState({fileInfo: res.data});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onPasswordInputChecked = () => {
|
||||
@@ -99,11 +106,16 @@ class GenerateShareLink extends React.Component {
|
||||
'can_edit': false,
|
||||
'can_download': true
|
||||
};
|
||||
} else {
|
||||
} else if (permission == 'preview') {
|
||||
this.permissions = {
|
||||
'can_edit': false,
|
||||
'can_download': false
|
||||
};
|
||||
} else if (permission == 'editOnCloudAndDownload'){
|
||||
this.permissions = {
|
||||
'can_edit': true,
|
||||
'can_download': true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,6 +383,7 @@ class GenerateShareLink extends React.Component {
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
let fileInfo = this.state.fileInfo;
|
||||
return (
|
||||
<Form className="generate-share-link">
|
||||
<FormGroup check>
|
||||
@@ -446,6 +459,13 @@ class GenerateShareLink extends React.Component {
|
||||
<Input type="radio" name="radio1" onChange={() => this.setPermission('preview')} />{' '}{gettext('Preview only')}
|
||||
</Label>
|
||||
</FormGroup>
|
||||
{(Utils.isOfficeFile(this.props.itemPath) && fileInfo && fileInfo.can_edit) &&
|
||||
<FormGroup check className="permission">
|
||||
<Label>
|
||||
<Input type="radio" name="radio1" onChange={() => this.setPermission('editOnCloudAndDownload')} />{' '}{gettext('Edit on cloud and download')}
|
||||
</Label>
|
||||
</FormGroup>
|
||||
}
|
||||
{this.state.errorInfo && <Alert color="danger" className="mt-2">{gettext(this.state.errorInfo)}</Alert>}
|
||||
<Button onClick={this.generateShareLink}>{gettext('Generate')}</Button>
|
||||
</Form>
|
||||
|
@@ -104,6 +104,20 @@ export const Utils = {
|
||||
}
|
||||
},
|
||||
|
||||
isOfficeFile: function(filename) {
|
||||
// no file ext
|
||||
if (filename.lastIndexOf('.') == -1) {
|
||||
return false;
|
||||
}
|
||||
var file_ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
|
||||
var exts = ['doc', 'ppt', 'xls', 'docx', 'pptx', 'xlsx'];
|
||||
if (exts.indexOf(file_ext) != -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// check if a file is a video
|
||||
videoCheck: function (filename) {
|
||||
// no file ext
|
||||
|
@@ -89,7 +89,7 @@ from seahub.utils.timeutils import utc_to_local, \
|
||||
timestamp_to_isoformat_timestr
|
||||
from seahub.views import is_registered_user, check_folder_permission, \
|
||||
create_default_library, list_inner_pub_repos
|
||||
from seahub.views.file import get_file_view_path_and_perm, send_file_access_msg
|
||||
from seahub.views.file import get_file_view_path_and_perm, send_file_access_msg, can_edit_file
|
||||
if HAS_FILE_SEARCH:
|
||||
from seahub_extra.search.utils import search_files, get_search_repos_map, SEARCH_FILEEXT
|
||||
from seahub.utils import HAS_OFFICE_CONVERTER
|
||||
@@ -3156,10 +3156,11 @@ class FileDetailView(APIView):
|
||||
entry["last_modifier_contact_email"] = email2contact_email(latest_contributor)
|
||||
|
||||
try:
|
||||
entry["size"] = get_file_size(real_repo_id, repo.version, obj_id)
|
||||
file_size = get_file_size(real_repo_id, repo.version, obj_id)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
entry["size"] = 0
|
||||
file_size = 0
|
||||
entry["size"] = file_size
|
||||
|
||||
starred_files = UserStarredFiles.objects.filter(repo_id=repo_id,
|
||||
path=path)
|
||||
@@ -3168,6 +3169,8 @@ class FileDetailView(APIView):
|
||||
comment_total = file_comments.count()
|
||||
entry["comment_total"] = comment_total
|
||||
|
||||
entry["can_edit"], _ = can_edit_file(file_name, file_size, repo)
|
||||
|
||||
return Response(entry)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user