Browse Source

fix: permissions dont refresh when switching doc

Grid permissions aren't refreshed when switching docs.

Setup permissions like this:

1. Normal perm - read
2. If owner - read + write + others
3. Open a normal doc -> is read only so grid is read only.
4. Now go back and open a created doc -> grid will be read only or empty
   (if no rows)

fix: make grid.perm a computed property that refers to form instead of
duplicating this.

ref: ISS-22-23-01733
(cherry picked from commit 80d264a7b4)
version-14
Ankush Menat 2 years ago
committed by Mergify
parent
commit
2e03bf7749
3 changed files with 18 additions and 4 deletions
  1. +0
    -1
      frappe/public/js/frappe/form/controls/table.js
  2. +10
    -3
      frappe/public/js/frappe/form/form.js
  3. +8
    -0
      frappe/public/js/frappe/form/grid.js

+ 0
- 1
frappe/public/js/frappe/form/controls/table.js View File

@@ -8,7 +8,6 @@ frappe.ui.form.ControlTable = class ControlTable extends frappe.ui.form.Control
this.grid = new Grid({
frm: this.frm,
df: this.df,
perm: this.perm || (this.frm && this.frm.perm) || this.df.perm,
parent: this.wrapper,
control: this,
});


+ 10
- 3
frappe/public/js/frappe/form/form.js View File

@@ -393,11 +393,17 @@ frappe.ui.form.Form = class FrappeForm {
this.doc = frappe.get_doc(this.doctype, this.docname);

// check permissions
this.fetch_permissions();
if (!this.has_read_permission()) {
frappe.show_not_permitted(__(this.doctype) + " " + __(cstr(this.docname)));
return;
}

// update grids with new permissions
this.grids.forEach((table) => {
table.grid.refresh();
});

// read only (workflow)
this.read_only = frappe.workflow.is_read_only(this.doctype, this.docname);
if (this.read_only) this.set_read_only(true);
@@ -1147,11 +1153,12 @@ frappe.ui.form.Form = class FrappeForm {
.attr("target", "_blank");
}

has_read_permission() {
// get perm
var dt = this.parent_doctype ? this.parent_doctype : this.doctype;
fetch_permissions() {
let dt = this.parent_doctype ? this.parent_doctype : this.doctype;
this.perm = frappe.perm.get_perm(dt, this.doc);
}

has_read_permission() {
if (!this.perm[0].read) {
return 0;
}


+ 8
- 0
frappe/public/js/frappe/form/grid.js View File

@@ -43,6 +43,14 @@ export default class Grid {
this.debounced_refresh = frappe.utils.debounce(this.debounced_refresh, 100);
}

get perm() {
return this.control?.perm || this.frm?.perm || this.df.perm;
}

set perm(_perm) {
console.error("Setting perm on grid isn't supported, update form's perm instead");
}

allow_on_grid_editing() {
if (frappe.utils.is_xs()) {
return false;


Loading…
Cancel
Save