<commit_before>Puppet::Type.type(:zarafauser).provide(:db) do
  desc "Provides the ability to create zarafa users using the db user_plugin"

  commands :zarafaadmin => "/bin/zarafa-admin"

  has_features :zarafadbuser

  def exists?
    begin
      zarafaadmin(['--type','user','--details',@resource[:name]])
      return true
    rescue => e
      debug(e.message)
      return false
    end
  end

  def create
    raise Puppet::Error, "You have to provide a full name for user #{@resource[:name]}" unless @resource[:fullname]
    raise Puppet::Error, "You have to provide an email address for user #{@resource[:name]}" unless @resource[:email]
    raise Puppet::Error, "You have to provide a password for user #{@resource[:name]}" unless @resource[:password]

    createopts = ['-c',@resource[:name],'-p',@resource[:password],'-f',@resource[:fullname],'-e',@resource[:email]]
    updateopts = ['-u',@resource[:name]]
    if @resource[:admin] == :true
      createopts << '-a' << 'yes'
    end

    if @resource[:active] == :false
      createopts << '-n' << 'yes'
    end

    if @resource[:quotaoverride] == :true
      updateopts << '--qo' << 'yes'
    end

    if @resource[:hardquota]
      updateopts << '--qh' << @resource[:hardquota]
    end

    if @resource[:softquota]
      updateopts << '--qs' << @resource[:softquota]
    end

    if @resource[:warnquota]
      updateopts << '--qw' << @resource[:warnquota]
    end

    zarafaadmin(createopts)

    if updateopts.length > 2
      zarafaadmin(updateopts)
    end

    if @resource[:groups]
      @resource[:groups].each do |group|
        zarafaadmin(['-b',@resource[:name],'-i',group])
      end
    end

    if @resource[:features]
      @resource[:features].each do |feature|
        zarafaadmin(['-u',@resource[:name],'--enable-feature',feature])
      end
    end
  end

  def destroy
    zarafaadmin(['-d',@resource[:name]])
  end

  def features
    getuserdetails[:features]
  end

  def features=(value)
  end

  def groups
    getuserdetails[:groups]
  end

  def groups=(value)
  end

  def fullname
    getuserdetails[:fullname]
  end

  def fullname=(value)
  end

  def admin
    if getuserdetails[:admin] == 'yes'
      :true
    else
      :false
    end
  end

  def admin=(value)
  end

  def active
    if getuserdetails[:active] == 'yes'
      :true
    else
      :false
    end
  end

  def active=(value)
  end

  def quotaoverride
    if getuserdetails[:quotaoverride] == 'yes'
      :true
    else
      :false
    end
  end

  def quotaoverride=(value)
  end

  def hardquota
    quota = getuserdetails[:hardquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def hardquota=(value)
  end

  def softquota
    quota = getuserdetails[:softquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def softquota=(value)
  end

  def warnquota
    quota = getuserdetails[:warnquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def warnquota=(value)
  end

  def email
    getuserdetails[:email]
  end

  def email=(value)
  end

private
  def getuserdetails
    userdetails = { :groups => []}
    foundgroups = false
    rawdetails = zarafaadmin(['--details',@resource[:name],'--type','user'])
    # go through each line of the zarafa-admin --details output and extract
    # the relevant information.
    # When a line starts with Groups, start collection the user groups
    # because all following lines contain the groups the user is member of
    rawdetails.each_line do |line|<commit_msg>Add code to actually set the different properties of the zarafauser resource (except features and groups).<commit_after>Puppet::Type.type(:zarafauser).provide(:db) do
  desc "Provides the ability to create zarafa users using the db user_plugin"

  commands :zarafaadmin => "/bin/zarafa-admin"

  has_features :zarafadbuser

  def exists?
    begin
      zarafaadmin(['--type','user','--details',@resource[:name]])
      return true
    rescue => e
      debug(e.message)
      return false
    end
  end

  def create
    raise Puppet::Error, "You have to provide a full name for user #{@resource[:name]}" unless @resource[:fullname]
    raise Puppet::Error, "You have to provide an email address for user #{@resource[:name]}" unless @resource[:email]
    raise Puppet::Error, "You have to provide a password for user #{@resource[:name]}" unless @resource[:password]

    createopts = ['-c',@resource[:name],'-p',@resource[:password],'-f',@resource[:fullname],'-e',@resource[:email]]
    updateopts = ['-u',@resource[:name]]
    if @resource[:admin] == :true
      createopts << '-a' << 'yes'
    end

    if @resource[:active] == :false
      createopts << '-n' << 'yes'
    end

    if @resource[:quotaoverride] == :true
      updateopts << '--qo' << 'yes'
    end

    if @resource[:hardquota]
      updateopts << '--qh' << @resource[:hardquota]
    end

    if @resource[:softquota]
      updateopts << '--qs' << @resource[:softquota]
    end

    if @resource[:warnquota]
      updateopts << '--qw' << @resource[:warnquota]
    end

    zarafaadmin(createopts)

    if updateopts.length > 2
      zarafaadmin(updateopts)
    end

    if @resource[:groups]
      @resource[:groups].each do |group|
        zarafaadmin(['-b',@resource[:name],'-i',group])
      end
    end

    if @resource[:features]
      @resource[:features].each do |feature|
        zarafaadmin(['-u',@resource[:name],'--enable-feature',feature])
      end
    end
  end

  def destroy
    zarafaadmin(['-d',@resource[:name]])
  end

  def features
    getuserdetails[:features]
  end

  def features=(value)
  end

  def groups
    getuserdetails[:groups]
  end

  def groups=(value)
  end

  def fullname
    getuserdetails[:fullname]
  end

  def fullname=(value)
    zarafaadmin(['-u',@resource[:name],'-f',@resource[:fullname]])
  end

  def admin
    if getuserdetails[:admin] == 'yes'
      :true
    else
      :false
    end
  end

  def admin=(value)
    if value == :true
      zarafaadmin(['-u',@resource[:name],'-a','yes'])
    else
      zarafaadmin(['-u',@resource[:name],'-a','no'])
    end
  end

  def active
    if getuserdetails[:active] == 'yes'
      :true
    else
      :false
    end
  end

  def active=(value)
    if value == :true
      zarafaadmin(['-u',@resource[:name],'-n','no'])
    else
      zarafaadmin(['-u',@resource[:name],'-n','yes'])
    end
  end

  def quotaoverride
    if getuserdetails[:quotaoverride] == 'yes'
      :true
    else
      :false
    end
  end

  def quotaoverride=(value)
    if value == :true
      zarafaadmin(['-u',@resource[:name],'--qo','yes'])
    else
      zarafaadmin(['-u',@resource[:name],'--qo','no'])
    end
  end

  def hardquota
    quota = getuserdetails[:hardquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def hardquota=(value)
    zarafaadmin(['-u',@resource[:name],'--qh',@resource[:hardquota]])
  end

  def softquota
    quota = getuserdetails[:softquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def softquota=(value)
    zarafaadmin(['-u',@resource[:name],'--qs',@resource[:softquota]])
  end

  def warnquota
    quota = getuserdetails[:warnquota]
    if quota == 'unlimited'
      0
    else
      quota.to_i
    end
  end

  def warnquota=(value)
    zarafaadmin(['-u',@resource[:name],'--qw',@resource[:warnquota]])
  end

  def email
    getuserdetails[:email]
  end

  def email=(value)
    zarafaadmin(['-u',@resource[:name],'-e',@resource[:email]])
  end

private
  def getuserdetails
    userdetails = { :groups => []}
    foundgroups = false
    rawdetails = zarafaadmin(['--details',@resource[:name],'--type','user'])
    # go through each line of the zarafa-admin --details output and extract
    # the relevant information.
    # When a line starts with Groups, start collection the user groups
    # because all following lines contain the groups the user is member of
    rawdetails.each_line do |line|
{'fraction_non_alphanumeric': 0.14388847398556137, 'fraction_numerical': 0.0009957679860592482, 'mean_word_length': 2.894813378574891, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1670797', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2588, 'n_words': 652}