Commit 5a66b453 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'jlouw-add-flags-to-audit-app' into 'master'

Add search token configuration to AuditLogApp

See merge request gitlab-org/gitlab!32951
parents f4dda7f9 1f5faffe
...@@ -26,6 +26,10 @@ export default { ...@@ -26,6 +26,10 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
enabledTokenTypes: {
type: Array,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -51,7 +55,7 @@ export default { ...@@ -51,7 +55,7 @@ export default {
class="filter-form d-flex justify-content-between audit-controls row" class="filter-form d-flex justify-content-between audit-controls row"
> >
<div class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8"> <div class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8">
<AuditLogFilter /> <AuditLogFilter v-bind="{ enabledTokenTypes }" />
</div> </div>
<div class="d-flex col-lg-auto flex-wrap pl-lg-0"> <div class="d-flex col-lg-auto flex-wrap pl-lg-0">
<div <div
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlFilteredSearch } from '@gitlab/ui'; import { GlFilteredSearch } from '@gitlab/ui';
import { queryToObject } from '~/lib/utils/url_utility'; import { queryToObject } from '~/lib/utils/url_utility';
import { FILTER_TOKENS, AVAILABLE_TOKEN_TYPES } from '../constants'; import { FILTER_TOKENS, AVAILABLE_TOKEN_TYPES } from '../constants';
import { availableTokensValidator } from '../validators';
export default { export default {
components: { components: {
...@@ -12,6 +13,7 @@ export default { ...@@ -12,6 +13,7 @@ export default {
type: Array, type: Array,
required: false, required: false,
default: () => AVAILABLE_TOKEN_TYPES, default: () => AVAILABLE_TOKEN_TYPES,
validator: availableTokensValidator,
}, },
}, },
data() { data() {
......
import { AVAILABLE_TOKEN_TYPES } from './constants';
export function availableTokensValidator(value) {
return value.every(type => AVAILABLE_TOKEN_TYPES.includes(type));
}
export default {};
...@@ -4,7 +4,7 @@ import AuditLogApp from 'ee/audit_logs/components/audit_log_app.vue'; ...@@ -4,7 +4,7 @@ import AuditLogApp from 'ee/audit_logs/components/audit_log_app.vue';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const el = document.querySelector('#js-audit-log-app'); const el = document.querySelector('#js-audit-log-app');
const { events, isLastPage, formPath } = el.dataset; const { events, isLastPage, formPath, enabledTokenTypes } = el.dataset;
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
...@@ -15,6 +15,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -15,6 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
props: { props: {
events: JSON.parse(events), events: JSON.parse(events),
isLastPage: parseBoolean(isLastPage), isLastPage: parseBoolean(isLastPage),
enabledTokenTypes: JSON.parse(enabledTokenTypes),
formPath, formPath,
}, },
}), }),
......
# frozen_string_literal: true # frozen_string_literal: true
module AuditLogsHelper module AuditLogsHelper
def audit_entity_type_options def admin_audit_log_token_types
[ %w[User Group Project].freeze
{ id: 'All', text: 'All Events' },
{ id: 'Group', text: 'Group Events' },
{ id: 'Project', text: 'Project Events' },
{ id: 'User', text: 'User Events' }
]
end
def audit_entity_type_label(selected)
selected = 'All' unless selected.present?
audit_entity_type_options.find { |type| type[:id] == selected }[:text]
end end
end end
- page_title 'Audit Log' - page_title 'Audit Log'
#js-audit-log-app{ data: { form_path: admin_audit_logs_path, events: @table_events.to_json, is_last_page: @events.last_page?.to_json, qa_selector: 'admin_audit_log_table' } } #js-audit-log-app{ data: { form_path: admin_audit_logs_path,
events: @table_events.to_json,
is_last_page: @events.last_page?.to_json,
qa_selector: 'admin_audit_log_table',
enabled_token_types: admin_audit_log_token_types } }
...@@ -16,8 +16,28 @@ exports[`AuditLogApp when initialized matches the snapshot 1`] = ` ...@@ -16,8 +16,28 @@ exports[`AuditLogApp when initialized matches the snapshot 1`] = `
class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8" class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8"
> >
<div <div
class="audit-log-filter" class="input-group bg-white flex-grow-1"
data-qa-selector="admin_audit_log_filter"
>
<gl-filtered-search-stub
availabletokens="[object Object],[object Object],[object Object]"
class="gl-h-32 w-100"
clearbuttontitle="Clear"
close-button-title="Close"
placeholder="Search"
value=""
/>
<input
name="entity_type"
type="hidden"
/> />
<input
name="entity_id"
type="hidden"
/>
</div>
</div> </div>
<div <div
......
...@@ -3,11 +3,14 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,11 +3,14 @@ import { shallowMount } from '@vue/test-utils';
import AuditLogApp from 'ee/audit_logs/components/audit_log_app.vue'; import AuditLogApp from 'ee/audit_logs/components/audit_log_app.vue';
import DateRangeField from 'ee/audit_logs/components/date_range_field.vue'; import DateRangeField from 'ee/audit_logs/components/date_range_field.vue';
import LogsTable from 'ee/audit_logs/components/logs_table.vue'; import LogsTable from 'ee/audit_logs/components/logs_table.vue';
import AuditLogFilter from 'ee/audit_logs/components/audit_log_filter.vue';
import { AVAILABLE_TOKEN_TYPES } from 'ee/audit_logs/constants';
describe('AuditLogApp', () => { describe('AuditLogApp', () => {
let wrapper; let wrapper;
const events = [{ foo: 'bar' }]; const events = [{ foo: 'bar' }];
const enabledTokenTypes = AVAILABLE_TOKEN_TYPES;
const initComponent = (props = {}) => { const initComponent = (props = {}) => {
wrapper = shallowMount(AuditLogApp, { wrapper = shallowMount(AuditLogApp, {
...@@ -15,13 +18,12 @@ describe('AuditLogApp', () => { ...@@ -15,13 +18,12 @@ describe('AuditLogApp', () => {
formPath: 'form/path', formPath: 'form/path',
isLastPage: true, isLastPage: true,
dataQaSelector: 'qa_selector', dataQaSelector: 'qa_selector',
enabledTokenTypes,
events, events,
...props, ...props,
}, },
stubs: { stubs: {
AuditLogFilter: { AuditLogFilter,
template: `<div class="audit-log-filter"></div>`,
},
}, },
}); });
}; };
...@@ -48,5 +50,9 @@ describe('AuditLogApp', () => { ...@@ -48,5 +50,9 @@ describe('AuditLogApp', () => {
it('passes its events property to the logs table', () => { it('passes its events property to the logs table', () => {
expect(wrapper.find(LogsTable).props('events')).toEqual(events); expect(wrapper.find(LogsTable).props('events')).toEqual(events);
}); });
it('passes its avilable token types to the logs filter', () => {
expect(wrapper.find(AuditLogFilter).props('enabledTokenTypes')).toEqual(enabledTokenTypes);
});
}); });
}); });
import { sample } from 'lodash';
import { AVAILABLE_TOKEN_TYPES } from 'ee/audit_logs/constants';
import { availableTokensValidator } from 'ee/audit_logs/validators';
describe('availableTokensValidator', () => {
it('returns true when the input contains an available token type', () => {
const input = [sample(AVAILABLE_TOKEN_TYPES)];
expect(availableTokensValidator(input)).toEqual(true);
});
it('returns false when the input contains an unavailable token type', () => {
const input = ['InvalidType'];
expect(availableTokensValidator(input)).toEqual(false);
});
});
...@@ -5,17 +5,10 @@ require 'spec_helper' ...@@ -5,17 +5,10 @@ require 'spec_helper'
describe AuditLogsHelper do describe AuditLogsHelper do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
describe '#audit_entity_type_label' do describe '#admin_audit_log_token_types' do
where(:label, :result) do it 'returns the available tokens' do
nil | 'All Events' available_tokens = %w[User Group Project]
'All' | 'All Events' expect(admin_audit_log_token_types).to eq(available_tokens)
'User' | 'User Events'
'Group' | 'Group Events'
'Project' | 'Project Events'
end
with_them do
it { expect(audit_entity_type_label(label)).to eq(result) }
end end
end end
end end
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