use of net.sourceforge.processdash.tool.perm.User in project processdash by dtuma.
the class WbsPermissionSettingsWriter method writeRoleSettings.
private void writeRoleSettings(XmlSerializer xml, Role r, List<User> allUsers, Set<String> usersToWrite) throws IOException {
// get a list of the active permissions that are assigned to this role
User prototypeUser = new User(null, null, false, Collections.singletonList(r.getId()));
Set<Permission> perms = PermissionsManager.getInstance().getPermissionsForUser(prototypeUser, true);
// filter the list to contain only wbs-specific permissions
for (Iterator i = perms.iterator(); i.hasNext(); ) {
Permission p = (Permission) i.next();
if (!wbsPermissionIDs.contains(p.getSpec().getId()))
i.remove();
}
// the WBS Editor doesn't need to know about it.
if (perms.isEmpty())
return;
// find the users who are assigned to this permission
List<String> userIDs = new ArrayList<String>();
for (User u : allUsers) {
if (u.getRoleIDs().contains(r.getId()))
userIDs.add(u.getUsername());
}
// doesn't need to know about it.
if (userIDs.isEmpty())
return;
// write XML data for this role
xml.startTag(null, ROLE_TAG);
xml.attribute(null, NAME_ATTR, r.getName());
xml.attribute(null, ID_ATTR, r.getId());
// write the list of users, as a comma-separated attribute
xml.attribute(null, USERS_ATTR, StringUtils.join(userIDs, ","));
usersToWrite.removeAll(userIDs);
// write the permissions granted by this role
for (Permission p : perms) PermissionsManager.writePermission(xml, p);
// end the role tag
xml.endTag(null, ROLE_TAG);
}
use of net.sourceforge.processdash.tool.perm.User in project processdash by dtuma.
the class WbsPermissionSettingsWriter method writeTeamSettings.
@Override
public void writeTeamSettings(String projectID, XmlSerializer xml) throws IOException {
// start a <roles> tag
xml.startTag(null, ROLES_TAG);
// gather the list of users known to this team dashboard
List<User> allUsers = getAllUsers();
Set<String> usersToWrite = new HashSet();
for (User u : allUsers) usersToWrite.add(u.getUsername());
// write data for each role
for (Role r : getAllRoles()) writeRoleSettings(xml, r, allUsers, usersToWrite);
// write an empty role for users with no WBS permissions
if (!usersToWrite.isEmpty())
writeEmptyRole(xml, usersToWrite);
// end the </roles> tag
xml.endTag(null, ROLES_TAG);
}