Skip to content

Commit

Permalink
CB-5710 change getters to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
devnaumov committed Oct 10, 2024
1 parent 524b5f6 commit 5118ef9
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 36 deletions.
4 changes: 2 additions & 2 deletions webapp/packages/core-authentication/src/AppAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { UserInfoResource } from './UserInfoResource.js';
@injectable()
export class AppAuthService extends Bootstrap {
get authenticated(): boolean {
return this.serverConfigResource.configurationMode || this.userInfoResource.hasAccess;
return this.serverConfigResource.configurationMode || this.userInfoResource.hasAccess();
}

get loaders(): ILoadableState[] {
Expand Down Expand Up @@ -56,7 +56,7 @@ export class AppAuthService extends Bootstrap {

await this.userInfoResource.load();

return !this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess;
return !this.serverConfigResource.configurationMode && !this.userInfoResource.hasAccess();
}

async authUser(): Promise<boolean> {
Expand Down
27 changes: 10 additions & 17 deletions webapp/packages/core-authentication/src/UserInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
return this.data !== null;
}

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

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

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

constructor(
private readonly graphQLService: GraphQLService,
private readonly authProviderService: AuthProviderService,
Expand All @@ -85,14 +73,19 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,

makeObservable(this, {
parametersAvailable: computed,
isAnonymous: computed,
isAuthenticated: computed,
hasAccess: computed,
});
}

isData(): this is { data: UserInfo } {
return !!this.data;
isAnonymous(): this is { data: UserInfo } {
return this.data?.isAnonymous === true;
}

isAuthenticated(): this is { data: UserInfo } {
return !!this.data && !this.isAnonymous();
}

hasAccess(): this is { data: UserInfo } {
return this.isAnonymous() || this.isAuthenticated();
}

isLinked(provideId: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/core-projects/src/ProjectsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ProjectsService extends Dependency {
get userProject(): ProjectInfo | undefined {
let project: ProjectInfo | undefined;

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

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.isData() && this.userInfoResource.data.configurationParameters !== this.lastConfig) {
if (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 @@ -67,7 +67,7 @@ export class AuthenticationService extends Bootstrap {
this.onLogin = new Executor();

this.onLogout.before(this.navigationService.navigationTask);
this.onLogin.before(this.navigationService.navigationTask, undefined, () => userInfoResource.isAnonymous);
this.onLogin.before(this.navigationService.navigationTask, undefined, () => userInfoResource.isAnonymous());

this.authPromise = null;
this.configureAuthProvider = null;
Expand Down
4 changes: 2 additions & 2 deletions webapp/packages/plugin-authentication/src/PluginBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PluginBootstrap extends Bootstrap {
this.menuService.addCreator({
menus: [TOP_NAV_BAR_SETTINGS_MENU],
getItems: (context, items) => {
if (this.serverConfigResource.enabledAuthProviders.length > 0 && this.userInfoResource.isAnonymous) {
if (this.serverConfigResource.enabledAuthProviders.length > 0 && this.userInfoResource.isAnonymous()) {
return [
...items,
new MenuBaseItem(
Expand All @@ -42,7 +42,7 @@ export class PluginBootstrap extends Bootstrap {
];
}

if (this.userInfoResource.isAuthenticated) {
if (this.userInfoResource.isAuthenticated()) {
return [
...items,
new MenuBaseItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ConnectionAuthService extends Dependency {
connections: connectionInfoResource.values.filter(connection => connection.connected).map(createConnectionParam),
state,
}),
state => state === 'before' && userInfoResource.isAnonymous,
state => state === 'before' && userInfoResource.isAnonymous(),
);
this.authenticationService.onLogout.before(
connectionsManagerService.onDisconnect,
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.isAuthenticated || 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,8 +60,9 @@ export class PublicConnectionFormService {
executorHandlerFilter(
() => !!this.formState && this.optionsPanelService.isOpen(formGetter),
async (event, context) => {
if (event === 'before' && !this.userInfoResource.isData()) {
if (event === 'before' && this.userInfoResource.isAnonymous()) {
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.isAuthenticated) {
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 @@ -15,7 +15,7 @@ import { ServerConfigResource } from '@cloudbeaver/core-root';
@injectable()
export class ResourceManagerService {
get enabled() {
return !!this.serverConfigResource.data?.resourceManagerEnabled && this.userInfoResource.isAuthenticated;
return !!this.serverConfigResource.data?.resourceManagerEnabled && this.userInfoResource.isAuthenticated();
}

constructor(
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.configurationMode && !this.userInfoResource.hasAccess) {
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.isData() || !userInfoResource.isAuthenticated) {
if (!userInfoResource.isAuthenticated()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class UserProfileFormBootstrap extends Bootstrap {
key: 'account',
name: 'plugin_user_profile_account_title',
order: 1,
isHidden: () => this.userInfoResource.isAnonymous,
isHidden: () => this.userInfoResource.isAnonymous(),
panel: () => UserProfileFormPanel,
});
}
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.isData()) {
if (!this.userInfoResource.hasAccess()) {
this.close(true);
}
}
Expand Down

0 comments on commit 5118ef9

Please sign in to comment.