<commit_before>class ElementPermissionProxy
  attr_reader :user, :element

  def initialize(user, element, user_ids = [])
    @user = user
    @element = element
    @user_ids = user_ids

    @collections = user_collections_for_element
    @sync_collections = sync_collections_users_for_element
  end

  def serialized
    serializer_class = serializer_class_by_element
    detail_level_for_element
    nested_dl = nested_details_levels_for_element

    serialized_element = restriction_by_dl(serializer_class, @dl, nested_dl).deep_symbolize_keys
  end

  private

  def detail_level_for_element
    # on max level everything can be read
    max_detail_level = max_detail_level_by_element_class
    # get collections where element belongs to
    c = @collections
    sc= @sync_collections
    # if user owns none of the collections which include the element, return minimum level
    @dl = 0
    return @dl if c.empty? && sc.empty?

    # Fall 1: User gehört eine unshared Collection, die das Element enthält -> alles
    # Fall 2: User besitzt mindestens einen Share, der das Element enthält...von diesen Shares nutzt man das maximale
    # Element Detaillevel

    c.map { |cc| [cc.is_shared, cc.send("#{element.class.to_s.downcase}_detail_level")] }.each do |bool, dl|
      return (@dl = max_detail_level) if !bool
      @dl = dl if dl > @dl
    end

    sc.map { |cc| [cc.send("#{element.class.to_s.downcase}_detail_level")] }.each do | dl|
      @dl = dl if dl > @dl
    end

    @dl

  end

  def nested_details_levels_for_element
    nested_detail_levels = {}
    c = @collections.map { |c| [c.sample_detail_level, c.wellplate_detail_level] } || []
    sc= @sync_collections.map { |sc| [sc.sample_detail_level, sc.wellplate_detail_level] } || []
    s_dl,w_dl= 0,0
    if element.is_a?(Sample)
      nested_detail_levels[:sample] = @dl<commit_msg>fix return sync coll dl as integer not array<commit_after>class ElementPermissionProxy
  attr_reader :user, :element

  def initialize(user, element, user_ids = [])
    @user = user
    @element = element
    @user_ids = user_ids

    @collections = user_collections_for_element
    @sync_collections = sync_collections_users_for_element
  end

  def serialized
    serializer_class = serializer_class_by_element
    detail_level_for_element
    nested_dl = nested_details_levels_for_element

    serialized_element = restriction_by_dl(serializer_class, @dl, nested_dl).deep_symbolize_keys
  end

  private

  def detail_level_for_element
    # on max level everything can be read
    max_detail_level = max_detail_level_by_element_class
    # get collections where element belongs to
    c = @collections
    sc= @sync_collections
    # if user owns none of the collections which include the element, return minimum level
    @dl = 0
    return @dl if c.empty? && sc.empty?

    # Fall 1: User gehört eine unshared Collection, die das Element enthält -> alles
    # Fall 2: User besitzt mindestens einen Share, der das Element enthält...von diesen Shares nutzt man das maximale
    # Element Detaillevel

    c.map { |cc| [cc.is_shared, cc.send("#{element.class.to_s.downcase}_detail_level")] }.each do |bool, dl|
      return (@dl = max_detail_level) if !bool
      @dl = dl if dl > @dl
    end

    sc.each do |sc|
      dl = sc.send("#{element.class.to_s.downcase}_detail_level")
      @dl = dl if dl > @dl
    end

    @dl

  end

  def nested_details_levels_for_element
    nested_detail_levels = {}
    c = @collections.map { |c| [c.sample_detail_level, c.wellplate_detail_level] } || []
    sc= @sync_collections.map { |sc| [sc.sample_detail_level, sc.wellplate_detail_level] } || []
    s_dl,w_dl= 0,0
    if element.is_a?(Sample)
      nested_detail_levels[:sample] = @dl
{'fraction_non_alphanumeric': 0.08832976445396146, 'fraction_numerical': 0.0026766595289079227, 'mean_word_length': 3.61358024691358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6801043', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1212, 'n_words': 322}