docbrown/app/views/users/_customization.html.erb
Jeremy Friesen 1d7436702f
Conditionally removing the "configure" editor (#16778)
Note, I'm not overly keen on writing permission tests for this
component.  Why?  Robust permissioning tests can create combinatorial
explosions.  And there are presently no Rspec request specs for this.
So to add an automated test, we'd need to add a set of seed data that
seeds data that conforms to the emerging business logic of the policy.

And while this is easy with use case 1-1, it gets harder as we move
into more nuanced use cases.  Instead we should rely on bombarding our
policy classes with lots of tests to let them demonstrate what we mean
when we say `if p.olicy(Article).create?`

Note, there is a potential relation to forem/forem#14807, namely if we
add a rich text editor to our comments, we may need to explore the
purpose and intention of this setting.

Closes forem/forem#16516
2022-03-04 12:41:56 -05:00

120 lines
4.6 KiB
Text

<%= javascript_packs_with_chunks_tag "stickySaveFooter", defer: true %>
<%= form_for @users_setting,
url: users_settings_path,
html: { id: "ux-customization-form", class: "sticky-footer-form" } do |f| %>
<%= f.hidden_field :user_id, value: @users_setting.user_id, id: nil %>
<%= f.hidden_field :tab, value: @tab, id: nil %>
<div class="crayons-card crayons-card--content-rows">
<h2 class="crayons-subtitle-1">
<%= t("views.settings.custom.appearance") %>
</h2>
<fieldset class="crayons-field">
<legend class="crayons-field__label"><%= t("views.settings.custom.theme") %></legend>
<div class="theme-selector-field grid gap-4 grid-cols-2 l:grid-cols-3">
<%# This is temporary while we're migrating themes %>
<% %w[light_theme dark_theme].each do |theme| %>
<%= render partial: "theme_selector", locals: { f: f, theme: theme } %>
<% end %>
</div>
</fieldset>
<div class="crayons-field">
<%= f.label :config_font, t("views.settings.custom.font"), class: "crayons-field__label" %>
<div class="theme-selector-field grid gap-4 grid-cols-2 l:grid-cols-3">
<% Users::Setting.config_fonts.keys.each do |font| %>
<%= render partial: "font_selector", locals: { f: f, font: font } %>
<% end %>
</div>
</div>
<div class="crayons-field">
<%= f.label :config_navbar, t("views.settings.custom.navbar"), class: "crayons-field__label" %>
<div class="theme-selector-field grid gap-4 grid-cols-2 l:grid-cols-3">
<% Users::Setting.config_navbars.keys.each do |navbar| %>
<%= render partial: "navbar_selector", locals: { f: f, navbar: navbar } %>
<% end %>
</div>
</div>
</div>
<% if policy(Article).create? %>
<div class="crayons-card crayons-card--content-rows">
<h2 class="crayons-subtitle-1">
<%= t("views.settings.custom.writing") %>
</h2>
<div class="crayons-field">
<%= f.label :editor_version, t("views.settings.custom.editor"), class: "crayons-field__label" %>
<div class="theme-selector-field grid gap-4 grid-cols-2 l:grid-cols-3">
<% Users::Setting.editor_versions.keys.each do |version| %>
<%= render partial: "editor_selector", locals: { f: f, version: version } %>
<% end %>
</div>
</div>
</div>
<% end %>
<div class="crayons-card crayons-card--content-rows">
<h2 class="crayons-subtitle-1">
<%= t("views.settings.custom.content") %>
</h2>
<div class="crayons-field">
<%= f.label :experience_level, t("views.settings.custom.level"), class: "crayons-field__label" %>
<div class="theme-selector-field grid grid-cols-5">
<% user_experience_levels.each_with_index do |exp, i| %>
<%= render partial: "experience_selector", locals: { f: f, exp: exp, i: i, label: user_experience_labels } %>
<% end %>
</div>
<p>
<%= t("views.settings.custom.level_desc") %>
</p>
</div>
</div>
<div class="crayons-card crayons-card--content-rows">
<header>
<h2 class="crayons-subtitle-1">
<%= t("views.settings.custom.sponsor") %>
</h2>
<p>
<%= t("views.settings.custom.sponsor_desc") %>
</p>
</header>
<fieldset class="grid gap-4">
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box :display_sponsors, class: "crayons-checkbox" %>
<%= f.label :display_sponsors, t("views.settings.custom.sponsor_field"), class: "crayons-field__label" %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box :permit_adjacent_sponsors, class: "crayons-checkbox" %>
<%= f.label :permit_adjacent_sponsors, t("views.settings.custom.adjacent"), class: "crayons-field__label" %>
</div>
</fieldset>
</div>
<div class="crayons-card crayons-card--content-rows">
<header>
<h2 class="crayons-subtitle-1">
<%= t("views.settings.custom.announce") %>
</h2>
<p>
<%= t("views.settings.custom.announce_desc") %>
</p>
</header>
<fieldset class="grid gap-4">
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box :display_announcements, class: "crayons-checkbox" %>
<%= f.label :display_announcements, t("views.settings.custom.announce_field"), class: "crayons-field__label" %>
</div>
</fieldset>
</div>
<div class="save-footer crayons-card crayons-card--content-rows">
<button class="crayons-btn" type="submit"><%= t("views.settings.custom.save") %></button>
</div>
<% end %>