rsanchez
2014-10-27 7f5a20aa40c00fea42c68211f311b6b24ad64c9e
#2021 feature - Added frontend validations and confirmations on
sensitive actions.
6 files modified
changed files
securis/src/main/java/net/curisit/securis/db/Pack.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/resources/db/schema.sql patch | view | blame | history
securis/src/main/resources/static/js/licenses.js patch | view | blame | history
securis/src/main/resources/static/licenses.html patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Pack.java
....@@ -95,6 +95,10 @@
9595 @JsonProperty("license_preactivation")
9696 private boolean licensePreactivation;
9797
98
+ @Column(name = "default_valid_period")
99
+ @JsonProperty("default_valid_period")
100
+ private Integer defaultValidPeriod;
101
+
98102 @OneToMany(fetch = FetchType.LAZY, mappedBy = "pack")
99103 private Set<PackMetadata> metadata;
100104
....@@ -327,6 +331,14 @@
327331 return (id == null ? 0 : id.hashCode());
328332 }
329333
334
+ public Integer getDefaultValidPeriod() {
335
+ return defaultValidPeriod;
336
+ }
337
+
338
+ public void setDefaultValidPeriod(Integer defaultValidPeriod) {
339
+ this.defaultValidPeriod = defaultValidPeriod;
340
+ }
341
+
330342 public static class Action {
331343 public static final int CREATE = 1;
332344 public static final int ACTIVATION = 2;
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -310,6 +310,16 @@
310310 return Response.ok(lic).build();
311311 }
312312
313
+ /**
314
+ * Cancel the license
315
+ *
316
+ * @param lic
317
+ * @param em
318
+ */
319
+ public static void cancelLicense(License lic, EntityManager em) throws SeCurisServiceException {
320
+
321
+ }
322
+
313323 @POST
314324 @Path("/")
315325 @Consumes(MediaType.APPLICATION_JSON)
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -337,14 +337,19 @@
337337 public Response delete(@PathParam("packId") String packId) {
338338 LOG.info("Deleting pack with id: {}", packId);
339339 EntityManager em = emProvider.get();
340
- Pack org = em.find(Pack.class, Integer.parseInt(packId));
341
- if (org == null) {
340
+ Pack pack = em.find(Pack.class, Integer.parseInt(packId));
341
+ if (pack == null) {
342342 LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId);
343343 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId)
344344 .build();
345345 }
346
+ if (pack.getMetadata() != null) {
347
+ for (PackMetadata md : pack.getMetadata()) {
348
+ em.remove(md);
349
+ }
350
+ }
346351
347
- em.remove(org);
352
+ em.remove(pack);
348353 return Response.ok(Utils.createMap("success", true, "id", packId)).build();
349354 }
350355
securis/src/main/resources/db/schema.sql
....@@ -84,6 +84,7 @@
8484 license_type_id INT NOT NULL,
8585 organization_id INT NOT NULL,
8686 license_preactivation BOOLEAN NOT NULL DEFAULT true,
87
+ default_valid_period INT NOT NULL DEFAULT 60,
8788 created_by varchar(45) NULL ,
8889 creation_timestamp DATETIME NOT NULL ,
8990 PRIMARY KEY (id));
securis/src/main/resources/static/js/licenses.js
....@@ -159,6 +159,53 @@
159159 return LIC_STATUSES[status];
160160 }
161161
162
+ var _createSuccessCallback = function(actionName, message, _innerCallback) {
163
+ return function() {
164
+ _innerCallback && _innerCallback();
165
+ toaster.pop('success', actionName, message);
166
+ }
167
+ }
168
+ var _createErrorCallback = function(pack, actionName, _innerCallback) {
169
+ return function(error) {
170
+ console.log(error);
171
+ _innerCallback && _innerCallback();
172
+ toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
173
+ }
174
+ }
175
+ this.getPacksList = function(pack, _onsuccess, _onerror) {
176
+ return packResource.query(_onsuccess, _onerror);
177
+ }
178
+ this.activate = function(license, _onsuccess, _onerror) {
179
+ console.log('Activation on license: ' + license.id);
180
+ var _success = _createSuccessCallback($L.get('Activation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("activated")), _onsuccess);
181
+ var _error = _createErrorCallback(license, $L.get('Activation'), _onerror);
182
+ licenseResource.activate({id: license.id}, _success, _error);
183
+ }
184
+ this.block = function(license, _onsuccess, _onerror) {
185
+ console.log('Block on license: ' + license.id);
186
+ var _success = _createSuccessCallback($L.get('Block'), $L.get("License '{0}' {1} successfully", license.code, $L.get("blocked")), _onsuccess);
187
+ var _error = _createErrorCallback(license, $L.get('Block'), _onerror);
188
+ licenseResource.putonhold({id: license.id}, _success, _error);
189
+ }
190
+ this.unblock = function(license, _onsuccess, _onerror) {
191
+ console.log('Unblock on license: ' + license.id);
192
+ var _success = _createSuccessCallback($L.get('Unblock'), $L.get("License '{0}' {1} successfully", license.code, $L.get("unblocked")), _onsuccess);
193
+ var _error = _createErrorCallback(license, $L.get('Unblock'), _onerror);
194
+ licenseResource.putonhold({id: license.id}, _success, _error);
195
+ }
196
+ this.cancel = function(license, extra_data, _onsuccess, _onerror) {
197
+ console.log('Cancellation on license: ' + license.id);
198
+ var _success = _createSuccessCallback($L.get('Cancellation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("cancelled")), _onsuccess);
199
+ var _error = _createErrorCallback(license, $L.get('Cancellation'), _onerror);
200
+ var params = angular.extend({id: license.id}, extra_data);
201
+ licenseResource.cancel(params, _success, _error);
202
+ }
203
+ this.delete = function(license, _onsuccess, _onerror) {
204
+ console.log('Delete on license: ' + license.id);
205
+ var _success = _createSuccessCallback($L.get('Deletion'), $L.get("License '{0}' {1} successfully", license.code, $L.get("deleted")), _onsuccess);
206
+ var _error = _createErrorCallback(license, $L.get('Deletion'), _onerror);
207
+ licenseResource.delete({licenseId: license.id}, _success, _error);
208
+ }
162209 }]);
163210
164211 app.directive('fileLoader',
....@@ -217,6 +264,9 @@
217264 $scope.mandatoryFieldErrorMsg = function(displayname) {
218265 return $L.get("'{0}' is required.", $L.get(displayname));
219266 }
267
+ $scope.field1ShouldBeGreaterThanField2 = function(field1, field2) {
268
+ return $L.get("{0} should be greater than {1}", $L.get(field1), $L.get(field2));
269
+ }
220270 $scope.ellipsis = function(txt, len) {
221271 if (!txt || txt.length <= len) return txt;
222272 return txt.substring(0, len) + '...';
....@@ -269,36 +319,79 @@
269319 $scope.packs = Packs.getPacksList();
270320
271321 $scope.save = function() {
272
- if ($scope.pack.num_activations > 0) {
273
- BootstrapDialog.confirm($L.get("The pack '{0}' has active licenses, Do you want to modify it ?", $scope.pack.code), function(answer){
274
- if (answer) {
275
- Packs.savePackData($scope.pack, $scope.isNew, function() {
276
- if (!$scope.isNew) $scope.showForm = false;
277
- $scope.packs = Packs.getPacksList();
278
- });
279
- }
280
- });
281
- } else {
282
- Packs.savePackData($scope.pack, $scope.isNew, function() {
283
- if (!$scope.isNew) {
284
- $scope.showForm = false;
285
- } else {
286
- $scope.newPack();
287
- }
288
- $scope.packs = Packs.getPacksList();
289
- });
290
- }
322
+ Packs.savePackData($scope.pack, $scope.isNew, function() {
323
+ if (!$scope.isNew) {
324
+ $scope.showForm = false;
325
+ } else {
326
+ $scope.newPack();
327
+ }
328
+ $scope.packs = Packs.getPacksList();
329
+ });
291330 }
292331
293332 /**
294333 * Execute an action over the pack, activation, onhold, cancellation
295334 */
296335 $scope.execute = function(action, pack) {
297
-
298
- Packs[action](pack || $scope.pack, function() {
299
- if (!$scope.isNew) $scope.showForm = false;
300
- $scope.packs = Packs.getPacksList();
301
- });
336
+ var _execute = function(extra_data) {
337
+ Packs[action](pack || $scope.pack, extra_data, function() {
338
+ if (!$scope.isNew) $scope.showForm = false;
339
+ $scope.packs = Packs.getPacksList();
340
+ });
341
+ }
342
+ if (action === 'delete') {
343
+ BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", $scope.pack.code), function(answer) {
344
+ if (answer) {
345
+ _execute();
346
+ }
347
+ });
348
+ } else {
349
+ if (action === 'cancel') {
350
+ BootstrapDialog.show({
351
+ title: $L.get("Pack cancellation"),
352
+ type: BootstrapDialog.TYPE_DANGER,
353
+ message: function(dialog) {
354
+ var $content = $('<div></div>');
355
+ var $message = $('<div></div>');
356
+ var pageToLoad = dialog.getData('pageToLoad');
357
+ $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", $scope.pack.code)));
358
+ $content.append($message);
359
+
360
+ var $message = $('<div style="margin-top:10pt;"/>');
361
+ var pageToLoad = dialog.getData('pageToLoad');
362
+ $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " "));
363
+ $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_cancellation_reason"/>'));
364
+ $content.append($message);
365
+ return $content;
366
+ },
367
+ closable: true,
368
+ buttons: [{
369
+ id: 'btn-cancel',
370
+ label: $L.get('Close'),
371
+ cssClass: 'btn-default',
372
+ action: function(dialogRef) {
373
+ dialogRef.close();
374
+ }
375
+ }, {
376
+ id: 'btn-ok',
377
+ label: $L.get('Cancel pack'),
378
+ cssClass: 'btn-primary',
379
+ action: function(dialogRef){
380
+ var reason = $('#_cancellation_reason').val();
381
+ console.log('Ready to cancel pack, by reason: ' + reason);
382
+ if (!reason) {
383
+ $('#_cancellation_reason').focus();
384
+ } else {
385
+ _execute({reason: reason});
386
+ dialogRef.close();
387
+ }
388
+ }
389
+ }]
390
+ });
391
+ } else {
392
+ _execute();
393
+ }
394
+ }
302395 }
303396
304397
....@@ -309,6 +402,8 @@
309402 license_preactivation: true,
310403 status: 'CR',
311404 num_licenses: 1,
405
+ init_valid_date: new Date(),
406
+ default_valid_period: 30,
312407 license_type_id: null,
313408 organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
314409 }
securis/src/main/resources/static/licenses.html
....@@ -79,12 +79,15 @@
7979 <div class="col-md-4">
8080 <input type="date" id="end_valid_date" name="end_valid_date" placeholder=""
8181 class="form-control" ng-model="pack.end_valid_date"
82
+ min="{{pack.init_valid_date | date: 'yyyy-MM-dd'}}"
8283 ng-required="mandatory.end_valid_date" />
8384 <div class="alert inline-alert alert-warning"
84
- ng-show="packForm.initValidDate.$invalid">
85
+ ng-show="packForm.end_valid_date.$invalid">
8586 <span class="glyphicon glyphicon-warning-sign"></span>
8687 <span ng-show="packForm.end_valid_date.$error.required"
8788 ng-bind="mandatoryFieldErrorMsg('End valid date')"></span>
89
+ <span ng-show="packForm.end_valid_date.$error.min"
90
+ ng-bind="field1ShouldBeGreaterThanField2('End date', 'Init date')"></span>
8891 </div>
8992 </div>
9093 </div>
....@@ -163,6 +166,23 @@
163166 <div class="col-md-8">
164167 <input type="checkbox" class="form-control"
165168 ng-model="pack.license_preactivation" />
169
+ </div>
170
+ </div>
171
+ <div class="form-group">
172
+ <label class="col-md-3 control-label" for="license_preactivation"
173
+ i18n>Default valid period (days)</label>
174
+ <div class="col-md-8">
175
+ <input type="number" id="default_valid_period" name="default_valid_period"
176
+ min="1" class="form-control" ng-model="pack.default_valid_period"
177
+ ng-required="pack.license_preactivation" />
178
+ <div class="alert inline-alert alert-warning"
179
+ ng-show="packForm.default_valid_period.$invalid">
180
+ <span class="glyphicon glyphicon-warning-sign"></span>
181
+ <span ng-show="packForm.default_valid_period.$error.required"
182
+ ng-bind="mandatoryFieldErrorMsg('Default valid period')"></span>
183
+ <span ng-show="packForm.default_valid_period.$error.min"
184
+ ng-bind="field1ShouldBeGreaterThanField2('The default valid period', '0')"></span>
185
+ </div>
166186 </div>
167187 </div>
168188
....@@ -246,6 +266,23 @@
246266 </form>
247267 </div>
248268
269
+<div class="modal fade" id="cancellationReasonDialog" tabindex="-1" role="dialog" aria-labelledby="cancelDialogLabel" aria-hidden="true">
270
+ <div class="modal-dialog">
271
+ <div class="modal-content">
272
+ <div class="modal-header">
273
+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
274
+ <h4 class="modal-title" id="cancelDialogLabel" i18n>Pack cancellation</h4>
275
+ </div>
276
+ <div class="modal-body">
277
+
278
+ </div>
279
+ <div class="modal-footer">
280
+ <button type="button" class="btn btn-default" data-dismiss="modal" i18n>Close</button>
281
+ <button type="button" class="btn btn-primary" i18n>Cancel pack</button>
282
+ </div>
283
+ </div>
284
+ </div>
285
+</div>
249286
250287 <div class="panel panel-default">
251288 <div class="panel-heading">
....@@ -625,4 +662,3 @@
625662
626663 </div>
627664 </div>
628
-