Search in sources :

Example 1 with User

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);
}
Also used : User(net.sourceforge.processdash.tool.perm.User) Permission(net.sourceforge.processdash.tool.perm.Permission) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 2 with User

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);
}
Also used : Role(net.sourceforge.processdash.tool.perm.Role) User(net.sourceforge.processdash.tool.perm.User) HashSet(java.util.HashSet)

Aggregations

User (net.sourceforge.processdash.tool.perm.User)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Permission (net.sourceforge.processdash.tool.perm.Permission)1 Role (net.sourceforge.processdash.tool.perm.Role)1