Skip to content

Private/Public Marketplace Feature #707

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 6 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Handle marketplace-apps api handling for public marketplace
  • Loading branch information
aq-ikhwa-tech committed Feb 24, 2024
commit d4ea385aaa4f9d35afde2e24ddb5d92a3c5fcfac
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.lowcoder.api.application.view.ApplicationView;
import org.lowcoder.api.application.view.MarketplaceApplicationInfoView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.SessionUserService;
import org.lowcoder.api.home.UserHomeApiService;
import org.lowcoder.api.home.UserHomepageView;
import org.lowcoder.api.util.BusinessEventPublisher;
Expand All @@ -39,6 +40,7 @@ public class ApplicationController implements ApplicationEndpoints {
private final UserHomeApiService userHomeApiService;
private final ApplicationApiService applicationApiService;
private final BusinessEventPublisher businessEventPublisher;
private final SessionUserService sessionUserService;

@Override
public Mono<ResponseView<ApplicationView>> create(@RequestBody CreateApplicationRequest createApplicationRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, CONFIG_URL + "/deploymentId"), // system config
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*/view"), // application view
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/*/view_marketplace"), // application view
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, APPLICATION_URL + "/marketplace-apps"), // marketplace apps

ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/currentUser"),

Expand All @@ -134,6 +136,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatchers.pathMatchers(HttpMethod.HEAD, NewUrl.STATE_URL + "/healthCheck"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/*/view"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/*/view_marketplace"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/marketplace-apps"), // marketplace apps
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/currentUser"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.GROUP_URL + "/list"),
Expand Down Expand Up @@ -180,6 +183,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
source.registerCorsConfiguration(QUERY_URL + "/execute", skipCheckCorsForAll);
source.registerCorsConfiguration(APPLICATION_URL + "/*/view", skipCheckCorsForAll);
source.registerCorsConfiguration(APPLICATION_URL + "/*/view_marketplace", skipCheckCorsForAll);
source.registerCorsConfiguration(APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
source.registerCorsConfiguration(GITHUB_STAR, skipCheckCorsForAll);
source.registerCorsConfiguration(ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
source.registerCorsConfiguration(DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);
Expand All @@ -190,6 +194,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
source.registerCorsConfiguration(NewUrl.QUERY_URL + "/execute", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/*/view", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/*/view_marketplace", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.lowcoder.domain.user.service.UserService;
import org.lowcoder.domain.user.service.UserStatusService;
import org.lowcoder.infra.util.NetworkUtils;
import org.lowcoder.sdk.config.CommonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
Expand Down Expand Up @@ -80,6 +81,9 @@ public class UserHomeApiServiceImpl implements UserHomeApiService {
@Autowired
private UserApplicationInteractionService userApplicationInteractionService;

@Autowired
private CommonConfig config;

@Override
public Mono<UserProfileView> buildUserProfileView(User user, ServerWebExchange exchange) {

Expand Down Expand Up @@ -260,8 +264,13 @@ public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@
@Override
public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nullable ApplicationType applicationType) {

return sessionUserService.getVisitorOrgMemberCache()
.flatMapMany(orgMember -> {
return sessionUserService.isAnonymousUser()
.flatMapMany(isAnonymousUser -> {

if(config.getMarketplace().isPrivateMode() && isAnonymousUser) {
return Mono.empty();
}

// application flux
Flux<Application> applicationFlux = Flux.defer(() -> applicationService.findAllMarketplaceApps())
.filter(application -> isNull(applicationType) || application.getApplicationType() == applicationType.getValue())
Expand All @@ -287,11 +296,11 @@ public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nulla

return applicationFlux
.flatMap(application -> Mono.zip(Mono.just(application), userMapMono, orgMapMono))
.map(tuple -> {
.map(tuple2 -> {
// build view
Application application = tuple.getT1();
Map<String, User> userMap = tuple.getT2();
Map<String, Organization> orgMap = tuple.getT3();
Application application = tuple2.getT1();
Map<String, User> userMap = tuple2.getT2();
Map<String, Organization> orgMap = tuple2.getT3();
MarketplaceApplicationInfoView marketplaceApplicationInfoView = MarketplaceApplicationInfoView.builder()
.applicationId(application.getId())
.name(application.getName())
Expand Down