0001-api-exposer-user-info-in-json-2851.patch
help/fr/api-user.page | ||
---|---|---|
21 | 21 |
de l'utilisateur, modification, etc.). |
22 | 22 |
</p> |
23 | 23 | |
24 |
<section> |
|
25 |
<title>Mode pull</title> |
|
26 | ||
27 |
<p> |
|
28 |
Les informations associées à un utilisateur sont accessibles à l'URL |
|
29 |
<code>/user</code>, elles reprennent son nom (<code>user_display_name</code>), |
|
30 |
son adresse électronique (<code>user_email</code>) ainsi que ses éventuelles |
|
31 |
autorisations d'accès au backoffice (<code>user_backoffice_access</code>) ou |
|
32 |
à l'interface d'administration (<code>user_admin_access</code>). |
|
33 |
</p> |
|
34 | ||
35 |
<screen> |
|
36 |
<output style="prompt">$ </output><input>curl -H "Accept: application/json" https://www.example.net/user</input> |
|
37 |
<output>{ |
|
38 |
"user_display_name": "Fred", |
|
39 |
"user_email": "fred@example.net", |
|
40 |
"user_backoffice_access": true, |
|
41 |
"user_admin_access": false |
|
42 |
} |
|
43 |
</output></screen> |
|
44 | ||
45 |
</section> |
|
46 | ||
24 | 47 |
</page> |
wcs/root.ptl | ||
---|---|---|
46 | 46 |
from formdef import FormDef |
47 | 47 |
from formdata import FormData |
48 | 48 |
from anonylink import AnonymityLink |
49 |
from wcs.api import get_user_from_api_query_string |
|
49 | 50 | |
50 | 51 | |
51 | 52 |
class CompatibilityDirectory(Directory): |
... | ... | |
175 | 176 | |
176 | 177 |
class RootDirectory(Directory): |
177 | 178 |
_q_exports = ['admin', 'backoffice', 'forms', 'login', 'logout', 'liberty', 'token', 'saml', |
178 |
'ident', 'register', 'afterjobs', 'themes', 'myspace', |
|
179 |
'ident', 'register', 'afterjobs', 'themes', 'myspace', 'user',
|
|
179 | 180 |
'pages', ('tmp-upload', 'tmp_upload'), '__version__'] |
180 | 181 | |
181 | 182 |
themes = template.ThemesDirectory() |
... | ... | |
262 | 263 | |
263 | 264 |
return redirect('.') |
264 | 265 | |
266 |
def user(self): |
|
267 |
if get_request().get_header(str('Accept'), '') == 'application/json' or \ |
|
268 |
get_request().get_query() == 'json': |
|
269 |
return self.user_json() |
|
270 |
return redirect('myspace/') |
|
271 | ||
272 |
def user_json(self): |
|
273 |
get_response().set_content_type('application/json') |
|
274 |
user = get_user_from_api_query_string() or get_request().user |
|
275 |
if not user: |
|
276 |
return errors.AccessForbiddenError() |
|
277 |
user_info = user.get_substitution_variables(prefix='') |
|
278 |
del user_info['user'] |
|
279 |
return json.dumps(user_info) |
|
280 | ||
265 | 281 |
def tmp_upload(self): |
266 | 282 |
results = [] |
267 | 283 |
for k, v in get_request().form.items(): |
wcs/users.py | ||
---|---|---|
149 | 149 |
data = get_dict_with_varnames(formdef.fields, self.form_data) |
150 | 150 |
for k, v in data.items(): |
151 | 151 |
d[prefix+'user_'+k] = v |
152 | ||
153 |
d[prefix + 'user_admin_access'] = self.can_go_in_admin() |
|
154 |
d[prefix + 'user_backoffice_access'] = self.can_go_in_backoffice() |
|
152 | 155 |
return d |
153 | 156 | |
154 | 157 |
def get_substitution_variables_list(cls, prefix='session_'): |
155 |
- |