Skip to content

Commit 3c51014

Browse files
committed
Merge branch 'develop' into 0valt/1699/erb_lint
2 parents 7ab02e1 + 00a8551 commit 3c51014

17 files changed

+226
-115
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ GEM
391391
lint_roller (~> 1.1)
392392
rubocop (>= 1.72.1)
393393
ruby-progressbar (1.13.0)
394-
ruby-saml (1.18.0)
394+
ruby-saml (1.18.1)
395395
nokogiri (>= 1.13.10)
396396
rexml
397397
ruby-vips (2.2.4)

app/assets/javascripts/comments.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ $(() => {
236236
* @type {Record<`${number}-${number}`, Record<string, number>>}
237237
*/
238238
const pingable = {};
239-
$(document).on('keyup', '.js-comment-field', pingable_popup);
239+
$(document).on('keyup', '.js-comment-field, .js-thread-title-field', pingable_popup);
240240

241241
/**
242242
* @type {QPixelPingablePopupCallback}
@@ -267,10 +267,12 @@ $(() => {
267267
$tgt.focus();
268268
};
269269

270-
// If the word the caret is currently in starts with an @, and has at least 3 characters after that, assume it's
271-
// an attempt to ping another user with a username, and kick off suggestions -- unless it starts with @#, in which
272-
// case it's likely an already-selected ping.
273-
if (currentWord.startsWith('@') && !currentWord.startsWith('@#') && currentWord.length >= 4) {
270+
// at least 1 character has to be present to trigger autocomplete (2 is because pings start with @)
271+
const hasReachedAutocompleteThreshold = currentWord.length >= 2;
272+
273+
// If the word the caret is currently in starts with an @, and is reached the autocomplete threshold, assume it's
274+
// a ping attempt and kick off suggestions (unless it starts with @#, meaning it's likely an already-selected ping)
275+
if (currentWord.startsWith('@') && !currentWord.startsWith('@#') && hasReachedAutocompleteThreshold) {
274276
const threadId = $tgt.data('thread');
275277
const postId = $tgt.data('post');
276278

app/assets/stylesheets/utilities.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ span.spoiler {
359359
overflow-wrap: anywhere;
360360
}
361361

362+
.wrap-word {
363+
overflow-wrap: break-word;
364+
}
365+
362366
.nowrap {
363367
white-space: nowrap;
364368
}

app/controllers/admin_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def send_all_email
6565

6666
Thread.new do
6767
emails = User.where.not(confirmed_at: nil).where('email NOT LIKE ?', '%localhost').select(:email).map(&:email)
68-
emails.each_slice(50) do |slice|
68+
emails.each_slice(49) do |slice|
6969
AdminMailer.with(body_markdown: params[:body_markdown],
7070
subject: params[:subject],
7171
emails: slice, community: community)

app/controllers/close_reasons_controller.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
class CloseReasonsController < ApplicationController
22
before_action :verify_moderator
3+
before_action :check_create_access, only: [:new, :create]
34
before_action :set_close_reason, only: [:edit, :update]
45
before_action :verify_admin_for_global_reasons, only: [:edit, :update]
56

67
def index
7-
@close_reasons = if current_user.is_global_admin && params[:global] == '1'
8+
@close_reasons = if current_user.global_admin? && params[:global] == '1'
89
CloseReason.unscoped.where(community_id: nil)
910
else
1011
CloseReason.unscoped.where(community_id: @community.id)
@@ -15,9 +16,12 @@ def edit; end
1516

1617
def update
1718
before = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')
18-
@close_reason.update close_reason_params
19+
@close_reason.update(close_reason_params)
1920
after = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')
20-
AuditLog.moderator_audit(event_type: 'close_reason_update', related: @close_reason, user: current_user,
21+
22+
AuditLog.moderator_audit(event_type: 'close_reason_update',
23+
related: @close_reason,
24+
user: current_user,
2125
comment: "from <<CloseReason #{before}>>\nto <<CloseReason #{after}>>")
2226

2327
if @close_reason.community.nil?
@@ -28,29 +32,23 @@ def update
2832
end
2933

3034
def new
31-
if !current_user.is_global_admin && params[:global] == '1'
32-
not_found!
33-
return
34-
end
35-
36-
@close_reason = CloseReason.new
35+
@close_reason = CloseReason.new(community: params[:global] == '1' ? nil : @community)
3736
end
3837

3938
def create
40-
if !current_user.is_global_admin && params[:global] == '1'
41-
not_found!
42-
return
43-
end
44-
4539
@close_reason = CloseReason.new(name: params[:close_reason][:name],
4640
description: params[:close_reason][:description],
4741
requires_other_post: params[:close_reason][:requires_other_post],
4842
active: params[:close_reason][:active],
4943
community: params[:global] == '1' ? nil : @community)
44+
5045
if @close_reason.save
5146
attr = @close_reason.attributes_print
52-
AuditLog.moderator_audit(event_type: 'close_reason_create', related: @close_reason, user: current_user,
47+
AuditLog.moderator_audit(event_type: 'close_reason_create',
48+
related: @close_reason,
49+
user: current_user,
5350
comment: "<<CloseReason #{attr}>>")
51+
5452
if @close_reason.community.nil?
5553
redirect_to close_reasons_path(global: 1)
5654
else
@@ -71,6 +69,10 @@ def set_close_reason
7169
@close_reason = CloseReason.unscoped.find(params[:id])
7270
end
7371

72+
def check_create_access
73+
not_found! unless current_user&.global_admin? || params[:global] != '1'
74+
end
75+
7476
def verify_admin_for_global_reasons
7577
if !current_user.global_admin? && @close_reason.community.nil?
7678
not_found!

app/controllers/pinned_links_controller.rb

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,42 @@ def new
2727
end
2828

2929
def create
30-
@link = PinnedLink.create pinned_link_params
30+
@link = PinnedLink.new(pinned_link_params)
3131

32-
attr = @link.attributes_print
33-
AuditLog.moderator_audit(event_type: 'pinned_link_create', related: @link, user: current_user,
34-
comment: "<<PinnedLink #{attr}>>")
32+
if @link.save
33+
attr = @link.attributes_print
3534

36-
flash[:success] = 'Your pinned link has been created. Due to caching, it may take some time until it is shown.'
37-
redirect_to pinned_links_path
35+
AuditLog.moderator_audit(event_type: 'pinned_link_create',
36+
related: @link,
37+
user: current_user,
38+
comment: "<<PinnedLink #{attr}>>")
39+
40+
flash[:success] =
41+
'Your pinned link has been created. Due to caching, it may take some time until it is shown.'
42+
redirect_to pinned_links_path
43+
else
44+
render 'pinned_links/new', status: :bad_request
45+
end
3846
end
3947

4048
def edit; end
4149

4250
def update
4351
before = @link.attributes_print
44-
@link.update pinned_link_params
45-
after = @link.attributes_print
46-
AuditLog.moderator_audit(event_type: 'pinned_link_update', related: @link, user: current_user,
47-
comment: "from <<PinnedLink #{before}>>\nto <<PinnedLink #{after}>>")
4852

49-
flash[:success] = 'The pinned link has been updated. Due to caching, it may take some time until it is shown.'
50-
redirect_to pinned_links_path
53+
if @link.update(pinned_link_params)
54+
after = @link.attributes_print
55+
56+
AuditLog.moderator_audit(event_type: 'pinned_link_update',
57+
related: @link,
58+
user: current_user,
59+
comment: "from <<PinnedLink #{before}>>\nto <<PinnedLink #{after}>>")
60+
61+
flash[:success] = 'The pinned link has been updated. Due to caching, it may take some time until it is shown.'
62+
redirect_to pinned_links_path
63+
else
64+
render 'pinned_links/edit', status: :bad_request
65+
end
5166
end
5267

5368
private

app/controllers/post_types_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def new
2121
end
2222

2323
def create
24-
@type = PostType.new post_type_params
24+
@type = PostType.new(post_type_params)
2525
if @type.save
2626
clear_cache!
2727
redirect_to post_types_path
@@ -55,8 +55,6 @@ def post_type_params
5555
end
5656

5757
def clear_cache!
58-
# FIXME: this is likely not clearing cache for rep changes
59-
Rails.cache.delete 'network/post_types/rep_changes'
6058
PostType.clear_ids_cache
6159
current_community = RequestContext.community
6260
Community.all.each do |c|

app/models/pinned_link.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
class PinnedLink < ApplicationRecord
22
include MaybeCommunityRelated
3-
belongs_to :post
3+
belongs_to :post, optional: true
4+
5+
validate :check_post_or_url
46

57
# Is the link time-constrained?
68
# @return [Boolean] check result
79
def timed?
810
shown_before.present? || shown_after.present?
911
end
12+
13+
def check_post_or_url
14+
unless post_id.present? || link.present?
15+
errors.add(:base, 'either a post or a URL must be set')
16+
end
17+
end
1018
end

app/views/close_reasons/_form.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<%#
2+
Instance variables:
3+
@close_reason : close reason to edit
4+
5+
Variables:
6+
submit_url : route URL to submit the form to
7+
%>
8+
19
<%= form_for @close_reason, url: submit_url do |f| %>
210
<div class="form-group">
311
<%= f.label :name, "Name", class: "form-element" %>

app/views/comments/_new_thread_modal.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
You can give your comment thread a title. If you leave this blank, the beginning of the initial comment will
4040
be shown.
4141
</span>
42-
<%= text_field_tag :title, '', class: 'form-element', data: { character_count: ".js-character-count-thread-title" } %>
42+
<%= text_field_tag :title, '',
43+
class: 'form-element js-thread-title-field',
44+
data: { post: post.id,
45+
thread: '-1',
46+
character_count: ".js-character-count-thread-title" } %>
4347
<%= render 'shared/char_count', type: 'thread-title' %>
4448

4549
<%= submit_tag 'Create thread', class: 'button is-filled', id: "create_thread_button_#{post.id}", disabled: true %>

0 commit comments

Comments
 (0)