cartodb/app/views/admin/organization_users/_form.html.erb
2020-06-15 10:58:47 +08:00

336 lines
17 KiB
Plaintext

<%= form_for @user, url: (@user.new? ? CartoDB.url(self, 'create_organization_user', user: current_user) : CartoDB.url(self, 'update_organization_user', params: { id: @user.username }, user: 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 @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 => "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 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' : '' %> <%= @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 (<%= @organization.assigned_seats %>/<%= @organization.seats %>)</label>
</div>
</div>
<div class="FormAccount-rowInfo u-lspace-23 u-bSpace--xl">
<p class="FormAccount-rowInfoText">Build and read</p>
</div>
<% admin_editing_admin = @user.organization_admin? && !current_user.organization_owner? %>
<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' : '' %> <%= (@organization.remaining_viewer_seats == 0 && !@user.viewer?) || @user.organization_owner? || admin_editing_admin ? '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 (<%= @organization.assigned_viewer_seats %>/<%= @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 admin_editing_admin %>
Organization admins can only be builder users.
<% elsif @organization.viewer_seats == 0 %>
You don't have viewer seats activated. <a href="mailto:enterprise-support@carto.com">Contact support</a> for more information.
<% else %>
Only read
<% end %>
</p>
</div>
</div>
<% if !@user.organization_owner? %>
<div class="FormAccount-row js-org-admin-row" <%= @user.builder? ? 'style="display: none;"' : '' %>>
<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.organization_owner? %>
<%= label_tag(:org_admin, '') %>
</div>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<p class="CDB-Text CDB-Size-small u-altTextColor">
<% if current_user.organization_owner? %>
User has permission to manage users and groups and send notifications
<% else %>
Only the organization owner can assign administrator rights
<% end %>
</p>
</div>
</div>
</div>
<% end %>
<% mfa_configured = @user.multifactor_authentication_configured? %>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">
Multi-factor authentication
</label>
</div>
<div class="FormAccount-rowData">
<div class="Toggler">
<%= f.check_box :mfa, id: "mfa", checked: mfa_configured %>
<%= label_tag(:mfa, '') %>
</div>
<div class="FormAccount-rowInfo u-lspace-23">
<p class="CDB-Text CDB-Size-small u-altTextColor">
If you change the Multi-factor authentication, it will be available only for this user. When you change the status, the user will be logged out and redirected to the login page.
</p>
</div>
</div>
</div>
<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 = @organization.unassigned_quota + @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>
Used by user
</li>
<% end %>
<li class="OrganizationUser-quotaLegendItem CDB-Size-small">
<i class="OrganizationUser-quotaLegendIcon OrganizationUser-quotaLegendIcon--assigned"></i>
Assigned to user
</li>
<li class="OrganizationUser-quotaLegendItem CDB-Size-small">
<i class="OrganizationUser-quotaLegendIcon"></i>
Total
</li>
</ul>
</div>
<div class="FormAccount-rowInfo u-lSpace--xl OrganizationUser-quotaInfo js-userQuotaSliderInput CDB-Text CDB-Size-medium u-altTextColor">
<span><%= text_field_tag nil, nil, :class => "CDB-InputText CDB-Text FormAccount-input OrganizationUser-quotaInfoInput js-assignedSize" %> MB<% unless cartodb_com_hosted? %>, <a href="<%= current_user.upgrade_url(request.protocol) %>">upgrade your account</a> if needed.<% end %></span>
</div>
<%= f.hidden_field :quota_in_bytes, :id => "user_quota" %>
</div>
</div>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Extra geocoding</label>
</div>
<div class="FormAccount-rowData">
<div class="Toggler">
<%= f.check_box :soft_geocoding_limit, id: "soft_geocoding_limit", disabled: !@organization.soft_geocoding_limit? %>
<%= label_tag(:soft_geocoding_limit, '') %>
</div>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<% if @organization.soft_geocoding_limit? %>
<p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to exceed organization's geocoding quota</p>
<% else %>
<p class="CDB-Text CDB-Size-small u-altTextColor">You can't enable extra quota. Contact support for more information.</p>
<% end %>
</div>
</div>
</div>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Extra Here Isolines</label>
</div>
<div class="FormAccount-rowData">
<div class="Toggler">
<%= f.check_box :soft_here_isolines_limit, id: "soft_here_isolines_limit", disabled: !@organization.soft_here_isolines_limit? %>
<%= label_tag(:soft_here_isolines_limit, '') %>
</div>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<% if @organization.soft_here_isolines_limit? %>
<p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to exceed organization's isolines quota from Here provider</p>
<% else %>
<p class="CDB-Text CDB-Size-small u-altTextColor">You can't enable extra quota. Contact support for more information.</p>
<% end %>
</div>
</div>
</div>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Extra Routing API calls</label>
</div>
<div class="FormAccount-rowData">
<div class="Toggler">
<%= f.check_box :soft_mapzen_routing_limit, id: "soft_mapzen_routing_limit", disabled: !@organization.soft_mapzen_routing_limit? %>
<%= label_tag(:soft_mapzen_routing_limit, '') %>
</div>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<% if @organization.soft_mapzen_routing_limit? %>
<p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to exceed organization's routing quota from Mapzen provider</p>
<% else %>
<p class="CDB-Text CDB-Size-small u-altTextColor">You can't enable extra quota. Contact support for more information.</p>
<% end %>
</div>
</div>
</div>
<% if @organization.twitter_datasource_enabled %>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">Extra tweets</label>
</div>
<div class="FormAccount-rowData">
<div class="Toggler">
<%= f.check_box :soft_twitter_datasource_limit, id: "soft_twitter_datasource_limit", disabled: !@organization.soft_twitter_datasource_limit? %>
<%= label_tag(:soft_twitter_datasource_limit, '') %>
</div>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<% if @organization.soft_twitter_datasource_limit? %>
<p class="CDB-Text CDB-Size-small u-altTextColor">User has permission to exceed organization's Twitter credits</p>
<% else %>
<p class="CDB-Text CDB-Size-small u-altTextColor">You can't enable extra quota. Contact support for more information.</p>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<% if !@user.new? && current_user.organization_owner? && @user.engine_enabled? -%>
<div class="FormAccount-row">
<div class="FormAccount-rowLabel">
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor">User master API key</label>
</div>
<div class="FormAccount-rowData">
<%= f.text_field :api_key, :class => "CDB-InputText CDB-Text FormAccount-input FormAccount-input--med is-disabled", :readonly => true %>
<div class="FormAccount-rowInfo FormAccount-rowInfo--marginLeft">
<button class="CDB-Text CDB-Size-medium Button--link js-regenerateOrgUserApiKey" data-username="<%= @user.username %>" data-current_username="<%= current_user.username %>" type="button">Regenerate all API keys</button>
</div>
</div>
</div>
<% end %>
<% if @user.new? -%>
<% if @organization.remaining_seats > 0 || @organization.remaining_viewer_seats > 0 %>
<div class="FormAccount-footer u-justifyEnd">
<button type="submit" class="CDB-Button CDB-Button--primary js-save">
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">Create user</span>
</button>
</div>
<% else %>
<div class="FormAccount-footer">
<p class="FormAccount-rowInfoText FormAccount-rowInfoText--maxWidth">You can't create new users because you've run out of seats. <a href="mailto:enterprise-support@carto.com">Contact support</a> for more information.</p>
<button type="submit" class="CDB-Button CDB-Button--primary is-disabled js-save">
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">Create user</span>
</button>
</div>
<% end %>
<% elsif @user.editable_by?(current_user) %>
<% if @user != current_user %>
<div class="FormAccount-footer">
<button href="<%= CartoDB.url(self, 'delete_organization_user', params: { id: @user.username }, user: current_user) %>" type="button" class="CDB-Button CDB-Button--error js-deleteAccount">
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">Delete user</span>
</button>
<button type="submit" class="CDB-Button CDB-Button--primary js-save">
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">Save changes</span>
</button>
</div>
<% else %>
<div class="FormAccount-footer u-justifyEnd">
<button class="CDB-Button CDB-Button--primary js-save">
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">Save changes</span>
</button>
</div>
<% end %>
<% end %>
<% end %>
<script type="text/javascript">
<% if !@user.new? %>
var organization_user_data = <%= safe_js_object @user.data.to_json %>;
<% else %>
<% @user.values[:db_size_in_bytes] = 0 %>
<% @user.values[:organization] = current_user.data[:organization] %>
<% @user.values[:quota_available_for_user] = current_user.data[:organization][:unassigned_quota] + @user.values[:quota_in_bytes] %>
var organization_user_data = <%= safe_js_object @user.values.to_json %>;
<% end %>
</script>