16 has_permission, has_add_permission, |
16 has_permission, has_add_permission, |
17 ) |
17 ) |
18 from cubicweb.web import uicfg, controller |
18 from cubicweb.web import uicfg, controller |
19 from cubicweb.web.action import Action |
19 from cubicweb.web.action import Action |
20 from cubicweb.web.views import linksearch_select_url, vid_from_rset |
20 from cubicweb.web.views import linksearch_select_url, vid_from_rset |
21 from cubicweb.web.views.autoform import AutomaticEntityForm |
|
22 |
21 |
23 |
22 |
24 class has_editable_relation(EntitySelector): |
23 class has_editable_relation(EntitySelector): |
25 """accept if some relations for an entity found in the result set is |
24 """accept if some relations for an entity found in the result set is |
26 editable by the logged user. |
25 editable by the logged user. |
29 """ |
28 """ |
30 |
29 |
31 def score_entity(self, entity): |
30 def score_entity(self, entity): |
32 # if user has no update right but it can modify some relation, |
31 # if user has no update right but it can modify some relation, |
33 # display action anyway |
32 # display action anyway |
34 for dummy in AutomaticEntityForm.esrelations_by_category( |
33 form = self._cw.vreg['forms'].select('edition', self._cw, |
35 entity, 'generic', 'add', strict=True): |
34 entity=entity) |
|
35 for dummy in form.editable_relations(): |
36 return 1 |
36 return 1 |
37 for rschema, targetschemas, role in AutomaticEntityForm.erelations_by_category( |
37 try: |
38 entity, ('primary', 'secondary'), 'add', strict=True): |
38 editableattrs = form.editable_attributes(strict=True) |
|
39 except TypeError: |
|
40 warn('[3.6] %s: editable_attributes now take strict=False as ' |
|
41 'optional argument', DeprecationWarning) |
|
42 editableattrs = form.editable_attributes() |
|
43 for rschema, targetschemas, role in editableattrs: |
39 if not rschema.is_final(): |
44 if not rschema.is_final(): |
40 return 1 |
45 return 1 |
41 return 0 |
46 return 0 |
42 |
47 |
43 @objectify_selector |
48 @objectify_selector |