1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
18 from flask_multipass
import IdentityInfo
20 from MaKaC
.common
.cache
import GenericCache
21 from MaKaC
.common
.ObjectHolders
import ObjectHolder
23 from indico
.modules
.users
import User
24 from indico
.modules
.users
.legacy
import AvatarProvisionalWrapper
30 "surName": "last_name",
31 "organisation": "affiliation"
35 class AvatarHolder(ObjectHolder
):
36 """Specialised ObjectHolder dealing with user (avatar) objects. Objects of
37 this class represent an access point to Avatars of the application and
38 provides different methods for accessing and retrieving them in several
42 counterName
= "PRINCIPAL"
44 def match(self
, criteria
, exact
=False, onlyActivated
=True, searchInAuthenticators
=False):
45 from indico
.modules
.users
.util
import search_users
46 cache
= GenericCache('pending_identities')
48 def _process_identities(obj
):
49 if isinstance(obj
, IdentityInfo
):
50 cache
.set(obj
.provider
.name
+ ":" + obj
.identifier
, obj
.data
)
51 return AvatarProvisionalWrapper(obj
)
55 results
= search_users(exact
=exact
, include_pending
=not onlyActivated
, include_deleted
=not onlyActivated
,
56 external
=searchInAuthenticators
,
57 **{AVATAR_FIELD_MAP
[k
]: v
for (k
, v
) in criteria
.iteritems() if v
})
59 return [_process_identities(obj
) for obj
in results
]
61 def getById(self
, id):
62 if isinstance(id, int) or id.isdigit():
63 user
= User
.get(int(id))