"add" permission for attributes (to distinguish from "update")

Closes #149216.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changesetad6204fe11c2
branchdefault
phasedraft
hiddenyes
parent revision#45f486c54ad5 Remove dead and deprecated code (closes #149361)
child revision<not specified>
files modified by this revision
buildobjs.py
schema.py
test/unittest_reader.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1372178936 -7200
# Tue Jun 25 18:48:56 2013 +0200
# Node ID ad6204fe11c27bb735d057337971da429f3522bd
# Parent 45f486c54ad58abf2e7ca15e0b602b9cb60231c5
"add" permission for attributes (to distinguish from "update")

Closes #149216.

diff --git a/buildobjs.py b/buildobjs.py
@@ -111,18 +111,18 @@
1      """add base (final) entity types to the given schema"""
2      for etype in BASE_TYPES:
3          edef = EntityType(name=etype)
4          schema.add_entity_type(edef)
5 
6 -# XXX use a "frozendict"
7 +
8  DEFAULT_RELPERMS = {'read': ('managers', 'users', 'guests',),
9                      'delete': ('managers', 'users'),
10                      'add': ('managers', 'users',)}
11 
12  DEFAULT_ATTRPERMS = {'read': ('managers', 'users', 'guests',),
13 -                     'update': ('managers', 'owners'),
14 -                     }
15 +                     'add': ('managers', 'users'),
16 +                     'update': ('managers', 'owners')}
17 
18  class Relation(object):
19      """Abstract class which have to be defined before the metadefinition
20      meta-class.
21      """
@@ -248,11 +248,10 @@
22      #:  .. automethod:: EntityType.remove_relation
23      #:  .. automethod:: EntityType.get_relation
24      #:  .. automethod:: EntityType.get_relations
25 
26      __metaclass__ = metadefinition
27 -    # XXX use a "frozendict"
28      __permissions__ = {
29          'read': ('managers', 'users', 'guests',),
30          'update': ('managers', 'owners',),
31          'delete': ('managers', 'owners'),
32          'add': ('managers', 'users',)
diff --git a/schema.py b/schema.py
@@ -49,10 +49,17 @@
33          assert action in schema.ACTIONS, \
34              'unknown action %s for %s' % (action, schema)
35          assert isinstance(groups, tuple), \
36                 ('permission for action %s of %s isn\'t a tuple as '
37                  'expected' % (action, schema))
38 +    if isinstance(schema, RelationDefinitionSchema) and schema.final:
39 +        if not 'add' in schema.permissions:
40 +            schema.permissions['add'] = schema.permissions['update']
41 +            warnings.warn('[yams 0.38] %s: new "add" permissions (%s) on attribute set as'
42 +                          '"update" by default, but you should make it explicit' %
43 +                          (schema, schema.permissions['add']),
44 +                          DeprecationWarning)
45      for action in schema.ACTIONS:
46          assert action in schema.permissions, \
47                 'missing expected permissions for action %s for %s' % (action, schema)
48 
49  def rehash(dictionary):
@@ -844,11 +851,11 @@
50          self.object = object
51 
52      @property
53      def ACTIONS(self):
54          if self.rtype.final:
55 -            return ('read', 'update')
56 +            return ('read', 'add', 'update')
57          else:
58              return ('read', 'add', 'delete')
59 
60      def update(self, values):
61          # XXX check we're copying existent properties
diff --git a/test/unittest_reader.py b/test/unittest_reader.py
@@ -254,10 +254,11 @@
62          self.assertEqual(rschema.rdef('Company', 'String').permissions,
63                            buildobjs.DEFAULT_ATTRPERMS)
64          rschema = schema.rschema('tel')
65          self.assertEqual(rschema.rdef('Person', 'Int').permissions,
66                            {'read': (),
67 +                           'add': ('managers',),
68                             'update': ('managers',)})
69 
70 
71      def test_entity_permissions(self):
72          eschema = schema.eschema('State')