Skip to content

Commit 1a72537

Browse files
author
Sebastian Reid
committed
Implement the following APIs
getBundles, getMarketplaceBundles, getAgencyProfileBundles, setBundlePublicToAll, setBundlePublicToMarketplace, setBundleAsAgencyProfile
1 parent f77e2eb commit 1a72537

File tree

6 files changed

+144
-1
lines changed

6 files changed

+144
-1
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public interface BundleService {
4343
@SuppressWarnings("ReactiveStreamsNullableInLambdaInTransform")
4444
Mono<Set<String>> getPublicAgencyBundleIds(Collection<String> bundleIds);
4545

46+
Mono<Boolean> setBundlePublicToAll(String bundleId, boolean publicToAll);
47+
48+
Mono<Boolean> setBundlePublicToMarketplace(String bundleId, Boolean publicToMarketplace);
49+
50+
Mono<Boolean> setBundleAsAgencyProfile(String bundleId, boolean agencyProfile);
51+
4652
Flux<Bundle> findAllMarketplaceBundles();
4753

4854
Flux<Bundle> findAllAgencyProfileBundles();

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleServiceImpl.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import reactor.core.publisher.Mono;
1919

2020
import java.util.Collection;
21+
import java.util.Map;
2122
import java.util.Set;
2223
import java.util.stream.Collectors;
2324

@@ -175,4 +176,33 @@ public Flux<Bundle> findAllAgencyProfileBundles() {
175176
return repository.findByPublicToAllIsTrueAndAgencyProfileIsTrue();
176177
}
177178

179+
@Override
180+
public Mono<Boolean> setBundlePublicToAll(String bundleId, boolean publicToAll) {
181+
Bundle bundle = Bundle.builder()
182+
.publicToAll(publicToAll)
183+
.build();
184+
return mongoUpsertHelper.updateById(bundle, bundleId);
185+
}
186+
187+
@Override
188+
public Mono<Boolean> setBundlePublicToMarketplace(String bundleId, Boolean publicToMarketplace) {
189+
190+
return findById(bundleId)
191+
192+
.map(bundle -> Bundle.builder()
193+
.publicToMarketplace(publicToMarketplace)
194+
.build())
195+
.flatMap(bundle -> mongoUpsertHelper.updateById(bundle, bundleId));
196+
197+
198+
}
199+
200+
@Override
201+
public Mono<Boolean> setBundleAsAgencyProfile(String bundleId, boolean agencyProfile) {
202+
Bundle bundle = Bundle.builder()
203+
.agencyProfile(agencyProfile)
204+
.build();
205+
return mongoUpsertHelper.updateById(bundle, bundleId);
206+
}
207+
178208
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import jakarta.annotation.Nonnull;
44
import jakarta.annotation.Nullable;
5+
import org.lowcoder.api.application.ApplicationEndpoints;
56
import org.lowcoder.api.bundle.view.BundleInfoView;
67
import org.lowcoder.api.bundle.view.BundlePermissionView;
78
import org.lowcoder.domain.application.model.ApplicationType;
@@ -48,4 +49,10 @@ public interface BundleApiService {
4849
Mono<BundlePermissionView> getPermissions(String bundleId);
4950

5051
Mono<BundleInfoView> buildBundleInfoView(Bundle bundle, boolean visible, boolean manageable, String folderId);
52+
53+
Mono<Boolean> setBundlePublicToAll(String bundleId, boolean publicToAll);
54+
55+
Mono<Boolean> setBundlePublicToMarketplace(String bundleId, BundleEndpoints.BundlePublicToMarketplaceRequest request);
56+
57+
Mono<Boolean> setBundleAsAgencyProfile(String bundleId, boolean agencyProfile);
5158
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiServiceImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.RequiredArgsConstructor;
66
import org.apache.commons.collections4.CollectionUtils;
77
import org.apache.commons.lang3.StringUtils;
8+
import org.lowcoder.api.application.ApplicationEndpoints;
89
import org.lowcoder.api.bundle.BundleEndpoints.CreateBundleRequest;
910
import org.lowcoder.api.application.view.ApplicationInfoView;
1011
import org.lowcoder.api.application.view.ApplicationPermissionView;
@@ -556,4 +557,28 @@ public Mono<BundleInfoView> buildBundleInfoView(Bundle bundle, boolean visible,
556557
.agencyProfile(bundle.getAgencyProfile())
557558
.build());
558559
}
560+
561+
@Override
562+
public Mono<Boolean> setBundlePublicToAll(String bundleId, boolean publicToAll) {
563+
return checkCurrentUserBundlePermission(bundleId, ResourceAction.SET_APPLICATIONS_PUBLIC)
564+
.then(checkBundleStatus(bundleId, BundleStatus.NORMAL))
565+
.then(bundleService.setBundlePublicToAll(bundleId, publicToAll));
566+
}
567+
568+
@Override
569+
public Mono<Boolean> setBundlePublicToMarketplace(String bundleId, BundleEndpoints.BundlePublicToMarketplaceRequest request) {
570+
return checkCurrentUserBundlePermission(bundleId, ResourceAction.SET_APPLICATIONS_PUBLIC_TO_MARKETPLACE)
571+
.then(checkBundleStatus(bundleId, BundleStatus.NORMAL))
572+
.then(bundleService.setBundlePublicToMarketplace
573+
(bundleId, request.publicToMarketplace()));
574+
}
575+
576+
// Falk: why we have request.publicToMarketplace() - but here only agencyProfile? Not from request?
577+
@Override
578+
public Mono<Boolean> setBundleAsAgencyProfile(String bundleId, boolean agencyProfile) {
579+
return checkCurrentUserBundlePermission(bundleId, ResourceAction.SET_APPLICATIONS_AS_AGENCY_PROFILE)
580+
.then(checkBundleStatus(bundleId, BundleStatus.NORMAL))
581+
.then(bundleService.setBundleAsAgencyProfile
582+
(bundleId, agencyProfile));
583+
}
559584
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.lowcoder.api.bundle;
22

33
import lombok.RequiredArgsConstructor;
4+
import org.lowcoder.api.application.ApplicationEndpoints;
45
import org.lowcoder.api.bundle.view.BundleInfoView;
56
import org.lowcoder.api.bundle.view.BundlePermissionView;
67
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
@@ -186,4 +187,25 @@ public Mono<ResponseView<List<MarketplaceBundleInfoView>>> getAgencyProfileBundl
186187
.collectList()
187188
.map(ResponseView::success);
188189
}
190+
191+
@Override
192+
public Mono<ResponseView<Boolean>> setBundlePublicToAll(@PathVariable String bundleId,
193+
@RequestBody BundleEndpoints.BundlePublicToAllRequest request) {
194+
return bundleApiService.setBundlePublicToAll(bundleId, request.publicToAll())
195+
.map(ResponseView::success);
196+
}
197+
198+
@Override
199+
public Mono<ResponseView<Boolean>> setBundlePublicToMarketplace(@PathVariable String bundleId,
200+
@RequestBody BundleEndpoints.BundlePublicToMarketplaceRequest request) {
201+
return bundleApiService.setBundlePublicToMarketplace(bundleId, request)
202+
.map(ResponseView::success);
203+
}
204+
205+
@Override
206+
public Mono<ResponseView<Boolean>> setBundleAsAgencyProfile(@PathVariable String bundleId,
207+
@RequestBody BundleEndpoints.BundleAsAgencyProfileRequest request) {
208+
return bundleApiService.setBundleAsAgencyProfile(bundleId, request.agencyProfile())
209+
.map(ResponseView::success);
210+
}
189211
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleEndpoints.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import io.swagger.v3.oas.annotations.Operation;
55
import jakarta.annotation.Nullable;
6+
import org.apache.commons.lang3.BooleanUtils;
7+
import org.lowcoder.api.application.ApplicationEndpoints;
68
import org.lowcoder.api.bundle.view.BundleInfoView;
79
import org.lowcoder.api.bundle.view.BundlePermissionView;
810
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
@@ -192,7 +194,6 @@ public Mono<ResponseView<Void>> grantPermission(
192194
@GetMapping("/marketplace-bundles")
193195
public Mono<ResponseView<List<MarketplaceBundleInfoView>>> getMarketplaceBundles();
194196

195-
// Falk: why we use MarketplaceBundleInfoView for AgencyProfile?
196197
@Operation(
197198
tags = TAG_BUNDLE_MANAGEMENT,
198199
operationId = "listAgencyProfileBundles",
@@ -202,6 +203,58 @@ public Mono<ResponseView<Void>> grantPermission(
202203
@GetMapping("/agency-profiles")
203204
public Mono<ResponseView<List<MarketplaceBundleInfoView>>> getAgencyProfileBundles();
204205

206+
@Operation(
207+
tags = TAG_BUNDLE_MANAGEMENT,
208+
operationId = "setBundleAsPublic",
209+
summary = "Set Bundle as publicly available",
210+
description = "Set a Lowcoder Bundle identified by its ID as generally publicly available. This is a preparation to published a Lowcoder Bundle in production mode."
211+
)
212+
@PutMapping("/{bundleId}/public-to-all")
213+
public Mono<ResponseView<Boolean>> setBundlePublicToAll(@PathVariable String bundleId,
214+
@RequestBody BundleEndpoints.BundlePublicToAllRequest request);
215+
216+
@Operation(
217+
tags = TAG_BUNDLE_MANAGEMENT,
218+
operationId = "setBundleAsPublicToMarketplace",
219+
summary = "Set Bundle as publicly available on marketplace but to only logged in users",
220+
description = "Set a Lowcoder Bundle identified by its ID as publicly available on marketplace but to only logged in users."
221+
)
222+
@PutMapping("/{bundleId}/public-to-marketplace")
223+
public Mono<ResponseView<Boolean>> setBundlePublicToMarketplace(@PathVariable String bundleId,
224+
@RequestBody BundleEndpoints.BundlePublicToMarketplaceRequest request);
225+
226+
@Operation(
227+
tags = TAG_BUNDLE_MANAGEMENT,
228+
operationId = "setBundleAsAgencyProfile",
229+
summary = "Set Bundle as agency profile",
230+
description = "Set a Lowcoder Bundle identified by its ID as as agency profile but to only logged in users."
231+
)
232+
@PutMapping("/{bundleId}/agency-profile")
233+
public Mono<ResponseView<Boolean>> setBundleAsAgencyProfile(@PathVariable String bundleId,
234+
@RequestBody BundleEndpoints.BundleAsAgencyProfileRequest request);
235+
236+
public record BundlePublicToAllRequest(Boolean publicToAll) {
237+
@Override
238+
public Boolean publicToAll() {
239+
return BooleanUtils.isTrue(publicToAll);
240+
}
241+
}
242+
243+
public record BundlePublicToMarketplaceRequest(Boolean publicToMarketplace) {
244+
@Override
245+
public Boolean publicToMarketplace() {
246+
return BooleanUtils.isTrue(publicToMarketplace);
247+
}
248+
249+
}
250+
251+
public record BundleAsAgencyProfileRequest(Boolean agencyProfile) {
252+
@Override
253+
public Boolean agencyProfile() {
254+
return BooleanUtils.isTrue(agencyProfile);
255+
}
256+
}
257+
205258
public record BatchAddPermissionRequest(String role, Set<String> userIds, Set<String> groupIds) {
206259
}
207260

0 commit comments

Comments
 (0)