diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java index ca3c77f093e..d0fe4e516da 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java @@ -37,7 +37,6 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.Arrays; @@ -106,8 +105,13 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_ID, registrationProfile.getConsumerKey()); jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_SECRET, registrationProfile.getConsumerSecret()); - jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, - ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD); + if (registrationProfile.getValidityPeriod() == 0) { + jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, + ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD); + } else { + jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, + registrationProfile.getValidityPeriod()); + } apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication( jsonStringObject.toJSONString(), registrationProfile.getApplicationName(), registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains(), diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java index c0d231039c3..3efd856cd4b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java @@ -41,6 +41,8 @@ public class RegistrationProfile { private boolean isMappingAnExistingOAuthApp; private String consumerKey; private String consumerSecret; + @XmlElement(required = false) + private int validityPeriod; public String getApplicationName() { return applicationName; @@ -89,4 +91,12 @@ public class RegistrationProfile { public void setConsumerSecret(String consumerSecret) { this.consumerSecret = consumerSecret; } + + public int getValidityPeriod() { + return validityPeriod; + } + + public void setValidityPeriod(int validityPeriod) { + this.validityPeriod = validityPeriod; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GroupDAOImpl.java index 52dba3579a5..7d9947a421b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GroupDAOImpl.java @@ -105,6 +105,11 @@ public class GroupDAOImpl implements GroupDAO { stmt.setInt(1, groupId); stmt.setInt(2, tenantId); stmt.executeUpdate(); + sql = "DELETE FROM DM_DEVICE_GROUP_POLICY WHERE DEVICE_GROUP_ID = ? AND TENANT_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, groupId); + stmt.setInt(2, tenantId); + stmt.executeUpdate(); } catch (SQLException e) { throw new GroupManagementDAOException("Error occurred while removing mappings for group.'", e); } finally { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 4053c641e3a..948b38976fb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1903,6 +1903,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv defaultGroup = new DeviceGroup(groupName); // Setting system level user (wso2.system.user) as the owner defaultGroup.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME); + defaultGroup.setDescription("Default system group for devices with " + groupName + " ownership."); try { service.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE, DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 0283fd214d2..f8a0fd1ad44 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -500,10 +500,11 @@ var userModule = function () { publicMethods.getUIPermissions = function () { var permissions = {}; - if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/list")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/any-device")) { permissions["LIST_DEVICES"] = true; + permissions["LIST_OWN_DEVICES"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/owning-device")) { permissions["LIST_OWN_DEVICES"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/view")) { @@ -524,10 +525,10 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/list")) { permissions["LIST_POLICIES"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/add")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/add")) { permissions["ADD_DEVICE"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/groups/add")) { + if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/add")) { permissions["ADD_GROUP"] = true; } if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/add")) { @@ -542,9 +543,6 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/view")) { permissions["VIEW_GROUP_DEVICES"] = true; } - if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/roles/create")) { - permissions["CREATE_GROUP_ROLES"] = true; - } if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/roles/view")) { permissions["VIEW_GROUP_ROLES"] = true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js index ed2dc01a8ec..a71495851f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js @@ -60,6 +60,8 @@ var WEB_SERVICE_ADDRESSING_VERSION = 1.0; var TOKEN_PAIR = "tokenPair"; var ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS = "encodedTenantBasedClientAppCredentials"; var CONTENT_TYPE_IDENTIFIER = "Content-Type"; +var ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS = "encodedTenantBasedWebSocketClientCredentials"; + var CONTENT_DISPOSITION_IDENTIFIER = "Content-Disposition"; var APPLICATION_JSON = "application/json"; var APPLICATION_ZIP = "application/zip"; @@ -76,4 +78,6 @@ var HTTP_CONFLICT = 409; var HTTP_CREATED = 201; var CACHED_CREDENTIALS = "tenantBasedCredentials"; +var CACHED_CREDENTIALS_FOR_WEBSOCKET_APP = "tenantBasedWebSocketClientCredentials"; + var ALLOWED_SCOPES = "scopes"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index bf5f26cac84..bc0fa5abb04 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -29,7 +29,9 @@ var carbonServer = new carbonModule.server.Server({ application.put("carbonServer", carbonServer); var permissions = { - "/permission/admin/device-mgt/devices": ["ui.execute"], + "/permission/admin/device-mgt/devices/enroll": ["ui.execute"], + "/permission/admin/device-mgt/devices/disenroll": ["ui.execute"], + "/permission/admin/device-mgt/devices/owning-device": ["ui.execute"], "/permission/admin/device-mgt/groups": ["ui.execute"], "/permission/admin/device-mgt/notifications": ["ui.execute"], "/permission/admin/device-mgt/policies": ["ui.execute"], diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js index e6cecaeba62..50cdb7f76fc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js @@ -138,6 +138,63 @@ var utils = function () { } }; + publicMethods["getTenantBasedWebSocketClientAppCredentials"] = function (username) { + if (!username) { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client app credentials. No username " + + "as input - getTenantBasedWebSocketClientAppCredentials(x)"); + return null; + } else { + //noinspection JSUnresolvedFunction, JSUnresolvedVariable + var tenantDomain = carbon.server.tenantDomain({username: username}); + if (!tenantDomain) { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client application credentials. Unable to obtain a valid tenant domain for provided " + + "username - getTenantBasedWebSocketClientAppCredentials(x, y)"); + return null; + } else { + var cachedBasedWebsocketClientAppCredentials = privateMethods. + getCachedBasedWebSocketClientAppCredentials(tenantDomain); + if (cachedBasedWebsocketClientAppCredentials) { + return cachedBasedWebsocketClientAppCredentials; + } else { + var adminUsername = deviceMgtProps["adminUser"]; + var adminUserTenantId = deviceMgtProps["adminUserTenantId"]; + //claims required for jwtAuthenticator. + var claims = {"http://wso2.org/claims/enduserTenantId": adminUserTenantId, + "http://wso2.org/claims/enduser": adminUsername}; + var jwtToken = publicMethods.getJwtToken(adminUsername, claims); + + // register a tenant based app at API Manager + var applicationName = "websocket_webapp_" + tenantDomain; + var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] + ["apiManagerClientAppRegistrationServiceURL"] + + "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; + var xhr = new XMLHttpRequest(); + xhr.open("POST", requestURL, false); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken); + xhr.send(); + if (xhr["status"] == 201 && xhr["responseText"]) { + var responsePayload = parse(xhr["responseText"]); + var tenantTenantBasedWebsocketClientAppCredentials = {}; + tenantTenantBasedWebsocketClientAppCredentials["clientId"] = responsePayload["client_id"]; + tenantTenantBasedWebsocketClientAppCredentials["clientSecret"] = + responsePayload["client_secret"]; + privateMethods.setCachedBasedWebSocketClientAppCredentials(tenantDomain, + tenantTenantBasedWebsocketClientAppCredentials); + return tenantTenantBasedWebsocketClientAppCredentials; + } else { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client application credentials from API " + + "Manager - getTenantBasedWebSocketClientAppCredentials(x, y)"); + return null; + } + } + } + } + }; + privateMethods["setCachedTenantBasedClientAppCredentials"] = function (tenantDomain, clientAppCredentials) { var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); if (!cachedTenantBasedClientAppCredentialsMap) { @@ -159,7 +216,32 @@ var utils = function () { } }; - publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) { + privateMethods["getCachedBasedWebSocketClientAppCredentials"] = function (tenantDomain) { + var cachedBasedWebSocketClientAppCredentialsMap + = application.get(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"]); + if (!cachedBasedWebSocketClientAppCredentialsMap || + !cachedBasedWebSocketClientAppCredentialsMap[tenantDomain]) { + return null; + } else { + return cachedBasedWebSocketClientAppCredentialsMap[tenantDomain]; + } + }; + + privateMethods["setCachedBasedWebSocketClientAppCredentials"] = function (tenantDomain, clientAppCredentials) { + var cachedBasedWebSocketClientAppCredentialsMap + = application.get(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"]); + if (!cachedBasedWebSocketClientAppCredentialsMap) { + cachedBasedWebSocketClientAppCredentialsMap = {}; + cachedBasedWebSocketClientAppCredentialsMap[tenantDomain] = clientAppCredentials; + application.put(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"] + , cachedBasedWebSocketClientAppCredentialsMap); + } else if (!cachedBasedWebSocketClientAppCredentialsMap[tenantDomain]) { + cachedBasedWebSocketClientAppCredentialsMap[tenantDomain] = clientAppCredentials; + } + }; + + publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password + , encodedClientAppCredentials, scopes) { if (!username || !password || !encodedClientAppCredentials || !scopes) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " + "grant type. No username, password, encoded client app credentials or scopes are " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index d5154711980..9c969f4ab16 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -39,6 +39,7 @@ var handlers = function () { "as input - setupTokenPairByPasswordGrantType(x, y)"); } else { privateMethods.setUpEncodedTenantBasedClientAppCredentials(username); + privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (!encodedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " + @@ -81,6 +82,7 @@ var handlers = function () { "as input - setupTokenPairByPasswordGrantType(x, y)"); } else { privateMethods.setUpEncodedTenantBasedClientAppCredentials(username); + privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (!encodedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " + @@ -168,5 +170,44 @@ var handlers = function () { } }; + privateMethods["setUpEncodedTenantBasedWebSocketClientAppCredentials"] = function (username) { + if (!username) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + + "client credentials to session context. No username of logged in user is found as " + + "input - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } else { + if (devicemgtProps["apimgt-gateway"]) { + var tenantBasedWebSocketClientAppCredentials + = tokenUtil.getTenantBasedWebSocketClientAppCredentials(username); + if (!tenantBasedWebSocketClientAppCredentials) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " + + "based client credentials to session context as the server is unable " + + "to obtain such credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } else { + var encodedTenantBasedWebSocketClientAppCredentials = + tokenUtil.encode(tenantBasedWebSocketClientAppCredentials["clientId"] + ":" + + tenantBasedWebSocketClientAppCredentials["clientSecret"]); + // setting up encoded tenant based client credentials to session context. + session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], + encodedTenantBasedWebSocketClientAppCredentials); + } + } else { + var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(); + if (!dynamicClientAppCredentials) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + + "client credentials to session context as the server is unable to obtain " + + "dynamic client credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } + var encodedTenantBasedWebSocketClientAppCredentials = + tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" + + dynamicClientAppCredentials["clientSecret"]); + // setting up encoded tenant based client credentials to session context. + session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], + encodedTenantBasedWebSocketClientAppCredentials); + } + + } + }; + return publicMethods; }(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs index 8ae4393a8f8..9d9edd0c534 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs @@ -36,9 +36,11 @@
-
+
+ data-errormsg="{{groupNameRegExViolationErrorMsg}}" class="form-control"> + +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js index b2a5598c0f7..a4fcc5ab258 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js @@ -35,12 +35,10 @@ $(function () { var description = $("input#description").val(); if (!name) { - $('.wr-validation-summary strong').text("Group Name is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); + triggerError($("input#name"),"Group Name is a required field. It cannot be empty."); return false; } else if (!inputIsValid($("input#name").data("regex"), name)) { - $('.wr-validation-summary strong').text($("input#name").data("errormsg")); - $('.wr-validation-summary').removeClass("hidden"); + triggerError($("input#name"),$("input#name").data("errormsg")); return false; } else { var group = {"name": name, "description": description}; @@ -69,6 +67,61 @@ $(function () { }); }); +/** + * @param el + * @param errorMsg + * + * Triggers validation error for provided element. + * Note : the basic jQuery validation elements should be present in the markup + * + */ +function triggerError(el,errorMsg){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + errorSpan.on('click',function(event){ + event.stopPropagation(); + removeErrorStyling($(this)); + el.unbind('.errorspace'); + }); + + el.bind('focusin.errorspace',function(){ + removeErrorStyling($(this)) + }).bind('focusout.errorspace',function(){ + addErrorStyling($(this)); + }).bind('keypress.errorspace',function(){ + $(this).unbind('.errorspace'); + removeErrorStyling($(this)); + }); + + errorMsgContainer.text(errorMsg); + + parent.addClass('has-error has-feedback'); + errorSpan.removeClass('hidden'); + errorMsgContainer.removeClass('hidden'); + + function removeErrorStyling(el){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + parent.removeClass('has-error has-feedback'); + errorSpan.addClass('hidden'); + errorMsgContainer.addClass('hidden'); + } + + function addErrorStyling(el){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + parent.addClass('has-error has-feedback'); + errorSpan.removeClass('hidden'); + errorMsgContainer.removeClass('hidden'); + } +} + function displayErrors(message) { $('#error-msg').html(message.responseText); modalDialog.header('Unexpected error occurred!'); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 439861e956a..af4c5606f6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -93,7 +93,7 @@ function loadGroups() { var currentUser = groupListing.data("currentUser"); var serviceURL; if ($.hasPermission("LIST_ALL_GROUPS")) { - serviceURL = "/api/device-mgt/v1.0/groups"; + serviceURL = "/api/device-mgt/v1.0/admin/groups"; } else if ($.hasPermission("LIST_GROUPS")) { //Get authenticated users groups serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser; @@ -113,8 +113,7 @@ function loadGroups() { groupId: data.deviceGroups[index].id, name: data.deviceGroups[index].name, description: data.deviceGroups[index].description, - owner: data.deviceGroups[index].owner, - dateOfCreation: data.deviceGroups[index].dateOfCreation + owner: data.deviceGroups[index].owner }) }); var json = { @@ -153,7 +152,7 @@ function loadGroups() { data: 'id', class: 'text-right content-fill text-left-on-grid-view no-wrap', render: function (id, type, row, meta) { - var html; + var html = ''; if ($.hasPermission("VIEW_GROUP_DEVICES")) { html = '' + @@ -166,46 +165,39 @@ function loadGroups() { '' + ''; - } else { - html = ''; - } - if ($.hasPermission("SHARE_GROUP")) { - html += - ''; - } else { - html += ''; - } - if ($.hasPermission("UPDATE_GROUP")) { - html += - '' + - ''; - } else { - html += ''; } - if ($.hasPermission("REMOVE_GROUP")) { - html += - '' - + - ''; - } else { - html += ''; + if (row.owner != "wso2.system.user") { + if ($.hasPermission("SHARE_GROUP")) { + html += + ''; + } + if ($.hasPermission("UPDATE_GROUP")) { + html += + '' + + ''; + } + if ($.hasPermission("REMOVE_GROUP")) { + html += + '' + + + ''; + } } return html; } } - ]; var fnCreatedRow = function (row, data) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js index 20cc6f96f51..61c094c3b6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js @@ -20,6 +20,7 @@ var deviceId = $(".device-id"); var deviceIdentifier = deviceId.data("deviceid"); var deviceType = deviceId.data("type"); + var deviceOwner = deviceId.data("owner"); $(document).ready(function () { $(".panel-body").removeClass("hidden"); @@ -45,7 +46,7 @@ }); }); - + function loadOperationsLog(update) { var operationsLogTable = "#operations-log-table"; if (update) { @@ -54,76 +55,78 @@ return; } operationTable = $(operationsLogTable).datatables_extended({ - serverSide: true, - processing: false, - searching: false, - ordering: false, - pageLength : 10, - order: [], - ajax: { - url: context + "/api/operation/paginate", - data: {deviceId : deviceIdentifier, deviceType: deviceType}, - dataSrc: function (json) { - $("#operations-spinner").addClass("hidden"); - $("#operations-log-container").empty(); - return json.data; - } - }, - columnDefs: [ - {targets: 0, data: "code" }, - {targets: 1, data: "status", render: - function (status) { - var html; - switch (status) { - case "COMPLETED" : - html = " Completed"; - break; - case "PENDING" : - html = " Pending"; - break; - case "ERROR" : - html = " Error"; - break; - case "IN_PROGRESS" : - html = " In Progress"; - break; - case "REPEATED" : - html = " Repeated"; - break; - } - return html; - } - }, - {targets: 2, data: "createdTimeStamp", render: - function (date) { - var value = String(date); - return value.slice(0, 16); - } - } - ], - "createdRow": function(row, data) { - $(row).attr("data-type", "selectable"); - $(row).attr("data-id", data["id"]); - $.each($("td", row), - function(colIndex) { - switch(colIndex) { - case 1: - $(this).attr("data-grid-label", "Code"); - $(this).attr("data-display", data["code"]); - break; - case 2: - $(this).attr("data-grid-label", "Status"); - $(this).attr("data-display", data["status"]); - break; - case 3: - $(this).attr("data-grid-label", "Created Timestamp"); - $(this).attr("data-display", data["createdTimeStamp"]); - break; - } - } - ); - } - }); + serverSide: true, + processing: false, + searching: false, + ordering: false, + pageLength : 10, + order: [], + ajax: { + + url: "/devicemgt/api/operation/paginate", + data: {deviceId : deviceIdentifier, deviceType: deviceType, owner: deviceOwner}, + dataSrc: function (json) { + $("#operations-spinner").addClass("hidden"); + $("#operations-log-container").empty(); + return json.data; + } + }, + columnDefs: [ + {targets: 0, data: "code" }, + {targets: 1, data: "status", render: + function (status) { + var html; + switch (status) { + case "COMPLETED" : + html = " Completed"; + break; + case "PENDING" : + html = " Pending"; + break; + case "ERROR" : + html = " Error"; + break; + case "IN_PROGRESS" : + html = " In Progress"; + break; + case "REPEATED" : + html = " Repeated"; + break; + } + return html; + } + }, + {targets: 2, data: "createdTimeStamp", render: + function (date) { + var value = String(date); + return value.slice(0, 16); + } + } + ], + "createdRow": function(row, data) { + + $(row).attr("data-type", "selectable"); + $(row).attr("data-id", data["id"]); + $.each($("td", row), + function(colIndex) { + switch(colIndex) { + case 1: + $(this).attr("data-grid-label", "Code"); + $(this).attr("data-display", data["code"]); + break; + case 2: + $(this).attr("data-grid-label", "Status"); + $(this).attr("data-display", data["status"]); + break; + case 3: + $(this).attr("data-grid-label", "Created Timestamp"); + $(this).attr("data-display", data["createdTimeStamp"]); + break; + } + } + ); + } + }); } function loadPolicyCompliance() { @@ -175,7 +178,7 @@ } else { $("#policy-list-container"). html("

This device " + - "has no policy applied.

"); + "has no policy applied.

"); } } }, @@ -183,7 +186,7 @@ function () { $("#policy-list-container"). html("

Loading policy compliance related data " + - "was not successful. please try refreshing data in a while.

"); + "was not successful. please try refreshing data in a while.

"); } ); } @@ -193,7 +196,7 @@ function () { $("#policy-list-container"). html("

Loading policy compliance related data " + - "was not successful. please try refreshing data in a while.

"); + "was not successful. please try refreshing data in a while.

"); } ); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/operations-log.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/operations-log.hbs deleted file mode 100644 index cc5db5117ad..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/operations-log.hbs +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - {{#each operations}} - - - - - - {{/each}} -
- -
Operation CodeStatusRequest created at
{{code}} - {{#equal status "COMPLETED"}} Completed{{/equal}} - {{#equal status "PENDING"}} Pending{{/equal}} - {{#equal status "ERROR"}} Error{{/equal}} - {{#equal status "IN_PROGRESS"}} In Progress{{/equal}} - {{createdTimeStamp}}
\ 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.unit.device.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs index ba038a531ba..252d7679ff9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs @@ -59,141 +59,108 @@ - {{#defineZone "device-detail-properties"}} -

- -
- -
- -
-
- -
- {{unit "cdmf.unit.device.details" device=device}} -
-
-
Policies
-
- -
-
- No policies found -
-
-
+
+ +
+
+ + + {{#defineZone "device-view-tab-contents"}} + {{#defineZone "device-details-tab-contents"}} +
+

+ + No Device details avaialbe yet. +

- - - - - Add device specific policy -
- -
-
Policy Compliance
-
- -
-
Device Location
-
-
-
-
- Not available yet -
-
-
-
-
-
Operations Log
-
- -
+ {{/defineZone}} + {{/defineZone}} +
- - {{/defineZone}} +
{{else}}

@@ -206,6 +173,7 @@

Device not found

+
You have tried to access either a removed or non-existing device. {{/if}} @@ -221,7 +189,4 @@ - {{/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.unit.device.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js index 209f3c06541..c93097ab791 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js @@ -95,8 +95,8 @@ function onRequest(context) { if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] != 0) { viewModel["internalMemory"]["usage"] = Math. round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] - - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 10000) / 100; + filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"]) + / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 10000) / 100; } else { viewModel["internalMemory"]["usage"] = 0; } @@ -107,8 +107,8 @@ function onRequest(context) { if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] != 0) { viewModel["externalMemory"]["usage"] = Math. round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] - - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_AVAILABLE_MEMORY"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100; + filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_AVAILABLE_MEMORY"]) + / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100; } else { viewModel["externalMemory"]["usage"] = 0; } @@ -122,8 +122,8 @@ function onRequest(context) { if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] != 0) { viewModel["internalMemory"]["usage"] = Math. round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] - - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["AvailableDeviceCapacity"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 10000) / 100; + filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["AvailableDeviceCapacity"]) + / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 10000) / 100; } else { viewModel["internalMemory"]["usage"] = 0; } @@ -162,8 +162,8 @@ function onRequest(context) { if (filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] != 0) { viewModel["ramUsage"]["value"] = Math. round((filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] - - filteredDeviceData["latestDeviceInfo"]["availableRAMMemory"]) - / filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100; + filteredDeviceData["latestDeviceInfo"]["availableRAMMemory"]) + / filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100; } else { viewModel["ramUsage"]["value"] = 0; } @@ -174,8 +174,8 @@ function onRequest(context) { if (filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] != 0) { viewModel["internalMemory"]["usage"] = Math. round((filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] - - filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"]) - / filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 10000) / 100; + filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"]) + / filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 10000) / 100; } else { viewModel["internalMemory"]["usage"] = 0; } @@ -186,8 +186,8 @@ function onRequest(context) { if (filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] != 0) { viewModel["externalMemory"]["usage"] = Math. round((filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] - - filteredDeviceData["latestDeviceInfo"]["externalAvailableMemory"]) - / filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100; + filteredDeviceData["latestDeviceInfo"]["externalAvailableMemory"]) + / filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100; } else { viewModel["externalMemory"]["usage"] = 0; } @@ -196,7 +196,7 @@ function onRequest(context) { viewModel["deviceInfoAvailable"] = false; } - deviceViewData["deviceView"] = viewModel; + deviceViewData["device"] = viewModel; } else if (response["status"] == "unauthorized") { deviceViewData["deviceFound"] = true; deviceViewData["isAuthorized"] = false; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js index b66dfd75665..2f849a44c94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js @@ -59,6 +59,11 @@ var disableInlineError = function (inputField, errorMsg, errorSign) { } }; +/** + * Load all device groups. + * + * @param callback function to call on loading completion. + */ function loadGroups(callback) { invokerUtil.get( "/api/device-mgt/v1.0/groups", @@ -68,6 +73,12 @@ function loadGroups(callback) { }); } +/** + * Creates DeviceGroupWrapper object from selected groups. + * + * @param selectedGroups + * @returns {Array} DeviceGroupWrapper list. + */ var createDeviceGroupWrapper = function (selectedGroups) { var groupObjects = []; loadGroups(function (deviceGroups) { @@ -136,7 +147,6 @@ stepForwardFrom["policy-platform"] = function (actionButton) { $.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) { var content = template(); $("#device-type-policy-operations").html(content).removeClass("hidden"); - // $("#device-type-policy-operations").removeClass("hidden"); $(".policy-platform").addClass("hidden"); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs index 5863d6ba762..9a6135b607d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs @@ -63,7 +63,7 @@ -
+