Skip to content

Commit

Permalink
Better path parameter names for organization and member APIs
Browse files Browse the repository at this point in the history
Closes keycloak#35745

Signed-off-by: Pedro Igor <[email protected]>
  • Loading branch information
pedroigor committed Dec 12, 2024
1 parent 6f469b9 commit 977f518
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,34 @@ public Stream<MemberRepresentation> search(
return provider.getMembersStream(organization, filters, exact, first, max).map(this::toRepresentation);
}

@Path("{id}")
@Path("{member-id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
@Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS)
@Operation( summary = "Returns the member of the organization with the specified id", description = "Searches for a" +
"user with the given id. If one is found, and is currently a member of the organization, returns it. Otherwise," +
"an error response with status NOT_FOUND is returned")
public MemberRepresentation get(@PathParam("id") String id) {
if (StringUtil.isBlank(id)) {
public MemberRepresentation get(@PathParam("member-id") String memberId) {
if (StringUtil.isBlank(memberId)) {
throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST);
}

return toRepresentation(getMember(id));
return toRepresentation(getMember(memberId));
}

@Path("{id}")
@Path("{member-id}")
@DELETE
@Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS)
@Operation(summary = "Removes the user with the specified id from the organization", description = "Breaks the association " +
"between the user and organization. The user itself is deleted in case the membership is managed, otherwise the user is not deleted. " +
"If no user is found, or if they are not a member of the organization, an error response is returned")
public Response delete(@PathParam("id") String id) {
if (StringUtil.isBlank(id)) {
public Response delete(@PathParam("member-id") String memberId) {
if (StringUtil.isBlank(memberId)) {
throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST);
}

UserModel member = getMember(id);
UserModel member = getMember(memberId);

if (provider.removeMember(organization, member)) {
adminEvent.operation(OperationType.DELETE).resource(ResourceType.ORGANIZATION_MEMBERSHIP)
Expand All @@ -196,18 +196,18 @@ public Response delete(@PathParam("id") String id) {
throw ErrorResponse.error("Not a member of the organization", Status.BAD_REQUEST);
}

@Path("{id}/organizations")
@Path("{member-id}/organizations")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
@Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS)
@Operation(summary = "Returns the organizations associated with the user that has the specified id")
public Stream<OrganizationRepresentation> getOrganizations(@PathParam("id") String id) {
if (StringUtil.isBlank(id)) {
public Stream<OrganizationRepresentation> getOrganizations(@PathParam("member-id") String memberId) {
if (StringUtil.isBlank(memberId)) {
throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST);
}

UserModel member = getUser(id);
UserModel member = getUser(memberId);

return provider.getByMember(member).map(ModelToRepresentation::toRepresentation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public Stream<OrganizationRepresentation> search(
/**
* Base path for the admin REST API for one particular organization.
*/
@Path("{id}")
public OrganizationResource get(@PathParam("id") String id) {
@Path("{org-id}")
public OrganizationResource get(@PathParam("org-id") String orgId) {
auth.realm().requireManageRealm();
Organizations.checkEnabled(provider);

if (StringUtil.isBlank(id)) {
if (StringUtil.isBlank(orgId)) {
throw ErrorResponse.error("Id cannot be null.", Response.Status.BAD_REQUEST);
}

OrganizationModel organizationModel = provider.getById(id);
OrganizationModel organizationModel = provider.getById(orgId);

if (organizationModel == null) {
throw ErrorResponse.error("Organization not found.", Response.Status.NOT_FOUND);
Expand All @@ -171,13 +171,13 @@ public OrganizationResource get(@PathParam("id") String id) {
return new OrganizationResource(session, organizationModel, adminEvent);
}

@Path("members/{id}/organizations")
@Path("members/{member-id}/organizations")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
@Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS)
@Operation(summary = "Returns the organizations associated with the user that has the specified id")
public Stream<OrganizationRepresentation> getOrganizations(@PathParam("id") String id) {
return new OrganizationMemberResource(session, null, adminEvent).getOrganizations(id);
public Stream<OrganizationRepresentation> getOrganizations(@PathParam("member-id") String memberId) {
return new OrganizationMemberResource(session, null, adminEvent).getOrganizations(memberId);
}
}

0 comments on commit 977f518

Please sign in to comment.