Project

General

Profile

Feature #31521 ยป user_api.patch

Alexander Meindl, 2019-06-05 17:55

View differences:

app/helpers/users_helper.rb
88 88
      end
89 89
    end
90 90
  end
91

  
92
  def render_api_user_includes(user, api, memberships = nil)
93
    api.array :groups do |groups|
94
      user.groups.each do |group|
95
        api.group :id => group.id, :name => group.name
96
      end
97
    end if User.current.admin? && include_in_api_response?('groups')
98

  
99
    api.array :memberships do
100
      memberships.each do |membership|
101
        api.membership do
102
          api.id membership.id
103
          api.project :id => membership.project.id, :name => membership.project.name
104
          api.array :roles do
105
            membership.member_roles.each do |member_role|
106
              if member_role.role
107
                attrs = {:id => member_role.role.id, :name => member_role.role.name}
108
                attrs.merge!(:inherited => true) if member_role.inherited_from.present?
109
                api.role attrs
110
              end
111
            end
112
          end
113
        end if membership.project
114
      end
115
    end if include_in_api_response?('memberships') && memberships
116
  end
91 117
end
app/views/users/index.api.rsb
11 11
      api.last_login_on user.last_login_on
12 12

  
13 13
      render_api_custom_values user.visible_custom_field_values, api
14
      render_api_user_includes(user, api)
14 15
    end
15 16
  end
16 17
end
app/views/users/show.api.rsb
11 11
  api.status     @user.status if User.current.admin?
12 12

  
13 13
  render_api_custom_values @user.visible_custom_field_values, api
14

  
15
  api.array :groups do |groups|
16
    @user.groups.each do |group|
17
      api.group :id => group.id, :name => group.name
18
    end
19
  end if User.current.admin? && include_in_api_response?('groups')
20

  
21
  api.array :memberships do
22
    @memberships.each do |membership|
23
      api.membership do
24
        api.id membership.id
25
        api.project :id => membership.project.id, :name => membership.project.name
26
        api.array :roles do
27
          membership.member_roles.each do |member_role|
28
            if member_role.role
29
              attrs = {:id => member_role.role.id, :name => member_role.role.name}
30
              attrs.merge!(:inherited => true) if member_role.inherited_from.present?
31
              api.role attrs
32
            end
33
          end
34
        end
35
      end if membership.project
36
    end
37
  end if include_in_api_response?('memberships') && @memberships
14
  render_api_user_includes(@user, api, @memberships)
38 15
end
    (1-1/1)