Skip to content

Commit bea0057

Browse files
committed
v0.12.1
2 parents 3dec9c6 + d0be299 commit bea0057

File tree

9 files changed

+116
-13
lines changed

9 files changed

+116
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
document.querySelectorAll('.js-log-type-select, .js-event-type-select').forEach((el) => {
3+
$(el).select2();
4+
});
5+
});

app/assets/javascripts/comments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ $(() => {
313313
ev.preventDefault();
314314
const $tgt = $(ev.target);
315315
const postId = $tgt.attr('data-post');
316-
const $reply = $(`#reply-to-thread-form-${postId}`);
316+
const threadId = $tgt.attr('data-thread');
317+
const $reply = $(`#reply-to-thread-form-${postId}-${threadId}`);
317318

318319
if ($reply.is(':hidden')) {
319320
$reply.show();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import 'variables';
2+
3+
.audit-log-filters {
4+
.select2-container {
5+
height: 37px;
6+
margin: 4px 0px;
7+
8+
.selection {
9+
.select2-selection {
10+
border-color: $muted-graphic;
11+
height: 100%;
12+
padding: 4px 0;
13+
}
14+
15+
.select2-selection__arrow {
16+
top: 50%;
17+
translate: 0 -50%;
18+
}
19+
}
20+
}
21+
}

app/assets/stylesheets/forms.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ select.form-element {
2020
}
2121

2222
& > .form-group {
23-
margin: 0.5em 0;
23+
margin: 0 0 1em 0;
2424

2525
@media screen and (min-width: $screen-md) {
26-
margin: 0 0.5em;
26+
margin: 0 1em 0 0;
2727
flex: 1;
2828
}
2929
}
3030

3131
& > .actions {
3232
display: flex;
3333
align-items: flex-end;
34+
margin-bottom: 4px; // to match bottom margin on .form-element
35+
36+
button, input[type="submit"] {
37+
margin: unset;
38+
padding: 9.5px 12px; // because for some reason it has to be 9.5px to match .form-elements' height
39+
}
3440
}
3541
}
3642

@@ -49,6 +55,10 @@ select.form-element {
4955
z-index: 8999;
5056
}
5157

58+
.select2-results__option {
59+
min-height: 2em;
60+
}
61+
5262
@for $i from 1 through 25 {
5363
textarea.has-rows[rows="#{$i}"] {
5464
min-height: (1.2em * $i) + 1.2em;

app/controllers/admin_controller.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,33 @@ def audit_log
8383
@page = helpers.safe_page(params)
8484
@per_page = helpers.safe_per_page(params)
8585

86+
@log_types = AuditLog.unscoped.select(:log_type).distinct.map(&:log_type) - ['user_annotation', 'user_history']
87+
@event_types = AuditLog.unscoped.select(:event_type).distinct.map(&:event_type)
88+
8689
@logs = if current_user.is_global_admin
8790
AuditLog.unscoped.where.not(log_type: ['user_annotation', 'user_history'])
8891
else
8992
AuditLog.where.not(log_type: ['block_log', 'user_annotation', 'user_history'])
90-
end.user_sort({ term: params[:sort], default: :created_at },
91-
age: :created_at, type: :log_type, event: :event_type,
92-
related: Arel.sql('related_type DESC, related_id DESC'), user: :user_id)
93-
.paginate(page: @page, per_page: @per_page)
93+
end
94+
95+
[:log_type, :event_type].each do |key|
96+
if params[key].present?
97+
@logs = @logs.where(key => params[key])
98+
end
99+
end
100+
101+
if params[:from].present?
102+
@logs = @logs.where('date(created_at) >= ?', params[:from])
103+
end
104+
105+
if params[:to].present?
106+
@logs = @logs.where('date(created_at) <= ?', params[:to])
107+
end
108+
109+
@logs = @logs.user_sort({ term: params[:sort], default: :created_at },
110+
age: :created_at, type: :log_type, event: :event_type,
111+
related: Arel.sql('related_type DESC, related_id DESC'), user: :user_id)
112+
.paginate(page: @page, per_page: @per_page)
94113

95114
render layout: 'without_sidebar'
96115
end

app/views/admin/audit_log.html.erb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
<h1><%= t 'admin.tools.audit_log' %></h1>
22

3+
<div>
4+
<h3>Filters</h3>
5+
<%= form_tag audit_log_path, method: :get, class: 'form-inline audit-log-filters' do %>
6+
<div class="form-group-horizontal">
7+
<div class="form-group">
8+
<%= label_tag :log_type, 'Log category', class: 'form-element' %>
9+
<%= select_tag :log_type, options_for_select(@log_types.map { |lt| [lt, lt] }, selected: params[:log_type]),
10+
include_blank: true, class: 'form-element js-log-type-select' %>
11+
</div>
12+
<div class="form-group">
13+
<%= label_tag :event_type, 'Event', class: 'form-element' %>
14+
<%= select_tag :event_type, options_for_select(@event_types.map { |et| [et, et] },
15+
selected: params[:event_type]),
16+
include_blank: true, class: 'form-element js-event-type-select' %>
17+
</div>
18+
<div class="form-group">
19+
<%= label_tag :from, 'From date', class: 'form-element' %>
20+
<%= date_field_tag :from, params[:from], class: 'form-element' %>
21+
</div>
22+
<div class="form-group">
23+
<%= label_tag :to, 'To date', class: 'form-element' %>
24+
<%= date_field_tag :to, params[:to], class: 'form-element' %>
25+
</div>
26+
<div class="actions">
27+
<%= submit_tag 'Filter', class: 'button is-filled' %>
28+
</div>
29+
</div>
30+
<% end %>
31+
</div>
32+
333
<div class="category-meta">
434
<h3><%= pluralize(@logs.count, t('g.log')) %></h3>
35+
536
<div class="button-list is-gutterless">
637
<% classes = 'button is-outlined is-muted' %>
738
<%= link_to t('g.age'), request.params.merge(sort: 'age'),

app/views/comments/_new_thread_modal.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
required: true,
3232
data: { post: post.id,
3333
thread: '-1',
34-
character_count: ".js-character-count-#{post.id}" } %>
35-
<%= render 'shared/char_count', type: post.id, min: min_chars, max: max_chars %>
34+
character_count: ".js-character-count-new-thread-#{post.id}" } %>
35+
<%= render 'shared/char_count', type: "new-thread-#{post.id}", min: min_chars, max: max_chars %>
3636

3737
<%= label_tag :title, 'Comment thread title (optional)', class: 'form-element' %>
3838
<span class="form-caption">

app/views/comments/_reply_to_thread.html.erb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
%>
1111

1212
<%
13+
# TODO: make configurable
14+
min_chars = 15
15+
max_chars = 1000
16+
1317
can_comment = user.can_reply_to?(thread)
1418
is_rate_limited, rate_limit_message = comment_rate_limited?(user, post, create_audit_log: false)
1519
text ||= defined?(text) && text.present? ? text : t('comments.labels.reply_to_thread')
@@ -28,7 +32,7 @@
2832

2933
<div class="reply-to-thread-wrapper">
3034
<%= link_to 'javascript:void(0)', class: 'button is-outlined is-small js-reply-to-thread-link',
31-
data: { post: post.id },
35+
data: { post: post.id, thread: thread.id },
3236
disabled: !can_comment,
3337
role: 'button',
3438
title: is_exempt ? '' : title do %>
@@ -40,16 +44,20 @@
4044
</div>
4145

4246
<% if can_comment %>
43-
<%= form_tag create_comment_path(thread.id), class: 'reply-to-thread-form', id: "reply-to-thread-form-#{post.id}" do %>
47+
<%= form_tag create_comment_path(thread.id), class: 'reply-to-thread-form',
48+
id: "reply-to-thread-form-#{post.id}-#{thread.id}" do %>
4449
<%= hidden_field_tag :post_id, post.id %>
4550
<%= hidden_field_tag :inline, inline %>
4651
<%= label_tag :content, 'Your message', class: 'form-element' %>
4752
<%= text_area_tag :content, '',
4853
class: 'form-element js-comment-field',
54+
minlength: min_chars,
55+
maxlength: max_chars,
56+
required: true,
4957
data: { thread: thread.id,
5058
post: thread.post_id,
51-
character_count: ".js-character-count-#{post.id}" } %>
52-
<%= render 'shared/char_count', type: post.id, min: 15, max: 1000 %>
59+
character_count: ".js-character-count-thread-reply-#{post.id}-#{thread.id}" } %>
60+
<%= render 'shared/char_count', type: "thread-reply-#{post.id}-#{thread.id}", min: min_chars, max: max_chars %>
5361
<%= submit_tag 'Add reply', class: 'button is-muted is-filled', disabled:true %>
5462
<% end %>
5563
<% end %>

test/controllers/admin_controller_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ class AdminControllerTest < ActionController::TestCase
157157
assert_not_nil flash[:success]
158158
end
159159
end
160+
161+
test 'audit log should work with filter params' do
162+
sign_in users(:admin)
163+
get :audit_log, params: { log_type: 'admin_audit', event_type: 'setting_update', from: '2025-04-13',
164+
to: '2025-04-13' }
165+
assert_response(:success)
166+
assert_not_nil assigns(:logs)
167+
end
160168
end

0 commit comments

Comments
 (0)