entities/authobjs.py
changeset 7141 ef29d3ea3909
parent 7120 e8b6fc55df2d
child 7370 96923d75610b
equal deleted inserted replaced
7109:611663348158 7141:ef29d3ea3909
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    78         except ValueError:
    78         except ValueError:
    79             self.warning('incorrect value for eproperty %s of user %s',
    79             self.warning('incorrect value for eproperty %s of user %s',
    80                          key, self.login)
    80                          key, self.login)
    81         return self._cw.vreg.property_value(key)
    81         return self._cw.vreg.property_value(key)
    82 
    82 
       
    83     def set_property(self, pkey, value):
       
    84         value = unicode(value)
       
    85         try:
       
    86             prop = self._cw.execute(
       
    87                 'CWProperty X WHERE X pkey %(k)s, X for_user U, U eid %(u)s',
       
    88                 {'k': pkey, 'u': self.eid}).get_entity(0, 0)
       
    89         except:
       
    90             kwargs = dict(pkey=unicode(pkey), value=value)
       
    91             if self.is_in_group('managers'):
       
    92                 kwargs['for_user'] = self
       
    93             self._cw.create_entity('CWProperty', **kwargs)
       
    94         else:
       
    95             prop.set_attributes(value=value)
       
    96 
    83     def matching_groups(self, groups):
    97     def matching_groups(self, groups):
    84         """return the number of the given group(s) in which the user is
    98         """return the number of the given group(s) in which the user is
    85 
    99 
    86         :type groups: str or iterable(str)
   100         :type groups: str or iterable(str)
    87         :param groups: a group name or an iterable on group names
   101         :param groups: a group name or an iterable on group names