Skip to content
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

CB-5710 return anonymous user info #2972

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
872589e
CB-5710 return anonymous user info
yagudin10 Oct 8, 2024
6761368
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
devnaumov Oct 8, 2024
97cb1e8
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
devnaumov Oct 8, 2024
1f1a9d2
CB-5710 support anonymous user
devnaumov Oct 8, 2024
9ab0f12
CB-5710 anonymous access disabled active user fix
yagudin10 Oct 9, 2024
97137c2
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
devnaumov Oct 9, 2024
8ab9b2e
CB-5710 simplify logic
devnaumov Oct 9, 2024
1688a7e
Merge branch 'CB-5710-aws-integration-for-cloud-explorer-and-storage'…
devnaumov Oct 9, 2024
0c95961
CB-5710 fix error messages
yagudin10 Oct 10, 2024
6cbb592
CB-5710 review fixes
devnaumov Oct 10, 2024
daf960d
Merge branch 'CB-5710-aws-integration-for-cloud-explorer-and-storage'…
devnaumov Oct 10, 2024
524b5f6
CB-5710 add computed
devnaumov Oct 10, 2024
5118ef9
CB-5710 change getters to methods
devnaumov Oct 10, 2024
dbdfb5f
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
devnaumov Oct 10, 2024
febdabc
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
dariamarutkina Oct 10, 2024
96160b7
CB-5710 fixes after review
yagudin10 Oct 10, 2024
d0a8c63
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
dariamarutkina Oct 11, 2024
11b0ccf
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
dariamarutkina Oct 11, 2024
0df320f
Merge remote-tracking branch 'origin/devel' into CB-5710-aws-integrat…
yagudin10 Oct 15, 2024
6b9bebe
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
dariamarutkina Oct 15, 2024
f2a1277
Merge branch 'devel' into CB-5710-aws-integration-for-cloud-explorer-…
serge-rider Oct 16, 2024
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
8 changes: 3 additions & 5 deletions webapp/packages/core-authentication/src/AppAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { UserInfoResource } from './UserInfoResource.js';
@injectable()
export class AppAuthService extends Bootstrap {
get authenticated(): boolean {
const user = this.userInfoResource.data;

return this.serverConfigResource.anonymousAccessEnabled || this.serverConfigResource.configurationMode || user !== null;
return this.serverConfigResource.configurationMode || this.userInfoResource.hasAccess;
}

get loaders(): ILoadableState[] {
Expand Down Expand Up @@ -56,9 +54,9 @@ export class AppAuthService extends Bootstrap {
throw new Error("Can't configure Authentication");
}

const user = await this.userInfoResource.load();
await this.userInfoResource.load();

return !this.serverConfigResource.configurationMode && !this.serverConfigResource.anonymousAccessEnabled && user === null;
return !this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess;
}

async authUser(): Promise<boolean> {
Expand Down
14 changes: 11 additions & 3 deletions webapp/packages/core-authentication/src/UserInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
}

get isAnonymous() {
return !this.data || this.data.isAnonymous;
return this.data?.isAnonymous === true;
}

get isAuthenticated() {
return !!this.data && !this.isAnonymous;
}

get hasAccess() {
return this.isAnonymous || this.isAuthenticated;
}

constructor(
Expand All @@ -81,8 +89,8 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
});
}

isAuthenticated(): this is { data: UserInfo } {
return !this.isAnonymous;
isData(): this is { data: UserInfo } {
return !!this.data;
}
Wroud marked this conversation as resolved.
Show resolved Hide resolved

isLinked(provideId: string): boolean {
Expand Down
6 changes: 2 additions & 4 deletions webapp/packages/core-projects/src/ProjectsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { computed, makeObservable } from 'mobx';

import { ANONYMOUS_USER_ID, UserDataService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { UserDataService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { Dependency, injectable } from '@cloudbeaver/core-di';
import { Executor, ExecutorInterrupter, type IExecutor, type ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor';
import { CachedMapAllKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource';
Expand All @@ -33,10 +33,8 @@ export class ProjectsService extends Dependency {
get userProject(): ProjectInfo | undefined {
let project: ProjectInfo | undefined;

if (this.userInfoResource.data) {
if (this.userInfoResource.isData()) {
project = this.projectInfoResource.getUserProject(this.userInfoResource.data.userId);
} else {
project = this.projectInfoResource.get(ANONYMOUS_USER_ID);
}

return project;
Expand Down
8 changes: 4 additions & 4 deletions webapp/packages/core-settings-user/src/UserSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UserSettingsService extends SettingsSource {
}

async save() {
if (this.userInfoResource.isAuthenticated()) {
if (this.userInfoResource.isAuthenticated) {
await this.userInfoResource.updatePreferences(Object.fromEntries(this.changes));
} else {
this.update(() => {
Expand Down Expand Up @@ -94,13 +94,13 @@ export class UserSettingsService extends SettingsSource {

private refreshConfig() {
this.update(() => {
if (!this.userInfoResource.isAuthenticated()) {
if (!this.userInfoResource.isAuthenticated) {
this.clear();
this.lastConfig = null;
return;
}

if (this.userInfoResource.data.configurationParameters !== this.lastConfig) {
if (this.userInfoResource.isData() && this.userInfoResource.data.configurationParameters !== this.lastConfig) {
this.clear();
this.localSettings.clear();
this.lastConfig = this.userInfoResource.data.configurationParameters;
Expand All @@ -121,7 +121,7 @@ export class UserSettingsService extends SettingsSource {
}

private getSource() {
if (this.userInfoResource.isAuthenticated()) {
if (this.userInfoResource.isAuthenticated) {
return this.settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap {
isActionApplicable: (context, action) => {
const tree = context.get(DATA_CONTEXT_ELEMENTS_TREE)!;

if (action !== ACTION_NEW_FOLDER || !this.userInfoResource.data || tree.baseRoot !== ROOT_NODE_PATH) {
if (action !== ACTION_NEW_FOLDER || !this.userInfoResource.isAuthenticated || tree.baseRoot !== ROOT_NODE_PATH) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PublicConnectionFormService {
executorHandlerFilter(
() => !!this.formState && this.optionsPanelService.isOpen(formGetter),
async (event, context) => {
if (event === 'before' && this.userInfoResource.data === null) {
if (event === 'before' && !this.userInfoResource.isData()) {
Wroud marked this conversation as resolved.
Show resolved Hide resolved
const confirmed = await this.showUnsavedChangesDialog();
if (!confirmed) {
ExecutorInterrupter.interrupt(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
isActionApplicable: context => {
const tree = context.get(DATA_CONTEXT_ELEMENTS_TREE);

if (!tree?.baseRoot.startsWith(RESOURCES_NODE_PATH) || !this.userInfoResource.data) {
if (!tree?.baseRoot.startsWith(RESOURCES_NODE_PATH) || !this.userInfoResource.isAuthenticated) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
*/
import { computed, makeObservable } from 'mobx';

import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { UserInfoResource } from '@cloudbeaver/core-authentication';
import { injectable } from '@cloudbeaver/core-di';
import type { ProjectInfo } from '@cloudbeaver/core-projects';
import { ServerConfigResource } from '@cloudbeaver/core-root';

@injectable()
export class ResourceManagerService {
get enabled() {
return !!this.serverConfigResource.data?.resourceManagerEnabled && !!this.authInfoService.userInfo;
return !!this.serverConfigResource.data?.resourceManagerEnabled && this.userInfoResource.isAuthenticated;
}

constructor(
private readonly authInfoService: AuthInfoService,
private readonly userInfoResource: UserInfoResource,
private readonly serverConfigResource: ServerConfigResource,
) {
makeObservable(this, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SessionExpireWarningDialogBootstrap extends Bootstrap {
}

private handleSessionResourceDataUpdate(isValid?: boolean, remainingTime?: number) {
if (!this.serverConfigResource.anonymousAccessEnabled && !this.userInfoResource.data && !this.serverConfigResource.configurationMode) {
if (!this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const UserMenu = observer(function UserMenu() {
context.set(DATA_CONTEXT_USER, userInfoResource.data, id);
});

if (!userInfoResource.isAuthenticated()) {
if (!userInfoResource.isData() || !userInfoResource.isAuthenticated) {
Wroud marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class UserProfileOptionsPanelService {
return;
}

if (this.userInfoResource.data === null) {
if (!this.userInfoResource.isData()) {
Wroud marked this conversation as resolved.
Show resolved Hide resolved
this.close(true);
}
}
Expand Down
Loading