Skip to content

Commit

Permalink
fix: Kanban Board Menu Items Accessibility via perms
Browse files Browse the repository at this point in the history
- Save Filters and Delete Board btns render if 'write' and 'delete' perms exist on Kanban Board
- `Create Kanban Board` renders only if 'create' perms exist on Kanban Board
- Bind board permisions to `board_perms` property of board object
- Get perms via backend call at board initialization, as frontend does not have document object (only doctype meta and perms are cached)

(cherry picked from commit 8d31e70)
  • Loading branch information
marination authored and mergify[bot] committed Mar 16, 2023
1 parent d1446b8 commit 4ffc7a5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
16 changes: 10 additions & 6 deletions frappe/public/js/frappe/list/list_view_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@ frappe.views.ListViewSelect = class ListViewSelect {
);
});

this.page.add_custom_menu_item(
kanban_switcher,
__("Create New Kanban Board"),
() => frappe.views.KanbanView.show_kanban_dialog(this.doctype),
true
);
let perms = this.list_view.board_perms;
let can_create = perms ? perms.create : true;
if (can_create) {
this.page.add_custom_menu_item(
kanban_switcher,
__("Create New Kanban Board"),
() => frappe.views.KanbanView.show_kanban_dialog(this.doctype),
true
);
}
}

get_page_name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ frappe.provide("frappe.views");

function init() {
make_dom();
// setup_sortable(); // drag card
setup_sortable(); // drag card
make_cards();
store.watch((state, getters) => {
return state.cards;
Expand Down
68 changes: 44 additions & 24 deletions frappe/public/js/frappe/views/kanban/kanban_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,53 @@ frappe.views.KanbanView = class KanbanView extends frappe.views.ListView {
this.card_meta = this.get_card_meta();
this.page_length = 0;

// frappe run serially get/set perms > push menu items > get_board
this.menu_items.push(
...[
{
label: __("Save filters"),
action: () => {
this.save_kanban_board_filters();
},
},
{
label: __("Delete Kanban Board"),
action: () => {
frappe.confirm("Are you sure you want to proceed?", () => {
frappe.db.delete_doc("Kanban Board", this.board_name).then(() => {
frappe.show_alert(`Kanban Board ${this.board_name} deleted.`);
frappe.set_route("List", this.doctype, "List");
});
});
},
},
]
);

return this.get_board();
return frappe.run_serially([
() => this.set_board_perms_and_push_menu_items(),
() => this.get_board(),
]);
});
}

set_board_perms_and_push_menu_items() {
// needs server-side call as client-side document instance is absent before kanban render
return frappe.call({
method: "frappe.client.get_doc_permissions",
args: {
doctype: "Kanban Board",
docname: this.board_name
},
callback: (result) => {
this.board_perms = result.message.permissions || {};
this.push_menu_items();
},
});
}

push_menu_items() {
if (this.board_perms.write) {
this.menu_items.push({
label: __("Save filters"),
action: () => {
this.save_kanban_board_filters();
}
});
}

if (this.board_perms.delete) {
this.menu_items.push({
label: __("Delete Kanban Board"),
action: () => {
frappe.confirm("Are you sure you want to proceed?", () => {
frappe.db.delete_doc("Kanban Board", this.board_name).then(() => {
frappe.show_alert(`Kanban Board ${this.board_name} deleted.`);
frappe.set_route("List", this.doctype, "List");
});
});
},
});
}
}

setup_paging_area() {
// pass
}
Expand Down

0 comments on commit 4ffc7a5

Please sign in to comment.