Skip to content

Fixed GrantApplicationPermission endpoint. #1898

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 number Diff line number Diff line change
@@ -1,21 +1,27 @@
package org.lowcoder.infra.birelation;

import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import static com.google.common.base.Strings.nullToEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.springframework.data.mongodb.core.query.Criteria.where;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.lowcoder.infra.mongo.MongoUpsertHelper;
import org.lowcoder.sdk.exception.BizError;
import org.lowcoder.sdk.exception.BizException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.List;
import com.google.common.base.Preconditions;

import static com.google.common.base.Strings.nullToEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
@RequiredArgsConstructor
Expand All @@ -36,8 +42,27 @@ public Mono<BiRelation> addBiRelation(BiRelation biRelation) {

@Override
public Mono<List<BiRelation>> batchAddBiRelation(Collection<BiRelation> biRelations) {
return biRelationRepository.saveAll(biRelations)
.collectList();
List<Mono<BiRelation>> tasks = new ArrayList<>();
List<BiRelation> alreadyGranted = new ArrayList<>();

for (BiRelation relation : biRelations) {
tasks.add(
biRelationRepository.insert(relation)
.onErrorResume(DuplicateKeyException.class, ex -> {
alreadyGranted.add(relation);
return Mono.empty();
})
);
}

return Flux.merge(tasks)
.collectList()
.map(inserted -> {
if (!alreadyGranted.isEmpty()) {
throw new BizException(BizError.APPLICATION_GRANTED_PERMISSION_CONFLICT, "APPLICATION_GRANTED_PERMISSION_CONFLICT", alreadyGranted);
}
return inserted;
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.lowcoder.sdk.exception;

import lombok.Getter;

import static org.lowcoder.sdk.exception.ErrorLogType.SIMPLE;
import static org.lowcoder.sdk.exception.ErrorLogType.VERBOSE;
import static org.lowcoder.sdk.util.EnumUtils.checkDuplicates;

import lombok.Getter;

@Getter
public enum BizError {

Expand Down Expand Up @@ -64,6 +64,7 @@ public enum BizError {

NO_PERMISSION_TO_REQUEST_APP(403, 5308),
APPLICATION_AND_ORG_NOT_MATCH(400, 5309),
APPLICATION_GRANTED_PERMISSION_CONFLICT(409, 5310),

// datasource related, code range 5500 - 5600
DATASOURCE_NOT_FOUND(500, 5500),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ EMAIL_PROVIDER_DISABLED=E-Mail-Anbieter ist deaktiviert.
SLUG_DUPLICATE_ENTRY=Slug existiert bereits.
SLUG_INVALID=Slug-Format ist ungültig.
FLOW_ERROR=Flow-Fehlermeldung: {0}.
APPLICATION_GRANTED_PERMISSION_CONFLICT=Das Recht wurde bereits gewährt.
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,5 @@ EMAIL_PROVIDER_DISABLED=Email provider is disabled.
SLUG_DUPLICATE_ENTRY=Slug already exists
SLUG_INVALID=Slug format is invalid
FLOW_ERROR=Flow error message: {0}
ORGANIZATION_NOT_FOUND=Organization not found.
ORGANIZATION_NOT_FOUND=Organization not found.
APPLICATION_GRANTED_PERMISSION_CONFLICT=Right was already granted.
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,5 @@ DUPLICATE_AUTH_CONFIG_ADDITION=提供商身份验证类型已添加到组织中
EMAIL_PROVIDER_DISABLED=电子邮件提供商已禁用。
SLUG_DUPLICATE_ENTRY=蛞蝓已经存在
SLUG_INVALID=Slug 格式无效
FLOW_ERROR=流程错误消息:{0}
FLOW_ERROR=流程错误消息:{0}
APPLICATION_GRANTED_PERMISSION_CONFLICT=权限已被提交。
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package org.lowcoder.api.application;

import lombok.RequiredArgsConstructor;
import org.lowcoder.api.application.view.*;
import static org.apache.commons.collections4.SetUtils.emptyIfNull;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_CREATE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_DELETE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_RECYCLED;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_RESTORE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_UPDATE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_VIEW;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.lowcoder.api.application.view.ApplicationInfoView;
import org.lowcoder.api.application.view.ApplicationPermissionView;
import org.lowcoder.api.application.view.ApplicationPublishRequest;
import org.lowcoder.api.application.view.ApplicationView;
import org.lowcoder.api.application.view.MarketplaceApplicationInfoView;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.UserHomeApiService;
Expand All @@ -18,17 +35,10 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Objects;

import static org.apache.commons.collections4.SetUtils.emptyIfNull;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.*;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import java.util.Map;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
@RestController
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy