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

Fixed sending /events requests from logged out users #7608

Merged
merged 13 commits into from
Mar 29, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Sending `/events` request from logged-out user (<https://github.com/opencv/cvat/pull/7608>)
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "15.0.1",
"version": "15.0.2",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default interface CVATCore {
enabled: boolean;
onEmptyMaskOccurrence: () => void | null;
};
onOrganizationChange: typeof config.onOrganizationChange;
onOrganizationChange: (newOrgId: number | null) => void | null;
globalObjectsCounter: typeof config.globalObjectsCounter;
},
client: {
Expand Down
2 changes: 2 additions & 0 deletions cvat-core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ Object.defineProperties(Logger.prototype.save, {
// potentially new events may be generated during saving
// that is why we add this.collection
this.collection = [...collectionToSend, ...this.collection];

throw error;
} finally {
this.saving = false;
}
Expand Down
15 changes: 11 additions & 4 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -71,7 +71,7 @@ import showPlatformNotification, {
} from 'utils/platform-checker';
import '../styles.scss';
import appConfig from 'config';
import EventRecorder from 'utils/controls-logger';
import EventRecorder from 'utils/event-recorder';
import { authQuery } from 'utils/auth-query';
import EmailConfirmationPage from './email-confirmation-pages/email-confirmed';
import EmailVerificationSentPage from './email-confirmation-pages/email-verification-sent';
Expand Down Expand Up @@ -149,7 +149,6 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
});

core.logger.configure(() => window.document.hasFocus, userActivityCallback);
EventRecorder.initSave();

core.config.onOrganizationChange = (newOrgId: number | null) => {
if (newOrgId === null) {
Expand Down Expand Up @@ -254,7 +253,7 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
}
}

public componentDidUpdate(): void {
public componentDidUpdate(prevProps: CVATAppProps): void {
const {
verifyAuthorized,
loadFormats,
Expand Down Expand Up @@ -302,6 +301,14 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
return;
}

if (user !== prevProps.user) {
if (user) {
EventRecorder.initSave();
} else {
EventRecorder.cancelSave();
}
}

if (!userAgreementsInitialized && !userAgreementsFetching) {
loadUserAgreements();
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 CVAT.ai Corporation
// Copyright (C) 2023-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -15,6 +15,7 @@ const parentClassFilter = ['ant-btn'];

class EventRecorder {
#savingTimeout: number | null;

public constructor() {
this.#savingTimeout = null;
core.logger.log(EventScope.loadTool, {
Expand Down Expand Up @@ -52,13 +53,29 @@ class EventRecorder {
public initSave(): void {
if (this.#savingTimeout) return;
this.#savingTimeout = window.setTimeout(() => {
core.logger.save().finally(() => {
const scheduleSave = (): void => {
this.#savingTimeout = null;
this.initSave();
});
};
core.logger.save()
.then(scheduleSave)
.catch((error) => {
if (error?.code === 401) {
this.cancelSave();
} else {
scheduleSave();
}
});
}, CONTROLS_LOGS_INTERVAL);
}

public cancelSave(): void {
if (this.#savingTimeout) {
window.clearTimeout(this.#savingTimeout);
this.#savingTimeout = null;
}
}

private filterClassName(cls: string): string {
if (typeof cls === 'string') {
return cls.split(' ').filter((_cls: string) => _cls.startsWith('cvat')).join(' ');
Expand Down
Loading