harshanl 8 years ago
commit 42c47cfff2

@ -42,7 +42,7 @@ var userModule = function () {
privateMethods.getCarbonUser = function () { privateMethods.getCarbonUser = function () {
var carbon = require("carbon"); var carbon = require("carbon");
var carbonUser = session.get(constants["USER_SESSION_KEY"]); var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/modules/utility.js")["utility"]; var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) { if (!carbonUser) {
log.error("User object was not found in the session"); log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"]; throw constants["ERRORS"]["USER_NOT_FOUND"];
@ -174,7 +174,11 @@ var userModule = function () {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username) + "/roles"; encodeURIComponent(username) + "/roles";
return privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
}
return response;
} catch (e) { } catch (e) {
throw e; throw e;
} finally { } finally {
@ -265,7 +269,7 @@ var userModule = function () {
/** /**
* Get Platforms. * Get Platforms.
*/ */
//TODO Move this piece of logic out of user.js to somewhere else appropriate. //TODO Move this piece of logic out of user.js to somewhere else appropriate.
publicMethods.getPlatforms = function () { publicMethods.getPlatforms = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]); var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"]; var utility = require("/app/modules/utility.js")["utility"];

@ -56,9 +56,9 @@
</label> </label>
<div class="wr-input-control"> <div class="wr-input-control">
<select id="userStore" class="form-control select"> <select id="userStore" class="form-control select">
<option>PRIMARY</option> <option value="PRIMARY">PRIMARY</option>
{{#each userStores}} {{#each userStores}}
<option>{{this}}</option> <option value="{{this}}">{{this}}</option>
{{/each}} {{/each}}
</select> </select>
</div> </div>
@ -113,15 +113,17 @@
<div id="user-created-msg" class="container col-centered wr-content hidden"> <div id="user-created-msg" class="container col-centered wr-content hidden">
<div class="wr-form"> <div class="wr-form">
<p class="page-sub-title">User was added successfully.</p> <p class="page-sub-title">User was added successfully.</p>
<br> <p>
An invitation mail will be sent to this user to initiate device enrollment. An invitation mail will be sent to this user to initiate device enrollment.
Below QR code can also be used to enroll a device. Below QR code can also be used to enroll a device.
</p>
<div class="panel panel-default"> <div class="panel panel-default">
<div id="qr-code-modal" class="hidden" data-enrollment-url="{{enrollmentURL}}"></div>
<div class="panel-body"> <div class="panel-body">
<div class="qr-code col-lg-5 col-md-6 col-centered"></div> <div class="qr-code col-lg-5 col-md-6 col-centered"></div>
</div> </div>
</div> </div>
<br>Please click <b>"Add Another User"</b>, if you wish to add another user or click <br>Please click <b>"Add Another User"</b>, if you wish to add another user or click
<b>"View User List"</b> to complete the process and go back to the user list. <b>"View User List"</b> to complete the process and go back to the user list.
<hr/> <hr/>

@ -39,6 +39,7 @@ function onRequest() {
page["firstnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"]; page["firstnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"];
page["lastnameJSRegEx"] = devicemgtProps["userValidationConfig"]["lastnameJSRegEx"]; page["lastnameJSRegEx"] = devicemgtProps["userValidationConfig"]["lastnameJSRegEx"];
page["lastnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"]; page["lastnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"];
page["enrollmentURL"] = devicemgtProps["generalConfig"]["host"] + devicemgtProps["enrollmentDir"];
return page; return page;
} }

@ -161,6 +161,18 @@ function emailIsValid(email) {
return regExp.test(email); return regExp.test(email);
} }
/*
* QR-code generation function.
*/
function generateQRCode(qrCodeClass) {
var enrollmentURL = $("#qr-code-modal").data("enrollment-url");
$(qrCodeClass).qrcode({
text: enrollmentURL,
width: 200,
height: 200
});
}
$("#userStore").change( $("#userStore").change(
function () { function () {
var str = ""; var str = "";

@ -15,7 +15,7 @@
specific language governing permissions and limitations specific language governing permissions and limitations
under the License. under the License.
}} }}
{{unit "cdmf.unit.ui.title" pageTitle="User Management"}} {{unit "cdmf.unit.ui.title" pageTitle="User Management | Edit User"}}
{{#zone "breadcrumbs"}} {{#zone "breadcrumbs"}}
<li> <li>
@ -51,6 +51,15 @@
<div id="user-create-error-msg" class="alert alert-danger hidden" role="alert"> <div id="user-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<label class="wr-input-label" title="Select the domain of the user store from the drop-down given below. The domain of the default user store is PRIMARY">
User Store Domain
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</label>
<div class="wr-input-control">
<select id="userStore" class="form-control select" disabled>
<option value="{{userStore}}" selected>{{userStore}}</option>
</select>
</div>
<label class="wr-input-label"> <label class="wr-input-label">
User Name <br> User Name <br>
</label> </label>
@ -59,8 +68,6 @@
data-errormsg="{{usernameRegExViolationErrorMsg}}" class="form-control" data-errormsg="{{usernameRegExViolationErrorMsg}}" class="form-control"
value="{{editUser.username}}" disabled/> value="{{editUser.username}}" disabled/>
</div> </div>
<label class="wr-input-label">First Name *</label> <label class="wr-input-label">First Name *</label>
<div id="firstNameField" class="form-group wr-input-control"> <div id="firstNameField" class="form-group wr-input-control">
<input type="text" id="firstname" data-regex="{{firstnameJSRegEx}}" <input type="text" id="firstname" data-regex="{{firstnameJSRegEx}}"
@ -95,12 +102,9 @@
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span> <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</label> </label>
<div class="wr-input-control"> <div class="wr-input-control">
<select id="roles" class="form-control select2" multiple="multiple" selectedVals=" <select id="roles" class="form-control select2" multiple="multiple"
{{#each usersRoles}} selectedVals="{{#each rolesByUsername}} {{this}}, {{/each}}">
{{this}}, {{#each rolesByUserStore}}
{{/each}}
">
{{#each userRoles}}
<option>{{this}}</option> <option>{{this}}</option>
{{/each}} {{/each}}
</select> </select>

@ -16,14 +16,16 @@
* under the License. * under the License.
*/ */
function onRequest(context) { function onRequest() {
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var userName = request.getParameter("username"); var userName = request.getParameter("username");
var user = userModule.getUser(userName)["content"]; var user = userModule.getUser(userName)["content"];
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
if (user) { if (user) {
var title; var title;
if (user.firstname || user.lastname) { if (user.firstname && user.lastname) {
title = user.firstname + " " + user.lastname; title = user.firstname + " " + user.lastname;
} else { } else {
title = user.username; title = user.username;
@ -34,6 +36,8 @@ function onRequest(context) {
if (userName.indexOf("/") > -1) { if (userName.indexOf("/") > -1) {
userStore = userName.substr(0, userName.indexOf('/')); userStore = userName.substr(0, userName.indexOf('/'));
} }
page["userStore"] = userStore;
var response = userModule.getUser(userName); var response = userModule.getUser(userName);
if (response["status"] == "success") { if (response["status"] == "success") {
@ -41,28 +45,27 @@ function onRequest(context) {
} }
response = userModule.getRolesByUsername(userName); response = userModule.getRolesByUsername(userName);
var rolesByUsername;
if (response["status"] == "success") { if (response["status"] == "success") {
page["usersRoles"] = response["content"]; rolesByUsername = response["content"];
} }
response = userModule.getRolesByUserStore(userStore); response = userModule.getRolesByUserStore(userStore);
var rolesByUserStore;
if (response["status"] == "success") { if (response["status"] == "success") {
var roleVals = response["content"]; rolesByUserStore = response["content"];
var filteredRoles = [];
var prefix = "Application";
for (i = 0; i < roleVals.length; i++) {
if(roleVals[i].indexOf(prefix) < 0){
filteredRoles.push(roleVals[i]);
}
}
page["userRoles"] = filteredRoles;
} }
page["rolesByUsername"] = rolesByUsername;
page["rolesByUserStore"] = rolesByUserStore;
} }
page["usernameJSRegEx"] = devicemgtProps.userValidationConfig.usernameJSRegEx;
page["usernameRegExViolationErrorMsg"] = devicemgtProps.userValidationConfig.usernameRegExViolationErrorMsg; page["usernameJSRegEx"] = devicemgtProps["userValidationConfig"]["usernameJSRegEx"];
page["firstnameJSRegEx"] = devicemgtProps.userValidationConfig.firstnameJSRegEx; page["usernameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["usernameRegExViolationErrorMsg"];
page["firstnameRegExViolationErrorMsg"] = devicemgtProps.userValidationConfig.firstnameRegExViolationErrorMsg; page["firstnameJSRegEx"] = devicemgtProps["userValidationConfig"]["firstnameJSRegEx"];
page["lastnameJSRegEx"] = devicemgtProps.userValidationConfig.lastnameJSRegEx; page["firstnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"];
page["lastnameRegExViolationErrorMsg"] = devicemgtProps.userValidationConfig.lastnameRegExViolationErrorMsg; page["lastnameJSRegEx"] = devicemgtProps["userValidationConfig"]["lastnameJSRegEx"];
page["lastnameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"];
return page; return page;
} }

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

@ -32,6 +32,8 @@ function inputIsValid(regExp, inputString) {
var validateInline = {}; var validateInline = {};
var clearInline = {}; var clearInline = {};
var deviceMgtBasePath = "/api/device-mgt/v1.0";
var enableInlineError = function (inputField, errorMsg, errorSign) { var enableInlineError = function (inputField, errorMsg, errorSign) {
var fieldIdentifier = "#" + inputField; var fieldIdentifier = "#" + inputField;
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg; var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
@ -180,7 +182,8 @@ $(document).ready(function () {
var usernameInput = $("input#username"); var usernameInput = $("input#username");
var firstnameInput = $("input#firstname"); var firstnameInput = $("input#firstname");
var lastnameInput = $("input#lastname"); var lastnameInput = $("input#lastname");
var charLimit = parseInt($("input#username").attr("limit")); // var charLimit = parseInt($("input#username").attr("limit"));
var domain = $("#userStore").val();
var username = usernameInput.val().trim(); var username = usernameInput.val().trim();
var firstname = firstnameInput.val(); var firstname = firstnameInput.val();
var lastname = lastnameInput.val(); var lastname = lastnameInput.val();
@ -215,7 +218,7 @@ $(document).ready(function () {
} else { } else {
var addUserFormData = {}; var addUserFormData = {};
addUserFormData.username = username; addUserFormData.username = domain + "/" + username;
addUserFormData.firstname = firstname; addUserFormData.firstname = firstname;
addUserFormData.lastname = lastname; addUserFormData.lastname = lastname;
addUserFormData.emailAddress = emailAddress; addUserFormData.emailAddress = emailAddress;
@ -225,14 +228,13 @@ $(document).ready(function () {
} }
addUserFormData.roles = roles; addUserFormData.roles = roles;
var addUserAPI = "/devicemgt_admin/users?username=" + username; var addUserAPI = deviceMgtBasePath + "/users/" + username;
invokerUtil.put( invokerUtil.put(
addUserAPI, addUserAPI,
addUserFormData, addUserFormData,
function (data) { function (data, textStatus, jqXHR) {
data = JSON.parse(data); if (jqXHR.status == 201) {
if (data["statusCode"] == 201) {
// Clearing user input fields. // Clearing user input fields.
$("input#username").val(""); $("input#username").val("");
$("input#firstname").val(""); $("input#firstname").val("");
@ -243,13 +245,14 @@ $(document).ready(function () {
$("#user-create-form").addClass("hidden"); $("#user-create-form").addClass("hidden");
$("#user-created-msg").removeClass("hidden"); $("#user-created-msg").removeClass("hidden");
} }
}, function (data) { }, function (jqXHR) {
if (data["statusCode"] == 409) { var payload = JSON.parse(jqXHR.responseText);
if (jqXHR.status == 409) {
$(errorMsg).text("User : " + username + " doesn't exists. You cannot proceed."); $(errorMsg).text("User : " + username + " doesn't exists. You cannot proceed.");
} else if (data["statusCode"] == 500) { } else if (jqXHR.status == 500) {
$(errorMsg).text("An unexpected error occurred @ backend server. Please try again later."); $(errorMsg).text("An unexpected error occurred at backend server. Please try again later.");
} else { } else {
$(errorMsg).text(data.errorMessage); $(errorMsg).text(payload.message);
} }
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} }

@ -16,6 +16,18 @@
* under the License. * under the License.
*/ */
/**
* Checks if provided input is valid against RegEx input.
*
* @param regExp Regular expression
* @param inputString Input string to check
* @returns {boolean} Returns true if input matches RegEx
*/
function inputIsValid(regExp, inputString) {
regExp = new RegExp(regExp);
return regExp.test(inputString);
}
$(function () { $(function () {
var sortableElem = '.wr-sortable'; var sortableElem = '.wr-sortable';
$(sortableElem).sortable({ $(sortableElem).sortable({
@ -116,9 +128,8 @@ $("a.invite-user-link").click(function () {
* when a user clicks on "Remove" link * when a user clicks on "Remove" link
* on User Listing page in WSO2 MDM Console. * on User Listing page in WSO2 MDM Console.
*/ */
function removeUser(uname, uid) { function removeUser(uname) {
var username = uname; var username = uname;
var userid = uid;
var removeUserAPI = apiBasePath + "/users/" + username; var removeUserAPI = apiBasePath + "/users/" + username;
$(modalPopupContent).html($('#remove-user-modal-content').html()); $(modalPopupContent).html($('#remove-user-modal-content').html());
showPopup(); showPopup();
@ -127,7 +138,7 @@ function removeUser(uname, uid) {
invokerUtil.delete( invokerUtil.delete(
removeUserAPI, removeUserAPI,
function () { function () {
$("#" + userid).remove(); $("#role-" + username).remove();
// get new user-list-count // get new user-list-count
var newUserListCount = $(".user-list > span").length; var newUserListCount = $(".user-list > span").length;
// update user-listing-status-msg with new user-count // update user-listing-status-msg with new user-count
@ -264,12 +275,12 @@ function loadUsers(searchParam) {
}; };
return JSON.stringify( json ); return JSON.stringify( json );
}; }
var fnCreatedRow = function( nRow, aData, iDataIndex ) { var fnCreatedRow = function( nRow, aData, iDataIndex ) {
$(nRow).attr('data-type', 'selectable'); $(nRow).attr('data-type', 'selectable');
$(nRow).attr('data-username', aData["filter"]); $(nRow).attr('data-username', aData["filter"]);
}; }
var columns = [ var columns = [
{ {
@ -302,19 +313,19 @@ function loadUsers(searchParam) {
class: "text-right content-fill text-left-on-grid-view no-wrap", class: "text-right content-fill text-left-on-grid-view no-wrap",
data: null, data: null,
render: function ( data, type, row, meta ) { render: function ( data, type, row, meta ) {
return '<a href="/emm/users/edit-user?username=' + data.username + '" data-username="' + data.username + return '<a href="/emm/user/edit?username=' + data.filter + '" data-username="' + data.filter +
'" data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-user-link"> ' + '" data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-user-link"> ' +
'<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-edit fw-stack-1x"></i>' + '<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-edit fw-stack-1x"></i>' +
' </span> <span class="hidden-xs hidden-on-grid-view">Edit</span> </a>' + ' </span> <span class="hidden-xs hidden-on-grid-view">Edit</span> </a>' +
'<a href="#" data-username="' + data.username + '" data-userid=' + data.username + '<a href="#" data-username="' + data.filter + '" data-userid=' + data.filter +
' data-click-event="remove-form" onclick="javascript:removeUser(\'' + data.username + '\', \'' + ' data-click-event="remove-form" onclick="javascript:removeUser(\'' + data.filter + '\')" ' +
data.username + '\')" class="btn padding-reduce-on-grid-view remove-user-link">' + 'class="btn padding-reduce-on-grid-view remove-user-link">' +
'<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-delete fw-stack-1x">' + '<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-delete fw-stack-1x">' +
'</i> </span> <span class="hidden-xs hidden-on-grid-view">Remove</span> </a>' + '</i> </span> <span class="hidden-xs hidden-on-grid-view">Remove</span> </a>' +
'<a href="#" data-username="' + data.username + '" data-userid="' + data.username + '<a href="#" data-username="' + data.filter + '" data-userid="' + data.filter +
'" data-click-event="edit-form" onclick="javascript:resetPassword(\'' + data.username + '" data-click-event="edit-form" onclick="javascript:resetPassword(\'' + data.filter +
'\')" class="btn padding-reduce-on-grid-view remove-user-link"> <span class="fw-stack"> <i class="fw fw-ring fw-stack-2x">' + '\')" class="btn padding-reduce-on-grid-view remove-user-link"> <span class="fw-stack"> <i class="fw fw-ring fw-stack-2x">' +
'</i> <i class="fw fw-key fw-stack-1x"></i> <span class="fw-stack fw-move-right fw-move-bottom"> <i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"><' + '</i> <i class="fw fw-key fw-stack-1x"></i> <span class="fw-stack fw-move-right fw-move-bottom"> <i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"><' +
'/i> <i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-refresh fw-stack-1x fw-inverse">' + '/i> <i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-refresh fw-stack-1x fw-inverse">' +

Loading…
Cancel
Save