Merge pull request #21378 from dvdl16/feature/force-web-capture-setting

feat: setting for force web capture mode for camera uploads
This commit is contained in:
mergify[bot] 2023-07-31 05:41:48 +00:00 committed by GitHub
commit 74899f510a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 2 deletions

View file

@ -92,4 +92,47 @@ context("Attach Control", () => {
cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click();
cy.click_modal_primary_button("Yes");
});
it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => {
//Navigating to the new form for the newly created doctype
let doctype = "Test Attach Control";
let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
cy.visit(`/app/${dt_in_route}/new`, {
onBeforeLoad(win) {
// Mock "window.navigator.mediaDevices" property
// to return mock mediaDevices object
win.navigator.mediaDevices = {
ondevicechange: null,
};
},
});
cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`);
cy.get("body").should("have.attr", "data-ajax-state", "complete");
//Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
cy.findByRole("button", { name: "Attach" }).click();
//Clicking on "Camera" button
cy.findByRole("button", { name: "Camera" }).should("exist");
});
it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => {
//Navigating to the new form for the newly created doctype
let doctype = "Test Attach Control";
let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
cy.visit(`/app/${dt_in_route}/new`, {
onBeforeLoad(win) {
// Delete "window.navigator.mediaDevices" property
delete win.navigator.mediaDevices;
},
});
cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`);
cy.get("body").should("have.attr", "data-ajax-state", "complete");
//Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
cy.findByRole("button", { name: "Attach" }).click();
//Clicking on "Camera" button
cy.findByRole("button", { name: "Camera" }).should("not.exist");
});
});

View file

@ -33,6 +33,7 @@
"apply_strict_user_permissions",
"column_break_21",
"allow_guests_to_upload_files",
"force_web_capture_mode_for_uploads",
"security",
"session_expiry",
"document_share_key_expiry",
@ -563,12 +564,19 @@
"fieldtype": "Link",
"label": "Reset Password Template",
"options": "Email Template"
},
{
"default": "0",
"description": "When uploading files, force the use of the web-based image capture. If this is unchecked, the default behavior is to use the mobile native camera when use from a mobile is detected.",
"fieldname": "force_web_capture_mode_for_uploads",
"fieldtype": "Check",
"label": "Force Web Capture Mode for Uploads"
}
],
"icon": "fa fa-cog",
"issingle": 1,
"links": [],
"modified": "2023-05-25 13:02:54.808773",
"modified": "2023-07-30 17:34:08.292152",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",

View file

@ -76,7 +76,9 @@ frappe.ui.Capture = class {
show() {
this.build_dialog();
if (frappe.is_mobile()) {
if (cint(frappe.boot.sysdefaults.force_web_capture_mode_for_uploads)) {
this.show_for_desktop();
} else if (frappe.is_mobile()) {
this.show_for_mobile();
} else {
this.show_for_desktop();