refactor: move get_involved_users to form

Involved users is a property of the form and doesn't have much to do
with reviews.
This commit is contained in:
Ankush Menat 2022-07-25 17:47:52 +05:30
parent d2a5b8b002
commit dd767bd687
2 changed files with 24 additions and 22 deletions

View file

@ -1873,6 +1873,29 @@ frappe.ui.form.Form = class FrappeForm {
get_active_tab() {
return this.active_tab_map && this.active_tab_map[this.docname];
}
get_involved_users() {
const user_fields = this.meta.fields
.filter(d => d.fieldtype === 'Link' && d.options === 'User')
.map(d => d.fieldname);
user_fields.push('owner');
let involved_users = user_fields.map(field => this.doc[field]);
const docinfo = this.get_docinfo();
involved_users = involved_users.concat(
docinfo.communications.map(d => d.sender && d.delivery_status === 'sent'),
docinfo.comments.map(d => d.owner),
docinfo.versions.map(d => d.owner),
docinfo.assignments.map(d => d.owner)
);
return involved_users
.uniqBy(u => u)
.filter(user => !['Administrator', frappe.session.user].includes(user))
.filter(Boolean);
}
};
frappe.validated = 0;

View file

@ -38,30 +38,9 @@ frappe.ui.form.Review = class Review {
review_button.click(() => this.show_review_dialog());
}
}
get_involved_users() {
const user_fields = this.frm.meta.fields
.filter(d => d.fieldtype === 'Link' && d.options === 'User')
.map(d => d.fieldname);
user_fields.push('owner');
let involved_users = user_fields.map(field => this.frm.doc[field]);
const docinfo = this.frm.get_docinfo();
involved_users = involved_users.concat(
docinfo.communications.map(d => d.sender && d.delivery_status === 'sent'),
docinfo.comments.map(d => d.owner),
docinfo.versions.map(d => d.owner),
docinfo.assignments.map(d => d.owner)
);
return involved_users
.uniqBy(u => u)
.filter(user => !['Administrator', frappe.session.user].includes(user))
.filter(Boolean);
}
show_review_dialog() {
const user_options = this.get_involved_users();
const user_options = this.frm.get_involved_users();
const review_dialog = new frappe.ui.Dialog({
'title': __('Add Review'),
'fields': [{