cubicweb/entities/authobjs.py
changeset 11348 70337ad23145
parent 11057 0b59724cb3f2
child 11349 865de6759a53
equal deleted inserted replaced
11347:b4dcfd734686 11348:70337ad23145
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2016 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
   130         """
   130         """
   131         if isinstance(groups, string_types):
   131         if isinstance(groups, string_types):
   132             groups = frozenset((groups,))
   132             groups = frozenset((groups,))
   133         elif isinstance(groups, (tuple, list)):
   133         elif isinstance(groups, (tuple, list)):
   134             groups = frozenset(groups)
   134             groups = frozenset(groups)
   135         return len(groups & self.groups) # XXX return the resulting set instead of its size
   135         return len(groups & self.groups)  # XXX return the resulting set instead of its size
   136 
   136 
   137     def is_in_group(self, group):
   137     def is_in_group(self, group):
   138         """convience / shortcut method to test if the user belongs to `group`
   138         """convience / shortcut method to test if the user belongs to `group`
   139         """
   139         """
   140         return group in self.groups
   140         return group in self.groups
   141 
   141 
   142     def is_anonymous(self):
   142     def is_anonymous(self):
   143         """ checks if user is an anonymous user"""
   143         """ checks if user is an anonymous user"""
   144         #FIXME on the web-side anonymous user is detected according
   144         # FIXME on the web-side anonymous user is detected according to config['anonymous-user'],
   145         # to config['anonymous-user'], we don't have this info on
   145         # we don't have this info on the server side.
   146         # the server side.
       
   147         return self.groups == frozenset(('guests', ))
   146         return self.groups == frozenset(('guests', ))
   148 
   147 
   149     def owns(self, eid):
   148     def owns(self, eid):
   150         try:
   149         try:
   151             return self._cw.execute(
   150             return self._cw.execute(
   160     def name(self):
   159     def name(self):
   161         """construct a name using firstname / surname or login if not defined"""
   160         """construct a name using firstname / surname or login if not defined"""
   162 
   161 
   163         if self.firstname and self.surname:
   162         if self.firstname and self.surname:
   164             return self._cw._('%(firstname)s %(surname)s') % {
   163             return self._cw._('%(firstname)s %(surname)s') % {
   165                 'firstname': self.firstname, 'surname' : self.surname}
   164                 'firstname': self.firstname, 'surname': self.surname}
   166         if self.firstname:
   165         if self.firstname:
   167             return self.firstname
   166             return self.firstname
   168         return self.login
   167         return self.login
   169 
   168 
   170     def dc_title(self):
   169     def dc_title(self):