<commit_before>
<%= form_for @user, url: (@user.new? ? CartoDB.url(self, 'create_organization_user', {}, current_user) : CartoDB.url(self, 'update_organization_user', {id: @user.username}, current_user)), :html => {:class => 'Form js-organizationUserForm CDB-Text'} do |f| %>

  <%= f.hidden_field :private_tables_enabled %>
  <%= hidden_field_tag :show_account_settings_flash, true %>
  <%= csrf_meta_tags %>

  <span class="FormAccount-separator"></span>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Username</label>
    </div>
    <div class="FormAccount-rowData">
      <%= f.text_field :username, :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.new? } #{ 'has-error' if @user.errors[:username].present? }", :readonly => !@user.new? %>
      <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
        <% if (@user.errors[:username].present?) %>
          <p class="FormAccount-rowInfoText FormAccount-rowInfoText--error u-tSpace">Username not valid</p>
        <% elsif @user.new? %>
          <p class="CDB-Text CDB-Size-small u-altTextColor">Once you choose the username, you won't be able to change it</p>
        <% end %>
      </div>
    </div>
  </div>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Email</label>
    </div>
    <div class="FormAccount-rowData">
      <%= f.text_field :email, :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_email? } #{ 'has-error' if @user.errors[:email].present? }", readonly: !@user.can_change_email? %>
      <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
        <% if (@user.errors[:email].present?) %>
          <p class="CDB-Text CDB-Size-small u-altTextColor FormAccount-rowInfoText--error">Email not valid</p>
        <% elsif @user.new? %>
          <p class="CDB-Text CDB-Size-small u-altTextColor">We encourage you to choose an email from your organization</p>
        <% end %>
      </div>
    </div>
  </div>

  <% if current_user.organization.auth_username_password_enabled %>

    <div class="VerticalAligned--FormRow">
      <div class="FormAccount-row">
        <div class="FormAccount-rowLabel">
          <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">New password</label>
        </div>
        <div class="FormAccount-rowData">
          <%= password_field_tag 'user[password]', nil, :placeholder => "<PASSWORD>", :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_password? } #{ 'has-error' if @user.errors[:password].present? }", readonly: !@user.can_change_password? %>
        </div>
        <div class="FormAccount-rowInfo">
          <% if (@user.errors[:password].present?) %>
            <p class="FormAccount-rowInfoText FormAccount-rowInfoText--error u-tSpace"><%= @user.errors[:password].first%></p>
          <% end %>
        </div>
      </div>

      <div class="FormAccount-row">
        <div class="FormAccount-rowLabel">
          <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Confirm password</label>
        </div>
        <div class="FormAccount-rowData">
          <%= password_field_tag 'user[password_confirmation]', nil, :placeholder => "<PASSWORD>", :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_password? } #{ 'has-error' if @user.errors[:password].present?}", readonly: !@user.can_change_password? %>
        </div>
      </div>
    </div>

  <% end %>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">User type</label>
    </div>

    <div class="FormAccount-rowData">
      <div class="CDB-Text CDB-Size-medium u-rSpace--xl">
        <input class="CDB-Radio js-userViewerOption" type="radio" name="user[viewer]" value="false" <%= @user.builder? ? 'checked' : '' %> <%= current_user.organization.remaining_seats > 0 || @user.builder? ? '' : 'disabled' %> required>
        <span class="u-iBlock CDB-Radio-face"></span>
        <label class="u-iBlock u-lSpace CDB-Text CDB-Size-medium u-secondaryTextColor is-semibold">Builder (<%= current_user.organization.assigned_seats %>/<%= current_user.organization.seats %>)</label>
      </div>
    </div>
    <div class="FormAccount-rowInfo u-lspace-23 u-bSpace--xl">
      <p class="FormAccount-rowInfoText">Build and read</p>
    </div>

    <div class="FormAccount-rowData">
      <div class="CDB-Text CDB-Size-medium u-rSpace--xl">
        <input class="CDB-Radio js-userViewerOption" type="radio" name="user[viewer]" value="true" <%= @user.viewer? ? 'checked' : '' %> <%= (current_user.organization.remaining_viewer_seats > 0 || @user.viewer?) && !@user.organization_owner? ? '' : 'disabled' %> required>
        <span class="u-iBlock CDB-Radio-face"></span>
        <label class="u-iBlock u-lSpace CDB-Text CDB-Size-medium u-secondaryTextColor is-semibold">Viewer (<%= current_user.organization.assigned_viewer_seats %>/<%= current_user.organization.viewer_seats %>)</label>
      </div>
    </div>
    <div class="FormAccount-rowInfo u-lspace-23">
      <p class="FormAccount-rowInfoText">
        <% if @user.organization_owner? %>
          The organization owner cannot be a viewer user.
        <% elsif current_user.organization.remaining_viewer_seats == 0 %>
          You don't have viewer seats activated. <a href="mailto:<EMAIL>">Contact support</a> for more information.
        <% else %>
          Only read
        <% end %>
      </p>
    </div>
  </div>

  <% if !@user.organization_owner? && current_user.organization.owner.has_feature_flag?('organization-admins') %>
    <div class="FormAccount-row js-org-admin-row">
      <div class="FormAccount-rowLabel">
        <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Administrator</label>
      </div>
      <div class="FormAccount-rowData">
        <div class="Toggler">
          <%= f.check_box :org_admin, id: "org_admin", disabled: current_user.viewer? %>
          <%= label_tag(:org_admin, '') %>
        </div>
        <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
          <% if current_user.builder? %>
            <p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to manage users and groups and send notifications</p>
          <% else %>
            <p class="CDB-Text CDB-Size-small u-altTextColor">Only Builder users can be administrators</p>
          <% end %>
        </div>
      </div>
    </div>
  <% end %>

  <div class="user-quotas" style="display: none">
    <div class="FormAccount-title">
      <p class="FormAccount-titleText">User quotas</p>
    </div>

    <span class="FormAccount-separator"></span>

    <div class="FormAccount-row">
      <div class="OrganizationUser-quota js-userQuota">
        <div class="FormAccount-rowData FormAccount-rowData--med OrganizationUser-quotaProgress js-userQuotaSlider">
          <div class="UISlider UserQuotaDropdown-slider js-slider progress-bar overflow-visible">
          <% available_quota_for_user = current_user.organization.unassigned_quota + current_user.quota_in_bytes %>
            <% assignedPer = ((@user.quota_in_bytes.to_f * 100) / available_quota_for_user) %>
            <% if !@user.new? %>
              <% usedPer = ((@user.db_size_in_bytes.to_f * 100) / available_quota_for_user) %>
              <span class="js-usedUserQuota bar-3" style="width:<%= usedPer %>%"></span>
            <% end %>
          </div>
          <ul class="OrganizationUser-quotaLegend">
            <% if !@user.new? %>
              <li class="OrganizationUser-quotaLegendItem CDB-Size-small">
                <i class="OrganizationUser-quotaLegendIcon OrganizationUser-quotaLegendIcon--used"></i><commit_msg>@user instead of current_user for form<commit_after>
<%= form_for @user, url: (@user.new? ? CartoDB.url(self, 'create_organization_user', {}, current_user) : CartoDB.url(self, 'update_organization_user', {id: @user.username}, current_user)), :html => {:class => 'Form js-organizationUserForm CDB-Text'} do |f| %>

  <%= f.hidden_field :private_tables_enabled %>
  <%= hidden_field_tag :show_account_settings_flash, true %>
  <%= csrf_meta_tags %>

  <span class="FormAccount-separator"></span>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Username</label>
    </div>
    <div class="FormAccount-rowData">
      <%= f.text_field :username, :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.new? } #{ 'has-error' if @user.errors[:username].present? }", :readonly => !@user.new? %>
      <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
        <% if (@user.errors[:username].present?) %>
          <p class="FormAccount-rowInfoText FormAccount-rowInfoText--error u-tSpace">Username not valid</p>
        <% elsif @user.new? %>
          <p class="CDB-Text CDB-Size-small u-altTextColor">Once you choose the username, you won't be able to change it</p>
        <% end %>
      </div>
    </div>
  </div>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Email</label>
    </div>
    <div class="FormAccount-rowData">
      <%= f.text_field :email, :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_email? } #{ 'has-error' if @user.errors[:email].present? }", readonly: !@user.can_change_email? %>
      <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
        <% if (@user.errors[:email].present?) %>
          <p class="CDB-Text CDB-Size-small u-altTextColor FormAccount-rowInfoText--error">Email not valid</p>
        <% elsif @user.new? %>
          <p class="CDB-Text CDB-Size-small u-altTextColor">We encourage you to choose an email from your organization</p>
        <% end %>
      </div>
    </div>
  </div>

  <% if current_user.organization.auth_username_password_enabled %>

    <div class="VerticalAligned--FormRow">
      <div class="FormAccount-row">
        <div class="FormAccount-rowLabel">
          <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">New password</label>
        </div>
        <div class="FormAccount-rowData">
          <%= password_field_tag 'user[password]', nil, :placeholder => "<PASSWORD>", :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_password? } #{ 'has-error' if @user.errors[:password].present? }", readonly: !@user.can_change_password? %>
        </div>
        <div class="FormAccount-rowInfo">
          <% if (@user.errors[:password].present?) %>
            <p class="FormAccount-rowInfoText FormAccount-rowInfoText--error u-tSpace"><%= @user.errors[:password].first%></p>
          <% end %>
        </div>
      </div>

      <div class="FormAccount-row">
        <div class="FormAccount-rowLabel">
          <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Confirm password</label>
        </div>
        <div class="FormAccount-rowData">
          <%= password_field_tag 'user[password_confirmation]', nil, :placeholder => "Confirm new password", :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med #{ 'is-disabled' if !@user.can_change_password? } #{ 'has-error' if @user.errors[:password].present?}", readonly: !@user.can_change_password? %>
        </div>
      </div>
    </div>

  <% end %>

  <div class="FormAccount-row">
    <div class="FormAccount-rowLabel">
      <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">User type</label>
    </div>

    <div class="FormAccount-rowData">
      <div class="CDB-Text CDB-Size-medium u-rSpace--xl">
        <input class="CDB-Radio js-userViewerOption" type="radio" name="user[viewer]" value="false" <%= @user.builder? ? 'checked' : '' %> <%= current_user.organization.remaining_seats > 0 || @user.builder? ? '' : 'disabled' %> required>
        <span class="u-iBlock CDB-Radio-face"></span>
        <label class="u-iBlock u-lSpace CDB-Text CDB-Size-medium u-secondaryTextColor is-semibold">Builder (<%= current_user.organization.assigned_seats %>/<%= current_user.organization.seats %>)</label>
      </div>
    </div>
    <div class="FormAccount-rowInfo u-lspace-23 u-bSpace--xl">
      <p class="FormAccount-rowInfoText">Build and read</p>
    </div>

    <div class="FormAccount-rowData">
      <div class="CDB-Text CDB-Size-medium u-rSpace--xl">
        <input class="CDB-Radio js-userViewerOption" type="radio" name="user[viewer]" value="true" <%= @user.viewer? ? 'checked' : '' %> <%= (current_user.organization.remaining_viewer_seats > 0 || @user.viewer?) && !@user.organization_owner? ? '' : 'disabled' %> required>
        <span class="u-iBlock CDB-Radio-face"></span>
        <label class="u-iBlock u-lSpace CDB-Text CDB-Size-medium u-secondaryTextColor is-semibold">Viewer (<%= current_user.organization.assigned_viewer_seats %>/<%= current_user.organization.viewer_seats %>)</label>
      </div>
    </div>
    <div class="FormAccount-rowInfo u-lspace-23">
      <p class="FormAccount-rowInfoText">
        <% if @user.organization_owner? %>
          The organization owner cannot be a viewer user.
        <% elsif current_user.organization.remaining_viewer_seats == 0 %>
          You don't have viewer seats activated. <a href="mailto:<EMAIL>">Contact support</a> for more information.
        <% else %>
          Only read
        <% end %>
      </p>
    </div>
  </div>

  <% if !@user.organization_owner? && current_user.organization.owner.has_feature_flag?('organization-admins') %>
    <div class="FormAccount-row js-org-admin-row">
      <div class="FormAccount-rowLabel">
        <label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Administrator</label>
      </div>
      <div class="FormAccount-rowData">
        <div class="Toggler">
          <%= f.check_box :org_admin, id: "org_admin", disabled: @user.viewer? %>
          <%= label_tag(:org_admin, '') %>
        </div>
        <div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
          <% if @user.builder? %>
            <p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to manage users and groups and send notifications</p>
          <% else %>
            <p class="CDB-Text CDB-Size-small u-altTextColor">Only Builder users can be administrators</p>
          <% end %>
        </div>
      </div>
    </div>
  <% end %>

  <div class="user-quotas" style="display: none">
    <div class="FormAccount-title">
      <p class="FormAccount-titleText">User quotas</p>
    </div>

    <span class="FormAccount-separator"></span>

    <div class="FormAccount-row">
      <div class="OrganizationUser-quota js-userQuota">
        <div class="FormAccount-rowData FormAccount-rowData--med OrganizationUser-quotaProgress js-userQuotaSlider">
          <div class="UISlider UserQuotaDropdown-slider js-slider progress-bar overflow-visible">
          <% available_quota_for_user = current_user.organization.unassigned_quota + current_user.quota_in_bytes %>
            <% assignedPer = ((@user.quota_in_bytes.to_f * 100) / available_quota_for_user) %>
            <% if !@user.new? %>
              <% usedPer = ((@user.db_size_in_bytes.to_f * 100) / available_quota_for_user) %>
              <span class="js-usedUserQuota bar-3" style="width:<%= usedPer %>%"></span>
            <% end %>
          </div>
          <ul class="OrganizationUser-quotaLegend">
            <% if !@user.new? %>
              <li class="OrganizationUser-quotaLegendItem CDB-Size-small">
                <i class="OrganizationUser-quotaLegendIcon OrganizationUser-quotaLegendIcon--used"></i>
{'fraction_non_alphanumeric': 0.1653367971794396, 'fraction_numerical': 0.0017319230531329252, 'mean_word_length': 3.3, 'pattern_counts': {'":': 0, '<': 338, '<?xml version=': 0, '>': 360, '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': '5005330', 'n_tokens_mistral': 5422, 'n_tokens_neox': 5130, 'n_words': 954}