1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01: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,21 +75,24 @@ 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 (
<AclProxy
aclName="acl_view_contract_settings"
aclObject={this.props.currentUser.acl}>
<CollapsibleParagraph <CollapsibleParagraph
title={getLangText('Contracts')} title={getLangText('Contracts')}
show={true} show={true}
defaultExpanded={true}> defaultExpanded={true}>
<CollapsibleParagraph <AclProxy
title={getLangText('Public Contracts')} aclName="acl_edit_public_contract"
show={true} aclObject={this.props.currentUser.acl}>
defaultExpanded={true}> <div>
{createPublicContractForm} {createPublicContractForm}
{publicContracts.map((contract, i) => { {publicContracts.map((contract, i) => {
return ( return (
@ -114,16 +120,17 @@ let ContractSettings = React.createClass({
rightColumnWidth="60%"/> rightColumnWidth="60%"/>
); );
})} })}
</CollapsibleParagraph> </div>
<CollapsibleParagraph </AclProxy>
title={getLangText('Private Contracts')} <AclProxy
show={true} aclName="acl_edit_private_contract"
defaultExpanded={true}> aclObject={this.props.currentUser.acl}>
<div>
<CreateContractForm <CreateContractForm
isPublic={false} isPublic={false}
fileClassToUpload={{ fileClassToUpload={{
singular: getLangText('new private contract'), singular: getLangText('new contract'),
plural: getLangText('new private contracts') plural: getLangText('new contracts')
}}/> }}/>
{privateContracts.map((contract, i) => { {privateContracts.map((contract, i) => {
return ( return (
@ -151,8 +158,10 @@ let ContractSettings = React.createClass({
rightColumnWidth="60%"/> rightColumnWidth="60%"/>
); );
})} })}
</div>
</AclProxy>
</CollapsibleParagraph> </CollapsibleParagraph>
</CollapsibleParagraph> </AclProxy>
); );
} }
}); });

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'){