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
@ -109,7 +109,7 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
|
||||
//URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
||||
data = {"username": user.username, "shareUser":shareUser, "role":role};
|
||||
data = {"username": user.username, "shareUser": shareUser, "role": role};
|
||||
result = post(endPoint, data, "json");
|
||||
|
||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/unshare")) {
|
||||
@ -118,10 +118,10 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
var unShareUser = request.getContent()["unShareUser"];
|
||||
role = request.getContent()["role"];
|
||||
|
||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
||||
data = {"username": user.username, "unShareUser":unShareUser, "role":role};
|
||||
result = del(endPoint, data, "json");
|
||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
||||
result = post(endPoint, data, "json");
|
||||
|
||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) {
|
||||
|
||||
@ -131,7 +131,7 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
|
||||
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/role";
|
||||
data = {"username": user.username, "permissions":permissions, "role":role};
|
||||
data = {"username": user.username, "permissions": permissions, "role": role};
|
||||
result = post(endPoint, data, "json");
|
||||
|
||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/delete")) {
|
||||
@ -141,7 +141,7 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
|
||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/role";
|
||||
data = {"username": user.username, "role":role};
|
||||
data = {"username": user.username, "role": role};
|
||||
result = del(endPoint, data, "json");
|
||||
|
||||
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) {
|
||||
@ -159,10 +159,60 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
var userId = uriMatcher.elements().userId;
|
||||
|
||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId +"/role/all";
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
|
||||
data = {"username": user.username};
|
||||
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")) {
|
||||
|
||||
groupId = uriMatcher.elements().groupId;
|
||||
@ -189,7 +239,7 @@ if (uriMatcher.match("/{context}/api/group/add")) {
|
||||
|
||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign
|
||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign";
|
||||
data = {"username": user.username, "deviceId":deviceId, "deviceType":deviceType};
|
||||
data = {"username": user.username, "deviceId": deviceId, "deviceType": deviceType};
|
||||
result = put(endPoint, data, "json");
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{{#zone "main"}}
|
||||
<span id="permission" data-permission="{{permissions}}"></span>
|
||||
<span id="user-details" data-username="{{user.username}}"></span>
|
||||
<!-- form content placeholder -->
|
||||
<div id="ast-container" class="ast-container list-view">
|
||||
<!-- no devices found -->
|
||||
@ -30,13 +31,38 @@
|
||||
<!-- /no groups found -->
|
||||
</div>
|
||||
|
||||
<div id="share-group-modal-content" class="hide">
|
||||
<div id="share-group-w1-modal-content" class="hide">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<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">
|
||||
<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">
|
||||
OK
|
||||
</a>
|
||||
@ -53,7 +79,7 @@
|
||||
<h3>Group sharing updated successfully.</h3>
|
||||
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-group-200-link" class="btn-operations">
|
||||
<a href="#" id="share-group-200-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
var log = new Log("modules/group-listing.js");
|
||||
|
||||
function onRequest(context){
|
||||
var constants = require("/modules/constants.js");
|
||||
var permissions = [];
|
||||
//var userModule = require("/modules/user.js").userModule;
|
||||
//if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){
|
||||
@ -13,5 +16,6 @@ function onRequest(context){
|
||||
permissions.push("SHARE_GROUPS");
|
||||
context.permissions = stringify(permissions);
|
||||
context.SHARE_GROUPS = true;
|
||||
context.user = session.get(constants.USER_SESSION_KEY);
|
||||
return context;
|
||||
}
|
||||
@ -223,6 +223,13 @@ function hidePopup() {
|
||||
$(modalPopup).hide();
|
||||
}
|
||||
|
||||
var errorHandler = function () {
|
||||
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
||||
$("a#group-unexpected-error-link").click(function () {
|
||||
hidePopup();
|
||||
});
|
||||
};
|
||||
|
||||
function attachGroupAdding() {
|
||||
/**
|
||||
* Following click function would execute
|
||||
@ -272,13 +279,7 @@ function attachGroupAdding() {
|
||||
hidePopup();
|
||||
});
|
||||
}
|
||||
},
|
||||
function () {
|
||||
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
||||
$("a#group-unexpected-error-link").click(function () {
|
||||
hidePopup();
|
||||
});
|
||||
}
|
||||
}, errorHandler
|
||||
);
|
||||
});
|
||||
|
||||
@ -309,62 +310,94 @@ function attachEvents() {
|
||||
*/
|
||||
$("a.share-group-link").click(function () {
|
||||
var groupId = $(this).data("groupid");
|
||||
var shareGroupApi = "/iotserver/api/group/id/" + groupId + "/share";
|
||||
var unShareGroupApi = "/iotserver/api/group/id/" + groupId + "/unshare";
|
||||
|
||||
$(modalPopupContent).html($('#share-group-modal-content').html());
|
||||
var username = $("#user-details").data("username");
|
||||
$(modalPopupContent).html($('#share-group-w1-modal-content').html());
|
||||
$('#user-names').html('Loading...');
|
||||
showPopup();
|
||||
|
||||
$("a#share-group-share-link").click(function () {
|
||||
var data = {"shareUser":"", "role":""};
|
||||
invokerUtil.post(
|
||||
shareGroupApi,
|
||||
data,
|
||||
$("a#share-group-next-link").hide();
|
||||
invokerUtil.get("/iotserver/api/users",
|
||||
function (data, txtStatus, jqxhr) {
|
||||
var users = JSON.parse(data);
|
||||
var status = jqxhr.status;
|
||||
if (status == 200) {
|
||||
|
||||
} else {
|
||||
displayErrors(status);
|
||||
var str = '<br /><select id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
||||
var hasUsers = false;
|
||||
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();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#share-group-unshare-link").click(function () {
|
||||
var data = {"shareUser":"", "role":""};
|
||||
invokerUtil.post(
|
||||
unShareGroupApi,
|
||||
data,
|
||||
str += '</select>';
|
||||
if (!hasUsers) {
|
||||
str = "There is no any other users registered";
|
||||
return;
|
||||
}
|
||||
$('#user-names').html(str);
|
||||
$("a#share-group-next-link").show();
|
||||
$("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) {
|
||||
var roleMap = JSON.parse(data);
|
||||
var status = jqxhr.status;
|
||||
if (status == 200) {
|
||||
|
||||
} else {
|
||||
displayErrors(status);
|
||||
var str = '';
|
||||
var isChecked = '';
|
||||
var hasRoles = false;
|
||||
for (var role in roleMap) {
|
||||
if (roleMap[role].assigned == true) {
|
||||
isChecked = 'checked';
|
||||
}
|
||||
},
|
||||
function () {
|
||||
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
||||
$("a#group-unexpected-error-link").click(function () {
|
||||
hidePopup();
|
||||
});
|
||||
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + roleMap[role].role + '" value="' + roleMap[role].role
|
||||
+ '" ' + isChecked + '/>' + roleMap[role].role + '</label> ';
|
||||
hasRoles = true;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
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 () {
|
||||
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();
|
||||
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();
|
||||
});
|
||||
|
||||
@ -477,7 +510,7 @@ function attachEvents() {
|
||||
});
|
||||
}
|
||||
|
||||
function displayErrors(status){
|
||||
function displayErrors(status) {
|
||||
if (status == 400) {
|
||||
$(modalPopupContent).html($('#group-400-content').html());
|
||||
$("a#group-400-link").click(function () {
|
||||
|
||||
@ -612,3 +612,22 @@ header{background-color: #2a2a2a;}
|
||||
:-ms-input-placeholder { /* Internet Explorer 10+ */
|
||||
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