docbrown/app/views/users/_web_monetization.html.erb
Jeremy Friesen 76933284b7
Authorize Web Monetization If User Can Create Article (#16824)
* Authorize Web Monetization If User Can Create Article

There are three things I'm introducing in this PR:

1. Extracting a partial
2. Reworking the i18n keys
3. Adding a policy check regarding Web Monetization

In *extracting a partial*, I'm following the existing pattern where
other extensions have their own partial.

In *reworking the i18n keys*, I'm ensuring that the keys are part of the
same namespace.  This will make finding their usage easier.  Further, if
we decide to remove (or convert to a plugin) the web_monetization, then
we're just a bit closer to that possibility.

Last, and the reason for the work, is *Adding a policy check regarding
Web Monetization*.  This follows on the work in forem/forem#16790.

Closes forem/forem#16820
Related to forem/forem#15098

There are two things to test:

1. Does the feature flag work or not.
2. Are the i18n keys properly applied.

For the feature flag:

- checkout this branch
- in rails console `FeatureFlag.enable(:limit_post_creation_to_admins)`
- start the rails server
- login as a non-admin user
- go to /settings/extensions and scroll to the bottom, you **shouldn't** see
  the partial
- login as an admin user
- go to /settings/extensions and scroll to the bottom, you **should** see
  the partial

Or visually verify the relatively simple change (and accept that it
conforms to #16790's existing pattern).

For the i18n keys, I have a before screenshot (from DEV.to) and the
after (from the changes on this branch).

* Adjustments based on contributor feedback
2022-03-08 09:39:34 -05:00

21 lines
1.2 KiB
Text

<% if policy(Article).create? %>
<div class="crayons-card crayons-card--content-rows">
<header>
<h2 class="crayons-subtitle-1 flex items-center">
<%= t("views.settings.extensions.web_monetization.header") %>
<span class="ml-2 c-indicator c-indicator--warning"><%= t("core.beta") %></span>
</h2>
<p class="color-base-70">
<%= t("views.settings.extensions.web_monetization.receive_payments") %> <a href="https://dev.to/hacksultan/web-monetization-like-i-m-5-1418"><%= t("views.settings.extensions.web_monetization.learn_more") %></a>
</p>
</header>
<%= form_for(@user, html: { id: nil, class: "grid gap-4" }) do |f| %>
<div class="crayons-field">
<%= f.label :payment_pointer, t("views.settings.extensions.web_monetization.payment_pointer"), class: "crayons-field__label" %>
<%= f.text_field :payment_pointer, class: "crayons-textfield", placeholder: "$pay.somethinglikethis.co/value" %>
</div>
<%= f.hidden_field :tab, value: @tab, id: nil %>
<button type="submit" class="crayons-btn w-max"><%= t("views.settings.extensions.web_monetization.save_settings") %></button>
<% end %>
</div>
<% end %>