5
5
import lombok .RequiredArgsConstructor ;
6
6
import org .apache .commons .collections4 .CollectionUtils ;
7
7
import org .apache .commons .lang3 .StringUtils ;
8
- import org .lowcoder .api .bundle .BundleEndpoints .CreateBundleRequest ;
9
8
import org .lowcoder .api .application .view .ApplicationInfoView ;
10
9
import org .lowcoder .api .application .view .ApplicationPermissionView ;
10
+ import org .lowcoder .api .bundle .BundleEndpoints .CreateBundleRequest ;
11
11
import org .lowcoder .api .bundle .view .BundleInfoView ;
12
12
import org .lowcoder .api .bundle .view .BundlePermissionView ;
13
13
import org .lowcoder .api .home .FolderApiService ;
17
17
import org .lowcoder .api .permission .view .PermissionItemView ;
18
18
import org .lowcoder .api .usermanagement .OrgDevChecker ;
19
19
import org .lowcoder .domain .application .model .Application ;
20
- import org .lowcoder .domain .application .model .ApplicationStatus ;
21
20
import org .lowcoder .domain .application .model .ApplicationType ;
22
21
import org .lowcoder .domain .application .repository .ApplicationRepository ;
23
22
import org .lowcoder .domain .application .service .ApplicationServiceImpl ;
24
- import org .lowcoder .domain .bundle .model .*;
23
+ import org .lowcoder .domain .bundle .model .Bundle ;
24
+ import org .lowcoder .domain .bundle .model .BundleApplication ;
25
+ import org .lowcoder .domain .bundle .model .BundleRequestType ;
26
+ import org .lowcoder .domain .bundle .model .BundleStatus ;
25
27
import org .lowcoder .domain .bundle .repository .BundleRepository ;
26
28
import org .lowcoder .domain .bundle .service .BundleElementRelationService ;
27
- import org .lowcoder .domain .bundle .service .BundleNode ;
28
29
import org .lowcoder .domain .bundle .service .BundleService ;
29
- import org .lowcoder .domain .bundle .service .*;
30
30
import org .lowcoder .domain .group .service .GroupService ;
31
31
import org .lowcoder .domain .organization .model .OrgMember ;
32
32
import org .lowcoder .domain .organization .model .Organization ;
33
+ import org .lowcoder .domain .organization .service .OrgMemberService ;
33
34
import org .lowcoder .domain .organization .service .OrganizationService ;
34
35
import org .lowcoder .domain .permission .model .*;
35
36
import org .lowcoder .domain .permission .service .ResourcePermissionService ;
36
- import org .lowcoder .domain .user .model .User ;
37
37
import org .lowcoder .domain .user .service .UserService ;
38
- import org .lowcoder .infra .birelation .BiRelation ;
39
38
import org .lowcoder .infra .birelation .BiRelationBizType ;
40
39
import org .lowcoder .infra .birelation .BiRelationServiceImpl ;
41
40
import org .lowcoder .sdk .exception .BizError ;
42
41
import org .lowcoder .sdk .exception .BizException ;
43
- import org .springframework .beans .factory .annotation .Autowired ;
44
42
import org .springframework .context .annotation .Lazy ;
45
43
import org .springframework .stereotype .Service ;
46
44
import reactor .core .publisher .Flux ;
49
47
50
48
import java .util .*;
51
49
import java .util .function .Function ;
52
- import java .util .function .ToLongFunction ;
53
- import java .util .stream .Collectors ;
54
50
55
- import static org .apache .commons .collections4 .CollectionUtils .isNotEmpty ;
56
51
import static org .lowcoder .domain .bundle .model .BundleStatus .NORMAL ;
57
52
import static org .lowcoder .domain .permission .model .ResourceAction .*;
58
- import static org .lowcoder .infra .util .MonoUtils .emptyIfNull ;
59
53
import static org .lowcoder .sdk .exception .BizError .*;
54
+ import static org .lowcoder .sdk .util .ExceptionUtils .deferredError ;
60
55
import static org .lowcoder .sdk .util .ExceptionUtils .ofError ;
61
56
62
57
@ RequiredArgsConstructor
@@ -65,6 +60,7 @@ public class BundleApiServiceImpl implements BundleApiService {
65
60
private final BiRelationServiceImpl biRelationService ;
66
61
private final BundleService bundleService ;
67
62
private final SessionUserService sessionUserService ;
63
+ private final OrgMemberService orgMemberService ;
68
64
private final OrgDevChecker orgDevChecker ;
69
65
@ Lazy
70
66
private final UserHomeApiService userHomeApiService ;
@@ -96,8 +92,10 @@ public Mono<BundleInfoView> create(CreateBundleRequest createBundleRequest) {
96
92
if (StringUtils .isBlank (bundle .getName ())) {
97
93
return Mono .error (new BizException (BizError .INVALID_PARAMETER , "BUNDLE_NAME_EMPTY" ));
98
94
}
99
- return orgDevChecker .checkCurrentOrgDev ()
100
- .then (sessionUserService .getVisitorOrgMemberCache ())
95
+ return sessionUserService .getVisitorId ()
96
+ .flatMap (userId -> orgMemberService .getOrgMember (bundle .getOrganizationId (), userId ))
97
+ .switchIfEmpty (deferredError (NOT_AUTHORIZED , "NOT_AUTHORIZED" ))
98
+ .delayUntil (orgMember -> orgDevChecker .checkCurrentOrgDev ())
101
99
.delayUntil (orgMember -> checkBundleNameUnique (bundle .getName (), orgMember .getUserId ()))
102
100
.delayUntil (orgMember -> {
103
101
String folderId = createBundleRequest .folderId ();
@@ -251,6 +249,29 @@ public Mono<BundleInfoView> update(Bundle bundle) {
251
249
.flatMap (f -> buildBundleInfoView (f , true , true , null ));
252
250
}
253
251
252
+ @ Override
253
+ public Mono <BundleInfoView > publish (String bundleId ) {
254
+ return checkBundleStatus (bundleId , BundleStatus .NORMAL )
255
+ .then (sessionUserService .getVisitorId ())
256
+ .flatMap (userId -> resourcePermissionService .checkAndReturnMaxPermission (userId ,
257
+ bundleId , PUBLISH_BUNDLES ))
258
+ .flatMap (permission -> bundleService .publish (bundleId )
259
+ .map (bundleUpdated -> BundleInfoView .builder ()
260
+ .bundleId (bundleUpdated .getId ())
261
+ .name (bundleUpdated .getName ())
262
+ .editingBundleDSL (bundleUpdated .getEditingBundleDSL ())
263
+ .publishedBundleDSL (bundleUpdated .getPublishedBundleDSL ())
264
+ .title (bundleUpdated .getTitle ())
265
+ .image (bundleUpdated .getImage ())
266
+ .createAt (bundleUpdated .getCreatedAt ().toEpochMilli ())
267
+ .category (bundleUpdated .getCategory ())
268
+ .agencyProfile (bundleUpdated .getAgencyProfile ())
269
+ .publicToAll (bundleUpdated .getPublicToAll ())
270
+ .publicToMarketplace (bundleUpdated .getPublicToMarketplace ())
271
+ .createBy (bundleUpdated .getCreatedBy ())
272
+ .build ()));
273
+ }
274
+
254
275
/**
255
276
* @param applicationId app id to move
256
277
* @param fromBundleId bundle id to remove app from
@@ -381,6 +402,32 @@ public Mono<BundleInfoView> getPublishedBundle(String bundleId, BundleRequestTyp
381
402
});
382
403
}
383
404
405
+ @ Override
406
+ public Mono <BundleInfoView > getEditingBundle (String bundleId ) {
407
+ return checkPermissionWithReadableErrorMsg (bundleId , READ_BUNDLES )
408
+ .zipWhen (permission -> bundleService .findById (bundleId )
409
+ .delayUntil (bundle -> checkBundleStatus (bundle , BundleStatus .NORMAL )))
410
+ .map (tuple -> {
411
+ Bundle bundle = tuple .getT2 ();
412
+ return BundleInfoView .builder ()
413
+ .bundleId (bundle .getId ())
414
+ .name (bundle .getName ())
415
+ .title (bundle .getTitle ())
416
+ .category (bundle .getCategory ())
417
+ .description (bundle .getDescription ())
418
+ .image (bundle .getImage ())
419
+ .editingBundleDSL (bundle .getEditingBundleDSL ())
420
+ // .publishedBundleDSL(bundle.getPublishedBundleDSL())
421
+ .publicToMarketplace (bundle .getPublicToMarketplace ())
422
+ .publicToAll (bundle .getPublicToAll ())
423
+ .agencyProfile (bundle .getAgencyProfile ())
424
+ .createAt (bundle .getCreatedAt ().toEpochMilli ())
425
+ .createTime (bundle .getCreatedAt ())
426
+ .createBy (bundle .getCreatedBy ())
427
+ .build ();
428
+ });
429
+ }
430
+
384
431
private Mono <Void > checkBundleViewRequest (Bundle bundle , BundleRequestType expected ) {
385
432
386
433
// TODO: check bundle.isPublicToAll() from v2.4.0
@@ -402,6 +449,28 @@ private Mono<Void> checkBundleViewRequest(Bundle bundle, BundleRequestType expec
402
449
return Mono .error (new BizException (BizError .UNSUPPORTED_OPERATION , "BAD_REQUEST" ));
403
450
}
404
451
452
+ @ Override
453
+ @ Nonnull
454
+ public Mono <ResourcePermission > checkPermissionWithReadableErrorMsg (String bundleId , ResourceAction action ) {
455
+ return sessionUserService .getVisitorId ()
456
+ .flatMap (visitorId -> resourcePermissionService .checkUserPermissionStatusOnResource (visitorId , bundleId , action ))
457
+ .flatMap (permissionStatus -> {
458
+ if (!permissionStatus .hasPermission ()) {
459
+ if (permissionStatus .failByAnonymousUser ()) {
460
+ return ofError (USER_NOT_SIGNED_IN , "USER_NOT_SIGNED_IN" );
461
+ }
462
+
463
+ if (permissionStatus .failByNotInOrg ()) {
464
+ return ofError (NO_PERMISSION_TO_REQUEST_APP , "INSUFFICIENT_PERMISSION" );
465
+ }
466
+
467
+ String messageKey = action == EDIT_APPLICATIONS ? "NO_PERMISSION_TO_EDIT" : "NO_PERMISSION_TO_VIEW" ;
468
+ return ofError (NO_PERMISSION_TO_REQUEST_APP , messageKey );
469
+ }
470
+ return Mono .just (permissionStatus .getPermission ());
471
+ });
472
+ }
473
+
405
474
@ Override
406
475
@ Nonnull
407
476
public Mono <ResourcePermission > checkBundlePermissionWithReadableErrorMsg (String bundleId , ResourceAction action , BundleRequestType requestType ) {
0 commit comments