Skip to content

Commit

Permalink
#1953 Disable confim buttons in import dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 12, 2021
1 parent 2e6b610 commit 0500d84
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
'use strict';

angular.module('theHiveControllers')
Expand All @@ -11,7 +11,7 @@

this.appConfig = appConfig;

self.load = function() {
self.load = function () {
this.loading = true;

this.list = new PaginatedQuerySrv({
Expand All @@ -26,27 +26,27 @@
filter: this.filtering.buildQuery(),
baseFilter: {
_field: 'patternType',
_value:'attack-pattern'
_value: 'attack-pattern'
},
operations: [
{'_name': 'listPattern'}
{ '_name': 'listPattern' }
],
extraData: ['enabled', 'parent'],
onUpdate: function() {
onUpdate: function () {
self.loading = false;
}
});
};

self.show = function(patternId) {
self.show = function (patternId) {
$uibModal.open({
animation: true,
templateUrl: 'views/partials/admin/attack/view.html',
controller: 'AttackPatternDialogCtrl',
controllerAs: '$modal',
size: 'max',
resolve: {
pattern: function() {
pattern: function () {
return AttackPatternSrv.get(patternId);
}
}
Expand All @@ -67,11 +67,11 @@
});

modalInstance.result
.then(function() {
.then(function () {
self.load();
})
.catch(function(err){
if(err && !_.isString(err)) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Pattern import', err.data, err.status);
}
});
Expand Down Expand Up @@ -104,7 +104,7 @@
this.search();
};

self.$onInit = function() {
self.$onInit = function () {
self.filtering = new FilteringSrv('pattern', 'attack-pattern.list', {
version: 'v1',
defaults: {
Expand All @@ -117,7 +117,7 @@
});

self.filtering.initContext('list')
.then(function() {
.then(function () {
self.load();

$scope.$watch('$vm.list.pageSize', function (newValue) {
Expand All @@ -138,7 +138,7 @@
$uibModalInstance.dismiss('cancel');
};

this.$onInit = function() {
this.$onInit = function () {
if (this.pattern.extraData.parent) {
this.pattern.isSubTechnique = true;
this.pattern.parentId = this.pattern.extraData.parent.patternId;
Expand All @@ -152,13 +152,19 @@
function AttackPatternImportCtrl($uibModalInstance, AttackPatternSrv, NotificationSrv, appConfig) {
this.appConfig = appConfig;
this.formData = {};
this.loading = false;

this.ok = function () {
this.loading = true;
AttackPatternSrv.import(this.formData)
.then(function() {
.then(function () {
$uibModalInstance.close();
}, function(response) {
})
.catch(function (response) {
NotificationSrv.error('AttackPatternImportCtrl', response.data, response.status);
})
.fincally(function () {
this.loading = false;
});
};

Expand Down
52 changes: 29 additions & 23 deletions frontend/app/scripts/controllers/admin/taxonomy/TaxonomyListCtrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
'use strict';

angular.module('theHiveControllers')
Expand All @@ -11,7 +11,7 @@

this.appConfig = appConfig;

self.load = function() {
self.load = function () {
this.loading = true;

this.list = new PaginatedQuerySrv({
Expand All @@ -25,16 +25,16 @@
pageSize: self.filtering.context.pageSize,
filter: this.filtering.buildQuery(),
operations: [
{'_name': 'listTaxonomy'}
{ '_name': 'listTaxonomy' }
],
extraData: ['enabled'],
onUpdate: function() {
onUpdate: function () {
self.loading = false;
}
});
};

self.show = function(taxonomy) {
self.show = function (taxonomy) {
// var modalInstance = $uibModal.open({

$uibModal.open({
Expand Down Expand Up @@ -73,52 +73,52 @@
});

modalInstance.result
.then(function() {
.then(function () {
self.load();
})
.catch(function(err){
if(err && !_.isString(err)) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Taxonomies import', err.data, err.status);
}
});
};

this.toggleActive = function(taxonomy) {
this.toggleActive = function (taxonomy) {
var active = !taxonomy.extraData.enabled;

TaxonomySrv.toggleActive(taxonomy._id, active)
.then(function() {
.then(function () {
NotificationSrv.log(['Taxonomy [', taxonomy.namespace, '] has been successfully', (active ? 'activated' : 'deactivated')].join(' '), 'success');

self.load();
})
.catch(function(err){
if(err && !_.isString(err)) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Taxonomies ' + active ? 'activation' : 'deactivation', err.data, err.status);
}
});
};

self.remove = function(taxonomy) {
self.remove = function (taxonomy) {
var modalInstance = ModalSrv.confirm(
'Remove taxonomy',
'Are you sure you want to remove the selected taxonomy?', {
flavor: 'danger',
okText: 'Yes, remove it'
}
flavor: 'danger',
okText: 'Yes, remove it'
}
);

modalInstance.result
.then(function() {
.then(function () {
return TaxonomySrv.remove(taxonomy._id);
})
.then(function( /*response*/ ) {
.then(function ( /*response*/) {
self.load();
NotificationSrv.success(
'Taxonomy ' + taxonomy.namespace + ' has been successfully removed.'
);
})
.catch(function(err) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('TaxonomyListCtrl', err.data, err.status);
}
Expand Down Expand Up @@ -152,7 +152,7 @@
this.search();
};

self.$onInit = function() {
self.$onInit = function () {
self.filtering = new FilteringSrv('taxonomy', 'taxonomy.list', {
version: 'v1',
defaults: {
Expand All @@ -165,7 +165,7 @@
});

self.filtering.initContext('list')
.then(function() {
.then(function () {
self.load();

$scope.$watch('$vm.list.pageSize', function (newValue) {
Expand All @@ -190,13 +190,19 @@
function TaxonomyImportCtrl($uibModalInstance, TaxonomySrv, NotificationSrv, appConfig) {
this.appConfig = appConfig;
this.formData = {};
this.loading = false;

this.ok = function () {
this.loading = true;
TaxonomySrv.import(this.formData)
.then(function() {
.then(function () {
$uibModalInstance.close();
}, function(response) {
})
.catch(function (response) {
NotificationSrv.error('TaxonomyImportCtrl', response.data, response.status);
})
.finally(function () {
this.loading = false;
});
};

Expand Down
7 changes: 5 additions & 2 deletions frontend/app/views/partials/admin/attack/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ <h3 class="modal-title">Import MITRE ATT&CK patterns</h3>

<div class="filter-panel mb-s">
<h4>Download the official MITRE ATT&CK library</h4>
<p>You can download the latest archive of the official MITRE ATT&CK patterns <a target="_blank" href="https://raw.githubusercontent.com/mitre/cti/master/enterprise-attack/enterprise-attack.json?version=TheHive-{{$vm.appConfig.versions.TheHive}}">from here</a></p>
<p>You can download the latest archive of the official MITRE ATT&CK patterns <a target="_blank"
href="https://raw.githubusercontent.com/mitre/cti/master/enterprise-attack/enterprise-attack.json?version=TheHive-{{$vm.appConfig.versions.TheHive}}">from
here</a></p>
</div>

<div class="form-group">
Expand All @@ -17,6 +19,7 @@ <h4>Download the official MITRE ATT&CK library</h4>
</div>
<div class="modal-footer">
<button class="btn btn-default pull-left" type="button" ng-click="$vm.cancel()">Cancel</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid">Yes, Import it</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid || $vm.loading">Yes, Import
it</button>
</div>
</form>
10 changes: 7 additions & 3 deletions frontend/app/views/partials/admin/taxonomy/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ <h3 class="modal-title">Import taxonomies archive</h3>

<div class="filter-panel mb-s">
<h4>Download the official MISP taxonomies archive</h4>
<p>You can download the latest archive of the official MISP Taxonomies <a target="_blank" href="https://github.com/MISP/misp-taxonomies/archive/main.zip?version=TheHive-{{$vm.appConfig.versions.TheHive}}">from here</a></p>
<p>You can download the latest archive of the official MISP Taxonomies <a target="_blank"
href="https://github.com/MISP/misp-taxonomies/archive/main.zip?version=TheHive-{{$vm.appConfig.versions.TheHive}}">from
here</a></p>
</div>

<div class="form-group">
Expand All @@ -15,12 +17,14 @@ <h4>Download the official MISP taxonomies archive</h4>
<div file-chooser="" filemodel="$vm.formData.attachment"></div>

<p class="help-block">
The taxonomies archive must be a valid ZIP file containing at least one file names <em>machinetag.json</em>
The taxonomies archive must be a valid ZIP file containing at least one file names
<em>machinetag.json</em>
</p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default pull-left" type="button" ng-click="$vm.cancel()">Cancel</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid">Yes, Import it</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid || !!$vm.loading">Yes,
Import it</button>
</div>
</form>

0 comments on commit 0500d84

Please sign in to comment.