1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 05:31:58 +02:00

Merged in AD-984-disable-contracts-for-regular-asc (pull request #64)

acl on contract settings
This commit is contained in:
TimDaubenschuetz 2015-09-18 15:20:08 +02:00
commit 26321571cb
4 changed files with 118 additions and 99 deletions

View File

@ -2,9 +2,6 @@
import React from 'react'; import React from 'react';
import UserStore from '../../stores/user_store';
import UserActions from '../../actions/user_actions';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
@ -19,38 +16,26 @@ import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
let AccountSettings = React.createClass({ let AccountSettings = React.createClass({
getInitialState() { propTypes: {
return UserStore.getState(); currentUser: React.PropTypes.object.required,
}, loadUser: React.PropTypes.func.required
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
}, },
handleSuccess(){ handleSuccess(){
UserActions.fetchCurrentUser(); this.props.loadUser();
let notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000); let notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
}, },
getFormDataProfile(){ getFormDataProfile(){
return {'email': this.state.currentUser.email}; return {'email': this.props.currentUser.email};
}, },
render() { render() {
let content = <img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />; let content = <img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />;
let profile = null; let profile = null;
if (this.state.currentUser.username) { if (this.props.currentUser.username) {
content = ( content = (
<Form <Form
url={ApiUrls.users_username} url={ApiUrls.users_username}
@ -60,7 +45,7 @@ let AccountSettings = React.createClass({
label={getLangText('Username')}> label={getLangText('Username')}>
<input <input
type="text" type="text"
defaultValue={this.state.currentUser.username} defaultValue={this.props.currentUser.username}
placeholder={getLangText('Enter your username')} placeholder={getLangText('Enter your username')}
required/> required/>
</Property> </Property>
@ -70,7 +55,7 @@ let AccountSettings = React.createClass({
editable={false}> editable={false}>
<input <input
type="text" type="text"
defaultValue={this.state.currentUser.email} defaultValue={this.props.currentUser.email}
placeholder={getLangText('Enter your username')} placeholder={getLangText('Enter your username')}
required/> required/>
</Property> </Property>
@ -87,7 +72,7 @@ let AccountSettings = React.createClass({
className="ascribe-settings-property-collapsible-toggle" className="ascribe-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}> style={{paddingBottom: 0}}>
<InputCheckbox <InputCheckbox
defaultChecked={this.state.currentUser.profile.hash_locally}> defaultChecked={this.props.currentUser.profile.hash_locally}>
<span> <span>
{' ' + getLangText('Enable hash option, e.g. slow connections or to keep piece private')} {' ' + getLangText('Enable hash option, e.g. slow connections or to keep piece private')}
</span> </span>

View File

@ -14,11 +14,14 @@ import ContractSettingsUpdateButton from './contract_settings_update_button';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
import AclProxy from '../acl_proxy';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
let ContractSettings = React.createClass({ let ContractSettings = React.createClass({
propTypes: { propTypes: {
currentUser: React.PropTypes.object,
defaultExpanded: React.PropTypes.bool defaultExpanded: React.PropTypes.bool
}, },
@ -72,87 +75,93 @@ let ContractSettings = React.createClass({
<CreateContractForm <CreateContractForm
isPublic={true} isPublic={true}
fileClassToUpload={{ fileClassToUpload={{
singular: 'new public contract', singular: 'new contract',
plural: 'new public contracts' plural: 'new contracts'
}}/> }}/>
); );
} }
return ( return (
<CollapsibleParagraph <AclProxy
title={getLangText('Contracts')} aclName="acl_view_contract_settings"
show={true} aclObject={this.props.currentUser.acl}>
defaultExpanded={true}>
<CollapsibleParagraph <CollapsibleParagraph
title={getLangText('Public Contracts')} title={getLangText('Contracts')}
show={true} show={true}
defaultExpanded={true}> defaultExpanded={true}>
{createPublicContractForm} <AclProxy
{publicContracts.map((contract, i) => { aclName="acl_edit_public_contract"
return ( aclObject={this.props.currentUser.acl}>
<ActionPanel <div>
key={i} {createPublicContractForm}
title={contract.name} {publicContracts.map((contract, i) => {
content={contract.name} return (
buttons={ <ActionPanel
<div className="pull-right"> key={i}
<ContractSettingsUpdateButton contract={contract}/> title={contract.name}
<a content={contract.name}
className="btn btn-default btn-sm margin-left-2px" buttons={
href={contract.blob.url_safe} <div className="pull-right">
target="_blank"> <ContractSettingsUpdateButton contract={contract}/>
{getLangText('PREVIEW')} <a
</a> className="btn btn-default btn-sm margin-left-2px"
<button href={contract.blob.url_safe}
className="btn btn-default btn-sm margin-left-2px" target="_blank">
onClick={this.removeContract(contract)}> {getLangText('PREVIEW')}
{getLangText('REMOVE')} </a>
</button> <button
</div> className="btn btn-default btn-sm margin-left-2px"
} onClick={this.removeContract(contract)}>
leftColumnWidth="40%" {getLangText('REMOVE')}
rightColumnWidth="60%"/> </button>
); </div>
})} }
leftColumnWidth="40%"
rightColumnWidth="60%"/>
);
})}
</div>
</AclProxy>
<AclProxy
aclName="acl_edit_private_contract"
aclObject={this.props.currentUser.acl}>
<div>
<CreateContractForm
isPublic={false}
fileClassToUpload={{
singular: getLangText('new contract'),
plural: getLangText('new contracts')
}}/>
{privateContracts.map((contract, i) => {
return (
<ActionPanel
key={i}
title={contract.name}
content={contract.name}
buttons={
<div className="pull-right">
<ContractSettingsUpdateButton contract={contract} />
<a
className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe}
target="_blank">
{getLangText('PREVIEW')}
</a>
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
{getLangText('REMOVE')}
</button>
</div>
}
leftColumnWidth="40%"
rightColumnWidth="60%"/>
);
})}
</div>
</AclProxy>
</CollapsibleParagraph> </CollapsibleParagraph>
<CollapsibleParagraph </AclProxy>
title={getLangText('Private Contracts')}
show={true}
defaultExpanded={true}>
<CreateContractForm
isPublic={false}
fileClassToUpload={{
singular: getLangText('new private contract'),
plural: getLangText('new private contracts')
}}/>
{privateContracts.map((contract, i) => {
return (
<ActionPanel
key={i}
title={contract.name}
content={contract.name}
buttons={
<div className="pull-right">
<ContractSettingsUpdateButton contract={contract} />
<a
className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe}
target="_blank">
{getLangText('PREVIEW')}
</a>
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
{getLangText('REMOVE')}
</button>
</div>
}
leftColumnWidth="40%"
rightColumnWidth="60%"/>
);
})}
</CollapsibleParagraph>
</CollapsibleParagraph>
); );
} }
}); });

View File

@ -3,6 +3,9 @@
import React from 'react'; import React from 'react';
import Router from 'react-router'; import Router from 'react-router';
import UserStore from '../../stores/user_store';
import UserActions from '../../actions/user_actions';
import AccountSettings from './account_settings'; import AccountSettings from './account_settings';
import BitcoinWalletSettings from './bitcoin_wallet_settings'; import BitcoinWalletSettings from './bitcoin_wallet_settings';
import ContractSettings from './contract_settings'; import ContractSettings from './contract_settings';
@ -18,14 +21,35 @@ let SettingsContainer = React.createClass({
mixins: [Router.Navigation], mixins: [Router.Navigation],
getInitialState() {
return UserStore.getState();
},
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
loadUser(){
UserActions.fetchCurrentUser();
},
onChange(state) {
this.setState(state);
},
render() { render() {
return ( return (
<div className="settings-container"> <div className="settings-container">
<AccountSettings /> <AccountSettings currentUser={this.state.currentUser} loadUser={this.loadUser}/>
{this.props.children} {this.props.children}
<APISettings /> <APISettings />
<BitcoinWalletSettings /> <BitcoinWalletSettings />
<ContractSettings /> <ContractSettings currentUser={this.state.currentUser} loadUser={this.loadUser}/>
</div> </div>
); );
} }

View File

@ -8,7 +8,8 @@ function getWalletApiUrls(subdomain) {
return { return {
'pieces_list': walletConstants.walletApiEndpoint + subdomain + '/pieces/', 'pieces_list': walletConstants.walletApiEndpoint + subdomain + '/pieces/',
'piece': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/', 'piece': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/',
'piece_extradata': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/extradata/' 'piece_extradata': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/extradata/',
'user': walletConstants.walletApiEndpoint + subdomain + '/users/'
}; };
} }
else if (subdomain === 'ikonotv'){ else if (subdomain === 'ikonotv'){