#396 fix - Many issues fixed: Block/Unblock commands, Upload request
data, Send second email, ...
| .. | .. |
|---|
| 115 | 115 | |
|---|
| 116 | 116 | @Column(name = "license_data") |
|---|
| 117 | 117 | @JsonProperty("license_data") |
|---|
| 118 | + @JsonIgnore |
|---|
| 119 | + // The license data is sent to user as a separate file, It doesn't need to |
|---|
| 120 | + // be included as License attribute on browser |
|---|
| 118 | 121 | private String licenseData; |
|---|
| 119 | 122 | |
|---|
| 120 | 123 | @Column(name = "creation_timestamp") |
|---|
| .. | .. |
|---|
| 136 | 139 | private String comments; |
|---|
| 137 | 140 | |
|---|
| 138 | 141 | @OneToMany(fetch = FetchType.LAZY, mappedBy = "license") |
|---|
| 142 | + @JsonIgnore |
|---|
| 139 | 143 | private List<LicenseHistory> history; |
|---|
| 140 | 144 | |
|---|
| 141 | 145 | public int getId() { |
|---|
| .. | .. |
|---|
| 334 | 338 | public static final int CANCEL = 6; |
|---|
| 335 | 339 | public static final int DELETE = 7; |
|---|
| 336 | 340 | public static final int BLOCK = 8; |
|---|
| 341 | + public static final int UNBLOCK = 9; |
|---|
| 337 | 342 | } |
|---|
| 338 | 343 | |
|---|
| 339 | 344 | public static class Status { |
|---|
| 340 | 345 | |
|---|
| 341 | 346 | private static final Map<Integer, List<LicenseStatus>> transitions = Utils.createMap( // |
|---|
| 342 | 347 | Action.REQUEST, Arrays.asList(LicenseStatus.CREATED, LicenseStatus.REQUESTED), // |
|---|
| 343 | | - Action.ACTIVATION, Arrays.asList(LicenseStatus.REQUESTED, LicenseStatus.PRE_ACTIVE, LicenseStatus.EXPIRED), // |
|---|
| 348 | + Action.ACTIVATION, Arrays.asList(LicenseStatus.CREATED, LicenseStatus.REQUESTED, LicenseStatus.PRE_ACTIVE, LicenseStatus.EXPIRED), // |
|---|
| 344 | 349 | Action.SEND, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE), // |
|---|
| 345 | 350 | Action.DOWNLOAD, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE), // |
|---|
| 346 | 351 | Action.CANCEL, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE, LicenseStatus.REQUESTED, LicenseStatus.EXPIRED), // |
|---|
| 347 | | - Action.DELETE, Arrays.asList(LicenseStatus.CANCELLED, LicenseStatus.CREATED), // |
|---|
| 352 | + Action.DELETE, Arrays.asList(LicenseStatus.CANCELLED, LicenseStatus.CREATED, LicenseStatus.BLOCKED), // |
|---|
| 353 | + Action.UNBLOCK, Arrays.asList(LicenseStatus.BLOCKED), // |
|---|
| 348 | 354 | Action.BLOCK, Arrays.asList(LicenseStatus.CANCELLED) // |
|---|
| 349 | 355 | ); |
|---|
| 350 | 356 | |
|---|
| .. | .. |
|---|
| 12 | 12 | * @author rob |
|---|
| 13 | 13 | */ |
|---|
| 14 | 14 | public enum LicenseStatus implements CodedEnum { |
|---|
| 15 | | - CREATED("CR"), REQUESTED("RE"), ACTIVE("AC"), PRE_ACTIVE("PA"), EXPIRED("EX"), CANCELLED("CA"); |
|---|
| 15 | + CREATED("CR"), REQUESTED("RE"), ACTIVE("AC"), PRE_ACTIVE("PA"), EXPIRED("EX"), CANCELLED("CA"), BLOCKED("BL"); |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private final String code; |
|---|
| 18 | 18 | |
|---|
| .. | .. |
|---|
| 55 | 55 | import net.curisit.securis.utils.EmailManager; |
|---|
| 56 | 56 | import net.curisit.securis.utils.JsonUtils; |
|---|
| 57 | 57 | import net.curisit.securis.utils.LicUtils; |
|---|
| 58 | | -import net.curisit.securis.utils.TokenHelper; |
|---|
| 59 | 58 | |
|---|
| 60 | 59 | import org.apache.commons.io.IOUtils; |
|---|
| 61 | 60 | import org.apache.commons.lang3.ObjectUtils; |
|---|
| .. | .. |
|---|
| 77 | 76 | public class LicenseResource { |
|---|
| 78 | 77 | |
|---|
| 79 | 78 | private static final Logger LOG = LogManager.getLogger(LicenseResource.class); |
|---|
| 80 | | - |
|---|
| 81 | | - @Inject |
|---|
| 82 | | - private TokenHelper tokenHelper; |
|---|
| 83 | 79 | |
|---|
| 84 | 80 | @Inject |
|---|
| 85 | 81 | private EmailManager emailManager; |
|---|
| .. | .. |
|---|
| 206 | 202 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId |
|---|
| 207 | 203 | + " can not be activated from the current license status"); |
|---|
| 208 | 204 | } |
|---|
| 205 | + |
|---|
| 206 | + if (lic.getPack().getNumAvailables() == 0) { |
|---|
| 207 | + throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "The pack has not available licenses"); |
|---|
| 208 | + } |
|---|
| 209 | + |
|---|
| 209 | 210 | validateRequestData(lic.getPack(), lic.getRequestData()); |
|---|
| 210 | 211 | |
|---|
| 211 | 212 | License existingLicense = License.findLicenseByRequestData(lic.getRequestData(), em); |
|---|
| .. | .. |
|---|
| 250 | 251 | Application app = lic.getPack().getLicenseType().getApplication(); |
|---|
| 251 | 252 | File licFile = null; |
|---|
| 252 | 253 | if (lic.getLicenseData() == null) { |
|---|
| 253 | | - throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "There is no license file available"); |
|---|
| 254 | + throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "There is no license file available"); |
|---|
| 254 | 255 | } |
|---|
| 255 | 256 | |
|---|
| 256 | 257 | if (lic.getFullName() == null) { |
|---|
| 257 | | - throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Please add an user name in license data to send it the license file"); |
|---|
| 258 | + throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "Please add an user name in license data to send it the license file"); |
|---|
| 258 | 259 | } |
|---|
| 259 | 260 | |
|---|
| 260 | 261 | User user = userHelper.getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| .. | .. |
|---|
| 276 | 277 | } |
|---|
| 277 | 278 | |
|---|
| 278 | 279 | // lic.setModificationTimestamp(new Date()); |
|---|
| 279 | | - em.merge(lic); |
|---|
| 280 | + // em.merge(lic); |
|---|
| 280 | 281 | em.persist(licenseHelper.createLicenseHistoryAction(lic, user, LicenseHistory.Actions.SEND, "Email sent to: " + lic.getEmail())); |
|---|
| 281 | 282 | return Response.ok(lic).build(); |
|---|
| 282 | 283 | } |
|---|
| .. | .. |
|---|
| 384 | 385 | .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "There is already an active license for current request data") |
|---|
| 385 | 386 | .type(MediaType.APPLICATION_JSON).entity(existingLicense).build(); |
|---|
| 386 | 387 | } |
|---|
| 387 | | - SignedLicenseBean signedLicense = generateLicense(lic, em); |
|---|
| 388 | | - // If user provide a request data the license status is passed |
|---|
| 389 | | - // directly to ACTIVE |
|---|
| 390 | | - lic.setStatus(LicenseStatus.ACTIVE); |
|---|
| 391 | | - try { |
|---|
| 392 | | - lic.setRequestData(JsonUtils.toJSON((RequestBean) signedLicense)); |
|---|
| 393 | | - if (BlockedRequest.isRequestBlocked(lic.getRequestData(), em)) { |
|---|
| 394 | | - throw new SeCurisServiceException(ErrorCodes.BLOCKED_REQUEST_DATA, "Given request data is blocked and cannot be activated"); |
|---|
| 388 | + |
|---|
| 389 | + if (pack.getNumAvailables() > 0) { |
|---|
| 390 | + |
|---|
| 391 | + SignedLicenseBean signedLicense = generateLicense(lic, em); |
|---|
| 392 | + // If user provide a request data the license status is passed |
|---|
| 393 | + // directly to ACTIVE |
|---|
| 394 | + lic.setStatus(LicenseStatus.ACTIVE); |
|---|
| 395 | + try { |
|---|
| 396 | + lic.setRequestData(JsonUtils.toJSON(signedLicense, RequestBean.class)); |
|---|
| 397 | + if (BlockedRequest.isRequestBlocked(lic.getRequestData(), em)) { |
|---|
| 398 | + throw new SeCurisServiceException(ErrorCodes.BLOCKED_REQUEST_DATA, "Given request data is blocked and cannot be activated"); |
|---|
| 399 | + } |
|---|
| 400 | + lic.setLicenseData(JsonUtils.toJSON(signedLicense)); |
|---|
| 401 | + } catch (SeCurisException e) { |
|---|
| 402 | + LOG.error("Error generating license JSON", e); |
|---|
| 403 | + throw new SeCurisServiceException(ErrorCodes.INVALID_FORMAT, "Error generating license JSON"); |
|---|
| 395 | 404 | } |
|---|
| 396 | | - lic.setLicenseData(JsonUtils.toJSON(signedLicense)); |
|---|
| 397 | | - } catch (SeCurisException e) { |
|---|
| 398 | | - LOG.error("Error generating license JSON", e); |
|---|
| 399 | | - throw new SeCurisServiceException(ErrorCodes.INVALID_FORMAT, "Error generating license JSON"); |
|---|
| 400 | 405 | } |
|---|
| 401 | 406 | } else { |
|---|
| 402 | 407 | lic.setStatus(LicenseStatus.CREATED); |
|---|
| .. | .. |
|---|
| 493 | 498 | if (lic.getRequestData() != null) { |
|---|
| 494 | 499 | SignedLicenseBean signedLicense = generateLicense(lic, em); |
|---|
| 495 | 500 | try { |
|---|
| 496 | | - // Next line is necessary to normalize the String that |
|---|
| 501 | + // Next 2 lines are necessary to normalize the String that |
|---|
| 497 | 502 | // contains |
|---|
| 498 | 503 | // the request. |
|---|
| 499 | | - lic.setRequestData(JsonUtils.toJSON((RequestBean) signedLicense)); |
|---|
| 500 | | - if (BlockedRequest.isRequestBlocked(lic.getRequestData(), em)) { |
|---|
| 504 | + currentLicense.setRequestData(JsonUtils.toJSON(signedLicense, RequestBean.class)); |
|---|
| 505 | + LOG.info("JSON generated for request: \n{}", currentLicense.getRequestData()); |
|---|
| 506 | + if (BlockedRequest.isRequestBlocked(currentLicense.getRequestData(), em)) { |
|---|
| 501 | 507 | throw new SeCurisServiceException(ErrorCodes.BLOCKED_REQUEST_DATA, "Given request data is blocked and cannot be used again"); |
|---|
| 502 | 508 | } |
|---|
| 503 | | - lic.setLicenseData(JsonUtils.toJSON(signedLicense)); |
|---|
| 509 | + currentLicense.setLicenseData(JsonUtils.toJSON(signedLicense)); |
|---|
| 504 | 510 | } catch (SeCurisException e) { |
|---|
| 505 | 511 | LOG.error("Error generaing license JSON", e); |
|---|
| 506 | 512 | throw new SeCurisServiceException(ErrorCodes.INVALID_FORMAT, "Error generaing license JSON"); |
|---|
| .. | .. |
|---|
| 534 | 540 | LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus()); |
|---|
| 535 | 541 | throw new SeCurisServiceException(ErrorCodes.WRONG_STATUS, "License can not be deleted in current status: " + lic.getStatus().name()); |
|---|
| 536 | 542 | } |
|---|
| 537 | | - if (lic.getStatus() == LicenseStatus.CANCELLED) { |
|---|
| 543 | + if (lic.getStatus() == LicenseStatus.BLOCKED) { |
|---|
| 538 | 544 | // If license is removed and it's blocked then the blocked request |
|---|
| 539 | 545 | // should be removed, that is, |
|---|
| 540 | 546 | // the license deletion will unblock the request data |
|---|
| 541 | | - TypedQuery<License> query = em.createNamedQuery("list-licenses-by-req-data", License.class); |
|---|
| 542 | | - query.setParameter("hash", lic.getReqDataHash()); |
|---|
| 543 | | - List<License> list = query.getResultList(); |
|---|
| 544 | | - if (list == null || list.size() == 0) { |
|---|
| 545 | | - BlockedRequest br = em.find(BlockedRequest.class, lic.getReqDataHash()); |
|---|
| 546 | | - if (br != null) { |
|---|
| 547 | | - em.remove(br); |
|---|
| 548 | | - } |
|---|
| 547 | + BlockedRequest blockedReq = em.find(BlockedRequest.class, lic.getReqDataHash()); |
|---|
| 548 | + if (blockedReq != null) { |
|---|
| 549 | + // This if is to avoid some race condition or if the request has |
|---|
| 550 | + // been already removed manually |
|---|
| 551 | + em.remove(blockedReq); |
|---|
| 549 | 552 | } |
|---|
| 550 | 553 | } |
|---|
| 551 | 554 | |
|---|
| .. | .. |
|---|
| 578 | 581 | blockedReq.setRequestData(lic.getRequestData()); |
|---|
| 579 | 582 | |
|---|
| 580 | 583 | em.persist(blockedReq); |
|---|
| 584 | + lic.setStatus(LicenseStatus.BLOCKED); |
|---|
| 585 | + lic.setModificationTimestamp(new Date()); |
|---|
| 586 | + em.merge(lic); |
|---|
| 581 | 587 | |
|---|
| 582 | 588 | em.persist(licenseHelper.createLicenseHistoryAction(lic, userHelper.getUser(bsc, em), LicenseHistory.Actions.BLOCK)); |
|---|
| 583 | 589 | return Response.ok(Utils.createMap("success", true, "id", licId)).build(); |
|---|
| .. | .. |
|---|
| 598 | 604 | if (BlockedRequest.isRequestBlocked(lic.getRequestData(), em)) { |
|---|
| 599 | 605 | BlockedRequest blockedReq = em.find(BlockedRequest.class, lic.getReqDataHash()); |
|---|
| 600 | 606 | em.remove(blockedReq); |
|---|
| 607 | + |
|---|
| 608 | + lic.setStatus(LicenseStatus.CANCELLED); |
|---|
| 609 | + lic.setModificationTimestamp(new Date()); |
|---|
| 610 | + em.merge(lic); |
|---|
| 601 | 611 | em.persist(licenseHelper.createLicenseHistoryAction(lic, userHelper.getUser(bsc, em), LicenseHistory.Actions.UNBLOCK)); |
|---|
| 602 | 612 | } else { |
|---|
| 603 | 613 | LOG.info("Request data for license {} is NOT blocked", licId); |
|---|
| .. | .. |
|---|
| 17 | 17 | import javax.inject.Singleton; |
|---|
| 18 | 18 | |
|---|
| 19 | 19 | import net.curisit.securis.SeCurisException; |
|---|
| 20 | +import net.curisit.securis.services.exception.SeCurisServiceException; |
|---|
| 21 | +import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes; |
|---|
| 20 | 22 | |
|---|
| 21 | 23 | import org.apache.commons.io.IOUtils; |
|---|
| 22 | 24 | import org.apache.http.HttpResponse; |
|---|
| 23 | 25 | import org.apache.http.auth.AuthScope; |
|---|
| 24 | 26 | import org.apache.http.auth.UsernamePasswordCredentials; |
|---|
| 25 | 27 | import org.apache.http.client.CredentialsProvider; |
|---|
| 28 | +import org.apache.http.client.HttpClient; |
|---|
| 26 | 29 | import org.apache.http.client.methods.HttpPost; |
|---|
| 27 | 30 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|---|
| 28 | 31 | import org.apache.http.entity.ContentType; |
|---|
| .. | .. |
|---|
| 30 | 33 | import org.apache.http.entity.mime.MultipartEntityBuilder; |
|---|
| 31 | 34 | import org.apache.http.entity.mime.content.FileBody; |
|---|
| 32 | 35 | import org.apache.http.impl.client.BasicCredentialsProvider; |
|---|
| 33 | | -import org.apache.http.impl.client.CloseableHttpClient; |
|---|
| 34 | 36 | import org.apache.http.impl.client.HttpClientBuilder; |
|---|
| 35 | 37 | import org.apache.http.ssl.SSLContextBuilder; |
|---|
| 36 | 38 | import org.apache.http.ssl.TrustStrategy; |
|---|
| .. | .. |
|---|
| 49 | 51 | private static final Logger LOG = LogManager.getLogger(EmailManager.class); |
|---|
| 50 | 52 | |
|---|
| 51 | 53 | private final String serverUrl; |
|---|
| 52 | | - private final CloseableHttpClient httpClient; |
|---|
| 54 | + private final HttpClientBuilder httpClientBuilder; |
|---|
| 53 | 55 | |
|---|
| 54 | 56 | /** |
|---|
| 55 | 57 | * |
|---|
| .. | .. |
|---|
| 61 | 63 | throw new SeCurisException("Please, add '" + Config.KEYS.MAILGUN_DOMAIN + "' parameter to config file"); |
|---|
| 62 | 64 | } |
|---|
| 63 | 65 | serverUrl = String.format("https://api.mailgun.net/v2/%s/messages", domain); |
|---|
| 64 | | - httpClient = createHttpClient(); |
|---|
| 66 | + httpClientBuilder = createHttpClient(); |
|---|
| 65 | 67 | |
|---|
| 66 | 68 | } |
|---|
| 67 | 69 | |
|---|
| 68 | | - private CloseableHttpClient createHttpClient() throws SeCurisException { |
|---|
| 70 | + private HttpClientBuilder createHttpClient() throws SeCurisException { |
|---|
| 69 | 71 | SSLContextBuilder builder = new SSLContextBuilder(); |
|---|
| 70 | 72 | SSLConnectionSocketFactory sslsf = null; |
|---|
| 71 | 73 | try { |
|---|
| .. | .. |
|---|
| 84 | 86 | UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("api", Config.get(Config.KEYS.MAILGUN_API_KEY)); |
|---|
| 85 | 87 | provider.setCredentials(AuthScope.ANY, credentials); |
|---|
| 86 | 88 | |
|---|
| 87 | | - return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).setSSLSocketFactory(sslsf).build(); |
|---|
| 89 | + return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).setSSLSocketFactory(sslsf); |
|---|
| 88 | 90 | } |
|---|
| 89 | 91 | |
|---|
| 90 | 92 | /** |
|---|
| .. | .. |
|---|
| 98 | 100 | * @throws SeCurisException |
|---|
| 99 | 101 | * @throws UnsupportedEncodingException |
|---|
| 100 | 102 | */ |
|---|
| 101 | | - public void sendEmail(String subject, String body, String to, String cc, File file) throws SeCurisException, UnsupportedEncodingException { |
|---|
| 103 | + public void sendEmail(String subject, String body, String to, String cc, File file) throws SeCurisServiceException, UnsupportedEncodingException { |
|---|
| 102 | 104 | HttpPost postRequest = new HttpPost(serverUrl); |
|---|
| 103 | 105 | |
|---|
| 104 | 106 | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
|---|
| .. | .. |
|---|
| 120 | 122 | |
|---|
| 121 | 123 | postRequest.setEntity(builder.build()); |
|---|
| 122 | 124 | HttpResponse response; |
|---|
| 125 | + HttpClient httpClient = httpClientBuilder.build(); |
|---|
| 123 | 126 | try { |
|---|
| 124 | 127 | response = httpClient.execute(postRequest); |
|---|
| 125 | 128 | |
|---|
| .. | .. |
|---|
| 130 | 133 | |
|---|
| 131 | 134 | LOG.debug("Response mail read OK: {}", responseBean); |
|---|
| 132 | 135 | } else { |
|---|
| 133 | | - throw new SeCurisException("Error sending email, response estatus: " + response.getStatusLine()); |
|---|
| 136 | + throw new SeCurisServiceException(ErrorCodes.UNEXPECTED_ERROR, "Error sending email, response estatus: " + response.getStatusLine()); |
|---|
| 134 | 137 | } |
|---|
| 135 | 138 | } catch (IOException e) { |
|---|
| 136 | 139 | LOG.error("Error sending email", e); |
|---|
| 137 | | - throw new SeCurisException("Error sending email"); |
|---|
| 140 | + throw new SeCurisServiceException(ErrorCodes.UNEXPECTED_ERROR, "Error sending email"); |
|---|
| 138 | 141 | } |
|---|
| 139 | 142 | } |
|---|
| 140 | 143 | |
|---|
| .. | .. |
|---|
| 160 | 163 | EmailManager.this.sendEmail(subject, body, to, cc, file); |
|---|
| 161 | 164 | callback.success(); |
|---|
| 162 | 165 | } catch (UnsupportedEncodingException e) { |
|---|
| 163 | | - callback.error(new SeCurisException("Error sending email", e)); |
|---|
| 164 | | - } catch (SeCurisException e) { |
|---|
| 166 | + callback.error(new SeCurisServiceException("Error sending email: " + e)); |
|---|
| 167 | + } catch (SeCurisServiceException e) { |
|---|
| 165 | 168 | callback.error(e); |
|---|
| 166 | 169 | } |
|---|
| 167 | 170 | |
|---|
| .. | .. |
|---|
| 173 | 176 | public static interface EmailCallback { |
|---|
| 174 | 177 | public void success(); |
|---|
| 175 | 178 | |
|---|
| 176 | | - public void error(SeCurisException e); |
|---|
| 179 | + public void error(SeCurisServiceException e); |
|---|
| 177 | 180 | } |
|---|
| 178 | 181 | |
|---|
| 179 | 182 | public static void main(String[] args) throws SeCurisException, UnsupportedEncodingException { |
|---|
| .. | .. |
|---|
| 190 | 193 | } |
|---|
| 191 | 194 | |
|---|
| 192 | 195 | @Override |
|---|
| 193 | | - public void error(SeCurisException e) { |
|---|
| 196 | + public void error(SeCurisServiceException e) { |
|---|
| 194 | 197 | LOG.error("Error: {} !!!", e); |
|---|
| 195 | 198 | } |
|---|
| 196 | 199 | }); |
|---|
| .. | .. |
|---|
| 148 | 148 | REQUESTED: 'RE', |
|---|
| 149 | 149 | PREACTIVE: 'PA', |
|---|
| 150 | 150 | EXPIRED: 'EX', |
|---|
| 151 | + BLOCKED: 'BL', |
|---|
| 151 | 152 | CANCELLED: 'CA' |
|---|
| 152 | 153 | } |
|---|
| 153 | 154 | |
|---|
| .. | .. |
|---|
| 157 | 158 | 'PA': $L.get('Pre-active'), |
|---|
| 158 | 159 | 'RE': $L.get('Requested'), |
|---|
| 159 | 160 | 'EX': $L.get('Expired'), |
|---|
| 161 | + 'BL': $L.get('Blocked'), |
|---|
| 160 | 162 | 'CA': $L.get('Cancelled') |
|---|
| 161 | 163 | }; |
|---|
| 162 | 164 | |
|---|
| .. | .. |
|---|
| 165 | 167 | * we copy them for simplicity, this info won't change easily |
|---|
| 166 | 168 | */ |
|---|
| 167 | 169 | var LIC_ACTIONS_BY_STATUS = { |
|---|
| 170 | + add_request: [LIC_STATUS.CREATED], |
|---|
| 168 | 171 | activate: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE], |
|---|
| 169 | 172 | send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], |
|---|
| 170 | 173 | download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], |
|---|
| 171 | 174 | block: [LIC_STATUS.CANCELLED], |
|---|
| 172 | | - unblock: [LIC_STATUS.CANCELLED], |
|---|
| 175 | + unblock: [LIC_STATUS.BLOCKED], |
|---|
| 173 | 176 | cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE], |
|---|
| 174 | | - 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED] |
|---|
| 177 | + 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED] |
|---|
| 175 | 178 | } |
|---|
| 176 | 179 | |
|---|
| 177 | 180 | var licenseResource = $resource('license/:licenseId/:action', { |
|---|
| .. | .. |
|---|
| 217 | 220 | 'AC': '#329e5a', |
|---|
| 218 | 221 | 'RE': '#2981d4', |
|---|
| 219 | 222 | 'EX': '#ea7824', |
|---|
| 223 | + 'BL': '#ff0000', |
|---|
| 220 | 224 | 'CA': '#a21717' |
|---|
| 221 | 225 | }; |
|---|
| 222 | 226 | |
|---|
| .. | .. |
|---|
| 236 | 240 | toaster.pop('error', 'Licenses', $L.get("Error {0} license '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))), 5000); |
|---|
| 237 | 241 | if (error.headers('X-SECURIS-ERROR-CODE') === '1301') { |
|---|
| 238 | 242 | Packs.nextliccode(license.pack_id, function(data) { |
|---|
| 239 | | - console.log('New code: ' + data); |
|---|
| 240 | | - license.code = data; |
|---|
| 241 | | - toaster.pop('info', 'Licenses', $L.get("New license code, {0}, has been generated, please try again", license.code), 5000); |
|---|
| 243 | + if (license.code !== data) { |
|---|
| 244 | + // Only if the new code is different we can think about an erro related with License CODE |
|---|
| 245 | + license.code = data; |
|---|
| 246 | + toaster.pop('info', 'Licenses', $L.get("New license code, {0}, has been generated, please try again", license.code), 5000); |
|---|
| 247 | + } |
|---|
| 242 | 248 | }); |
|---|
| 243 | 249 | } |
|---|
| 244 | 250 | } |
|---|
| .. | .. |
|---|
| 348 | 354 | scope.$apply(); |
|---|
| 349 | 355 | } |
|---|
| 350 | 356 | |
|---|
| 351 | | - reader.readAsText(fileList[0]); |
|---|
| 357 | + reader.readAsText(fileList[0]); |
|---|
| 358 | + element.val(''); |
|---|
| 352 | 359 | } else { |
|---|
| 353 | 360 | setter(scope.$parent, ''); |
|---|
| 354 | 361 | scope.$apply(); |
|---|
| .. | .. |
|---|
| 383 | 390 | return txt.substring(0, len) + '...'; |
|---|
| 384 | 391 | } |
|---|
| 385 | 392 | $scope.currentPack = $store.get('currentPack'); |
|---|
| 393 | + setTimeout(function() { |
|---|
| 394 | + $scope.$broadcast('pack_changed', $scope.currentPack); |
|---|
| 395 | + }, 0); |
|---|
| 386 | 396 | |
|---|
| 387 | 397 | }]); |
|---|
| 388 | 398 | |
|---|
| .. | .. |
|---|
| 445 | 445 | </div> |
|---|
| 446 | 446 | </div> |
|---|
| 447 | 447 | </div> |
|---|
| 448 | | - <div class="form-group" ng-if="isNew || !license.request_data"> |
|---|
| 448 | + <div class="form-group" > |
|---|
| 449 | 449 | <label class="col-md-3 control-label" for="request_data" i18n>Request |
|---|
| 450 | 450 | data</label> |
|---|
| 451 | 451 | <div class="col-md-7"> |
|---|
| .. | .. |
|---|
| 455 | 455 | ng-maxlength="{{maxlength.request_data}}"></textarea> |
|---|
| 456 | 456 | <div class="alert inline-alert alert-warning" |
|---|
| 457 | 457 | ng-show="licenseForm.request_data.$invalid"> |
|---|
| 458 | | - Invalid ? {{licenseForm.request_data.$invalid}} |
|---|
| 458 | + <!-- Invalid ? {{licenseForm.request_data.$invalid}} |
|---|
| 459 | 459 | Error ? {{licenseForm.request_data.$error | json}} |
|---|
| 460 | | - Error ? {{licenseForm.request_data.$error.maxlength}} |
|---|
| 460 | + Error ? {{licenseForm.request_data.$error.maxlength}} --> |
|---|
| 461 | 461 | <span class="glyphicon glyphicon-warning-sign"> |
|---|
| 462 | 462 | <span |
|---|
| 463 | 463 | ng-show="licenseForm.request_data.$error.maxlength" |
|---|
| .. | .. |
|---|
| 467 | 467 | </span> |
|---|
| 468 | 468 | </div> |
|---|
| 469 | 469 | </div> |
|---|
| 470 | | - <span class="btn btn-file btn-default btn-xs"> |
|---|
| 470 | + <span class="btn btn-file btn-default btn-xs" ng-if="isNew || Licenses.isActionAvailable('add_request', license)"> |
|---|
| 471 | 471 | <span class="glyphicon glyphicon-folder-open"></span> |
|---|
| 472 | 472 | <input file-loader="license.request_data" type="file" /> |
|---|
| 473 | 473 | </span> |
|---|
| .. | .. |
|---|
| 489 | 489 | <span ng-show="licenseForm.comments.$error.required" |
|---|
| 490 | 490 | ng-bind="mandatoryFieldErrorMsg('comments')"></span> |
|---|
| 491 | 491 | </div> |
|---|
| 492 | | - </div> |
|---|
| 493 | | - </div> |
|---|
| 494 | | - |
|---|
| 495 | | - <div class="form-group" ng-if="!isNew && license.request_data"> |
|---|
| 496 | | - <label class="col-md-3 control-label" i18n>Request data</label> |
|---|
| 497 | | - <div class="col-md-8"> |
|---|
| 498 | | - <pre class="form-control-static" |
|---|
| 499 | | - ng-bind="license.request_data | json"></pre> |
|---|
| 500 | 492 | </div> |
|---|
| 501 | 493 | </div> |
|---|
| 502 | 494 | |
|---|