use of com.walmartlabs.concord.server.user.UserType in project concord by walmartlabs.
the class PolicyResource method link.
@PUT
@ApiOperation("Link an existing policy to an organization, a project or user")
@Path("/{policyName}/link")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult link(@ApiParam @PathParam("policyName") @ConcordKey String policyName, @ApiParam @Valid PolicyLinkEntry entry) {
assertAdmin();
// TODO: add user type into request
UserType userType = UserPrincipal.assertCurrent().getType();
PolicyLink l = assertLink(policyName, entry.getOrgName(), entry.getProjectName(), entry.getUserName(), entry.getUserDomain(), userType);
policyManager.link(l.policyId, l.orgId, l.projectId, l.userId);
auditLog.add(AuditObject.POLICY, AuditAction.UPDATE).field("policyId", l.policyId).field("name", policyName).field("link", l).field("action", "link").log();
return new GenericOperationResult(OperationResult.UPDATED);
}
use of com.walmartlabs.concord.server.user.UserType in project concord by walmartlabs.
the class TeamManager method addUsers.
public void addUsers(String orgName, String teamName, boolean replace, Collection<TeamUserEntry> users) {
TeamEntry t = assertTeam(orgName, teamName, TeamRole.MAINTAINER, true, true);
Map<UUID, TeamRole> effectiveUsers = new HashMap<>();
for (TeamUserEntry u : users) {
UserType type = u.getUserType();
if (type == null) {
type = UserPrincipal.assertCurrent().getType();
}
UUID id = u.getUserId();
if (id == null) {
id = userManager.getId(u.getUsername(), u.getUserDomain(), type).orElseThrow(() -> new ConcordApplicationException("User not found: " + u.getUsername()));
}
TeamRole role = u.getRole();
if (role == null) {
role = TeamRole.MEMBER;
}
effectiveUsers.put(id, role);
}
teamDao.tx(tx -> {
if (replace) {
teamDao.removeUsers(tx, t.getId());
}
for (Map.Entry<UUID, TeamRole> u : effectiveUsers.entrySet()) {
UUID id = u.getKey();
TeamRole role = u.getValue();
teamDao.upsertUser(tx, t.getId(), id, role);
}
validateUsers(tx, t.getOrgId());
});
auditLog.add(AuditObject.TEAM, AuditAction.UPDATE).field("orgId", t.getOrgId()).field("teamId", t.getId()).field("name", t.getName()).field("action", "addUsers").field("users", users).field("replace", replace).log();
}
use of com.walmartlabs.concord.server.user.UserType in project concord by walmartlabs.
the class TeamResource method removeUsers.
/**
* Remove users from the specified team.
*
* @param teamName
* @param usernames
* @return
*/
@DELETE
@ApiOperation("Remove users from a team")
@Path("/{orgName}/team/{teamName}/users")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public RemoveTeamUsersResponse removeUsers(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("teamName") @ConcordKey String teamName, @ApiParam Collection<String> usernames) {
if (usernames == null || usernames.isEmpty()) {
throw new ValidationErrorsException("Empty user list");
}
// TODO: add user type into request params
UserType type = UserPrincipal.assertCurrent().getType();
// TODO: add user domain into request params
String domain = null;
teamManager.removeUsers(orgName, teamName, usernames.stream().map(n -> User.of(n, domain, type)).collect(Collectors.toList()));
return new RemoveTeamUsersResponse();
}
Aggregations