1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

only display hashing toggle on user permissions

This commit is contained in:
Tim Daubenschütz 2015-07-27 15:34:45 +02:00
parent b105e77009
commit d52a89cd3e
4 changed files with 21 additions and 14 deletions

View File

@ -174,7 +174,7 @@ let FileUploader = React.createClass({
}
}}
multiple={false}
localHashing={false} />
enableLocalHashing={true} />
);
}
});

View File

@ -30,7 +30,7 @@ let FileDragAndDrop = React.createClass({
areAssetsDownloadable: React.PropTypes.bool,
areAssetsEditable: React.PropTypes.bool,
localHashing: React.PropTypes.bool,
enableLocalHashing: React.PropTypes.bool,
// triggers a FileDragAndDrop-global spinner
hashingProgress: React.PropTypes.number,
@ -177,7 +177,7 @@ let FileDragAndDrop = React.createClass({
multipleFiles={this.props.multiple}
hasFiles={hasFiles}
onClick={this.handleOnClick}
localHashing={this.props.localHashing}/>
enableLocalHashing={this.props.enableLocalHashing}/>
<FileDragAndDropPreviewIterator
files={this.props.filesToUpload}
handleDeleteFile={this.handleDeleteFile}

View File

@ -3,8 +3,6 @@
import React from 'react';
import Router from 'react-router';
import ButtonLink from 'react-router-bootstrap/lib/ButtonLink';
import { getLangText } from '../../utils/lang_utils';
let Link = Router.Link;
@ -14,7 +12,7 @@ let FileDragAndDropDialog = React.createClass({
hasFiles: React.PropTypes.bool,
multipleFiles: React.PropTypes.bool,
onClick: React.PropTypes.func,
localHashing: React.PropTypes.bool
enableLocalHashing: React.PropTypes.bool
},
mixins: [Router.State],
@ -25,7 +23,7 @@ let FileDragAndDropDialog = React.createClass({
if(this.props.hasFiles) {
return null;
} else {
if(!queryParams.method) {
if(this.props.enableLocalHashing && !queryParams.method) {
let queryParamsHash = Object.assign({}, queryParams);
queryParamsHash.method = 'hash';

View File

@ -1,6 +1,7 @@
'use strict';
import React from 'react/addons';
import Router from 'react-router';
import Raven from 'raven-js';
import Q from 'q';
@ -106,9 +107,14 @@ var ReactS3FineUploader = React.createClass({
// the file in the browser using md5 and then uploading the resulting text document instead
// of the actual file.
// This boolean essentially enables that behavior
localHashing: React.PropTypes.bool
enableLocalHashing: React.PropTypes.bool,
// automatically injected by React-Router
query: React.PropTypes.object
},
mixins: [Router.State],
getDefaultProps() {
return {
autoUpload: true,
@ -167,10 +173,10 @@ var ReactS3FineUploader = React.createClass({
};
},
// since the csrf header is defined in this component's props,
// everytime the csrf cookie is changed we'll need to reinitalize
// fineuploader and update the actual csrf token
componentWillUpdate() {
// since the csrf header is defined in this component's props,
// everytime the csrf cookie is changed we'll need to reinitalize
// fineuploader and update the actual csrf token
let potentiallyNewCSRFToken = getCookie(AppConstants.csrftoken);
if(this.state.csrfToken !== potentiallyNewCSRFToken) {
this.setState({
@ -511,8 +517,11 @@ var ReactS3FineUploader = React.createClass({
// As mentioned already in the propTypes declaration, in some instances we need to calculate the
// md5 hash of a file locally and just upload a txt file containing that hash.
// This if statement essentially takes care of that solution.
if(this.props.localHashing) {
//
// In the view this only happens when the user is allowed to do local hashing as well
// as when the correct query parameter is present in the url ('hash' and not 'upload')
let queryParams = this.getQuery();
if(this.props.enableLocalHashing && queryParams && queryParams.method === 'hash') {
let convertedFilePromises = [];
let overallFileSize = 0;
@ -704,7 +713,7 @@ var ReactS3FineUploader = React.createClass({
areAssetsEditable={this.props.areAssetsEditable}
dropzoneInactive={!this.props.areAssetsEditable || !this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1).length > 0}
hashingProgress={this.state.hashingProgress}
localHashing={this.props.localHashing} />
enableLocalHashing={this.props.enableLocalHashing} />
</div>
);
}