]> git.openstreetmap.org Git - rails.git/blob - app/views/api/users/_user.json.jbuilder
Use where instead of find to prevent 404
[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.created_at.xmlschema
5   json.description user.description if user.description
6
7   if current_user && current_user == user && can?(:details, 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 && can?(:details, User)
49     if user.home_location?
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     json.languages user.languages if user.languages?
58
59     json.messages do
60       json.received do
61         json.count user.messages.size
62         json.unread user.new_messages.size
63       end
64       json.sent do
65         json.count user.sent_messages.size
66       end
67     end
68
69     json.email user.email if scope_enabled?(:read_email)
70   end
71 end