Fixes related to having special characters in role name

revert-70aa11f8
Megala 8 years ago
parent a04f91cddb
commit e55b3a6d5f

@ -175,7 +175,6 @@
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId> <artifactId>org.wso2.carbon.user.core</artifactId>
<version>4.4.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.registry</groupId> <groupId>org.wso2.carbon.registry</groupId>

@ -187,7 +187,7 @@ var userModule = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username); encodeURIComponent(username);
if (domain) { if (domain) {
url += '?domain=' + domain; url += '?domain=' + encodeURIComponent(domain);
} }
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
response["content"] = parse(response.content); response["content"] = parse(response.content);
@ -217,7 +217,7 @@ var userModule = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username) + "/roles"; encodeURIComponent(username) + "/roles";
if (domain) { if (domain) {
url += '?domain=' + domain; url += '?domain=' + encodeURIComponent(domain);
} }
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
@ -328,7 +328,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?user-store=" + userStore + "&limit=100"; "/roles?user-store=" + encodeURIComponent(userStore) + "&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content).roles; response.content = parse(response.content).roles;
@ -388,7 +388,7 @@ var userModule = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles/" + encodeURIComponent(roleName); "/roles/" + encodeURIComponent(roleName);
if (userStore) { if (userStore) {
url += "?user-store=" + userStore; url += "?user-store=" + encodeURIComponent(userStore);
} }
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {

@ -130,7 +130,7 @@ $(document).ready(function () {
var postData = {}; var postData = {};
postData.requestMethod = "GET"; postData.requestMethod = "GET";
postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term + postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term +
"&domain=" + domain; "&domain=" + encodeURIComponent(domain);
postData.requestPayload = null; postData.requestPayload = null;
return JSON.stringify(postData); return JSON.stringify(postData);
}, },
@ -204,7 +204,7 @@ $(document).ready(function () {
$("input#roleName").val(""); $("input#roleName").val("");
$("#domain").val("PRIMARY"); $("#domain").val("PRIMARY");
$("#users").val(""); $("#users").val("");
window.location.href = appContext + "/role/edit-permission/" + addRoleFormData.roleName; window.location.href = appContext + "/role/edit-permission/?rolename=" + encodeURIComponent(addRoleFormData.roleName);
} }
}, },
function (jqXHR) { function (jqXHR) {

@ -1,5 +1,5 @@
{ {
"version": "1.0.0", "version": "1.0.0",
"uri": "/role/edit-permission/{+any}", "uri": "/role/edit-permission/",
"layout": "cdmf.layout.default" "layout": "cdmf.layout.default"
} }

@ -206,9 +206,9 @@ $("#role-grid").on("click", ".remove-role-link", function () {
userStore = role.substr(0, role.indexOf('/')); userStore = role.substr(0, role.indexOf('/'));
role = role.substr(role.indexOf('/') + 1); role = role.substr(role.indexOf('/') + 1);
} }
var removeRoleAPI = apiBasePath + "/roles/" + role; var removeRoleAPI = apiBasePath + "/roles/" + encodeURIComponent(role);
if (userStore) { if (userStore) {
removeRoleAPI += "?user-store=" + userStore; removeRoleAPI += "?user-store=" + encodeURIComponent(userStore);
} }
$(modalPopupContent).html($('#remove-role-modal-content').html()); $(modalPopupContent).html($('#remove-role-modal-content').html());
showPopup(); showPopup();

@ -180,8 +180,7 @@ $("#userStore").change(
str += $(this).text() + ""; str += $(this).text() + "";
}); });
if ($("#roles").length > 0) { if ($("#roles").length > 0) {
var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + str + "&limit=100"; var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + encodeURIComponent(str) + "&limit=100";
invokerUtil.get( invokerUtil.get(
getRolesAPI, getRolesAPI,
function (data) { function (data) {
@ -189,7 +188,7 @@ $("#userStore").change(
if (data.errorMessage) { if (data.errorMessage) {
$(errorMsg).text("Selected user store prompted an error : " + data.errorMessage); $(errorMsg).text("Selected user store prompted an error : " + data.errorMessage);
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} else if (data.count > 0) { } else {
$("#roles").empty(); $("#roles").empty();
for (var i = 0; i < data.roles.length; i++) { for (var i = 0; i < data.roles.length; i++) {
var newOption = $('<option value="' + data.roles[i] + '">' + data.roles[i] + '</option>'); var newOption = $('<option value="' + data.roles[i] + '">' + data.roles[i] + '</option>');

@ -236,7 +236,8 @@ $(document).ready(function () {
} }
addUserFormData.roles = roles; addUserFormData.roles = roles;
username = username.substr(username.indexOf('/') + 1); username = username.substr(username.indexOf('/') + 1);
var addUserAPI = deviceMgtBasePath + "/users/" + username + "?domain=" + domain; var addUserAPI = deviceMgtBasePath + "/users/" + encodeURIComponent(username) + "?domain=" +
encodeURIComponent(domain);
invokerUtil.put( invokerUtil.put(
addUserAPI, addUserAPI,

@ -158,7 +158,7 @@ function resetPassword(username) {
} }
var resetPasswordServiceURL = apiBasePath + "/admin/users/" + username + "/credentials"; var resetPasswordServiceURL = apiBasePath + "/admin/users/" + username + "/credentials";
if (domain) { if (domain) {
resetPasswordServiceURL += '?domain=' + domain; resetPasswordServiceURL += '?domain=' + encodeURIComponent(domain);
} }
invokerUtil.post( invokerUtil.post(
resetPasswordServiceURL, resetPasswordServiceURL,
@ -198,11 +198,10 @@ function removeUser(username) {
domain = username.substr(0, username.indexOf('/')); domain = username.substr(0, username.indexOf('/'));
username = username.substr(username.indexOf('/') + 1); username = username.substr(username.indexOf('/') + 1);
} }
var removeUserAPI = apiBasePath + "/users/" + username; var removeUserAPI = apiBasePath + "/users/" + encodeURIComponent(username);
if (domain) { if (domain) {
removeUserAPI += '?domain=' + domain; removeUserAPI += '?domain=' + encodeURIComponent(domain);
} }
modalDialog.header("Remove User"); modalDialog.header("Remove User");
modalDialog.content("Do you really want to remove this user ?"); modalDialog.content("Do you really want to remove this user ?");
modalDialog.footer('<div class="buttons"> <a href="#" id="remove-user-yes-link" class="btn-operations">Remove</a> ' + modalDialog.footer('<div class="buttons"> <a href="#" id="remove-user-yes-link" class="btn-operations">Remove</a> ' +

@ -24,22 +24,6 @@
*/ */
function onRequest(context) { function onRequest(context) {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var uri = request.getRequestURI(); context["roleName"] = request.getParameter("rolename");
var uriMatcher = new URIMatcher(String(uri));
var isMatched = uriMatcher.match("/{context}/role/edit-permission/{rolename}");
var matchedElements;
var roleName;
var userStore;
if (isMatched) {
matchedElements = uriMatcher.elements();
roleName = matchedElements.rolename;
context["roleName"] = roleName;
} else if (uriMatcher.match("/{context}/role/edit-permission/{userStore}/{rolename}")) {
matchedElements = uriMatcher.elements();
userStore = matchedElements.userStore;
roleName = matchedElements.rolename;
context["roleName"] = userStore + '/' + roleName;
}
return context; return context;
} }

@ -109,7 +109,7 @@ $(document).ready(function () {
} }
var serviceUrl = apiBasePath + "/roles/" +encodeURIComponent(roleName)+"/permissions"; var serviceUrl = apiBasePath + "/roles/" +encodeURIComponent(roleName)+"/permissions";
if (userStore) { if (userStore) {
serviceUrl += "?user-store=" + userStore; serviceUrl += "?user-store=" + encodeURIComponent(userStore);
} }
$.registerPartial("list", listPartialSrc, function(){ $.registerPartial("list", listPartialSrc, function(){
$.template("treeTemplate", treeTemplateSrc, function (template) { $.template("treeTemplate", treeTemplateSrc, function (template) {
@ -158,14 +158,14 @@ $(document).ready(function () {
userStore = roleName.substr(0, roleName.indexOf('/')); userStore = roleName.substr(0, roleName.indexOf('/'));
roleName = roleName.substr(roleName.indexOf('/') + 1); roleName = roleName.substr(roleName.indexOf('/') + 1);
} }
var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName; var updateRolePermissionAPI = apiBasePath + "/roles/" + encodeURIComponent(roleName);
var updateRolePermissionData = {}; var updateRolePermissionData = {};
var perms = []; var perms = [];
$("#permissionList li input:checked").each(function(){ $("#permissionList li input:checked").each(function(){
perms.push($(this).data("resourcepath")); perms.push($(this).data("resourcepath"));
}); });
if (userStore) { if (userStore) {
updateRolePermissionAPI += "?user-store=" + userStore; updateRolePermissionAPI += "?user-store=" + encodeURIComponent(userStore);
updateRolePermissionData.roleName = userStore + "/" + roleName; updateRolePermissionData.roleName = userStore + "/" + roleName;
} else { } else {
updateRolePermissionData.roleName = roleName; updateRolePermissionData.roleName = roleName;

@ -131,7 +131,8 @@ $(document).ready(function () {
data: function (params) { data: function (params) {
var postData = {}; var postData = {};
postData.actionMethod = "GET"; postData.actionMethod = "GET";
postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term + "&domain=" + domain; postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term + "&domain=" +
encodeURIComponent(domain);
postData.actionPayload = null; postData.actionPayload = null;
return JSON.stringify(postData); return JSON.stringify(postData);
}, },
@ -182,10 +183,10 @@ $(document).ready(function () {
} else { } else {
var addRoleFormData = {}; var addRoleFormData = {};
addRoleFormData.roleName = roleName; addRoleFormData.roleName = roleName;
var addRoleAPI = apiBasePath + "/roles/" + currentRoleName; var addRoleAPI = apiBasePath + "/roles/" + encodeURIComponent(currentRoleName);
if (domain != "PRIMARY"){ if (domain != "PRIMARY"){
addRoleFormData.roleName = domain + "/" + roleName; addRoleFormData.roleName = domain + "/" + roleName;
addRoleAPI = addRoleAPI + "?user-store=" + domain; addRoleAPI = addRoleAPI + "?user-store=" + encodeURIComponent(domain);
} }
invokerUtil.put( invokerUtil.put(
addRoleAPI, addRoleAPI,

Loading…
Cancel
Save