summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/user_organizations_endpoint.rb
blob: 98824d6491f1a94fc2eb5d3d817c7a08b216d36a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'json'
require 'chef_zero/rest_base'

module ChefZero
  module Endpoints
    # /users/USER/organizations
    class UserOrganizationsEndpoint < RestBase
      def get(request)
        username = request.rest_path[1]
        result = list_data(request, [ 'organizations' ]).select do |orgname|
          exists_data?(request, [ 'organizations', orgname, 'users', username ])
        end
        result = result.map do |orgname|
          org = get_data(request, [ 'organizations', orgname, 'org' ])
          org = JSON.parse(org, :create_additions => false)
          ChefData::DataNormalizer.normalize_organization(org, orgname)
        end
        json_response(200, result)
      end
    end
  end
end