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
This commit is contained in:
Jeremy Friesen 2022-03-08 09:39:34 -05:00 committed by GitHub
parent 68808c7104
commit 76933284b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 31 deletions

View file

@ -2,24 +2,6 @@
<%= render partial: "publishing_from_rss" %>
<div class="crayons-card crayons-card--content-rows">
<header>
<h2 class="crayons-subtitle-1 flex items-center">
<%= t("views.settings.extensions.web") %>
<span class="ml-2 c-indicator c-indicator--warning"><%= t("core.beta") %></span>
</h2>
<p class="color-base-70">
<%= t("views.settings.extensions.micro") %><a href="https://dev.to/hacksultan/web-monetization-like-i-m-5-1418"><%= t("views.settings.extensions.learn") %></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.payment"), 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.save_web") %></button>
<% end %>
</div>
<%= render partial: "web_monetization" %>
<%= render partial: "users/integrations_github_repositories", locals: { show_integration: @github_repositories_show } %>

View file

@ -0,0 +1,21 @@
<% 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 %>

View file

@ -135,9 +135,6 @@ en:
heading: GitHub
desc1: Pin your GitHub repositories to your profile.
desc2: Repositories will disappear from your profile if you remove the OAuth association with GitHub.
learn: Learn more
micro: 'Receive micropayments for time spent reading your posts directly. '
payment: Payment Pointer
rss:
heading: Publishing to %{community} from RSS
desc1_html: Posts will land in your %{dashboard} <strong>as drafts</strong>, and then you can publish from there.
@ -154,8 +151,12 @@ en:
referential_html: Replace self-referential links with %{community}-specific links <p class='crayons-field__description'>If you check this box, the post will automatically change any URLs included in the post to refer to the version of that article on %{community} if available. This is primarily meant for folks migrating their entire blog onto %{community}.</p>
save: Save Feed Settings
submit: Submit Feed Settings
save_web: Save Web Monetization Settings
web: Web monetization
web_monetization:
header: Web monetization
receive_payments: 'Receive micropayments for time spent reading your posts directly. '
learn_more: Learn more
payment_pointer: Payment Pointer
save_settings: Save Web Monetization Settings
finalize_html: You have requested a change to %{email}. Check your inbox for the verification link to finalize the change.
for_html: Settings for %{name}
group:
@ -180,7 +181,7 @@ en:
button:
aria_label: Copy organization secret code to clipboard
icon: Copy to clipboard
input:
input:
aria_label: Organization secret (to be rotated regularly)
text: Copied to clipboard!
cta: Call-to-action box

View file

@ -135,9 +135,6 @@ fr:
heading: GitHub
desc1: Pin your GitHub repositories to your profile.
desc2: Repositories will disappear from your profile if you remove the OAuth association with GitHub.
learn: Learn more
micro: 'Receive micropayments for time spent reading your posts directly. '
payment: Payment Pointer
rss:
heading: Publishing to %{community} from RSS
desc1_html: Posts will land in your %{dashboard} <strong>as drafts</strong>, and then you can publish from there.
@ -154,8 +151,12 @@ fr:
referential_html: Replace self-referential links with %{community}-specific links <p class='crayons-field__description'>If you check this box, the post will automatically change any URLs included in the post to refer to the version of that article on %{community} if available. This is primarily meant for folks migrating their entire blog onto %{community}.</p>
save: Save Feed Settings
submit: Submit Feed Settings
save_web: Save Web Monetization Settings
web: Web monetization
web_monetization:
header: Web monetization
receive_payments: 'Receive micropayments for time spent reading your posts directly.'
learn_more: Learn more
payment_pointer: Payment Pointer
save_settings: Save Web Monetization Settings
finalize_html: You have requested a change to %{email}. Check your inbox for the verification link to finalize the change.
for_html: Settings for %{name}
group:
@ -177,7 +178,7 @@ fr:
admin:
admin: Admin
copy:
button:
button:
aria_label: Copy organization secret code to clipboard
icon: Copy to clipboard
input: