<commit_before>require 'json'

module Carto
  module Api
    class ApiKeyPresenter
      def initialize(api_key)
        @api_key = api_key
      end

      def to_poro
        return {} unless @api_key
        {
          name: @api_key.name,
          user: { username: @api_key.user.username },
          type: @api_key.type,
          token: @api_key.token,
          grants: [
            {
              type: 'apis',
              apis: @api_key.granted_apis
            },
            {
              type: 'database',
              tables: @api_key.table_permissions_from_db.map do |p|
                {
                  schema: p.schema,
                  name: p.name,
                  permissions: p.permissions
                }
              end
            }
          ],
          created_at: @api_key.created_at.to_s,
          updated_at: @api_key.updated_at.to_s
        }
      end
    end
  end
end<commit_msg>Show empty permission list for master and default_public keys<commit_after>require 'json'

module Carto
  module Api
    class ApiKeyPresenter
      def initialize(api_key)
        @api_key = api_key
      end

      def to_poro
        return {} unless @api_key
        {
          name: @api_key.name,
          user: { username: @api_key.user.username },
          type: @api_key.type,
          token: @api_key.token,
          grants: [
            {
              type: 'apis',
              apis: @api_key.granted_apis
            },
            {
              type: 'database',
              tables: table_permissions_for_api_key
            }
          ],
          created_at: @api_key.created_at.to_s,
          updated_at: @api_key.updated_at.to_s
        }
      end

      private

      def table_permissions_for_api_key
        return [] if @api_key.master? || @api_key.default_public?

        @api_key.table_permissions_from_db.map do |p|
          {
            schema: p.schema,
            name: p.name,
            permissions: p.permissions
          }
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08199121522693997, 'fraction_numerical': 0.0, 'mean_word_length': 1.295632698768197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '816585', 'n_tokens_mistral': 620, 'n_tokens_neox': 615, 'n_words': 122}