|
3 | 3 | import jakarta.annotation.Nonnull;
|
4 | 4 | import jakarta.annotation.Nullable;
|
5 | 5 | import lombok.RequiredArgsConstructor;
|
6 |
| -import org.apache.commons.collections4.CollectionUtils; |
7 | 6 | import org.apache.commons.lang3.StringUtils;
|
8 | 7 | import org.lowcoder.api.application.view.ApplicationInfoView;
|
9 | 8 | import org.lowcoder.api.application.view.ApplicationPermissionView;
|
@@ -200,6 +199,42 @@ public Mono<Boolean> restore(String bundleId) {
|
200 | 199 | public Flux<BundleInfoView> getRecycledBundles() {
|
201 | 200 | return userHomeApiService.getAllAuthorisedBundles4CurrentOrgMember(BundleStatus.RECYCLED);
|
202 | 201 | }
|
| 202 | + @Override |
| 203 | + public Mono<BundlePermissionView> getBundlePermissions(String bundleId) { |
| 204 | + |
| 205 | + Mono<List<ResourcePermission>> bundlePermissions = resourcePermissionService.getByBundleId(bundleId).cache(); |
| 206 | + |
| 207 | + Mono<List<PermissionItemView>> groupPermissionPairsMono = bundlePermissions |
| 208 | + .flatMap(permissionHelper::getGroupPermissions); |
| 209 | + |
| 210 | + Mono<List<PermissionItemView>> userPermissionPairsMono = bundlePermissions |
| 211 | + .flatMap(permissionHelper::getUserPermissions); |
| 212 | + |
| 213 | + return checkCurrentUserBundlePermission(bundleId, READ_BUNDLES) |
| 214 | + .then(bundleService.findByIdWithoutDsl(bundleId)) |
| 215 | + .delayUntil(bundle -> checkBundleStatus(bundle, BundleStatus.NORMAL)) |
| 216 | + .flatMap(bundle -> { |
| 217 | + String creatorId = bundle.getCreatedBy(); |
| 218 | + String orgId = bundle.getOrganizationId(); |
| 219 | + |
| 220 | + Mono<Organization> orgMono = organizationService.getById(orgId); |
| 221 | + return Mono.zip(groupPermissionPairsMono, userPermissionPairsMono, orgMono) |
| 222 | + .map(tuple -> { |
| 223 | + List<PermissionItemView> groupPermissionPairs = tuple.getT1(); |
| 224 | + List<PermissionItemView> userPermissionPairs = tuple.getT2(); |
| 225 | + Organization organization = tuple.getT3(); |
| 226 | + return BundlePermissionView.builder() |
| 227 | + .groupPermissions(groupPermissionPairs) |
| 228 | + .userPermissions(userPermissionPairs) |
| 229 | + .creatorId(creatorId) |
| 230 | + .orgName(organization.getName()) |
| 231 | + .publicToAll(bundle.isPublicToAll()) |
| 232 | + .publicToMarketplace(bundle.isPublicToMarketplace()) |
| 233 | + .agencyProfile(bundle.agencyProfile()) |
| 234 | + .build(); |
| 235 | + }); |
| 236 | + }); |
| 237 | + } |
203 | 238 |
|
204 | 239 | private Mono<Void> checkBundleStatus(String bundleId, BundleStatus expected) {
|
205 | 240 | return bundleService.findById(bundleId)
|
@@ -511,30 +546,38 @@ private Mono<Boolean> isCreator(String bundleId) {
|
511 | 546 | }
|
512 | 547 |
|
513 | 548 | @Override
|
514 |
| - public Mono<Void> grantPermission(String bundleId, Set<String> userIds, Set<String> groupIds, ResourceRole role) { |
515 |
| - if (CollectionUtils.isEmpty(userIds) && CollectionUtils.isEmpty(groupIds)) { |
516 |
| - return Mono.empty(); |
| 549 | + public Mono<Boolean> grantPermission(String bundleId, Set<String> userIds, Set<String> groupIds, ResourceRole role) { |
| 550 | + if (userIds.isEmpty() && groupIds.isEmpty()) { |
| 551 | + return Mono.just(true); |
517 | 552 | }
|
518 |
| - return Mono.from(checkManagePermission(bundleId)) |
519 |
| - .then(checkBundleExist(bundleId)) |
520 |
| - .then(Mono.defer(() -> resourcePermissionService.insertBatchPermission(ResourceType.BUNDLE, bundleId, userIds, groupIds, role))) |
521 |
| - .then(); |
| 553 | + |
| 554 | + return checkCurrentUserBundlePermission(bundleId, MANAGE_BUNDLES) |
| 555 | + .then(bundleService.findByIdWithoutDsl(bundleId)) |
| 556 | + .delayUntil(bundle -> checkBundleStatus(bundle, BundleStatus.NORMAL)) |
| 557 | + .switchIfEmpty(deferredError(BizError.BUNDLE_NOT_EXIST, "BUNDLE_NOT_FOUND", bundleId)) |
| 558 | + .then(resourcePermissionService.insertBatchPermission(ResourceType.BUNDLE, bundleId, |
| 559 | + userIds, groupIds, role)) |
| 560 | + .thenReturn(true); |
522 | 561 | }
|
523 | 562 |
|
524 | 563 | @Override
|
525 |
| - public Mono<Void> updatePermission(String bundleId, String permissionId, ResourceRole role) { |
526 |
| - return Mono.from(checkManagePermission(bundleId)) |
527 |
| - .then(checkPermissionResource(permissionId, bundleId)) |
528 |
| - .then(resourcePermissionService.updateRoleById(permissionId, role)) |
529 |
| - .then(); |
| 564 | + public Mono<Boolean> updatePermission(String bundleId, String permissionId, ResourceRole role) { |
| 565 | + return checkCurrentUserBundlePermission(bundleId, MANAGE_BUNDLES) |
| 566 | + .then(checkBundleStatus(bundleId, BundleStatus.NORMAL)) |
| 567 | + .then(resourcePermissionService.getById(permissionId)) |
| 568 | + .filter(permission -> StringUtils.equals(permission.getResourceId(), bundleId)) |
| 569 | + .switchIfEmpty(deferredError(ILLEGAL_BUNDLE_PERMISSION_ID, "ILLEGAL_BUNDLE_PERMISSION_ID")) |
| 570 | + .then(resourcePermissionService.updateRoleById(permissionId, role)); |
530 | 571 | }
|
531 | 572 |
|
532 | 573 | @Override
|
533 |
| - public Mono<Void> removePermission(String bundleId, String permissionId) { |
534 |
| - return Mono.from(checkManagePermission(bundleId)) |
535 |
| - .then(checkPermissionResource(permissionId, bundleId)) |
536 |
| - .then(resourcePermissionService.removeById(permissionId)) |
537 |
| - .then(); |
| 574 | + public Mono<Boolean> removePermission(String bundleId, String permissionId) { |
| 575 | + return checkCurrentUserBundlePermission(bundleId, MANAGE_BUNDLES) |
| 576 | + .then(checkBundleStatus(bundleId, BundleStatus.NORMAL)) |
| 577 | + .then(resourcePermissionService.getById(permissionId)) |
| 578 | + .filter(permission -> StringUtils.equals(permission.getResourceId(), bundleId)) |
| 579 | + .switchIfEmpty(deferredError(ILLEGAL_BUNDLE_PERMISSION_ID, "ILLEGAL_BUNDLE_PERMISSION_ID")) |
| 580 | + .then(resourcePermissionService.removeById(permissionId)); |
538 | 581 | }
|
539 | 582 |
|
540 | 583 | private Mono<Void> checkPermissionResource(String permissionId, String bundleId) {
|
|
0 commit comments