]> git.openstreetmap.org Git - rails.git/blob - app/views/api/users/_user.json.jbuilder
API User details JSON format
[rails.git] / app / views / api / users / _user.json.jbuilder
1 json.user do
2   json.id user.id
3   json.display_name user.display_name
4   json.account_created user.creation_time.xmlschema
5   json.description user.description if user.description
6
7   if current_user && current_user == user
8     json.contributor_terms do
9       json.agreed user.terms_agreed.present?
10       json.pd user.consider_pd
11     end
12   else
13     json.contributor_terms do
14       json.agreed user.terms_agreed.present?
15     end
16   end
17
18   json.img do
19     json.href user_image_url(user) if user.avatar.attached? || user.image_use_gravatar
20   end
21
22   json.roles do
23     json.array! user.roles.map(&:role)
24   end
25
26   json.changesets do
27     json.count user.changesets.size
28   end
29
30   json.traces do
31     json.count user.traces.size
32   end
33
34   json.blocks do
35     json.received do
36       json.count user.blocks.size
37       json.active user.blocks.active.size
38     end
39
40     if user.moderator?
41       json.issued do
42         json.count user.blocks_created.size
43         json.active user.blocks_created.active.size
44       end
45     end
46   end
47
48   if current_user && current_user == user
49     if user.home_lat && user.home_lon
50       json.home do
51         json.lat user.home_lat
52         json.lon user.home_lon
53         json.zoom user.home_zoom
54       end
55     end
56
57     if user.languages
58       json.languages do
59         json.array! user.languages.split(",")
60       end
61     end
62
63     json.messages do
64       json.received do
65         json.count user.messages.size
66         json.unread user.new_messages.size
67       end
68       json.sent do
69         json.count user.sent_messages.size
70       end
71     end
72   end
73 end