Add group sharing UI functionality

4.x.x
Charitha Goonetilleke 9 years ago
parent d15e52491a
commit 92784120bd

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser; import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -42,6 +43,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -261,8 +263,10 @@ public class Group {
if (isShared) { if (isShared) {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} else { } else {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).entity("Group not found").build();
} }
} catch (UserDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
@ -281,8 +285,10 @@ public class Group {
if (isUnShared) { if (isUnShared) {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} else { } else {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).entity("Group not found").build();
} }
} catch (UserDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
@ -346,6 +352,34 @@ public class Group {
String[] rolesArray = new String[roles.size()]; String[] rolesArray = new String[roles.size()];
roles.toArray(rolesArray); roles.toArray(rolesArray);
return Response.status(Response.Status.OK).entity(rolesArray).build(); return Response.status(Response.Status.OK).entity(rolesArray).build();
} catch (UserDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (GroupManagementException e) {
log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@PUT
@Path("/owner/{owner}/name/{groupName}/user/{userName}/share/roles")
@Produces("application/json")
public Response setRoles(@PathParam("groupName") String groupName,
@PathParam("owner") String owner, @PathParam("userName") String userName,
List<String> selectedRoles) {
try {
List<String> allRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupName, owner);
for (String role : allRoles) {
if (selectedRoles.contains(role)) {
DeviceMgtAPIUtils.getGroupManagementProviderService()
.shareGroup(userName, groupName, owner, role);
} else {
DeviceMgtAPIUtils.getGroupManagementProviderService()
.unshareGroup(userName, groupName, owner, role);
}
}
return Response.status(Response.Status.OK).build();
} catch (UserDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
@ -452,6 +486,8 @@ public class Group {
String[] permissions = DeviceMgtAPIUtils.getGroupManagementProviderService() String[] permissions = DeviceMgtAPIUtils.getGroupManagementProviderService()
.getPermissions(userName, groupName, owner); .getPermissions(userName, groupName, owner);
return Response.status(Response.Status.OK).entity(permissions).build(); return Response.status(Response.Status.OK).entity(permissions).build();
} catch (UserDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();

@ -1038,7 +1038,7 @@
<Permission> <Permission>
<name>Group Roles</name> <name>Group Roles</name>
<path>/device-mgt/user/groups/roles</path> <path>/device-mgt/user/groups/roles</path>
<url>/groups/owner/*/name/*/share/roles</url> <url>/groups/owner/*/name/*/user/*/share/roles</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser; import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
import java.util.List; import java.util.List;
@ -148,10 +149,10 @@ public interface GroupManagementProviderService {
* @param owner of the group * @param owner of the group
* @param sharingRole to be shared * @param sharingRole to be shared
* @return is group shared * @return is group shared
* @throws GroupManagementException * @throws GroupManagementException UserDoesNotExistException
*/ */
boolean shareGroup(String username, String groupName, String owner, String sharingRole) boolean shareGroup(String username, String groupName, String owner, String sharingRole)
throws GroupManagementException; throws GroupManagementException, UserDoesNotExistException;
/** /**
* Un share existing group sharing with user specified by role * Un share existing group sharing with user specified by role
@ -161,10 +162,10 @@ public interface GroupManagementProviderService {
* @param owner of the group * @param owner of the group
* @param sharingRole to be un shared * @param sharingRole to be un shared
* @return is group un shared * @return is group un shared
* @throws GroupManagementException * @throws GroupManagementException UserDoesNotExistException
*/ */
boolean unshareGroup(String userName, String groupName, String owner, String sharingRole) boolean unshareGroup(String userName, String groupName, String owner, String sharingRole)
throws GroupManagementException; throws GroupManagementException, UserDoesNotExistException;
/** /**
* Add new sharing role for device group * Add new sharing role for device group
@ -208,9 +209,10 @@ public interface GroupManagementProviderService {
* @param groupName of the group * @param groupName of the group
* @param owner of the group * @param owner of the group
* @return list of roles * @return list of roles
* @throws GroupManagementException * @throws GroupManagementException UserDoesNotExistException
*/ */
List<String> getRoles(String userName, String groupName, String owner) throws GroupManagementException; List<String> getRoles(String userName, String groupName, String owner)
throws GroupManagementException, UserDoesNotExistException;
/** /**
* Get device group users * Get device group users
@ -284,9 +286,10 @@ public interface GroupManagementProviderService {
* @param groupName of the group. * @param groupName of the group.
* @param owner of the group. * @param owner of the group.
* @return array of permissions. * @return array of permissions.
* @throws GroupManagementException * @throws GroupManagementException UserDoesNotExistException
*/ */
String[] getPermissions(String username, String groupName, String owner) throws GroupManagementException; String[] getPermissions(String username, String groupName, String owner)
throws GroupManagementException, UserDoesNotExistException;
/** /**
* Get device groups of user with permission. * Get device groups of user with permission.

@ -41,6 +41,7 @@ import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
import org.wso2.carbon.user.core.util.UserCoreUtil; import org.wso2.carbon.user.core.util.UserCoreUtil;
import java.sql.SQLException; import java.sql.SQLException;
@ -379,7 +380,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public boolean shareGroup(String username, String groupName, String owner, String sharingRole) public boolean shareGroup(String username, String groupName, String owner, String sharingRole)
throws GroupManagementException { throws GroupManagementException, UserDoesNotExistException {
int groupId = getGroupId(groupName, owner); int groupId = getGroupId(groupName, owner);
return modifyGroupShare(username, groupId, sharingRole, true); return modifyGroupShare(username, groupId, sharingRole, true);
} }
@ -389,14 +390,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public boolean unshareGroup(String username, String groupName, String owner, String sharingRole) public boolean unshareGroup(String username, String groupName, String owner, String sharingRole)
throws GroupManagementException { throws GroupManagementException, UserDoesNotExistException {
int groupId = getGroupId(groupName, owner); int groupId = getGroupId(groupName, owner);
return modifyGroupShare(username, groupId, sharingRole, false); return modifyGroupShare(username, groupId, sharingRole, false);
} }
private boolean modifyGroupShare(String username, int groupId, String sharingRole, private boolean modifyGroupShare(String username, int groupId, String sharingRole,
boolean isAddNew) boolean isAddNew)
throws GroupManagementException { throws GroupManagementException, UserDoesNotExistException {
if (groupId == -1) { if (groupId == -1) {
return false; return false;
} }
@ -407,14 +408,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
userStoreManager = userStoreManager =
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm( DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
tenantId).getUserStoreManager(); tenantId).getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
throw new UserDoesNotExistException("User not exists with name " + username);
}
roles[0] = "Internal/group-" + groupId + "-" + sharingRole; roles[0] = "Internal/group-" + groupId + "-" + sharingRole;
if (isAddNew) { List<String> currentRoles = getRoles(username, groupId);
if (isAddNew && !currentRoles.contains(sharingRole)) {
userStoreManager.updateRoleListOfUser(username, null, roles); userStoreManager.updateRoleListOfUser(username, null, roles);
} else { } else if (!isAddNew && currentRoles.contains(sharingRole)) {
userStoreManager.updateRoleListOfUser(username, roles, null); userStoreManager.updateRoleListOfUser(username, roles, null);
} }
return true; return true;
} catch (UserStoreException e) { } catch (UserStoreException e) {
if (e instanceof UserDoesNotExistException) {
throw (UserDoesNotExistException) e;
}
throw new GroupManagementException("User store error in adding user " + username + " to group name:" + throw new GroupManagementException("User store error in adding user " + username + " to group name:" +
groupId, e); groupId, e);
} }
@ -532,18 +540,23 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public List<String> getRoles(String username, String groupName, String owner) throws GroupManagementException { public List<String> getRoles(String username, String groupName, String owner)
throws GroupManagementException, UserDoesNotExistException {
int groupId = getGroupId(groupName, owner); int groupId = getGroupId(groupName, owner);
return getRoles(username, groupId); return getRoles(username, groupId);
} }
private List<String> getRoles(String username, int groupId) throws GroupManagementException { private List<String> getRoles(String username, int groupId)
throws GroupManagementException, UserDoesNotExistException {
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
List<String> groupRoleList = new ArrayList<>(); List<String> groupRoleList = new ArrayList<>();
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
.getUserStoreManager(); .getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
throw new UserDoesNotExistException("User not exists with name " + username);
}
String[] roleList = userStoreManager.getRoleListOfUser(username); String[] roleList = userStoreManager.getRoleListOfUser(username);
for (String role : roleList) { for (String role : roleList) {
if (role != null && role.contains("Internal/group-" + groupId)) { if (role != null && role.contains("Internal/group-" + groupId)) {
@ -553,6 +566,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
return groupRoleList; return groupRoleList;
} catch (UserStoreException e) { } catch (UserStoreException e) {
if (e instanceof UserDoesNotExistException) {
throw (UserDoesNotExistException) e;
}
throw new GroupManagementException("Error occurred while getting user store manager.", e); throw new GroupManagementException("Error occurred while getting user store manager.", e);
} }
} }
@ -723,7 +739,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String[] getPermissions(String username, String groupName, String owner) throws GroupManagementException { public String[] getPermissions(String username, String groupName, String owner)
throws GroupManagementException, UserDoesNotExistException {
UserRealm userRealm; UserRealm userRealm;
int groupId = getGroupId(groupName, owner); int groupId = getGroupId(groupName, owner);
List<String> roles = getRoles(username, groupId); List<String> roles = getRoles(username, groupId);

@ -81,8 +81,12 @@
<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>Select user to manage group sharing</h3> <h3>Enter user name to manage group sharing</h3>
<div id="user-names">Loading...</div> <div id="user-names">
<br />
<input type="text" id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">
</input>
</div>
<div class="buttons"> <div class="buttons">
<a href="#" id="share-group-next-link" class="btn-operations"> <a href="#" id="share-group-next-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp;
@ -233,6 +237,22 @@
</div> </div>
</div> </div>
<div id="group-404-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3 id="group-404-message">Not found.</h3>
<div class="buttons">
<a href="#" id="group-404-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-409-content" class="hide"> <div id="group-409-content" class="hide">
<div class="content"> <div class="content">
<div class="row"> <div class="row">

@ -100,10 +100,10 @@ function loadGroups() {
var currentUser = groupListing.data("currentUser"); var currentUser = groupListing.data("currentUser");
var serviceURL; var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) { if ($.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000"; serviceURL = "/devicemgt_admin/groups";
} else if ($.hasPermission("LIST_GROUPS")) { } else if ($.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups //Get authenticated users groups
serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000"; serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
} else { } else {
$("#loading-content").remove(); $("#loading-content").remove();
$('#device-table').addClass('hidden'); $('#device-table').addClass('hidden');
@ -133,9 +133,7 @@ function loadGroups() {
{ targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) { { targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) {
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>'; return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}}, }},
{ targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) { {targets: 1, data: 'name', className: 'fade-edge'},
return '<h4 data-groupid="' + row.id + '">' + name + '</h4>';
}},
{ targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'}, { targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'},
{ targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' , { targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
render: function ( id, type, row, meta ) { render: function ( id, type, row, meta ) {
@ -293,58 +291,23 @@ function attachEvents() {
* on Group Management page in WSO2 Device Management Server Console. * on Group Management page in WSO2 Device Management Server Console.
*/ */
$("a.share-group-link").click(function () { $("a.share-group-link").click(function () {
var username = $("#group-listing").data("current-user");
var groupName = $(this).data("group-name"); var groupName = $(this).data("group-name");
var groupOwner = $(this).data("group-owner"); var groupOwner = $(this).data("group-owner");
$(modalPopupContent).html($('#share-group-w1-modal-content').html()); $(modalPopupContent).html($('#share-group-w1-modal-content').html());
$('#user-names').html('<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
showPopup();
$("a#share-group-next-link").hide();
var userRequest = $.ajax(
{
url: "api/user/all",
method: "GET",
contentType: "application/json",
accept: "application/json"
}
);
userRequest.done(function (data, txtStatus, jqxhr) {
var users = JSON.parse(data);
var status = jqxhr.status;
if (status == 200) {
var str = '<br /><select id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
var hasUsers = false;
users = users.content;
for (var user in users) {
if (users[user].username != username) {
str += '<option value="' + users[user].username + '">' + users[user].username + '</option>';
hasUsers = true;
}
}
str += '</select>';
if (!hasUsers) {
str = "There is no any other users registered";
$('#user-names').html(str);
return;
}
$('#user-names').html(str);
$("a#share-group-next-link").show(); $("a#share-group-next-link").show();
showPopup();
$("a#share-group-next-link").click(function () { $("a#share-group-next-link").click(function () {
var selectedUser = $('#share-user-selector').val(); var selectedUser = $('#share-user-selector').val();
getAllRoles(groupName, groupOwner, selectedUser); if (selectedUser == $("#group-listing").data("current-user")) {
}); $("#user-names").html("Please specify a user other than current user.");
$("a#share-group-next-link").hide();
} else { } else {
displayErrors(status); getAllRoles(groupName, groupOwner, selectedUser);
} }
}); });
userRequest.fail(function (jqXHR) {
displayErrors(jqXHR);
});
$("a#share-group-w1-cancel-link").click(function () { $("a#share-group-w1-cancel-link").click(function () {
hidePopup(); hidePopup();
}); });
}); });
/** /**
@ -375,7 +338,7 @@ function attachEvents() {
invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName,
successCallback, function (message) { successCallback, function (message) {
displayErrors(message.content); displayErrors(message);
}); });
}); });
@ -419,7 +382,7 @@ function attachEvents() {
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group, invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group,
successCallback, function (message) { successCallback, function (message) {
displayErrors(message.content); displayErrors(message);
}); });
}); });
@ -448,7 +411,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles", invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles",
successCallback, function (message) { successCallback, function (message) {
displayErrors(message.content); displayErrors(message);
}); });
$("a#share-group-w2-cancel-link").click(function () { $("a#share-group-w2-cancel-link").click(function () {
@ -461,34 +424,31 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
data = JSON.parse(data); data = JSON.parse(data);
if (xhr.status == 200) { if (xhr.status == 200) {
var userRoles = data; var userRoles = data;
var roleMap = [];
var str = ''; var str = '';
var isChecked = '';
for (var role in allRoles) { for (var i = 0; i < allRoles.length; i++) {
var objRole = {"role": allRoles[role], "assigned": false}; var isChecked = '';
for (var usrRole in userRoles) { for (var j = 0; j < userRoles.length; j++) {
if (allRoles[role] == userRoles[usrRole]) { if (allRoles[i] == userRoles[j]) {
objRole.assigned = true;
isChecked = 'checked'; isChecked = 'checked';
break; break;
} }
} }
roleMap.push(objRole); str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + allRoles[i] + '" value="' + allRoles[i]
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + roleMap[role].role + '" value="' + roleMap[role].role + '" ' + isChecked + '/>' + allRoles[i] + '</label>&nbsp;&nbsp;&nbsp;&nbsp;';
+ '" ' + isChecked + '/>' + roleMap[role].role + '</label>&nbsp;&nbsp;&nbsp;&nbsp;';
} }
$('#user-roles').html(str); $('#user-roles').html(str);
$("a#share-group-yes-link").show(); $("a#share-group-yes-link").show();
$("a#share-group-yes-link").show(); $("a#share-group-yes-link").show();
$("a#share-group-yes-link").click(function () { $("a#share-group-yes-link").click(function () {
for (var role in roleMap) { var roles = [];
if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned) { for (var i = 0; i < allRoles.length; i++) {
roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked'); if ($('#user-role-' + allRoles[i]).is(':checked')) {
updateGroupShare(groupName, groupOwner, selectedUser, roleMap[role]); roles.push(allRoles[i]);
} }
} }
updateGroupShare(groupName, groupOwner, selectedUser, roles);
}); });
} else { } else {
displayErrors(xhr); displayErrors(xhr);
@ -497,7 +457,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser,
successCallback, function (message) { successCallback, function (message) {
displayErrors(message.content); displayErrors(message);
}); });
$("a#share-group-w2-cancel-link").click(function () { $("a#share-group-w2-cancel-link").click(function () {
@ -505,24 +465,18 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
}); });
} }
function updateGroupShare(groupName, groupOwner, selectedUser, role) { function updateGroupShare(groupName, groupOwner, selectedUser, roles) {
var successCallback = function (data, textStatus, xhr) { var successCallback = function (data) {
data = JSON.parse(data);
var status = xhr.status;
if (status == 200) {
$(modalPopupContent).html($('#share-group-200-content').html()); $(modalPopupContent).html($('#share-group-200-content').html());
setTimeout(function () { setTimeout(function () {
hidePopup(); hidePopup();
location.reload(false); location.reload(false);
}, 2000); }, 2000);
} else {
displayErrors(xhr);
}
}; };
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/user/" + selectedUser + "/share/roles",
role, successCallback, function (message) { roles, successCallback, function (message) {
displayErrors(message.content); displayErrors(message);
}); });
} }
@ -538,6 +492,12 @@ function displayErrors(jqXHR) {
$("a#group-403-link").click(function () { $("a#group-403-link").click(function () {
hidePopup(); hidePopup();
}); });
} else if (jqXHR.status == 404) {
$(modalPopupContent).html($('#group-404-content').html());
$("#group-404-message").html(jqXHR.responseText);
$("a#group-404-link").click(function () {
hidePopup();
});
} else if (jqXHR.status == 409) { } else if (jqXHR.status == 409) {
$(modalPopupContent).html($('#group-409-content').html()); $(modalPopupContent).html($('#group-409-content').html());
$("a#group-409-link").click(function () { $("a#group-409-link").click(function () {

Loading…
Cancel
Save