Skip to content

add endpoint "user/myorg" #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,7 @@ public Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationTyp
.zipWith(folderApiService.getElements(null, applicationType, null, null).collectList())
.map(tuple2 -> {
Organization organization = tuple2.getT1();
List<?> list = tuple2.getT2();
List<ApplicationInfoView> applicationInfoViews = list.stream()
.map(o -> {
if (o instanceof ApplicationInfoView applicationInfoView) {
return applicationInfoView;
}
return null;
})
.filter(Objects::nonNull)
.toList();
List<FolderInfoView> folderInfoViews = list.stream()
.map(o -> {
if (o instanceof FolderInfoView folderInfoView) {
return folderInfoView;
}
return null;
})
.filter(Objects::nonNull)
.toList();
userHomepageVO.setOrganization(organization);
userHomepageVO.setHomeApplicationViews(applicationInfoViews);
userHomepageVO.setFolderInfoViews(folderInfoViews);
return userHomepageVO;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import org.apache.commons.lang3.StringUtils;
import org.lowcoder.api.authentication.dto.OrganizationDomainCheckResult;
import org.lowcoder.api.authentication.service.AuthenticationApiService;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.SessionUserService;
import org.lowcoder.api.home.UserHomeApiService;
import org.lowcoder.api.usermanagement.view.OrgView;
import org.lowcoder.api.usermanagement.view.UpdateUserRequest;
import org.lowcoder.api.usermanagement.view.UserProfileView;
import org.lowcoder.domain.organization.model.MemberRole;
import org.lowcoder.domain.organization.model.OrgMember;
import org.lowcoder.domain.organization.service.OrgMemberService;
import org.lowcoder.domain.organization.service.OrganizationService;
import org.lowcoder.domain.user.constant.UserStatusType;
import org.lowcoder.domain.user.model.User;
import org.lowcoder.domain.user.model.UserDetail;
Expand All @@ -23,6 +27,7 @@
import org.springframework.http.codec.multipart.Part;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import static org.lowcoder.sdk.exception.BizError.INVALID_USER_STATUS;
Expand All @@ -41,6 +46,7 @@ public class UserController implements UserEndpoints
private final CommonConfig commonConfig;
private final AuthenticationApiService authenticationApiService;
private final OrgMemberService orgMemberService;
private final OrganizationService organizationService;

@Override
public Mono<ResponseView<?>> createUserAndAddToOrg(@PathVariable String orgId, CreateUserRequest request) {
Expand All @@ -62,6 +68,36 @@ public Mono<ResponseView<?>> getUserProfile(ServerWebExchange exchange) {
.switchIfEmpty(Mono.just(ResponseView.success(view))));
}

@Override
public Mono<ResponseView<?>> getUserOrgs(ServerWebExchange exchange,
@RequestParam(required = false) String orgName,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
return sessionUserService.getVisitor()
.flatMap(user -> {
// Get all active organizations for the user
Flux<OrgMember> orgMemberFlux = orgMemberService.getAllActiveOrgs(user.getId());

// If orgName filter is provided, filter organizations by name
if (StringUtils.isNotBlank(orgName)) {
return orgMemberFlux
.flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
.filter(org -> StringUtils.containsIgnoreCase(org.getName(), orgName))
.map(OrgView::new)
.collectList()
.map(orgs -> PageResponseView.success(orgs, pageNum, pageSize, orgs.size()));
}

// If no filter, return all organizations
return orgMemberFlux
.flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
.map(OrgView::new)
.collectList()
.map(orgs -> PageResponseView.success(orgs, pageNum, pageSize, orgs.size()));
})
.map(ResponseView::success);
}

@Override
public Mono<ResponseView<Boolean>> newUserGuidanceShown() {
return sessionUserService.getVisitorId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public interface UserEndpoints
@GetMapping("/me")
public Mono<ResponseView<?>> getUserProfile(ServerWebExchange exchange);

@Operation(
tags = {TAG_USER_MANAGEMENT},
operationId = "getUserOrgs",
summary = "Get User Organizations",
description = "Retrieve a paginated list of organizations for the current user, filtered by organization name if provided."
)
@GetMapping("/myorg")
public Mono<ResponseView<?>> getUserOrgs(
ServerWebExchange exchange,
@RequestParam(required = false) String orgName,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "10") Integer pageSize
);

@Operation(
tags = TAG_USER_MANAGEMENT,
operationId = "newUserGuidanceShown",
Expand Down Expand Up @@ -218,5 +232,4 @@ public record MarkUserStatusRequest(String type, Object value) {

public record CreateUserRequest(String email, String password) {
}

}
Loading