mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 15:42:27 -05:00
Ensure default currency isn't modified to be a non-currency
This commit is contained in:
parent
4e73e8b508
commit
a42e051f74
@ -32,6 +32,17 @@ function clientError(error) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function userError(error) {
|
||||||
|
var e = new Error();
|
||||||
|
e.ErrorId = 999;
|
||||||
|
e.ErrorString = error;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: ErrorConstants.ERROR_USER,
|
||||||
|
error: e
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function clearError() {
|
function clearError() {
|
||||||
return {
|
return {
|
||||||
type: ErrorConstants.CLEAR_ERROR,
|
type: ErrorConstants.CLEAR_ERROR,
|
||||||
@ -42,5 +53,6 @@ module.exports = {
|
|||||||
serverError: serverError,
|
serverError: serverError,
|
||||||
ajaxError: ajaxError,
|
ajaxError: ajaxError,
|
||||||
clientError: clientError,
|
clientError: clientError,
|
||||||
|
userError: userError,
|
||||||
clearError: clearError
|
clearError: clearError
|
||||||
};
|
};
|
||||||
|
@ -136,7 +136,7 @@ class AddEditSecurityModal extends React.Component {
|
|||||||
symbol: template.Symbol,
|
symbol: template.Symbol,
|
||||||
precision: template.Precision,
|
precision: template.Precision,
|
||||||
type: template.Type,
|
type: template.Type,
|
||||||
alternateid: template.AlternateId
|
alternateid: template.AlternateId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleCancel() {
|
handleCancel() {
|
||||||
@ -287,13 +287,17 @@ class AddEditSecurityModal extends React.Component {
|
|||||||
|
|
||||||
class DeletionFailedModal extends React.Component {
|
class DeletionFailedModal extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
|
var msg = "We are unable to delete your " + this.props.deletingSecurity.Name + " security because it is in use by " + this.props.securityAccounts.length + " account(s). Please change those accounts to use other securities and try again.";
|
||||||
|
if (this.props.user.DefaultCurrency == this.props.deletingSecurity.SecurityId) {
|
||||||
|
msg = "We are unable to delete your default currency: " + this.props.deletingSecurity.Name + ". To delete this security, select another as your default currency under Account Settings.";
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Modal show={this.props.show} onHide={this.props.onClose}>
|
<Modal show={this.props.show} onHide={this.props.onClose}>
|
||||||
<Modal.Header closeButton>
|
<Modal.Header closeButton>
|
||||||
<Modal.Title>Cannot Delete Security</Modal.Title>
|
<Modal.Title>Cannot Delete Security</Modal.Title>
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
We are unable to delete this security because it is in use by {this.props.securityAccounts.length} account(s). Please change those accounts to use other securities and try again.
|
{msg}
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
<Modal.Footer>
|
<Modal.Footer>
|
||||||
<ButtonGroup className="pull-right">
|
<ButtonGroup className="pull-right">
|
||||||
@ -366,8 +370,10 @@ class SecuritiesTab extends React.Component {
|
|||||||
this.setState({editingSecurity: true});
|
this.setState({editingSecurity: true});
|
||||||
}
|
}
|
||||||
handleDeleteSecurity() {
|
handleDeleteSecurity() {
|
||||||
if (this.props.selectedSecurityAccounts.length == 0)
|
// check if user has this as their default currency
|
||||||
this.props.onDeleteSecurity(this.props.securities[this.props.selectedSecurity]);
|
var security = this.props.securities[this.props.selectedSecurity];
|
||||||
|
if (this.props.selectedSecurityAccounts.length == 0 && security.SecurityId != this.props.user.DefaultCurrency)
|
||||||
|
this.props.onDeleteSecurity(security);
|
||||||
else
|
else
|
||||||
this.setState({deletionFailedModal: true});
|
this.setState({deletionFailedModal: true});
|
||||||
}
|
}
|
||||||
@ -383,7 +389,12 @@ class SecuritiesTab extends React.Component {
|
|||||||
}
|
}
|
||||||
handleEditingSubmit(security) {
|
handleEditingSubmit(security) {
|
||||||
this.setState({editingSecurity: false});
|
this.setState({editingSecurity: false});
|
||||||
this.props.onUpdateSecurity(security);
|
|
||||||
|
if (security.SecurityId == this.props.user.DefaultCurrency && security.Type != SecurityType.Currency) {
|
||||||
|
this.props.onUserError("Unable to modify the default currency to be a non-currency security");
|
||||||
|
} else {
|
||||||
|
this.props.onUpdateSecurity(security);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleCloseDeletionFailed() {
|
handleCloseDeletionFailed() {
|
||||||
this.setState({deletionFailedModal: false});
|
this.setState({deletionFailedModal: false});
|
||||||
@ -412,6 +423,7 @@ class SecuritiesTab extends React.Component {
|
|||||||
securityTemplates={this.props.securityTemplates} />
|
securityTemplates={this.props.securityTemplates} />
|
||||||
<DeletionFailedModal
|
<DeletionFailedModal
|
||||||
show={this.state.deletionFailedModal}
|
show={this.state.deletionFailedModal}
|
||||||
|
user={this.props.user}
|
||||||
deletingSecurity={selectedSecurity}
|
deletingSecurity={selectedSecurity}
|
||||||
onClose={this.onCloseDeletionFailed}
|
onClose={this.onCloseDeletionFailed}
|
||||||
securityAccounts={this.props.selectedSecurityAccounts} />
|
securityAccounts={this.props.selectedSecurityAccounts} />
|
||||||
|
@ -2,6 +2,8 @@ var connect = require('react-redux').connect;
|
|||||||
|
|
||||||
var SecurityActions = require('../actions/SecurityActions');
|
var SecurityActions = require('../actions/SecurityActions');
|
||||||
var SecurityTemplateActions = require('../actions/SecurityTemplateActions');
|
var SecurityTemplateActions = require('../actions/SecurityTemplateActions');
|
||||||
|
var ErrorActions = require('../actions/ErrorActions');
|
||||||
|
|
||||||
var SecuritiesTab = require('../components/SecuritiesTab');
|
var SecuritiesTab = require('../components/SecuritiesTab');
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
@ -12,6 +14,7 @@ function mapStateToProps(state) {
|
|||||||
selectedSecurityAccounts.push(state.accounts.map[accountId]);
|
selectedSecurityAccounts.push(state.accounts.map[accountId]);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
user: state.user,
|
||||||
securities: state.securities.map,
|
securities: state.securities.map,
|
||||||
security_list: state.securities.list,
|
security_list: state.securities.list,
|
||||||
selectedSecurityAccounts: selectedSecurityAccounts,
|
selectedSecurityAccounts: selectedSecurityAccounts,
|
||||||
@ -26,7 +29,8 @@ function mapDispatchToProps(dispatch) {
|
|||||||
onUpdateSecurity: function(security) {dispatch(SecurityActions.update(security))},
|
onUpdateSecurity: function(security) {dispatch(SecurityActions.update(security))},
|
||||||
onDeleteSecurity: function(securityId) {dispatch(SecurityActions.remove(securityId))},
|
onDeleteSecurity: function(securityId) {dispatch(SecurityActions.remove(securityId))},
|
||||||
onSelectSecurity: function(securityId) {dispatch(SecurityActions.select(securityId))},
|
onSelectSecurity: function(securityId) {dispatch(SecurityActions.select(securityId))},
|
||||||
onSearchTemplates: function(search, type, limit) {dispatch(SecurityTemplateActions.search(search, type, limit))}
|
onSearchTemplates: function(search, type, limit) {dispatch(SecurityTemplateActions.search(search, type, limit))},
|
||||||
|
onUserError: function(error) {dispatch(ErrorActions.userError(error))}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,15 @@ func UpdateSecurity(s *Security) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user, err := GetUserTx(transaction, s.UserId)
|
||||||
|
if err != nil {
|
||||||
|
transaction.Rollback()
|
||||||
|
return err
|
||||||
|
} else if user.DefaultCurrency == s.SecurityId && s.Type != Currency {
|
||||||
|
transaction.Rollback()
|
||||||
|
return errors.New("Cannot change security which is user's default currency to be non-currency")
|
||||||
|
}
|
||||||
|
|
||||||
count, err := transaction.Update(s)
|
count, err := transaction.Update(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
transaction.Rollback()
|
transaction.Rollback()
|
||||||
|
Loading…
Reference in New Issue
Block a user