CB-3491 fix: restrict projects list loading (#1667)

* CB-3491 fix: restrict projects list loading

* CB-3491 allow listUserProfileProperties without license

---------

Co-authored-by: Aleksandr Skoblikov <aleksandr.skoblikov@dbeaver.com>
This commit is contained in:
Alexey
2023-05-18 14:33:23 +03:00
committed by GitHub
co-authored by Aleksandr Skoblikov
parent 33e132172d
commit b90f7f7e65
5 changed files with 24 additions and 5 deletions
@@ -56,7 +56,7 @@ public interface DBWServiceAuth extends DBWService {
@WebAction()
boolean changeLocalPassword(@NotNull WebSession webSession, @NotNull String oldPassword, @NotNull String newPassword) throws DBWebException;
@WebAction()
@WebAction(authRequired = false)
WebPropertyInfo[] listUserProfileProperties(@NotNull WebSession webSession);
@WebAction()
+2 -1
View File
@@ -46,7 +46,8 @@ export const Body = observer(function Body() {
const Screen = screenService.screen?.component;
const { backendVersion } = useAppVersion();
useResource(Body, ProjectInfoResource, CachedMapAllKey);
// TODO: must be loaded in place where it is used
useResource(Body, ProjectInfoResource, CachedMapAllKey, { silent: true });
// sync classes from theme with body for popup components and etc
useLayoutEffect(() => {
@@ -250,7 +250,7 @@ export function useResource<
await this.loadingPromise;
this.exception = null;
} catch (exception: any) {
if (propertiesRef.errorContext) {
if (actions?.silent !== true && propertiesRef.errorContext) {
if (this.isResourceError()) {
const errors = Array.isArray(this.resourceException) ? this.resourceException : [this.resourceException];
@@ -267,6 +267,7 @@ export function useResource<
propertiesRef.errorContext.catch(this.exception);
}
}
actions?.onError?.(exception);
} finally {
this.loadingPromise = null;
}
@@ -439,7 +440,7 @@ export function useResource<
if (!result.isError()) {
return;
}
if (propertiesRef.errorContext) {
if (actions?.silent !== true && propertiesRef.errorContext) {
const errors = Array.isArray(exception) ? exception : [exception];
for (const error of errors) {
@@ -8,6 +8,7 @@
import { AppAuthService, UserInfoResource } from '@cloudbeaver/core-authentication';
import { injectable } from '@cloudbeaver/core-di';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { GraphQLService, ProjectInfo as SchemaProjectInfo, CachedMapResource, CachedMapAllKey, resourceKeyList, RmResourceType } from '@cloudbeaver/core-sdk';
export type ProjectInfo = SchemaProjectInfo;
@@ -18,12 +19,14 @@ export class ProjectInfoResource extends CachedMapResource<string, ProjectInfo>
constructor(
private readonly graphQLService: GraphQLService,
private readonly userInfoResource: UserInfoResource,
serverConfigResource: ServerConfigResource,
appAuthService: AppAuthService,
) {
super(() => new Map(), []);
this.sync(this.userInfoResource, () => {}, () => CachedMapAllKey);
appAuthService.requireAuthentication(this);
serverConfigResource.requirePublic(this);
this.userInfoResource.onUserChange.addPostHandler(() => {
this.clear();
});
@@ -9,7 +9,8 @@
import { action, makeObservable, observable } from 'mobx';
import { injectable } from '@cloudbeaver/core-di';
import { GraphQLService, CachedDataResource, ServerConfig, ServerConfigInput, NavigatorSettingsInput } from '@cloudbeaver/core-sdk';
import { ExecutorInterrupter } from '@cloudbeaver/core-executor';
import { GraphQLService, CachedDataResource, ServerConfig, ServerConfigInput, NavigatorSettingsInput, CachedResource } from '@cloudbeaver/core-sdk';
import { isArraysEqual } from '@cloudbeaver/core-utils';
import { isNavigatorViewSettingsEqual } from './ConnectionNavigatorViewSettings';
@@ -61,6 +62,19 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
}, () => undefined, undefined, this);
}
requirePublic<T>(
resource: CachedResource<any, any, T, any, any>,
map?: (param: void) => T
): this {
resource
.preloadResource(this, () => {})
.before(ExecutorInterrupter.interrupter(() => this.publicDisabled));
this.outdateResource<T>(resource, map as any);
return this;
}
get redirectOnFederatedAuth(): boolean {
return this.data?.redirectOnFederatedAuth ?? false;
}