mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
Completed group sharing
This commit is contained in:
parent
2f6e195f95
commit
665e88acfb
@ -118,10 +118,10 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
|||||||
var unShareUser = request.getContent()["unShareUser"];
|
var unShareUser = request.getContent()["unShareUser"];
|
||||||
role = request.getContent()["role"];
|
role = request.getContent()["role"];
|
||||||
|
|
||||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||||
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
||||||
result = del(endPoint, data, "json");
|
result = post(endPoint, data, "json");
|
||||||
|
|
||||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) {
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) {
|
||||||
|
|
||||||
@ -163,6 +163,56 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
|||||||
data = {"username": user.username};
|
data = {"username": user.username};
|
||||||
result = get(endPoint, data, "json");
|
result = get(endPoint, data, "json");
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/rolemapping")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
|
||||||
|
data = {"username": user.username};
|
||||||
|
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all";
|
||||||
|
var allRoles = get(endPoint, data, "json").data;
|
||||||
|
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
|
||||||
|
var userRolesObj = get(endPoint, data, "json");
|
||||||
|
var userRoles = userRolesObj.data;
|
||||||
|
var roleMap = [];
|
||||||
|
for (var role in allRoles) {
|
||||||
|
var objRole = {"role": allRoles[role], "assigned": false};
|
||||||
|
for (var usrRole in userRoles) {
|
||||||
|
if (allRoles[role] == userRoles[usrRole]) {
|
||||||
|
objRole.assigned = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
roleMap.push(objRole);
|
||||||
|
}
|
||||||
|
result = {};
|
||||||
|
result.data = roleMap;
|
||||||
|
result.xhr = userRolesObj.xhr;
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/roleupdate")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
roleMap = request.getContent();
|
||||||
|
|
||||||
|
for (role in roleMap) {
|
||||||
|
if (roleMap[role].assigned == true) {
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
||||||
|
data = {"username": user.username, "shareUser": userId, "role": roleMap[role].role};
|
||||||
|
result = post(endPoint, data, "json");
|
||||||
|
} else {
|
||||||
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||||
|
data = {"username": user.username, "unShareUser": userId, "role": roleMap[role].role};
|
||||||
|
result = post(endPoint, data, "json");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) {
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) {
|
||||||
|
|
||||||
groupId = uriMatcher.elements().groupId;
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{{#zone "main"}}
|
{{#zone "main"}}
|
||||||
<span id="permission" data-permission="{{permissions}}"></span>
|
<span id="permission" data-permission="{{permissions}}"></span>
|
||||||
|
<span id="user-details" data-username="{{user.username}}"></span>
|
||||||
<!-- form content placeholder -->
|
<!-- form content placeholder -->
|
||||||
<div id="ast-container" class="ast-container list-view">
|
<div id="ast-container" class="ast-container list-view">
|
||||||
<!-- no devices found -->
|
<!-- no devices found -->
|
||||||
@ -30,13 +31,38 @@
|
|||||||
<!-- /no groups found -->
|
<!-- /no groups found -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="share-group-modal-content" class="hide">
|
<div id="share-group-w1-modal-content" class="hide">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
<h3>Share group with others</h3>
|
<h3>Select user to manage group sharing</h3>
|
||||||
|
<div id="user-names">Loading...</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
|
<a href="#" id="share-group-w1-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="share-group-next-link" class="btn-operations">
|
||||||
|
Next
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="share-group-w2-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Select sharing roles</h3>
|
||||||
|
<br />
|
||||||
|
<div id="user-roles">Loading...</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="share-group-w2-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="#" id="share-group-yes-link" class="btn-operations">
|
<a href="#" id="share-group-yes-link" class="btn-operations">
|
||||||
OK
|
OK
|
||||||
</a>
|
</a>
|
||||||
@ -53,7 +79,7 @@
|
|||||||
<h3>Group sharing updated successfully.</h3>
|
<h3>Group sharing updated successfully.</h3>
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="#" id="remove-group-200-link" class="btn-operations">
|
<a href="#" id="share-group-200-link" class="btn-operations">
|
||||||
Ok
|
Ok
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
|
var log = new Log("modules/group-listing.js");
|
||||||
|
|
||||||
function onRequest(context){
|
function onRequest(context){
|
||||||
|
var constants = require("/modules/constants.js");
|
||||||
var permissions = [];
|
var permissions = [];
|
||||||
//var userModule = require("/modules/user.js").userModule;
|
//var userModule = require("/modules/user.js").userModule;
|
||||||
//if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){
|
//if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){
|
||||||
@ -13,5 +16,6 @@ function onRequest(context){
|
|||||||
permissions.push("SHARE_GROUPS");
|
permissions.push("SHARE_GROUPS");
|
||||||
context.permissions = stringify(permissions);
|
context.permissions = stringify(permissions);
|
||||||
context.SHARE_GROUPS = true;
|
context.SHARE_GROUPS = true;
|
||||||
|
context.user = session.get(constants.USER_SESSION_KEY);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@ -223,6 +223,13 @@ function hidePopup() {
|
|||||||
$(modalPopup).hide();
|
$(modalPopup).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errorHandler = function () {
|
||||||
|
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
||||||
|
$("a#group-unexpected-error-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function attachGroupAdding() {
|
function attachGroupAdding() {
|
||||||
/**
|
/**
|
||||||
* Following click function would execute
|
* Following click function would execute
|
||||||
@ -272,13 +279,7 @@ function attachGroupAdding() {
|
|||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}, errorHandler
|
||||||
function () {
|
|
||||||
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
|
||||||
$("a#group-unexpected-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -309,62 +310,94 @@ function attachEvents() {
|
|||||||
*/
|
*/
|
||||||
$("a.share-group-link").click(function () {
|
$("a.share-group-link").click(function () {
|
||||||
var groupId = $(this).data("groupid");
|
var groupId = $(this).data("groupid");
|
||||||
var shareGroupApi = "/iotserver/api/group/id/" + groupId + "/share";
|
var username = $("#user-details").data("username");
|
||||||
var unShareGroupApi = "/iotserver/api/group/id/" + groupId + "/unshare";
|
$(modalPopupContent).html($('#share-group-w1-modal-content').html());
|
||||||
|
$('#user-names').html('Loading...');
|
||||||
$(modalPopupContent).html($('#share-group-modal-content').html());
|
|
||||||
showPopup();
|
showPopup();
|
||||||
|
$("a#share-group-next-link").hide();
|
||||||
$("a#share-group-share-link").click(function () {
|
invokerUtil.get("/iotserver/api/users",
|
||||||
var data = {"shareUser":"", "role":""};
|
|
||||||
invokerUtil.post(
|
|
||||||
shareGroupApi,
|
|
||||||
data,
|
|
||||||
function (data, txtStatus, jqxhr) {
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var users = JSON.parse(data);
|
||||||
var status = jqxhr.status;
|
var status = jqxhr.status;
|
||||||
if (status == 200) {
|
if (status == 200) {
|
||||||
|
var str = '<br /><select id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
||||||
} else {
|
var hasUsers = false;
|
||||||
displayErrors(status);
|
for (var user in users) {
|
||||||
|
if (users[user].username != username) {
|
||||||
|
str += '<option value="' + users[user].username + '">' + users[user].username + '</option>';
|
||||||
|
hasUsers = true;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
function () {
|
|
||||||
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
|
||||||
$("a#group-unexpected-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
str += '</select>';
|
||||||
});
|
if (!hasUsers) {
|
||||||
|
str = "There is no any other users registered";
|
||||||
$("a#share-group-unshare-link").click(function () {
|
return;
|
||||||
var data = {"shareUser":"", "role":""};
|
}
|
||||||
invokerUtil.post(
|
$('#user-names').html(str);
|
||||||
unShareGroupApi,
|
$("a#share-group-next-link").show();
|
||||||
data,
|
$("a#share-group-next-link").click(function () {
|
||||||
|
var selectedUser = $('#share-user-selector').val();
|
||||||
|
$(modalPopupContent).html($('#share-group-w2-modal-content').html());
|
||||||
|
$('#user-roles').html('Loading...');
|
||||||
|
$("a#share-group-yes-link").hide();
|
||||||
|
invokerUtil.get("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/rolemapping",
|
||||||
function (data, txtStatus, jqxhr) {
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var roleMap = JSON.parse(data);
|
||||||
var status = jqxhr.status;
|
var status = jqxhr.status;
|
||||||
if (status == 200) {
|
if (status == 200) {
|
||||||
|
var str = '';
|
||||||
} else {
|
var isChecked = '';
|
||||||
displayErrors(status);
|
var hasRoles = false;
|
||||||
|
for (var role in roleMap) {
|
||||||
|
if (roleMap[role].assigned == true) {
|
||||||
|
isChecked = 'checked';
|
||||||
}
|
}
|
||||||
},
|
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + roleMap[role].role + '" value="' + roleMap[role].role
|
||||||
function () {
|
+ '" ' + isChecked + '/>' + roleMap[role].role + '</label> ';
|
||||||
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
hasRoles = true;
|
||||||
$("a#group-unexpected-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
if (!hasRoles) {
|
||||||
});
|
str = "There is no any roles for this group";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$('#user-roles').html(str);
|
||||||
|
$("a#share-group-yes-link").show();
|
||||||
$("a#share-group-yes-link").click(function () {
|
$("a#share-group-yes-link").click(function () {
|
||||||
|
var updatedRoleMap = [];
|
||||||
|
for (var role in roleMap) {
|
||||||
|
if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned){
|
||||||
|
roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked');
|
||||||
|
updatedRoleMap.push(roleMap[role]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invokerUtil.post("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/roleupdate",
|
||||||
|
updatedRoleMap,
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
$(modalPopupContent).html($('#share-group-200-content').html());
|
||||||
|
$("a#share-group-200-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
location.reload();
|
|
||||||
});
|
});
|
||||||
|
}else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
$("a#share-group-w2-cancel-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
|
||||||
$("a#share-group-cancel-link").click(function () {
|
$("a#share-group-w1-cancel-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -612,3 +612,22 @@ header{background-color: #2a2a2a;}
|
|||||||
:-ms-input-placeholder { /* Internet Explorer 10+ */
|
:-ms-input-placeholder { /* Internet Explorer 10+ */
|
||||||
color: #b2b2b2;
|
color: #b2b2b2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
padding: 0;
|
||||||
|
margin:0;
|
||||||
|
vertical-align: bottom;
|
||||||
|
position: relative;
|
||||||
|
top: -1px;
|
||||||
|
*overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-text
|
||||||
|
{
|
||||||
|
/* Checkbox text */
|
||||||
|
display: inline;
|
||||||
|
padding-left: 15px;
|
||||||
|
text-indent: -15px;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user