Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cb4e02ae
Commit
cb4e02ae
authored
Oct 31, 2019
by
Dmitriy Zaporozhets
Committed by
Douglas Barbosa Alexandre
Oct 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add before/after filter to admin audit events UI
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
5ea88bf9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
99 additions
and
1 deletion
+99
-1
ee/app/controllers/admin/audit_logs_controller.rb
ee/app/controllers/admin/audit_logs_controller.rb
+15
-1
ee/app/views/admin/audit_logs/index.html.haml
ee/app/views/admin/audit_logs/index.html.haml
+14
-0
ee/changelogs/unreleased/dz-filter-audit-events.yml
ee/changelogs/unreleased/dz-filter-audit-events.yml
+5
-0
ee/spec/features/admin/admin_audit_logs_spec.rb
ee/spec/features/admin/admin_audit_logs_spec.rb
+42
-0
lib/gitlab/regex.rb
lib/gitlab/regex.rb
+4
-0
locale/gitlab.pot
locale/gitlab.pot
+9
-0
spec/lib/gitlab/regex_spec.rb
spec/lib/gitlab/regex_spec.rb
+10
-0
No files found.
ee/app/controllers/admin/audit_logs_controller.rb
View file @
cb4e02ae
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
class
Admin::AuditLogsController
<
Admin
::
ApplicationController
class
Admin::AuditLogsController
<
Admin
::
ApplicationController
before_action
:check_license_admin_audit_log_available!
before_action
:check_license_admin_audit_log_available!
before_action
:validate_date_params
PER_PAGE
=
25
PER_PAGE
=
25
def
index
def
index
...
@@ -18,11 +20,23 @@ class Admin::AuditLogsController < Admin::ApplicationController
...
@@ -18,11 +20,23 @@ class Admin::AuditLogsController < Admin::ApplicationController
end
end
end
end
private
def
audit_logs_params
def
audit_logs_params
params
.
permit
(
:entity_type
,
:entity_id
)
params
.
permit
(
:entity_type
,
:entity_id
,
:created_before
,
:created_after
)
end
end
def
check_license_admin_audit_log_available!
def
check_license_admin_audit_log_available!
render_404
unless
License
.
feature_available?
(
:admin_audit_log
)
render_404
unless
License
.
feature_available?
(
:admin_audit_log
)
end
end
def
validate_date_params
unless
valid_utc_date?
(
params
[
:created_before
])
&&
valid_utc_date?
(
params
[
:created_after
])
flash
[
:alert
]
=
_
(
'Invalid date format. Please use UTC format as YYYY-MM-DD'
)
end
end
def
valid_utc_date?
(
date
)
date
.
blank?
||
date
=~
Gitlab
::
Regex
.
utc_date_regex
end
end
end
ee/app/views/admin/audit_logs/index.html.haml
View file @
cb4e02ae
...
@@ -41,6 +41,20 @@
...
@@ -41,6 +41,20 @@
placeholder:
@entity
&
.
full_path
||
_
(
'Search groups'
),
idAttribute:
'id'
,
placeholder:
@entity
&
.
full_path
||
_
(
'Search groups'
),
idAttribute:
'id'
,
data:
{
order_by:
'last_activity_at'
,
idattribute:
'id'
,
all_available:
true
}
})
data:
{
order_by:
'last_activity_at'
,
idattribute:
'id'
,
all_available:
true
}
})
.prepend-top-10
.form-group
=
label_tag
:created_after
,
_
(
'Created after'
),
class:
'label-bold'
=
date_field_tag
:created_after
,
params
[
:created_after
],
class:
'form-control'
,
placeholder:
'YYYY-MM-DD'
.form-group
=
label_tag
:created_before
,
_
(
'Created before'
),
class:
'label-bold'
=
date_field_tag
:created_before
,
params
[
:created_before
],
class:
'form-control'
,
placeholder:
'YYYY-MM-DD'
=
submit_tag
_
(
'Search'
),
class:
'btn'
-
if
@events
.
present?
-
if
@events
.
present?
%table
#events-table
.table
%table
#events-table
.table
%thead
%thead
...
...
ee/changelogs/unreleased/dz-filter-audit-events.yml
0 → 100644
View file @
cb4e02ae
---
title
:
Add created_before/after filter to audit events
merge_request
:
19035
author
:
type
:
changed
ee/spec/features/admin/admin_audit_logs_spec.rb
View file @
cb4e02ae
...
@@ -106,6 +106,48 @@ describe 'Admin::AuditLogs', :js do
...
@@ -106,6 +106,48 @@ describe 'Admin::AuditLogs', :js do
expect
(
page
).
to
have_content
(
'Removed user access'
)
expect
(
page
).
to
have_content
(
'Removed user access'
)
end
end
end
end
describe
'filter by date'
,
js:
false
do
set
(
:audit_event_1
)
{
create
(
:user_audit_event
,
created_at:
5
.
days
.
ago
)
}
set
(
:audit_event_2
)
{
create
(
:user_audit_event
,
created_at:
3
.
days
.
ago
)
}
set
(
:audit_event_3
)
{
create
(
:user_audit_event
,
created_at:
1
.
day
.
ago
)
}
before
do
visit
admin_audit_logs_path
end
it
'shows only 2 days old events'
do
page
.
within
'.content'
do
fill_in
'Created after'
,
with:
4
.
days
.
ago
fill_in
'Created before'
,
with:
2
.
days
.
ago
click_button
'Search'
end
expect
(
page
).
to
have_content
(
audit_event_2
.
author_name
)
expect
(
page
).
not_to
have_content
(
audit_event_1
.
author_name
)
expect
(
page
).
not_to
have_content
(
audit_event_3
.
author_name
)
end
it
'shows only yesterday events'
do
page
.
within
'.content'
do
fill_in
'Created after'
,
with:
2
.
days
.
ago
click_button
'Search'
end
expect
(
page
).
to
have_content
(
audit_event_3
.
author_name
)
expect
(
page
).
not_to
have_content
(
audit_event_1
.
author_name
)
expect
(
page
).
not_to
have_content
(
audit_event_2
.
author_name
)
end
it
'shows a message if provided date is invalid'
do
page
.
within
'.content'
do
fill_in
'Created after'
,
with:
'12-345-6789'
click_button
'Search'
end
expect
(
page
).
to
have_content
(
'Invalid date format. Please use UTC format as YYYY-MM-DD'
)
end
end
end
end
def
filter_by_type
(
type
)
def
filter_by_type
(
type
)
...
...
lib/gitlab/regex.rb
View file @
cb4e02ae
...
@@ -128,6 +128,10 @@ module Gitlab
...
@@ -128,6 +128,10 @@ module Gitlab
def
aws_arn_regex_message
def
aws_arn_regex_message
"must be a valid Amazon Resource Name"
"must be a valid Amazon Resource Name"
end
end
def
utc_date_regex
@utc_date_regex
||=
/\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/
.
freeze
end
end
end
end
end
...
...
locale/gitlab.pot
View file @
cb4e02ae
...
@@ -4801,6 +4801,12 @@ msgstr ""
...
@@ -4801,6 +4801,12 @@ msgstr ""
msgid "Created a branch and a merge request to resolve this issue."
msgid "Created a branch and a merge request to resolve this issue."
msgstr ""
msgstr ""
msgid "Created after"
msgstr ""
msgid "Created before"
msgstr ""
msgid "Created branch '%{branch_name}' and a merge request to resolve this issue."
msgid "Created branch '%{branch_name}' and a merge request to resolve this issue."
msgstr ""
msgstr ""
...
@@ -9153,6 +9159,9 @@ msgstr ""
...
@@ -9153,6 +9159,9 @@ msgstr ""
msgid "Invalid date"
msgid "Invalid date"
msgstr ""
msgstr ""
msgid "Invalid date format. Please use UTC format as YYYY-MM-DD"
msgstr ""
msgid "Invalid feature"
msgid "Invalid feature"
msgstr ""
msgstr ""
...
...
spec/lib/gitlab/regex_spec.rb
View file @
cb4e02ae
...
@@ -75,4 +75,14 @@ describe Gitlab::Regex do
...
@@ -75,4 +75,14 @@ describe Gitlab::Regex do
it
{
is_expected
.
not_to
match
(
'123456789012'
)
}
it
{
is_expected
.
not_to
match
(
'123456789012'
)
}
it
{
is_expected
.
not_to
match
(
'role/role-name'
)
}
it
{
is_expected
.
not_to
match
(
'role/role-name'
)
}
end
end
describe
'.utc_date_regex'
do
subject
{
described_class
.
utc_date_regex
}
it
{
is_expected
.
to
match
(
'2019-10-20'
)
}
it
{
is_expected
.
to
match
(
'1990-01-01'
)
}
it
{
is_expected
.
not_to
match
(
'11-1234-90'
)
}
it
{
is_expected
.
not_to
match
(
'aa-1234-cc'
)
}
it
{
is_expected
.
not_to
match
(
'9/9/2018'
)
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment