Commit bcd4a289 authored by Tan Le's avatar Tan Le

Remove unused audit events helper methods

These methods were no longer called since we moved from server template
to front-end rendering.
parent 92c70ac9
......@@ -2,40 +2,26 @@
module AuditEventsHelper
FILTER_TOKEN_TYPES = {
user: :user,
group: :group,
project: :project,
member: :member
user: :user,
group: :group,
project: :project,
member: :member
}.freeze
def admin_audit_event_tokens
[{ type: FILTER_TOKEN_TYPES[:user] }, { type: FILTER_TOKEN_TYPES[:group] }, { type: FILTER_TOKEN_TYPES[:project] }].freeze
[
{ type: FILTER_TOKEN_TYPES[:user] },
{ type: FILTER_TOKEN_TYPES[:group] },
{ type: FILTER_TOKEN_TYPES[:project] }
].freeze
end
def group_audit_event_tokens(group_id)
[{ type: FILTER_TOKEN_TYPES[:member], group_id: group_id }]
[{ type: FILTER_TOKEN_TYPES[:member], group_id: group_id }].freeze
end
def project_audit_event_tokens(project_path)
[{ type: FILTER_TOKEN_TYPES[:member], project_path: project_path }]
end
def human_text(details)
return details[:custom_message] if details[:custom_message]
details.map { |key, value| select_keys(key, value) }.join(" ").humanize
end
def select_keys(key, value)
if key =~ /^(author|target)_.*/
""
elsif key.to_s == 'ip_address' && value.blank?
""
elsif key =~ /^expiry_(from|to)$/ && value.blank?
"#{key} <strong>never expires</strong>"
else
"#{key} <strong>#{value}</strong>"
end
[{ type: FILTER_TOKEN_TYPES[:member], project_path: project_path }].freeze
end
def export_url
......
......@@ -32,68 +32,6 @@ RSpec.describe AuditEventsHelper do
end
end
describe '#human_text' do
let(:target_type) { 'User' }
let(:details) do
{
author_name: 'John Doe',
target_id: 1,
target_type: target_type,
target_details: 'Michael'
}
end
subject { human_text(details) }
context 'when message consist of hash keys' do
subject { human_text({ remove: 'user_access' }.merge(details))}
it 'ignores keys that start with start with author_, or target_' do
expect(subject).to eq 'Remove <strong>user access</strong> '
end
end
context 'when details contain custom message' do
let(:custom_message) { 'Custom message <strong>with tags</strong>' }
subject { human_text( { custom_message: custom_message }.merge(details)) }
it 'returns custom message' do
expect(subject).to eq(custom_message)
end
end
end
describe '#select_keys' do
it 'returns empty string if key starts with author_' do
expect(select_keys('author_name', 'John Doe')).to eq ''
end
it 'returns empty string if key starts with target_' do
expect(select_keys('target_name', 'John Doe')).to eq ''
end
it 'returns empty string if key is ip_address and the value is blank' do
expect(select_keys('ip_address', nil)).to eq ''
end
it 'returns formatted text if key is ip_address and the value is not blank' do
expect(select_keys('ip_address', '127.0.0.1')).to eq 'ip_address <strong>127.0.0.1</strong>'
end
it 'returns formatted text if key does not start with author_, or target_' do
expect(select_keys('remove', 'user_access')).to eq 'remove <strong>user_access</strong>'
end
it 'returns formatted text with `never expires` if key is expiry_from and the value is blank' do
expect(select_keys('expiry_from', nil)).to eq 'expiry_from <strong>never expires</strong>'
end
it 'returns formatted text with `never expires` if key is expiry_to and the value is blank' do
expect(select_keys('expiry_to', nil)).to eq 'expiry_to <strong>never expires</strong>'
end
end
describe '#export_url' do
subject { export_url }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment