From 217f5419913bc66dbc83d961e7e048c00a17c205 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Fri, 12 Aug 2016 12:27:14 +0530 Subject: [PATCH] added certificate units --- .../cdmf.page.certificate.create/create.hbs | 101 ++++++++++ .../cdmf.page.certificate.create/create.js | 45 +++++ .../cdmf.page.certificate.create/create.json | 5 + .../public/js/certificate-create.js | 129 +++++++++++++ .../cdmf.page.certificates/certificates.hbs | 177 ++++++++++++++++++ .../cdmf.page.certificates/certificates.js | 15 ++ .../cdmf.page.certificates/certificates.json | 5 + .../public/js/certificate-listing.js | 171 +++++++++++++++++ .../public/templates/certificate-listing.hbs | 30 +++ 9 files changed, 678 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/public/js/certificate-create.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/js/certificate-listing.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/templates/certificate-listing.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.hbs new file mode 100644 index 00000000000..3093ca27a9d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.hbs @@ -0,0 +1,101 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} +{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + + + + Add Certificate + +
  • +{{/zone}} + +{{#zone "content"}} + +
    +
    + +
    +
    +

    Add Certificate

    +

    Please note that * sign represents required fields of data.

    +
    +
    +
    + + + +
    +
    + +
    + +
    + +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + + +
    +
    + +{{/zone}} + +{{#zone "bottomJs"}} + {{js "/js/certificate-create.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.js new file mode 100644 index 00000000000..4e7585163a2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.js @@ -0,0 +1,45 @@ +/* + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +/** + * Returns the dynamic state to be populated by add-user page. + * + * @param context Object that gets updated with the dynamic state of this page to be presented + * @returns {*} A context object that returns the dynamic state of this page to be presented + */ +function onRequest(context) { + // var log = new Log("units/user-create/create.js"); + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; + + var response = userModule.getRolesByUserStore(); + if (response["status"] == "success") { + context["roles"] = response["content"]; + } + + context["charLimit"] = mdmProps["usernameLength"]; + context["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"]; + context["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"]; + context["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"]; + context["firstnameJSRegEx"] = mdmProps["userValidationConfig"]["firstnameJSRegEx"]; + context["firstnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"]; + context["lastnameJSRegEx"] = mdmProps["userValidationConfig"]["lastnameJSRegEx"]; + context["lastnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"]; + + return context; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.json new file mode 100644 index 00000000000..db293d5ab12 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/create.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/certificates/add", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/public/js/certificate-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/public/js/certificate-create.js new file mode 100644 index 00000000000..6ff663ea0db --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificate.create/public/js/certificate-create.js @@ -0,0 +1,129 @@ +/* + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +var pemContent = ""; +var errorMsgWrapper = "#certificate-create-error-msg"; +var errorMsg = "#certificate-create-error-msg span"; +var validateInline = {}; +var clearInline = {}; + +var base_api_url = "/api/device-mgt/v1.0"; + +var enableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).addClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).removeClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).removeClass(" hidden"); + } +}; + +var disableInlineError = function (inputField, errorMsg, errorSign) { + var fieldIdentifier = "#" + inputField; + var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; + var errorSignIdentifier = "#" + inputField + " ." + errorSign; + + if (inputField) { + $(fieldIdentifier).removeClass(" has-error has-feedback"); + } + + if (errorMsg) { + $(errorMsgIdentifier).addClass(" hidden"); + } + + if (errorSign) { + $(errorSignIdentifier).addClass(" hidden"); + } +}; + +function readSingleFile(evt) { + var f = evt.target.files[0]; + if (f) { + var r = new FileReader(); + r.onload = function (e) { + var contents = e.target.result; + if (f.type == "application/x-x509-ca-cert") { + pemContent = contents; + console.log(contents); + console.log(pemContent); + pemContent = pemContent.substring(28, pemContent.length - 27); + console.log(pemContent); + $(errorMsgWrapper).addClass("hidden"); + } else { + $(errorMsg).text("Certificate must be a .pem file containing a valid certificate data."); + $(errorMsgWrapper).removeClass("hidden"); + } + } + r.readAsText(f); + } else { + //inline error + } +} + +$(document).ready(function () { + pemContent = ""; + document.getElementById('certificate').addEventListener('change', readSingleFile, false); + + /** + * Following click function would execute + * when a user clicks on "Add Certificate" button. + */ + $("button#add-certificate-btn").click(function () { + var serialNoInput = $("input#serialNo"); + var serialNo = serialNoInput.val(); + if (!serialNo) { + $(errorMsg).text("Serial Number is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (!pemContent) { + $(errorMsg).text(" .pem file must contains certificate information."); + $(errorMsgWrapper).removeClass("hidden"); + } else { + var addCertificateFormData = {}; + addCertificateFormData.serial = serialNo; + addCertificateFormData.pem = pemContent; + var certificateList = []; + certificateList.push(addCertificateFormData); + + var serviceUrl = base_api_url + "/admin/certificates"; + invokerUtil.post( + serviceUrl, + certificateList, + function (data) { + // Refreshing with success message + $("#certificate-create-form").addClass("hidden"); + $("#certificate-created-msg").removeClass("hidden"); + }, function (data) { + if (data["status"] == 500) { + $(errorMsg).text("An unexpected error occurred at backend server. Please try again later."); + } else { + $(errorMsg).text(data); + } + $(errorMsgWrapper).removeClass("hidden"); + } + ); + } + }); +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.hbs new file mode 100644 index 00000000000..b20da073afa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.hbs @@ -0,0 +1,177 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} +{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + + + + Add Certificate + +
  • +{{/zone}} + +{{#zone "content"}} + {{unit "cdmf.unit.data-tables-extended"}} + + +
    + {{#if removePermitted}} + + {{/if}} + {{#if viewPermitted}} + + {{/if}} + + Loading Certificates . . . +
    +
    + + + +
    + + + + + + + + + + + + + + + + +
    + +
    By Serial Number
    + + + + +
    +
    +
    + + +
    +
    +
    +
    +

    Do you really want to remove this certificate ?

    + + +
    +
    +
    +
    + +
    +
    +
    +
    +

    Done. Certificate was successfully removed.

    + +
    +
    +
    +
    + +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    + + +
    +
    +
    +
    + +
    +
    +
    +
    +

    + + + + + Unauthorized action! +

    +
    +
    +
    +
    +{{/zone}} + +{{#zone "bottomJs"}} + + + {{js "/js/certificate-listing.js"}} +{{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.js new file mode 100644 index 00000000000..8aeb02353e3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.js @@ -0,0 +1,15 @@ +function onRequest(context) { + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; + + context["permissions"] = userModule.getUIPermissions(); + + if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/certificate/Get")) { + context["removePermitted"] = true; + } + if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/certificate/Get")) { + context["viewPermitted"] = true; + } + context["adminUser"] = mdmProps.adminUser; + return context; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.json new file mode 100644 index 00000000000..39fb7ff01b7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/certificates.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/certificates", + "layout": "cdmf.layout.default" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/js/certificate-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/js/certificate-listing.js new file mode 100644 index 00000000000..d911d7fb451 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/js/certificate-listing.js @@ -0,0 +1,171 @@ +/* + * Sorting function of certificates + * listed on Certificate Management page in WSO2 MDM Console. + */ +$(function () { + var sortableElem = '.wr-sortable'; + $(sortableElem).sortable({ + beforeStop: function () { + var sortedIDs = $(this).sortable('toArray'); + } + }); + $(sortableElem).disableSelection(); +}); + +var modalPopup = ".wr-modalpopup"; +var modalPopupContainer = modalPopup + " .modalpopup-container"; +var modalPopupContent = modalPopup + " .modalpopup-content"; +var body = "body"; +var isInit = true; + +var base_api_url = "/api/certificate-mgt/v1.0"; + +$(".icon .text").res_text(0.2); + +/* + * set popup maximum height function. + */ +function setPopupMaxHeight() { + $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30))); + $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2))); +} + +/* + * show popup function. + */ +function showPopup() { + $(modalPopup).show(); + setPopupMaxHeight(); +} + +/* + * hide popup function. + */ +function hidePopup() { + $(modalPopupContent).html(''); + $(modalPopup).hide(); +} + +/** + * Following click function would execute + * when a user clicks on "Remove" link + * on Certificate Listing page in WSO2 MDM Console. + */ +function removeCertificate(serialNumber) { + var serviceUrl = base_api_url + "/admin/certificates/" + serialNumber; + $(modalPopupContent).html($('#remove-certificate-modal-content').html()); + showPopup(); + + $("a#remove-certificate-yes-link").click(function () { + invokerUtil.delete( + serviceUrl, + function () { + $("#" + serialNumber).remove(); + var newCertificateListCount = $(".user-list > span").length; + $("#certificate-listing-status-msg").text("Total number of Certificates found : " + newCertificateListCount); + $(modalPopupContent).html($('#remove-certificate-success-content').html()); + $("a#remove-certificate-success-link").click(function () { + hidePopup(); + }); + }, + function () { + $(modalPopupContent).html($('#remove-certificate-error-content').html()); + $("a#remove-certificate-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#remove-certificate-cancel-link").click(function () { + hidePopup(); + }); +} + +/** + * Following on click function would execute + * when a user type on the search field on certificate Listing page in + * WSO2 MDM Console then click on the search button. + */ +$("#search-btn").click(function () { + var searchQuery = $("#search-by-certificate").val(); + $("#ast-container").empty(); + loadCertificates(searchQuery); +}); + +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption() { + if ($("#can-view").val()) { + $(location).attr('href', $(this).data("url")); + } else { + $(modalPopupContent).html($('#errorCertificateView').html()); + showPopup(); + } +} + +function loadCertificates(searchParam) { + $("#loading-content").show(); + var certificateListing = $("#certificate-listing"); + var certificateListingSrc = certificateListing.attr("src"); + $.template("certificate-listing", certificateListingSrc, function (template) { + var serviceURL = base_api_url + "/admin/certificates"; + + if (searchParam != null && searchParam != undefined && searchParam.trim() != '') { + serviceURL = base_api_url + "/admin/certificates?" + searchParam; + } + + var successCallback = function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + + var viewModel = {}; + viewModel.certificates = data.certificates; + + for (var i = 0; i < viewModel.certificates.length; i++) { + viewModel.certificates[i].removePermitted = true; + viewModel.certificates[i].viewPermitted = true; + } + + if (viewModel.certificates.length > 0) { + $('#ast-container').removeClass('hidden'); + $('#certificate-listing-status-msg').text(""); + var content = template(viewModel); + $("#ast-container").html(content); + } else { + $('#ast-container').addClass('hidden'); + $('#certificate-listing-status-msg').text('No certificate is available to be displayed.'); + $('#certificate-listing-status').removeClass('hidden'); + } + + $("#loading-content").hide(); + + if (isInit) { + $('#certificate-grid').datatables_extended(); + isInit = false; + } + + $(".icon .text").res_text(0.2); + } + }; + invokerUtil.get(serviceURL, + successCallback, + function (message) { + $('#ast-container').addClass('hidden'); + $('#certificate-listing-status-msg'). + text('Invalid search query. Try again with a valid search query'); + } + ); + }); +} + +$(document).ready(function () { + loadCertificates(); + + $(".viewEnabledIcon").click(function () { + InitiateViewOption(); + }); +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/templates/certificate-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/templates/certificate-listing.hbs new file mode 100644 index 00000000000..c492e4f8002 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.page.certificates/public/templates/certificate-listing.hbs @@ -0,0 +1,30 @@ +{{#each certificates}} + + + +
    + +
    + + {{serialNumber}} + {{subject}} + + {{#unequal adminUser serialNumber }} + {{#if removePermitted}} + + + + + + + + {{/if}} + {{/unequal}} + + + +{{/each}} \ No newline at end of file