fix(db_query): selecting linked fields as alias (#20085)
* fix(db_query): Don't track link_tables separately Treat all joined tables the same, expand the fieldnames whether Table or Link type with their respective table names * fix(db_query): Add link join conditions for all relevant fields * Revert "fix(db_query): Add link join conditions for all relevant fields" This reverts commit 79622ab4cea5aa73a24f4ba7afde8e83510a79fb. * Revert "fix(db_query): Don't track link_tables separately" This reverts commit b8364f781e52e7ffaa7faa8878ef409b023f2288. * fix: Check link field tables permissions in permlevel checks * test: Fix, add for test_permlevel_fields Previous assertion was wrong :') added extra to check if access is fine
This commit is contained in:
parent
d5ce94d6a5
commit
3406b6d752
2 changed files with 14 additions and 9 deletions
|
|
@ -75,6 +75,10 @@ class DatabaseQuery:
|
|||
self._doctype_meta = frappe.get_meta(self.doctype)
|
||||
return self._doctype_meta
|
||||
|
||||
@property
|
||||
def query_tables(self):
|
||||
return self.tables + [d.table_name for d in self.link_tables]
|
||||
|
||||
def execute(
|
||||
self,
|
||||
fields=None,
|
||||
|
|
@ -473,9 +477,7 @@ class DatabaseQuery:
|
|||
table_name = table_name[13:]
|
||||
if not table_name[0] == "`":
|
||||
table_name = f"`{table_name}`"
|
||||
if table_name not in self.tables and table_name not in (
|
||||
d.table_name for d in self.link_tables
|
||||
):
|
||||
if table_name not in self.query_tables:
|
||||
self.append_table(table_name)
|
||||
|
||||
def append_table(self, table_name):
|
||||
|
|
@ -641,7 +643,7 @@ class DatabaseQuery:
|
|||
table, column = column.split(".", 1)
|
||||
ch_doctype = table.replace("`", "").replace("tab", "", 1)
|
||||
|
||||
if wrap_grave_quotes(table) in self.tables:
|
||||
if wrap_grave_quotes(table) in self.query_tables:
|
||||
permitted_child_table_fields = get_permitted_fields(
|
||||
doctype=ch_doctype, parenttype=self.doctype
|
||||
)
|
||||
|
|
|
|||
|
|
@ -845,11 +845,14 @@ class TestDBQuery(FrappeTestCase):
|
|||
self.assertTrue("count" in data[0])
|
||||
self.assertEqual(len(data[0]), 2)
|
||||
|
||||
with self.assertRaises(frappe.PermissionError):
|
||||
frappe.get_list(
|
||||
"Blog Post",
|
||||
fields=["blog_category.description"],
|
||||
)
|
||||
data = frappe.get_list(
|
||||
"Blog Post",
|
||||
fields=["name", "blogger.full_name as blogger_full_name", "blog_category.description"],
|
||||
limit=1,
|
||||
)
|
||||
self.assertTrue("name" in data[0])
|
||||
self.assertTrue("blogger_full_name" in data[0])
|
||||
self.assertTrue("description" in data[0])
|
||||
|
||||
def test_cast_name(self):
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue