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

Commit db735f3

Browse files
Thomasrludomikula
Thomasr
authored andcommitted
#1379: Fix errors that were choosing wrong organization when enterprise mode is active
In enterprise mode, all login and apis deals with one organization.
1 parent fe0111a commit db735f3

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
import org.lowcoder.domain.user.service.UserService;
3333
import org.lowcoder.sdk.auth.AbstractAuthConfig;
3434
import org.lowcoder.sdk.config.AuthProperties;
35+
import org.lowcoder.sdk.config.CommonConfig;
36+
import org.lowcoder.sdk.constants.WorkspaceMode;
3537
import org.lowcoder.sdk.exception.BizError;
3638
import org.lowcoder.sdk.exception.BizException;
39+
import org.lowcoder.sdk.models.HasIdAndAuditing;
3740
import org.lowcoder.sdk.util.CookieHelper;
3841
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
3942
import org.springframework.stereotype.Service;
@@ -69,6 +72,7 @@ public class AuthenticationApiServiceImpl implements AuthenticationApiService {
6972
private final OrgMemberService orgMemberService;
7073
private final JWTUtils jwtUtils;
7174
private final AuthProperties authProperties;
75+
private final CommonConfig commonConfig;
7276

7377
@Override
7478
public Mono<AuthUser> authenticateByForm(String loginId, String password, String source, boolean register, String authId, String orgId) {
@@ -238,10 +242,16 @@ public Mono<Void> onUserRegister(User user, boolean isSuperAdmin) {
238242
}
239243

240244
protected Mono<Void> onUserLogin(String orgId, User user, String source) {
241-
if (StringUtils.isEmpty(orgId)) {
242-
return Mono.empty();
245+
Mono<String> orgMono;
246+
if(commonConfig.getWorkspace().getMode() == WorkspaceMode.ENTERPRISE) {
247+
orgMono = organizationService.getOrganizationInEnterpriseMode().map(HasIdAndAuditing::getId);
248+
} else {
249+
if (StringUtils.isEmpty(orgId)) {
250+
return Mono.empty();
251+
}
252+
orgMono = Mono.just(orgId);
243253
}
244-
return orgApiService.tryAddUserToOrgAndSwitchOrg(orgId, user.getId()).then();
254+
return orgMono.flatMap(orgId2 -> orgApiService.tryAddUserToOrgAndSwitchOrg(orgId2, user.getId())).then();
245255
}
246256

247257
@Override

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/usermanagement/OrganizationController.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import org.lowcoder.domain.plugin.DatasourceMetaInfo;
2020
import org.lowcoder.domain.plugin.service.DatasourceMetaInfoService;
2121
import org.lowcoder.domain.user.service.UserService;
22+
import org.lowcoder.sdk.config.CommonConfig;
23+
import org.lowcoder.sdk.constants.WorkspaceMode;
2224
import org.springframework.beans.factory.annotation.Autowired;
2325
import org.springframework.http.codec.multipart.Part;
2426
import org.springframework.web.bind.annotation.*;
2527
import org.springframework.web.server.ServerWebExchange;
28+
import reactor.core.publisher.Flux;
2629
import reactor.core.publisher.Mono;
2730

2831
import java.util.List;
@@ -47,14 +50,21 @@ public class OrganizationController implements OrganizationEndpoints
4750
private OrganizationService organizationService;
4851
@Autowired
4952
private UserService userService;
53+
@Autowired
54+
private CommonConfig commonConfig;
5055

5156
@Override
5257
public Mono<PageResponseView<?>> getOrganizationByUser(@PathVariable String email,
5358
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
5459
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
55-
var flux = userService.findByEmailDeep(email).flux().flatMap(user -> orgMemberService.getAllActiveOrgs(user.getId()))
56-
.flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
57-
.map(OrgView::new).cache();
60+
Flux<?> flux;
61+
if (commonConfig.getWorkspace().getMode() == WorkspaceMode.SAAS) {
62+
flux = userService.findByEmailDeep(email).flux().flatMap(user -> orgMemberService.getAllActiveOrgs(user.getId()))
63+
.flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
64+
.map(OrgView::new).cache();
65+
} else {
66+
flux = organizationService.getOrganizationInEnterpriseMode().flux().cache();
67+
}
5868
return fluxToPageResponseView(pageNum, pageSize, flux);
5969
}
6070

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /