Skip to content

Commit d4ea385

Browse files
committed
Handle marketplace-apps api handling for public marketplace
1 parent 060851e commit d4ea385

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/application/ApplicationController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.lowcoder.api.application.view.ApplicationView;
1818
import org.lowcoder.api.application.view.MarketplaceApplicationInfoView;
1919
import org.lowcoder.api.framework.view.ResponseView;
20+
import org.lowcoder.api.home.SessionUserService;
2021
import org.lowcoder.api.home.UserHomeApiService;
2122
import org.lowcoder.api.home.UserHomepageView;
2223
import org.lowcoder.api.util.BusinessEventPublisher;
@@ -39,6 +40,7 @@ public class ApplicationController implements ApplicationEndpoints {
3940
private final UserHomeApiService userHomeApiService;
4041
private final ApplicationApiService applicationApiService;
4142
private final BusinessEventPublisher businessEventPublisher;
43+
private final SessionUserService sessionUserService;
4244

4345
@Override
4446
public Mono<ResponseView<ApplicationView>> create(@RequestBody CreateApplicationRequest createApplicationRequest) {

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security/SecurityConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
109109
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, CONFIG_URL + "/deploymentId"), // system config
110110
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*/view"), // application view
111111
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*/view_marketplace"), // application view
112+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/marketplace-apps"), // marketplace apps
113+
112114
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/me"),
113115
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/currentUser"),
114116

@@ -134,6 +136,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
134136
ServerWebExchangeMatchers.pathMatchers(HttpMethod.HEAD, NewUrl.STATE_URL + "/healthCheck"),
135137
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/*/view"),
136138
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/*/view_marketplace"),
139+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/marketplace-apps"), // marketplace apps
137140
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/me"),
138141
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/currentUser"),
139142
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.GROUP_URL + "/list"),
@@ -180,6 +183,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
180183
source.registerCorsConfiguration(QUERY_URL + "/execute", skipCheckCorsForAll);
181184
source.registerCorsConfiguration(APPLICATION_URL + "/*/view", skipCheckCorsForAll);
182185
source.registerCorsConfiguration(APPLICATION_URL + "/*/view_marketplace", skipCheckCorsForAll);
186+
source.registerCorsConfiguration(APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
183187
source.registerCorsConfiguration(GITHUB_STAR, skipCheckCorsForAll);
184188
source.registerCorsConfiguration(ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
185189
source.registerCorsConfiguration(DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);
@@ -190,6 +194,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
190194
source.registerCorsConfiguration(NewUrl.QUERY_URL + "/execute", skipCheckCorsForAll);
191195
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/*/view", skipCheckCorsForAll);
192196
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/*/view_marketplace", skipCheckCorsForAll);
197+
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
193198
source.registerCorsConfiguration(NewUrl.ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
194199
source.registerCorsConfiguration(NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);
195200

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/home/UserHomeApiServiceImpl.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.lowcoder.domain.user.service.UserService;
4141
import org.lowcoder.domain.user.service.UserStatusService;
4242
import org.lowcoder.infra.util.NetworkUtils;
43+
import org.lowcoder.sdk.config.CommonConfig;
4344
import org.springframework.beans.factory.annotation.Autowired;
4445
import org.springframework.stereotype.Component;
4546
import org.springframework.web.server.ServerWebExchange;
@@ -80,6 +81,9 @@ public class UserHomeApiServiceImpl implements UserHomeApiService {
8081
@Autowired
8182
private UserApplicationInteractionService userApplicationInteractionService;
8283

84+
@Autowired
85+
private CommonConfig config;
86+
8387
@Override
8488
public Mono<UserProfileView> buildUserProfileView(User user, ServerWebExchange exchange) {
8589

@@ -260,8 +264,13 @@ public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@
260264
@Override
261265
public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nullable ApplicationType applicationType) {
262266

263-
return sessionUserService.getVisitorOrgMemberCache()
264-
.flatMapMany(orgMember -> {
267+
return sessionUserService.isAnonymousUser()
268+
.flatMapMany(isAnonymousUser -> {
269+
270+
if(config.getMarketplace().isPrivateMode() && isAnonymousUser) {
271+
return Mono.empty();
272+
}
273+
265274
// application flux
266275
Flux<Application> applicationFlux = Flux.defer(() -> applicationService.findAllMarketplaceApps())
267276
.filter(application -> isNull(applicationType) || application.getApplicationType() == applicationType.getValue())
@@ -287,11 +296,11 @@ public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nulla
287296

288297
return applicationFlux
289298
.flatMap(application -> Mono.zip(Mono.just(application), userMapMono, orgMapMono))
290-
.map(tuple -> {
299+
.map(tuple2 -> {
291300
// build view
292-
Application application = tuple.getT1();
293-
Map<String, User> userMap = tuple.getT2();
294-
Map<String, Organization> orgMap = tuple.getT3();
301+
Application application = tuple2.getT1();
302+
Map<String, User> userMap = tuple2.getT2();
303+
Map<String, Organization> orgMap = tuple2.getT3();
295304
MarketplaceApplicationInfoView marketplaceApplicationInfoView = MarketplaceApplicationInfoView.builder()
296305
.applicationId(application.getId())
297306
.name(application.getName())

0 commit comments

Comments
 (0)