Skip to content

Commit

Permalink
Merge branch 'develop' into 0valt/1229/post-history-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trichoplax authored Jun 2, 2024
2 parents f61b9a2 + d66b777 commit 3a9bd5a
Show file tree
Hide file tree
Showing 35 changed files with 242 additions and 62 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ gem 'will_paginate-bootstrap', '~> 1.0'

# AWS for S3 (image storage) and SES (emails).
gem 'aws-sdk-s3', '~> 1.61', require: false
gem 'aws-sdk-sns', '~> 1.72'
gem 'aws-ses-v4', require: 'aws/ses'

# Task scheduler.
Expand Down
28 changes: 16 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.1)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.628.0)
aws-sdk-core (3.145.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
aws-eventstream (1.3.0)
aws-partitions (1.908.0)
aws-sdk-core (3.191.6)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.58.0)
aws-sdk-core (~> 3, >= 3.127.0)
Expand All @@ -84,12 +84,15 @@ GEM
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sdk-sns (1.72.0)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sigv4 (~> 1.1)
aws-ses-v4 (0.8.1)
builder
mail (> 2.2.5)
mime-types
xml-simple
aws-sigv4 (1.5.1)
aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.18)
bindex (0.8.1)
Expand Down Expand Up @@ -126,7 +129,7 @@ GEM
thor (>= 0.19.4, < 2.0)
tins (~> 1.6)
crass (1.0.6)
css_parser (1.11.0)
css_parser (1.16.0)
addressable
date (3.3.4)
devise (4.8.1)
Expand Down Expand Up @@ -209,7 +212,7 @@ GEM
net-smtp (0.4.0)
net-protocol
nio4r (2.7.0)
nokogiri (1.15.4-x86_64-linux)
nokogiri (1.16.2-x86_64-linux)
racc (~> 1.4)
omniauth (2.1.0)
hashie (>= 3.4.6)
Expand All @@ -227,7 +230,7 @@ GEM
premailer-rails (1.11.1)
actionmailer (>= 3)
premailer (~> 1.7, >= 1.7.9)
public_suffix (5.0.0)
public_suffix (5.0.4)
puma (5.6.8)
nio4r (~> 2.0)
racc (1.7.3)
Expand Down Expand Up @@ -391,6 +394,7 @@ PLATFORMS
DEPENDENCIES
awesome_print (~> 1.9)
aws-sdk-s3 (~> 1.61)
aws-sdk-sns (~> 1.72)
aws-ses-v4
byebug (~> 11.1)
capybara (~> 3.38)
Expand Down Expand Up @@ -452,4 +456,4 @@ RUBY VERSION
ruby 2.7.6p219

BUNDLED WITH
2.4.15
2.4.13
4 changes: 2 additions & 2 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ You will need to set the Redis connection details there too. If you've followed
the sample file should already contain the correct values for you, but if you've customised your
setup you'll need to correct them.

You'll also need to copy the Active Storage configuration from `config/storage.sample.yml` to `config/storage.yml`.

If you are using MariaDB instead of MySQL, you will need to replace all occurrences of
`utf8mb4_0900_ai_ci` with `utf8mb4_unicode_ci` in `db/schema.rb`.

You'll also need to copy the Active Storage configuration from `config/storage.sample.yml` to `config/storage.yml`.

Set up the database:

rails db:create
Expand Down
18 changes: 15 additions & 3 deletions app/assets/javascripts/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ $(() => {
tags: true
});

/**
* Attempts to save a draft with a given body
* @param {string} postText draft text
* @param {JQuery<Element>} $field body input element
* @param {boolean} [manual] whether manual draft saving is enabled
* @returns {Promise<void>}
*/
const saveDraft = async (postText, $field, manual = false) => {
const autosavePref = await QPixel.preference('autosave', true);
if (autosavePref !== 'on' && !manual) {
Expand All @@ -111,10 +118,15 @@ $(() => {
path: location.pathname
})
});

if (resp.status === 200) {
const $el = $(`<span>&middot; <span class="has-color-green-600">draft saved</span></span>`);
$field.parents('.widget').find('.js-post-field-footer').append($el);
$el.fadeOut(1500, function () { $(this).remove() });
const $statusEl = $field.parents('.widget').find('.js-post-draft-status');

$statusEl.removeClass('transparent');

setTimeout(() => {
$statusEl.addClass('transparent');
}, 1500);
}
};

Expand Down
20 changes: 19 additions & 1 deletion app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,25 @@ h1 .badge.is-tag.is-master-tag {
width: calc(100% + 2px);

+ .widget--footer {
margin-bottom: 0;
border-top: none;
align-items: center;
margin: 0;

&.mdhint {
display: flex;
flex-wrap: wrap;
gap: 1em 0;
justify-content: space-between;

& > * {
padding: 0;
}
}

& > .draft-status {
text-align: center;
transition: opacity 0.5s ease-in-out;
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,8 @@ span.spoiler {

.clearfix {
overflow: hidden;
}
}

.transparent {
opacity: 0;
}
24 changes: 24 additions & 0 deletions app/controllers/email_logs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class EmailLogsController < ApplicationController
skip_forgery_protection only: [:log]
skip_before_action :set_globals, only: [:log]
skip_before_action :distinguish_fake_community, only: [:log]
skip_before_action :enforce_signed_in, only: [:log]

def log
message_type = request.headers['X-Amz-SNS-Message-Type']
if ['SubscriptionConfirmation', 'Notification'].include? message_type
verifier = Aws::SNS::MessageVerifier.new
body = request.body.read
if verifier.authentic? body
aws_data = JSON.parse body
message_data = JSON.parse aws_data['Message']
log_type = message_data['notificationType']
destination = message_data['mail']['destination'].join(', ')
EmailLog.create(log_type: log_type, destination: destination, data: aws_data['Message'])
render plain: 'OK'
else
render plain: "You're not AWS. Go away.", status: 401
end
end
end
end
12 changes: 7 additions & 5 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def category
@tag_set.tags.where(excerpt: '').or(@tag_set.tags.where(excerpt: nil))
.order(Arel.sql('COUNT(posts.id) DESC'))
else
@tag_set.tags.order(Arel.sql('COUNT(posts.id) DESC'))
@tag_set&.tags&.order(Arel.sql('COUNT(posts.id) DESC'))
end
@count = @tags.count
@count = @tags&.size || 0
table = params[:hierarchical].present? ? 'tags_paths' : 'tags'
@tags = @tags.left_joins(:posts).group(Arel.sql("#{table}.id"))
.select(Arel.sql("#{table}.*, COUNT(DISTINCT IF(posts.deleted = 0, posts.id, NULL)) AS post_count"))
.paginate(per_page: 96, page: params[:page])
if @count.positive?
@tags = @tags.left_joins(:posts).group(Arel.sql("#{table}.id"))
.select(Arel.sql("#{table}.*, COUNT(DISTINCT IF(posts.deleted = 0, posts.id, NULL)) AS post_count"))
.paginate(per_page: 96, page: params[:page])
end
end

def show
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def set_preference
end

def posts
@posts = if current_user&.privilege?('flag_curate')
@posts = if current_user&.privilege?('flag_curate') || @user == current_user
Post.all
else
Post.undeleted
Expand Down Expand Up @@ -579,7 +579,7 @@ def vote_summary
def avatar
respond_to do |format|
format.png do
size = params[:size]&.to_i&.positive? ? params[:size]&.to_i : 64
size = params[:size]&.to_i&.positive? ? [params[:size]&.to_i, 256].min : 64
send_data helpers.user_auto_avatar(size, user: @user).to_blob, type: 'image/png', disposition: 'inline'
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/email_logs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module EmailLogsHelper
end
2 changes: 2 additions & 0 deletions app/models/email_log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class EmailLog < ApplicationRecord
end
19 changes: 11 additions & 8 deletions app/views/abilities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@
<% unless @ability.manual? %>
<% unless params[:thresholds].nil? %>
<div class="widget--body">
<p>You need to reach these thresholds to earn the ability:</p>

<% if @user.id == current_user&.id %>
<p>You need to reach these thresholds to earn the ability:</p>
<% else %>
<p><%= @user.username %> needs to reach these thresholds to earn the ability:</p>
<% end %>
<% unless @ability.post_score_threshold.nil? %>
<% post_score_percent = (linearize_progress(@user.community_user.post_score) / linearize_progress(@ability.post_score_threshold) * 100).to_i %>

<p><strong>Post score threshold</strong></p>
<% if post_score_percent < 100 %>
<p>You need to have more well-received posts.</p>
<p>Need to have more well-received posts.</p>
<div class="meter is-progress">
<div class="meter--bar is-<%= post_score_percent %>%"></div>
<div class="meter--label"><%= post_score_percent %>%</div>
</div>
<% else %>
<p>You need to have many well-received posts.</p>
<p>Need to have many well-received posts.</p>
<div class="meter is-progress">
<div class="meter--bar is-100%"></div>
<div class="meter--label">100%</div>
Expand All @@ -75,13 +78,13 @@

<p><strong>Edit score threshold</strong></p>
<% if edit_score_percent < 100 %>
<p>You need to have more accepted suggested edits.</p>
<p>Need to have more accepted suggested edits.</p>
<div class="meter is-progress">
<div class="meter--bar is-<%= edit_score_percent %>%"></div>
<div class="meter--label"><%= edit_score_percent %>%</div>
</div>
<% else %>
<p>You need to have many accepted suggested edits.</p>
<p>Need to have many accepted suggested edits.</p>
<div class="meter is-progress">
<div class="meter--bar is-100%"></div>
<div class="meter--label">100%</div>
Expand All @@ -94,13 +97,13 @@

<p><strong>Flag score threshold</strong></p>
<% if flag_score_percent < 100 %>
<p>You need to have more helpful flags.</p>
<p>Need to have more helpful flags.</p>
<div class="meter is-progress">
<div class="meter--bar is-<%= flag_score_percent %>%"></div>
<div class="meter--label"><%= flag_score_percent %>%</div>
</div>
<% else %>
<p>You need to have many helpful flags.</p>
<p>Need to have many helpful flags.</p>
<div class="meter is-progress">
<div class="meter--bar is-100%"></div>
<div class="meter--label">100%</div>
Expand Down
7 changes: 5 additions & 2 deletions app/views/flags/_flag.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="widget--body">
<p>
<strong><%= flag.post_flag_type&.name || 'Flag reason' %></strong>: <%= flag.reason %> &mdash;
<%= user_link flag.user %>
<%= user_link flag.user %> at <%= flag.created_at.iso8601 %>
</p>
</div>
<% if escalation %>
Expand All @@ -30,6 +30,9 @@
<strong>Escalation reason</strong>: <%= flag.escalation_comment %> &mdash;
<%= user_link flag.escalated_by %> <%= flag.escalated_at.iso8601 %>
</p>
<p>
<strong>Attention</strong>: The reply to the flag will be shown to the flagger, not the mod escalating this flag. Do not share sensitive, mod-only information.
</p>
</div>
<% end %>
<% if controls %>
Expand All @@ -50,4 +53,4 @@
</div>
</div>
<% end %>
</div>
</div>
7 changes: 4 additions & 3 deletions app/views/flags/_handled.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="widget--body">
<p>
<strong><%= flag.post_flag_type&.name || 'Flag reason' %>: </strong><%= flag.reason %> &mdash;
<%= user_link flag.user %>
<%= user_link flag.user %> at <%= flag.created_at.iso8601 %>
(<%= link_to 'history', flag_history_path(flag.user) %>)
</p>
<p>
Expand All @@ -24,8 +24,9 @@
&mdash;
<%= link_to user_path(flag.handled_by) do %>
<span dir="ltr"><%= rtl_safe_username(flag.handled_by) %></span>
<% end %>
<% end %>
handled at <%= flag.handled_at.iso8601 %>
<% end %>
</p>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion app/views/flags/handled.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

<% @flags.each do |flag| %>
<%= render 'handled', flag: flag %>
<% end %>
<% end %>

<%= will_paginate @flags, renderer: BootstrapPagination::Rails %>
11 changes: 7 additions & 4 deletions app/views/posts/_mdhint.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
max_length = (defined?(max_length) ? max_length : nil) || 30_000
%>

<div class="form-caption widget--footer js-post-field-footer">
We <a href="/help/formatting">support Markdown</a> for posts:
<strong>**bold**</strong>, <em>*italics*</em>, <code>`code`</code>, two newlines for paragraphs
<%= render 'shared/char_count', type: 'post-body', cur: cur_length, min: min_length, max: max_length %>
<div class="mdhint form-caption widget--footer js-post-field-footer">
<span>Markdown <a href="/help/formatting">support</a> for posts:
<strong>**bold**</strong>, <em>*italics*</em>, <code>`code`</code>, 2 newlines for paragraphs</span>
<span class="draft-status transparent has-color-green-600 js-post-draft-status">draft saved</span>
<div class="clearfix">
<%= render 'shared/char_count', type: 'post-body', cur: cur_length, min: min_length, max: max_length %>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/posts/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
<div class="notice is-danger is-filled">
You don't have a high enough trust level to post in the <%= @category.name %> category.
</div>
<p>Not where you meant to post? See <%= link_to 'Categories', categories_path %></p>

<% end %>
Loading

0 comments on commit 3a9bd5a

Please sign in to comment.