Skip to content

Commit cd9c737

Browse files
authored
Merge branch 'develop' into 0valt/387/post-title-search
2 parents 75df417 + e43a81c commit cd9c737

17 files changed

Lines changed: 297 additions & 145 deletions

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ on:
1010

1111
env:
1212
RAILS_ENV: test
13+
RUBY_VERSION: 3.2
1314

1415
jobs:
1516
rubocop:
1617
name: Rubocop checking
1718
runs-on: ubuntu-latest
1819

19-
strategy:
20-
matrix:
21-
ruby_version: [3.1, 3.2]
22-
2320
steps:
2421
- name: Checkout repo
2522
uses: actions/checkout@v3
@@ -30,7 +27,7 @@ jobs:
3027
- name: Setup Ruby
3128
uses: ruby/setup-ruby@v1
3229
with:
33-
ruby-version: ${{ matrix.ruby_version }}
30+
ruby-version: ${{ env.RUBY_VERSION }}
3431
bundler-cache: true
3532
- run: bundle exec rubocop
3633

@@ -106,7 +103,7 @@ jobs:
106103
path: tmp/screenshots
107104
if-no-files-found: ignore
108105
- uses: codecov/codecov-action@v5
109-
if: ${{ matrix.ruby_version == 3.2 && matrix.test_type == 'test' && github.actor != 'dependabot[bot]' }}
106+
if: ${{ matrix.ruby_version == env.RUBY_VERSION && matrix.test_type == 'test' && github.actor != 'dependabot[bot]' }}
110107
with:
111108
directory: coverage
112109
fail_ci_if_error: true

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: 28 additions & 25 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,49 +16,47 @@ 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-
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-
comment: "from <<CloseReason #{before}>>\nto <<CloseReason #{after}>>")
19+
if @close_reason.update(close_reason_params)
20+
after = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')
2221

23-
if @close_reason.community.nil?
24-
redirect_to close_reasons_path(global: 1)
22+
AuditLog.moderator_audit(event_type: 'close_reason_update',
23+
related: @close_reason,
24+
user: current_user,
25+
comment: "from <<CloseReason #{before}>>\nto <<CloseReason #{after}>>")
26+
27+
if @close_reason.community.nil?
28+
redirect_to close_reasons_path(global: 1)
29+
else
30+
redirect_to close_reasons_path
31+
end
2532
else
26-
redirect_to close_reasons_path
33+
render :edit, status: :bad_request
2734
end
2835
end
2936

3037
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
38+
@close_reason = CloseReason.new(community: params[:global] == '1' ? nil : @community)
3739
end
3840

3941
def create
40-
if !current_user.is_global_admin && params[:global] == '1'
41-
not_found!
42-
return
43-
end
42+
community_params = { community: params[:global] == '1' ? nil : @community }
43+
@close_reason = CloseReason.new(close_reason_params.merge(community_params))
4444

45-
@close_reason = CloseReason.new(name: params[:close_reason][:name],
46-
description: params[:close_reason][:description],
47-
requires_other_post: params[:close_reason][:requires_other_post],
48-
active: params[:close_reason][:active],
49-
community: params[:global] == '1' ? nil : @community)
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+
48+
AuditLog.moderator_audit(event_type: 'close_reason_create',
49+
related: @close_reason,
50+
user: current_user,
5351
comment: "<<CloseReason #{attr}>>")
52+
5453
if @close_reason.community.nil?
5554
redirect_to close_reasons_path(global: 1)
5655
else
5756
redirect_to close_reasons_path
5857
end
5958
else
60-
render :new
59+
render :new, status: :bad_request
6160
end
6261
end
6362

@@ -71,6 +70,10 @@ def set_close_reason
7170
@close_reason = CloseReason.unscoped.find(params[:id])
7271
end
7372

73+
def check_create_access
74+
not_found! unless current_user&.global_admin? || params[:global] != '1'
75+
end
76+
7477
def verify_admin_for_global_reasons
7578
if !current_user.global_admin? && @close_reason.community.nil?
7679
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/close_reason.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ class CloseReason < ApplicationRecord
33

44
scope :active, -> { where(active: true) }
55

6-
validates :name, uniqueness: { scope: [:community_id], case_sensitive: false }
6+
validates :name, length: { maximum: 255 },
7+
presence: true,
8+
uniqueness: { scope: [:community_id], case_sensitive: false }
9+
10+
def global?
11+
community.nil?
12+
end
713
end

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" %>

0 commit comments

Comments
 (0)