schemas/base.py
changeset 3890 d7a270f50f54
parent 3392 36bcf206e157
parent 3877 7ca53fc72a0a
child 4003 b9436fe77c9e
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
    14                              ERQLExpression, RRQLExpression)
    14                              ERQLExpression, RRQLExpression)
    15 from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
    15 from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
    16 
    16 
    17 class CWUser(WorkflowableEntityType):
    17 class CWUser(WorkflowableEntityType):
    18     """define a CubicWeb user"""
    18     """define a CubicWeb user"""
    19     permissions = {
    19     __permissions__ = {
    20         'read':   ('managers', 'users', ERQLExpression('X identity U')),
    20         'read':   ('managers', 'users', ERQLExpression('X identity U')),
    21         'add':    ('managers',),
    21         'add':    ('managers',),
    22         'delete': ('managers',),
    22         'delete': ('managers',),
    23         'update': ('managers', ERQLExpression('X identity U, NOT U in_group G, G name "guests"'),),
    23         'update': ('managers', ERQLExpression('X identity U, NOT U in_group G, G name "guests"'),),
    24         }
    24         }
    35                                     description=_('email address to use for notification'))
    35                                     description=_('email address to use for notification'))
    36     use_email     = SubjectRelation('EmailAddress', cardinality='*?', composite='subject')
    36     use_email     = SubjectRelation('EmailAddress', cardinality='*?', composite='subject')
    37 
    37 
    38     in_group = SubjectRelation('CWGroup', cardinality='+*',
    38     in_group = SubjectRelation('CWGroup', cardinality='+*',
    39                                constraints=[RQLConstraint('NOT O name "owners"')],
    39                                constraints=[RQLConstraint('NOT O name "owners"')],
    40                                description=_('groups grant permissions to the user'))
    40                                description=_('groups grant __permissions__ to the user'))
    41 
    41 
    42 
    42 
    43 class EmailAddress(EntityType):
    43 class EmailAddress(EntityType):
    44     """an electronic mail address associated to a short alias"""
    44     """an electronic mail address associated to a short alias"""
    45     permissions = {
    45     __permissions__ = {
    46         'read':   ('managers', 'users', 'guests',), # XXX if P use_email X, U has_read_permission P
    46         'read':   ('managers', 'users', 'guests',), # XXX if P use_email X, U has_read_permission P
    47         'add':    ('managers', 'users',),
    47         'add':    ('managers', 'users',),
    48         'delete': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    48         'delete': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    49         'update': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    49         'update': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    50         }
    50         }
    57 (such as python-projects@logilab.org and python-projects@lists.logilab.org), set this \
    57 (such as python-projects@logilab.org and python-projects@lists.logilab.org), set this \
    58 to indicate which is the preferred form.'))
    58 to indicate which is the preferred form.'))
    59 
    59 
    60 class use_email(RelationType):
    60 class use_email(RelationType):
    61     """ """
    61     """ """
    62     permissions = {
    62     __permissions__ = {
    63         'read':   ('managers', 'users', 'guests',),
    63         'read':   ('managers', 'users', 'guests',),
    64         'add':    ('managers', RRQLExpression('U has_update_permission S'),),
    64         'add':    ('managers', RRQLExpression('U has_update_permission S'),),
    65         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
    65         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
    66         }
    66         }
    67     fulltext_container = 'subject'
    67     fulltext_container = 'subject'
    68 
    68 
    69 class primary_email(RelationType):
    69 class primary_email(RelationType):
    70     """the prefered email"""
    70     """the prefered email"""
    71     permissions = use_email.permissions
    71     __permissions__ = use_email.__permissions__
    72 
    72 
    73 class prefered_form(RelationType):
    73 class prefered_form(RelationType):
    74     permissions = {
    74     __permissions__ = {
    75         'read':   ('managers', 'users', 'guests',),
    75         'read':   ('managers', 'users', 'guests',),
    76         # XXX should have update permissions on both subject and object,
    76         # XXX should have update __permissions__ on both subject and object,
    77         #     though by doing this we will probably have no way to add
    77         #     though by doing this we will probably have no way to add
    78         #     this relation in the web ui. The easiest way to acheive this
    78         #     this relation in the web ui. The easiest way to acheive this
    79         #     is probably to be able to have "U has_update_permission O" as
    79         #     is probably to be able to have "U has_update_permission O" as
    80         #     RQLConstraint of the relation definition, though this is not yet
    80         #     RQLConstraint of the relation definition, though this is not yet
    81         #     possible
    81         #     possible
    83         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
    83         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
    84         }
    84         }
    85 
    85 
    86 class in_group(RelationType):
    86 class in_group(RelationType):
    87     """core relation indicating a user's groups"""
    87     """core relation indicating a user's groups"""
    88     permissions = META_RTYPE_PERMS
    88     __permissions__ = META_RTYPE_PERMS
    89 
    89 
    90 class owned_by(RelationType):
    90 class owned_by(RelationType):
    91     """core relation indicating owners of an entity. This relation
    91     """core relation indicating owners of an entity. This relation
    92     implicitly put the owner into the owners group for the entity
    92     implicitly put the owner into the owners group for the entity
    93     """
    93     """
    94     permissions = {
    94     __permissions__ = {
    95         'read':   ('managers', 'users', 'guests'),
    95         'read':   ('managers', 'users', 'guests'),
    96         'add':    ('managers', RRQLExpression('S owned_by U'),),
    96         'add':    ('managers', RRQLExpression('S owned_by U'),),
    97         'delete': ('managers', RRQLExpression('S owned_by U'),),
    97         'delete': ('managers', RRQLExpression('S owned_by U'),),
    98         }
    98         }
    99     # 0..n cardinality for entities created by internal session (no attached user)
    99     # 0..n cardinality for entities created by internal session (no attached user)
   102     subject = '*'
   102     subject = '*'
   103     object = 'CWUser'
   103     object = 'CWUser'
   104 
   104 
   105 class created_by(RelationType):
   105 class created_by(RelationType):
   106     """core relation indicating the original creator of an entity"""
   106     """core relation indicating the original creator of an entity"""
   107     permissions = {
   107     __permissions__ = {
   108         'read':   ('managers', 'users', 'guests'),
   108         'read':   ('managers', 'users', 'guests'),
   109         'add':    ('managers',),
   109         'add':    ('managers',),
   110         'delete': ('managers',),
   110         'delete': ('managers',),
   111         }
   111         }
   112     # 0..1 cardinality for entities created by internal session (no attached user)
   112     # 0..1 cardinality for entities created by internal session (no attached user)
   131 class cwuri(RelationType):
   131 class cwuri(RelationType):
   132     """internal entity uri"""
   132     """internal entity uri"""
   133     cardinality = '11'
   133     cardinality = '11'
   134     subject = '*'
   134     subject = '*'
   135     object = 'String'
   135     object = 'String'
       
   136 
       
   137 
       
   138 class CWProperty(EntityType):
       
   139     """used for cubicweb configuration. Once a property has been created you
       
   140     can't change the key.
       
   141     """
       
   142     __permissions__ = {
       
   143         'read':   ('managers', 'users', 'guests'),
       
   144         'add':    ('managers', 'users',),
       
   145         'update': ('managers', 'owners',),
       
   146         'delete': ('managers', 'owners',),
       
   147         }
       
   148     # key is a reserved word for mysql
       
   149     pkey = String(required=True, internationalizable=True, maxsize=256,
       
   150                   description=_('defines what\'s the property is applied for. '
       
   151                                 'You must select this first to be able to set '
       
   152                                 'value'))
       
   153     value = String(internationalizable=True, maxsize=256)
       
   154 
       
   155     for_user = SubjectRelation('CWUser', cardinality='?*', composite='object',
       
   156                                description=_('user for which this property is '
       
   157                                              'applying. If this relation is not '
       
   158                                              'set, the property is considered as'
       
   159                                              ' a global property'))
       
   160 
   136 
   161 
   137 # XXX find a better relation name
   162 # XXX find a better relation name
   138 class for_user(RelationType):
   163 class for_user(RelationType):
   139     """link a property to the user which want this property customization. Unless
   164     """link a property to the user which want this property customization. Unless
   140     you're a site manager, this relation will be handled automatically.
   165     you're a site manager, this relation will be handled automatically.
   141     """
   166     """
   142     permissions = {
   167     __permissions__ = {
   143         'read':   ('managers', 'users', 'guests'),
   168         'read':   ('managers', 'users', 'guests'),
   144         'add':    ('managers',),
   169         'add':    ('managers',),
   145         'delete': ('managers',),
   170         'delete': ('managers',),
   146         }
   171         }
   147     inlined = True
   172     inlined = True
   148     subject = 'CWProperty'
   173     subject = 'CWProperty'
   149     object = 'CWUser'
   174     object = 'CWUser'
   150     composite = 'object'
   175     composite = 'object'
   151     cardinality = '?*'
   176     cardinality = '?*'
   152 
   177 
       
   178 
   153 class CWPermission(EntityType):
   179 class CWPermission(EntityType):
   154     """entity type that may be used to construct some advanced security configuration
   180     """entity type that may be used to construct some advanced security configuration
   155     """
   181     """
   156     permissions = META_ETYPE_PERMS
   182     __permissions__ = META_ETYPE_PERMS
   157 
   183 
   158     name = String(required=True, indexed=True, internationalizable=True, maxsize=100,
   184     name = String(required=True, indexed=True, internationalizable=True, maxsize=100,
   159                   description=_('name or identifier of the permission'))
   185                   description=_('name or identifier of the permission'))
   160     label = String(required=True, internationalizable=True, maxsize=100,
   186     label = String(required=True, internationalizable=True, maxsize=100,
   161                    description=_('distinct label to distinguate between other permission entity of the same name'))
   187                    description=_('distinct label to distinguate between other permission entity of the same name'))
   166 # configurable security
   192 # configurable security
   167 class require_permission(RelationType):
   193 class require_permission(RelationType):
   168     """link a permission to the entity. This permission should be used in the
   194     """link a permission to the entity. This permission should be used in the
   169     security definition of the entity's type to be useful.
   195     security definition of the entity's type to be useful.
   170     """
   196     """
   171     permissions = {
   197     __permissions__ = {
   172         'read':   ('managers', 'users', 'guests'),
   198         'read':   ('managers', 'users', 'guests'),
   173         'add':    ('managers',),
   199         'add':    ('managers',),
   174         'delete': ('managers',),
   200         'delete': ('managers',),
   175         }
   201         }
   176 
   202 
   177 class require_group(RelationType):
   203 class require_group(RelationType):
   178     """used to grant a permission to a group"""
   204     """used to grant a permission to a group"""
   179     permissions = {
   205     __permissions__ = {
   180         'read':   ('managers', 'users', 'guests'),
   206         'read':   ('managers', 'users', 'guests'),
   181         'add':    ('managers',),
   207         'add':    ('managers',),
   182         'delete': ('managers',),
   208         'delete': ('managers',),
   183         }
   209         }
   184 
   210 
   194        http://www.w3.org/TR/owl-ref/#sameAs-def
   220        http://www.w3.org/TR/owl-ref/#sameAs-def
   195 
   221 
   196     NOTE: You'll have to explicitly declare which entity types can have a
   222     NOTE: You'll have to explicitly declare which entity types can have a
   197     same_as relation
   223     same_as relation
   198     """
   224     """
   199     permissions = {
   225     __permissions__ = {
   200         'read':   ('managers', 'users', 'guests',),
   226         'read':   ('managers', 'users', 'guests',),
   201         'add':    ('managers', 'users'),
   227         'add':    ('managers', 'users'),
   202         'delete': ('managers', 'owners'),
   228         'delete': ('managers', 'owners'),
   203         }
   229         }
   204     cardinality = '*1'
   230     cardinality = '*1'
   214     The target application is responsible for updating timestamp
   240     The target application is responsible for updating timestamp
   215     when necessary to invalidate the cache (typically in hooks).
   241     when necessary to invalidate the cache (typically in hooks).
   216 
   242 
   217     Also, checkout the AppObject.get_cache() method.
   243     Also, checkout the AppObject.get_cache() method.
   218     """
   244     """
   219     permissions = {
   245     __permissions__ = {
   220         'read':   ('managers', 'users', 'guests'),
   246         'read':   ('managers', 'users', 'guests'),
   221         'add':    ('managers',),
   247         'add':    ('managers',),
   222         'update': ('managers', 'users',), # XXX
   248         'update': ('managers', 'users',), # XXX
   223         'delete': ('managers',),
   249         'delete': ('managers',),
   224         }
   250         }
   231 # "abtract" relation types, not used in cubicweb itself
   257 # "abtract" relation types, not used in cubicweb itself
   232 
   258 
   233 class identical_to(RelationType):
   259 class identical_to(RelationType):
   234     """identical to"""
   260     """identical to"""
   235     symetric = True
   261     symetric = True
   236     permissions = {
   262     __permissions__ = {
   237         'read':   ('managers', 'users', 'guests',),
   263         'read':   ('managers', 'users', 'guests',),
   238         # XXX should have update permissions on both subject and object,
   264         # XXX should have update __permissions__ on both subject and object,
   239         #     though by doing this we will probably have no way to add
   265         #     though by doing this we will probably have no way to add
   240         #     this relation in the web ui. The easiest way to acheive this
   266         #     this relation in the web ui. The easiest way to acheive this
   241         #     is probably to be able to have "U has_update_permission O" as
   267         #     is probably to be able to have "U has_update_permission O" as
   242         #     RQLConstraint of the relation definition, though this is not yet
   268         #     RQLConstraint of the relation definition, though this is not yet
   243         #     possible
   269         #     possible
   246         }
   272         }
   247 
   273 
   248 class see_also(RelationType):
   274 class see_also(RelationType):
   249     """generic relation to link one entity to another"""
   275     """generic relation to link one entity to another"""
   250     symetric = True
   276     symetric = True
   251     permissions = {
   277     __permissions__ = {
   252         'read':   ('managers', 'users', 'guests',),
   278         'read':   ('managers', 'users', 'guests',),
   253         'add':    ('managers', RRQLExpression('U has_update_permission S'),),
   279         'add':    ('managers', RRQLExpression('U has_update_permission S'),),
   254         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
   280         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
   255         }
   281         }