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
PTM apps enhancements
  • Loading branch information
aq-ikhwa-tech committed Feb 23, 2024
commit 060851e16f84a949b3be6a5a52713bc11384976c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface ApplicationRepository extends ReactiveMongoRepository<Applicati
Flux<Application> findByPublicToAllIsTrueAndPublicToMarketplaceIsOrAgencyProfileIsAndIdIn
(Boolean publicToMarketplace, Boolean agencyProfile, Collection<String> ids);

Flux<Application> findByPublicToAllIsTrueAndPublicToMarketplaceIsAndAgencyProfileIsAndIdIn(Boolean publicToMarketplace, Boolean agencyProfile, Collection<String> ids);

Flux<Application> findByPublicToAllIsTrueAndPublicToMarketplaceIsTrue();

Flux<Application> findByPublicToAllIsTrueAndAgencyProfileIsTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,24 @@ public Mono<Boolean> setApplicationAsAgencyProfile(String applicationId, boolean

@NonEmptyMono
@SuppressWarnings("ReactiveStreamsNullableInLambdaInTransform")
public Mono<Set<String>> getPublicApplicationIds(Collection<String> applicationIds, Boolean isAnonymous) {
return repository.findByPublicToAllIsTrueAndPublicToMarketplaceIsOrAgencyProfileIsAndIdIn(!isAnonymous, !isAnonymous, applicationIds)
.map(HasIdAndAuditing::getId)
.collect(Collectors.toSet());
public Mono<Set<String>> getPublicApplicationIds(Collection<String> applicationIds, Boolean isAnonymous, Boolean isPrivateMarketplace) {

if(isAnonymous) {
if(isPrivateMarketplace) {
return repository.findByPublicToAllIsTrueAndPublicToMarketplaceIsAndAgencyProfileIsAndIdIn(false, false, applicationIds)
.map(HasIdAndAuditing::getId)
.collect(Collectors.toSet());
} else {
return repository.findByPublicToAllIsTrueAndPublicToMarketplaceIsAndAgencyProfileIsAndIdIn(true, false, applicationIds)
.map(HasIdAndAuditing::getId)
.collect(Collectors.toSet());
}
} else {
return repository.findByPublicToAllIsTrueAndPublicToMarketplaceIsOrAgencyProfileIsAndIdIn(true, true, applicationIds)
.map(HasIdAndAuditing::getId)
.collect(Collectors.toSet());
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected Mono<Map<String, List<ResourcePermission>>> getAnonymousUserPermission
}

Set<String> applicationIds = newHashSet(resourceIds);
return Mono.zip(applicationService.getPublicApplicationIds(applicationIds, Boolean.TRUE),
return Mono.zip(applicationService.getPublicApplicationIds(applicationIds, Boolean.TRUE, config.getMarketplace().isPrivateMode()),
templateSolution.getTemplateApplicationIds(applicationIds))
.map(tuple -> {
Set<String> publicAppIds = tuple.getT1();
Expand All @@ -61,7 +61,7 @@ protected Mono<Map<String, List<ResourcePermission>>> getAnonymousUserPermission
(Collection<String> resourceIds, ResourceAction resourceAction) {

Set<String> applicationIds = newHashSet(resourceIds);
return Mono.zip(applicationService.getPublicApplicationIds(applicationIds, Boolean.FALSE),
return Mono.zip(applicationService.getPublicApplicationIds(applicationIds, Boolean.FALSE, config.getMarketplace().isPrivateMode()),
templateSolution.getTemplateApplicationIds(applicationIds))
.map(tuple -> {
Set<String> publicAppIds = tuple.getT1();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.lowcoder.domain.permission.model.ResourceRole;
import org.lowcoder.domain.permission.model.ResourceType;
import org.lowcoder.domain.permission.model.UserPermissionOnResourceStatus;
import org.lowcoder.sdk.config.CommonConfig;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.collect.Maps;
Expand All @@ -44,6 +45,9 @@ abstract class ResourcePermissionHandler {
@Autowired
private OrgMemberService orgMemberService;

@Autowired
protected CommonConfig config;

public Mono<Map<String, List<ResourcePermission>>> getAllMatchingPermissions(String userId,
Collection<String> resourceIds,
ResourceAction resourceAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class CommonConfig {
private Cookie cookie = new Cookie();
private JsExecutor jsExecutor = new JsExecutor();
private Set<String> disallowedHosts = new HashSet<>();
private Marketplace marketplace = new Marketplace();

public boolean isSelfHost() {
return !isCloud();
Expand Down Expand Up @@ -145,6 +146,12 @@ public static class JsExecutor {
private String host;
}

@Data
public static class Marketplace {

private boolean privateMode = Boolean.TRUE;
}


@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Mono<ResponseView<List<MarketplaceApplicationInfoView>>> getMarketplaceAp
@Override
public Mono<ResponseView<List<MarketplaceApplicationInfoView>>> getAgencyProfileApplications(@RequestParam(required = false) Integer applicationType) {
ApplicationType applicationTypeEnum = applicationType == null ? null : ApplicationType.fromValue(applicationType);
return userHomeApiService.getAllMarketplaceApplications(applicationTypeEnum)
return userHomeApiService.getAllAgencyProfileApplications(applicationTypeEnum)
.collectList()
.map(ResponseView::success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.lowcoder.domain.application.model.ApplicationStatus;

@Builder
@Getter
@Setter
public class MarketplaceApplicationInfoView {

// marketplace specific details
private String title;
private String description;
private String category;

// org details
private final String orgId;
private final String orgName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, CONFIG_URL), // system config
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, USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/currentUser"),

Expand All @@ -132,6 +133,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.CONFIG_URL + "/deploymentId"),
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.USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/currentUser"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.GROUP_URL + "/list"),
Expand Down Expand Up @@ -177,6 +179,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
source.registerCorsConfiguration(GROUP_URL + "/list", skipCheckCorsForAll);
source.registerCorsConfiguration(QUERY_URL + "/execute", skipCheckCorsForAll);
source.registerCorsConfiguration(APPLICATION_URL + "/*/view", skipCheckCorsForAll);
source.registerCorsConfiguration(APPLICATION_URL + "/*/view_marketplace", skipCheckCorsForAll);
source.registerCorsConfiguration(GITHUB_STAR, skipCheckCorsForAll);
source.registerCorsConfiguration(ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
source.registerCorsConfiguration(DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);
Expand All @@ -186,6 +189,7 @@ private CorsConfigurationSource buildCorsConfigurationSource() {
source.registerCorsConfiguration(NewUrl.GROUP_URL + "/list", skipCheckCorsForAll);
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.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 @@ -292,7 +292,7 @@ public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nulla
Application application = tuple.getT1();
Map<String, User> userMap = tuple.getT2();
Map<String, Organization> orgMap = tuple.getT3();
return MarketplaceApplicationInfoView.builder()
MarketplaceApplicationInfoView marketplaceApplicationInfoView = MarketplaceApplicationInfoView.builder()
.applicationId(application.getId())
.name(application.getName())
.applicationType(application.getApplicationType())
Expand All @@ -305,6 +305,16 @@ public Flux<MarketplaceApplicationInfoView> getAllMarketplaceApplications(@Nulla
.createAt(application.getCreatedAt().toEpochMilli())
.createBy(application.getCreatedBy())
.build();

// marketplace specific fields
Map<String, Object> marketplaceMeta = (Map<String, Object>)
((Map<String, Object>)application.getEditingApplicationDSL().get("ui")).get("marketplaceMeta");
marketplaceApplicationInfoView.setTitle((String)marketplaceMeta.get("title"));
marketplaceApplicationInfoView.setCategory((String)marketplaceMeta.get("category"));
marketplaceApplicationInfoView.setDescription((String)marketplaceMeta.get("description"));

return marketplaceApplicationInfoView;

});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ common:
block-hound-enable: false
js-executor:
host: http://127.0.0.1:6060
marketplace:
private-mode: false

material:
mongodb-grid-fs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ common:
max-query-timeout: ${LOWCODER_MAX_QUERY_TIMEOUT:120}
workspace:
mode: ${LOWCODER_WORKSPACE_MODE:SAAS}
marketplace:
private-mode: ${MARKETPLACE_PRIVATE_MODE:true}

material:
mongodb-grid-fs:
Expand Down