Commit 1bce67ba authored by Viet-Hung Nhu's avatar Viet-Hung Nhu
Browse files

fix(views): Fix reledit errors when trying modify relation with multi subjects

- closes #352
- related to #324
- caused by !244

--HG--
branch : 3.32
parent 3ccb26166050
......@@ -114,6 +114,7 @@ class Personne(EntityType):
description = String()
salary = Float()
travaille = SubjectRelation("Societe")
tags = SubjectRelation("BlogEntry")
class connait(RelationDefinition):
......
......@@ -396,6 +396,7 @@ class RQLSuggestionsBuilderTC(CubicWebTC):
"Any X WHERE X is Personne, X promo A",
"Any X WHERE X is Personne, X salary A",
"Any X WHERE X is Personne, X sexe A",
"Any X WHERE X is Personne, X tags A",
"Any X WHERE X is Personne, X tel A",
"Any X WHERE X is Personne, X test A",
"Any X WHERE X is Personne, X titre A",
......@@ -407,6 +408,7 @@ class RQLSuggestionsBuilderTC(CubicWebTC):
)
self.assertListEqual(
[
"Any X WHERE X is Personne, X tags A",
"Any X WHERE X is Personne, X tel A",
"Any X WHERE X is Personne, X test A",
"Any X WHERE X is Personne, X titre A",
......@@ -418,6 +420,7 @@ class RQLSuggestionsBuilderTC(CubicWebTC):
# try completion on selected
self.assertListEqual(
[
"Any X WHERE X is Personne, Y is Societe, X tags A",
"Any X WHERE X is Personne, Y is Societe, X tel A",
"Any X WHERE X is Personne, Y is Societe, X test A",
"Any X WHERE X is Personne, Y is Societe, X titre A",
......
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# copyright 2003-2021 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact https://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
......@@ -97,6 +97,18 @@ class ClickAndEditFormTC(ReleditMixinTC, CubicWebTC):
fields["manager"] = """<not specified>"""
self._test_fields(fields, login="contrib")
def test_admins_edit_permissions_multiple(self):
"""
Add test for the permission of relation for all subjects possibles.
- Personne has the relation "tags" only with "BlogEntry" but
- Tag could have the relations "tags" with "BlogEntry" and "CWUser"
This test check that do not generate the KeyError when trying to get
the relation between "Personne" <--> "CWUser"
"""
with self.new_access("admin").web_request() as cnx:
entity = cnx.find("Personne").limit(1).one()
entity.view("reledit", rtype="tags", role="subject")
def test_default_forms(self):
self.skipTest(
"Need to check if this test should still run post reledit/doreledit merge"
......
......@@ -179,6 +179,7 @@ class AutomaticEntityFormTC(CubicWebTC):
("travaille", "subject"),
("manager", "object"),
("connait", "object"),
("tags", "subject"),
],
)
self.assertListEqual(rbc(e, "main", "hidden"), [])
......
......@@ -436,9 +436,12 @@ class AutoClickAndEditFormView(EntityView):
ttypes = self._compute_ttypes(rschema, role)
# check permission which are not rqlexprs
for target in ttypes:
rdef = rschema.role_rdef(self.entity.e_schema, target, role)
if rdef.has_perm(self._cw, "add", **perm_args):
return True
try:
rdef = rschema.role_rdef(self.entity.e_schema, target, role)
if rdef.has_perm(self._cw, "add", **perm_args):
return True
except KeyError:
pass
# can delete related entities
related_rset = self.entity.related(rschema.type, role)
if related_rset:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment