[FIX] web, project: avoid crash on file upload in portal
This commit fixes a crash that would happen on file upload in the project sharing portal chatter. This crash was caused by the file size check in the uploadFiles method of the FileInput component due to the fact that the PortalFileInput calls this method once per file instead of once for all files. The fix therefore ensures that the file size check will be correctly applied in the case of a single file parameter instead of a files array. Steps to reproduce: - Access the portal (with the /my route) - Go to Projects - Open the AGR - S00064 - Sales Order project - Open any task in the kanban view - Send an attachment in the chatter - Before the fix, a traceback occurs on file upload Crash introduced by https://github.com/odoo/odoo/pull/138203/commits/82b4395b2f12e1c86d2bd5c4acd47c321be071d8 opw-3628996 closes odoo/odoo#146214 X-original-commit: 8e2aef9ab607b06eb4667859204cfd7186b3f060 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
'project/static/src/js/portal_rating.js',
|
||||
],
|
||||
'web.qunit_suite_tests': [
|
||||
'project/static/src/project_sharing/components/portal_file_input/portal_file_input.js',
|
||||
'project/static/tests/**/*.js',
|
||||
],
|
||||
'web.assets_tests': [
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
|
||||
import {
|
||||
editInput,
|
||||
getFixture,
|
||||
mount,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/helpers/utils";
|
||||
import { PortalFileInput } from "@project/project_sharing/components/portal_file_input/portal_file_input";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from "@web/session";
|
||||
import { makeFakeLocalizationService } from "@web/../tests/helpers/mock_services";
|
||||
|
||||
const serviceRegistry = registry.category("services");
|
||||
|
||||
let target;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
async function createFileInput({ mockPost, mockAdd, props }) {
|
||||
serviceRegistry.add("notification", {
|
||||
start: () => ({
|
||||
add: mockAdd || (() => {}),
|
||||
}),
|
||||
});
|
||||
serviceRegistry.add("http", {
|
||||
start: () => ({
|
||||
post: mockPost || (() => {}),
|
||||
}),
|
||||
});
|
||||
const env = await makeTestEnv();
|
||||
await mount(PortalFileInput, target, { env, props });
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
QUnit.module("Project", ({ beforeEach }) => {
|
||||
beforeEach(() => {
|
||||
patchWithCleanup(odoo, { csrf_token: "dummy" });
|
||||
|
||||
target = getFixture();
|
||||
});
|
||||
|
||||
QUnit.module("PortalComponents");
|
||||
|
||||
QUnit.test("uploading a file that is too heavy in portal will send a notification", async (assert) => {
|
||||
serviceRegistry.add("localization", makeFakeLocalizationService());
|
||||
patchWithCleanup(session, { max_file_upload_size: 2 });
|
||||
await createFileInput({
|
||||
props: {
|
||||
onUpload(files) {
|
||||
assert.deepEqual(files, [null]);
|
||||
},
|
||||
},
|
||||
mockAdd: (message) => {
|
||||
assert.step("notification");
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"The selected file (4B) is over the maximum allowed file size (2B)."
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const file = new File(["test"], "fake_file.txt", { type: "text/plain" });
|
||||
await editInput(target, ".o_file_input input", file);
|
||||
assert.verifySteps(
|
||||
["notification"],
|
||||
"Only the notification will be triggered and the file won't be uploaded."
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -56,8 +56,8 @@ export class FileInput extends Component {
|
||||
}
|
||||
|
||||
async uploadFiles(params) {
|
||||
if (params.ufile.length) {
|
||||
const fileSize = params.ufile[0].size;
|
||||
if ((params.ufile && params.ufile.length) || params.file) {
|
||||
const fileSize = (params.ufile && params.ufile[0].size) || params.file.size;
|
||||
if (!checkFileSize(fileSize, this.notification)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user