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
This commit is contained in:
parent
4e6a5b6cd9
commit
80d264a7b4
3 changed files with 18 additions and 4 deletions
|
|
@ -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,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -403,11 +403,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);
|
||||
|
|
@ -1157,11 +1163,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Reference in a new issue