Skip to content

Commit 3a9bd5a

Browse files
authored
Merge branch 'develop' into 0valt/1229/post-history-fixes
2 parents f61b9a2 + d66b777 commit 3a9bd5a

35 files changed

+242
-62
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ gem 'will_paginate-bootstrap', '~> 1.0'
4141

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

4647
# Task scheduler.

Gemfile.lock

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ GEM
6666
i18n (>= 1.6, < 2)
6767
minitest (>= 5.1)
6868
tzinfo (~> 2.0)
69-
addressable (2.8.1)
69+
addressable (2.8.6)
7070
public_suffix (>= 2.0.2, < 6.0)
7171
ast (2.4.2)
7272
awesome_print (1.9.2)
73-
aws-eventstream (1.2.0)
74-
aws-partitions (1.628.0)
75-
aws-sdk-core (3.145.0)
76-
aws-eventstream (~> 1, >= 1.0.2)
77-
aws-partitions (~> 1, >= 1.525.0)
78-
aws-sigv4 (~> 1.1)
73+
aws-eventstream (1.3.0)
74+
aws-partitions (1.908.0)
75+
aws-sdk-core (3.191.6)
76+
aws-eventstream (~> 1, >= 1.3.0)
77+
aws-partitions (~> 1, >= 1.651.0)
78+
aws-sigv4 (~> 1.8)
7979
jmespath (~> 1, >= 1.6.1)
8080
aws-sdk-kms (1.58.0)
8181
aws-sdk-core (~> 3, >= 3.127.0)
@@ -84,12 +84,15 @@ GEM
8484
aws-sdk-core (~> 3, >= 3.127.0)
8585
aws-sdk-kms (~> 1)
8686
aws-sigv4 (~> 1.4)
87+
aws-sdk-sns (1.72.0)
88+
aws-sdk-core (~> 3, >= 3.191.0)
89+
aws-sigv4 (~> 1.1)
8790
aws-ses-v4 (0.8.1)
8891
builder
8992
mail (> 2.2.5)
9093
mime-types
9194
xml-simple
92-
aws-sigv4 (1.5.1)
95+
aws-sigv4 (1.8.0)
9396
aws-eventstream (~> 1, >= 1.0.2)
9497
bcrypt (3.1.18)
9598
bindex (0.8.1)
@@ -126,7 +129,7 @@ GEM
126129
thor (>= 0.19.4, < 2.0)
127130
tins (~> 1.6)
128131
crass (1.0.6)
129-
css_parser (1.11.0)
132+
css_parser (1.16.0)
130133
addressable
131134
date (3.3.4)
132135
devise (4.8.1)
@@ -209,7 +212,7 @@ GEM
209212
net-smtp (0.4.0)
210213
net-protocol
211214
nio4r (2.7.0)
212-
nokogiri (1.15.4-x86_64-linux)
215+
nokogiri (1.16.2-x86_64-linux)
213216
racc (~> 1.4)
214217
omniauth (2.1.0)
215218
hashie (>= 3.4.6)
@@ -227,7 +230,7 @@ GEM
227230
premailer-rails (1.11.1)
228231
actionmailer (>= 3)
229232
premailer (~> 1.7, >= 1.7.9)
230-
public_suffix (5.0.0)
233+
public_suffix (5.0.4)
231234
puma (5.6.8)
232235
nio4r (~> 2.0)
233236
racc (1.7.3)
@@ -391,6 +394,7 @@ PLATFORMS
391394
DEPENDENCIES
392395
awesome_print (~> 1.9)
393396
aws-sdk-s3 (~> 1.61)
397+
aws-sdk-sns (~> 1.72)
394398
aws-ses-v4
395399
byebug (~> 11.1)
396400
capybara (~> 3.38)
@@ -452,4 +456,4 @@ RUBY VERSION
452456
ruby 2.7.6p219
453457

454458
BUNDLED WITH
455-
2.4.15
459+
2.4.13

INSTALLATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ You will need to set the Redis connection details there too. If you've followed
118118
the sample file should already contain the correct values for you, but if you've customised your
119119
setup you'll need to correct them.
120120

121+
You'll also need to copy the Active Storage configuration from `config/storage.sample.yml` to `config/storage.yml`.
122+
121123
If you are using MariaDB instead of MySQL, you will need to replace all occurrences of
122124
`utf8mb4_0900_ai_ci` with `utf8mb4_unicode_ci` in `db/schema.rb`.
123125

124-
You'll also need to copy the Active Storage configuration from `config/storage.sample.yml` to `config/storage.yml`.
125-
126126
Set up the database:
127127

128128
rails db:create

app/assets/javascripts/posts.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ $(() => {
9393
tags: true
9494
});
9595

96+
/**
97+
* Attempts to save a draft with a given body
98+
* @param {string} postText draft text
99+
* @param {JQuery<Element>} $field body input element
100+
* @param {boolean} [manual] whether manual draft saving is enabled
101+
* @returns {Promise<void>}
102+
*/
96103
const saveDraft = async (postText, $field, manual = false) => {
97104
const autosavePref = await QPixel.preference('autosave', true);
98105
if (autosavePref !== 'on' && !manual) {
@@ -111,10 +118,15 @@ $(() => {
111118
path: location.pathname
112119
})
113120
});
121+
114122
if (resp.status === 200) {
115-
const $el = $(`<span>&middot; <span class="has-color-green-600">draft saved</span></span>`);
116-
$field.parents('.widget').find('.js-post-field-footer').append($el);
117-
$el.fadeOut(1500, function () { $(this).remove() });
123+
const $statusEl = $field.parents('.widget').find('.js-post-draft-status');
124+
125+
$statusEl.removeClass('transparent');
126+
127+
setTimeout(() => {
128+
$statusEl.addClass('transparent');
129+
}, 1500);
118130
}
119131
};
120132

app/assets/stylesheets/posts.scss

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,25 @@ h1 .badge.is-tag.is-master-tag {
8989
width: calc(100% + 2px);
9090

9191
+ .widget--footer {
92-
margin-bottom: 0;
92+
border-top: none;
93+
align-items: center;
94+
margin: 0;
95+
96+
&.mdhint {
97+
display: flex;
98+
flex-wrap: wrap;
99+
gap: 1em 0;
100+
justify-content: space-between;
101+
102+
& > * {
103+
padding: 0;
104+
}
105+
}
106+
107+
& > .draft-status {
108+
text-align: center;
109+
transition: opacity 0.5s ease-in-out;
110+
}
93111
}
94112
}
95113

app/assets/stylesheets/utilities.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,8 @@ span.spoiler {
284284

285285
.clearfix {
286286
overflow: hidden;
287-
}
287+
}
288+
289+
.transparent {
290+
opacity: 0;
291+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class EmailLogsController < ApplicationController
2+
skip_forgery_protection only: [:log]
3+
skip_before_action :set_globals, only: [:log]
4+
skip_before_action :distinguish_fake_community, only: [:log]
5+
skip_before_action :enforce_signed_in, only: [:log]
6+
7+
def log
8+
message_type = request.headers['X-Amz-SNS-Message-Type']
9+
if ['SubscriptionConfirmation', 'Notification'].include? message_type
10+
verifier = Aws::SNS::MessageVerifier.new
11+
body = request.body.read
12+
if verifier.authentic? body
13+
aws_data = JSON.parse body
14+
message_data = JSON.parse aws_data['Message']
15+
log_type = message_data['notificationType']
16+
destination = message_data['mail']['destination'].join(', ')
17+
EmailLog.create(log_type: log_type, destination: destination, data: aws_data['Message'])
18+
render plain: 'OK'
19+
else
20+
render plain: "You're not AWS. Go away.", status: 401
21+
end
22+
end
23+
end
24+
end

app/controllers/tags_controller.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ def category
3232
@tag_set.tags.where(excerpt: '').or(@tag_set.tags.where(excerpt: nil))
3333
.order(Arel.sql('COUNT(posts.id) DESC'))
3434
else
35-
@tag_set.tags.order(Arel.sql('COUNT(posts.id) DESC'))
35+
@tag_set&.tags&.order(Arel.sql('COUNT(posts.id) DESC'))
3636
end
37-
@count = @tags.count
37+
@count = @tags&.size || 0
3838
table = params[:hierarchical].present? ? 'tags_paths' : 'tags'
39-
@tags = @tags.left_joins(:posts).group(Arel.sql("#{table}.id"))
40-
.select(Arel.sql("#{table}.*, COUNT(DISTINCT IF(posts.deleted = 0, posts.id, NULL)) AS post_count"))
41-
.paginate(per_page: 96, page: params[:page])
39+
if @count.positive?
40+
@tags = @tags.left_joins(:posts).group(Arel.sql("#{table}.id"))
41+
.select(Arel.sql("#{table}.*, COUNT(DISTINCT IF(posts.deleted = 0, posts.id, NULL)) AS post_count"))
42+
.paginate(per_page: 96, page: params[:page])
43+
end
4244
end
4345

4446
def show

app/controllers/users_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def set_preference
174174
end
175175

176176
def posts
177-
@posts = if current_user&.privilege?('flag_curate')
177+
@posts = if current_user&.privilege?('flag_curate') || @user == current_user
178178
Post.all
179179
else
180180
Post.undeleted
@@ -579,7 +579,7 @@ def vote_summary
579579
def avatar
580580
respond_to do |format|
581581
format.png do
582-
size = params[:size]&.to_i&.positive? ? params[:size]&.to_i : 64
582+
size = params[:size]&.to_i&.positive? ? [params[:size]&.to_i, 256].min : 64
583583
send_data helpers.user_auto_avatar(size, user: @user).to_blob, type: 'image/png', disposition: 'inline'
584584
end
585585
end

app/helpers/email_logs_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module EmailLogsHelper
2+
end

0 commit comments

Comments
 (0)