Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pending only filter #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/audits1984/filtered_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update

private
def filtered_sessions_param
params.require(:filtered_sessions).permit(:sensitive_only, :from_date, :to_date)
params.require(:filtered_sessions).permit(:sensitive_only, :from_date, :to_date, :pending_only)
end
end
end
2 changes: 2 additions & 0 deletions app/models/audits1984/filtered_sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class FilteredSessions
attribute :from_date, :date
attribute :to_date, :date
attribute :sensitive_only, :boolean
attribute :pending_only, :boolean

def self.resume(attributes)
new attributes&.with_indifferent_access&.slice(*attribute_names)
Expand All @@ -18,6 +19,7 @@ def to_h
def all
sessions = Console1984::Session.order(created_at: :desc, id: :desc)
sessions = sessions.sensitive if sensitive_only
sessions = sessions.pending if pending_only
sessions = sessions.where("console1984_sessions.created_at >= ?", from_date.beginning_of_day) if from_date.present?
sessions = sessions.where("console1984_sessions.created_at <= ?", to_date.end_of_day) if to_date.present?
sessions
Expand Down
7 changes: 6 additions & 1 deletion app/views/audits1984/sessions/_filter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
</div>
</div>

<div class="field">
<div class="field is-grouped">
<div class="control">
<%= form.label :sensitive_only, "Only with sensitive access", class: "checkbox" %>
<%= form.check_box :sensitive_only %>
</div>

<div class="control">
<%= form.label :sensitive_only, "Pending review only", class: "checkbox" %>
<%= form.check_box :pending_only %>
</div>
</div>

<div class="field is-grouped">
Expand Down
16 changes: 14 additions & 2 deletions test/models/audits1984/filtered_sessions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ class Audits1984::FilteredSessionsTest < ActiveSupport::TestCase
assert_equal second, filtered_sessions.pending_session_after(first)
end

test "filter pending sessiosn" do
audited_session = console1984_sessions(:sensitive_printing)
auditor = ::Auditor.create!(name: "Jorge")
audited_session.audits.create!(status: "approved", auditor_id: auditor.id)
pending_session = console1984_sessions(:arithmetic)

assert_filtered_sessions \
included: pending_session,
excluded: audited_session,
pending: true
end

private
def assert_filtered_sessions(included: [], excluded: [], sensitive: false, from: nil, to: nil)
def assert_filtered_sessions(included: [], excluded: [], sensitive: false, from: nil, to: nil, pending: false)
assert included.present? || excluded.present?, "Not really testing anything?"

filtered_sessions = Audits1984::FilteredSessions.new(sensitive_only: sensitive, from_date: from, to_date: to)
filtered_sessions = Audits1984::FilteredSessions.new(sensitive_only: sensitive, from_date: from, to_date: to, pending_only: pending)

Array(included).each do |expected_session|
assert_includes filtered_sessions.all, expected_session
Expand Down