implement model-based credential copy

This commit is contained in:
Jake McDermott 2017-12-05 17:38:41 -05:00
parent 21a32f90ce
commit 50d95ddc3f
No known key found for this signature in database
GPG Key ID: 3B02CAD476EECB35
2 changed files with 24 additions and 1 deletions

View File

@ -69,7 +69,15 @@ export default ['i18n', function(i18n) {
dataPlacement: 'top',
ngShow: 'credential.summary_fields.user_capabilities.edit'
},
copy: {
label: i18n._('Copy'),
ngClick: 'copyCredential(credential)',
"class": 'btn-danger btn-xs',
awToolTip: i18n._('Copy credential'),
dataPlacement: 'top',
// requires future api rbac changes
//ngShow: 'credential.summary_fields.user_capabilities.copy'
},
view: {
ngClick: "editCredential(credential.id)",
label: i18n._('View'),

View File

@ -89,6 +89,21 @@ export default ['$scope', 'Rest', 'CredentialList', 'Prompt', 'ProcessErrors', '
}
}
$scope.copyCredential = credential => {
Wait('start');
new Credential('get', credential.id)
.then(model => model.copy())
.then(({ id }) => {
const params = { credential_id: id };
$state.go('credentials.edit', params, { reload: true });
})
.catch(({ data, status }) => {
const params = { hdr: 'Error!', msg: `Call to copy failed. Return status: ${status}` };
ProcessErrors($scope, data, status, null, params);
})
.finally(() => Wait('stop'));
};
$scope.addCredential = function() {
$state.go('credentials.add');
};