Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FalkWolsky merged 6 commits intodevfromptm-apps-enhancements
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
Expand Up@@ -3,10 +3,7 @@

import static org.lowcoder.domain.application.ApplicationUtil.getDependentModulesFromDsl;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import org.lowcoder.domain.application.model.Application;
Expand DownExpand Up@@ -155,11 +152,43 @@ public Mono<Boolean> setApplicationPublicToAll(String applicationId, boolean pub
return mongoUpsertHelper.updateById(application, applicationId);
}

public Mono<Boolean> setApplicationPublicToMarketplace(String applicationId, boolean publicToMarketplace) {
Application application = Application.builder()
.publicToMarketplace(publicToMarketplace)
.build();
return mongoUpsertHelper.updateById(application, applicationId);
public Mono<Boolean> setApplicationPublicToMarketplace(String applicationId, Boolean publicToMarketplace,
String title, String category, String description, String image) {

return findById(applicationId)
.map(application -> {
Map<String, Object> applicationDsl = application.getEditingApplicationDSL();
if (applicationDsl.containsKey("ui")) {
Map<String, Object> dataObject = (Map<String, Object>) applicationDsl.get("ui");

if(publicToMarketplace) {
Map<String, Object> marketplaceMeta = new HashMap<>();
marketplaceMeta.put("title", title);
marketplaceMeta.put("description", description);
marketplaceMeta.put("category", category);
marketplaceMeta.put("image", image);
if (dataObject.containsKey("marketplaceMeta")) {
dataObject.replace("marketplaceMeta", marketplaceMeta);
} else {
dataObject.put("marketplaceMeta", marketplaceMeta);
}
} else {
dataObject.remove("marketplaceMeta");
}

applicationDsl.replace("ui", dataObject);

}

return Application.builder()
.publicToMarketplace(publicToMarketplace)
.editingApplicationDSL(applicationDsl)
.build();

})
.flatMap(application -> mongoUpsertHelper.updateById(application, applicationId));


}

public Mono<Boolean> setApplicationAsAgencyProfile(String applicationId, boolean agencyProfile) {
Expand All@@ -171,10 +200,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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff line change
Expand Up@@ -514,10 +514,11 @@ public Mono<Boolean> setApplicationPublicToAll(String applicationId, boolean pub
.then(applicationService.setApplicationPublicToAll(applicationId, publicToAll));
}

public Mono<Boolean> setApplicationPublicToMarketplace(String applicationId,boolean publicToMarketplace) {
public Mono<Boolean> setApplicationPublicToMarketplace(String applicationId,ApplicationEndpoints.ApplicationPublicToMarketplaceRequest request) {
return checkCurrentUserApplicationPermission(applicationId, ResourceAction.SET_APPLICATIONS_PUBLIC_TO_MARKETPLACE)
.then(checkApplicationStatus(applicationId, NORMAL))
.then(applicationService.setApplicationPublicToMarketplace(applicationId, publicToMarketplace));
.then(applicationService.setApplicationPublicToMarketplace
(applicationId, request.publicToMarketplace(), request.title(), request.category(), request.description(), request.image()));
}

public Mono<Boolean> setApplicationAsAgencyProfile(String applicationId, boolean agencyProfile) {
Expand Down
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -155,7 +157,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 DownExpand Up@@ -214,7 +216,7 @@ public Mono<ResponseView<Boolean>> setApplicationPublicToAll(@PathVariable Strin
@Override
public Mono<ResponseView<Boolean>> setApplicationPublicToMarketplace(@PathVariable String applicationId,
@RequestBody ApplicationPublicToMarketplaceRequest request) {
return applicationApiService.setApplicationPublicToMarketplace(applicationId, request.publicToMarketplace())
return applicationApiService.setApplicationPublicToMarketplace(applicationId, request)
.map(ResponseView::success);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -270,11 +270,33 @@ public Boolean publicToAll() {
}
}

public record ApplicationPublicToMarketplaceRequest(Boolean publicToMarketplace) {
public record ApplicationPublicToMarketplaceRequest(Boolean publicToMarketplace, String title,
String description, String category, String image) {
@Override
public Boolean publicToMarketplace() {
return BooleanUtils.isTrue(publicToMarketplace);
}

@Override
public String title() {
return title;
}

@Override
public String description() {
return description;
}

@Override
public String category() {
return category;
}

@Override
public String image() {
return image;
}

}

public record ApplicationAsAgencyProfileRequest(Boolean agencyProfile) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,12 +2,20 @@

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;
private String image;

// org details
private final String orgId;
private final String orgName;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ 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, APPLICATION_URL + "/marketplace-apps"), // marketplace apps

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

Expand All@@ -132,6 +135,8 @@ 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.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 DownExpand Up@@ -177,6 +182,8 @@ 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(APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
source.registerCorsConfiguration(GITHUB_STAR, skipCheckCorsForAll);
source.registerCorsConfiguration(ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
source.registerCorsConfiguration(DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);
Expand All@@ -186,6 +193,8 @@ 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.APPLICATION_URL + "/marketplace-apps", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.ORGANIZATION_URL + "/*/datasourceTypes", skipCheckCorsForAll);
source.registerCorsConfiguration(NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins", skipCheckCorsForAll);

Expand Down
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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,12 +296,12 @@ 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();
return MarketplaceApplicationInfoView.builder()
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())
.applicationType(application.getApplicationType())
Expand All@@ -305,6 +314,17 @@ 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"));
marketplaceApplicationInfoView.setImage((String)marketplaceMeta.get("image"));

return marketplaceApplicationInfoView;

});

});
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp