Skip to content

Commit 2fff9b7

Browse files
committed
auth logging UI
closes CNVS-6069 This modifies the "view notifications" ui in the admin tools to use user search, rather than just taking a canvas user id. It then generalizes that user+daterange search form and re-uses it to implement ui for viewing user login/logout audit logs. test plan: * Visit /accounts/X/admin_tools as a site admin, and verify that View Notifications still works * You should be able to search for users by id, name, email or sis id, just like the course roster page * Then you can select a date range and view their notification history * On the same page, test the new "Logging" tab, you will need the auditors cassandra keyspace enabled * Just like with notifications, search for a user and date range (date range depends on another commit) * You should then see the user's login/logout history * If an account admin without "view statistics" or "manage login" permissions visits the page, the "Logging" tab shouldn't appear Change-Id: I79b15a52b82f23b7fea8eeae2c50437762892ccf Reviewed-on: https://gerrit.instructure.com/22420 Reviewed-by: Brian Palmer <brianp@instructure.com> Product-Review: Brian Palmer <brianp@instructure.com> QA-Review: Brian Palmer <brianp@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
1 parent fa47cbb commit 2fff9b7

24 files changed

Lines changed: 460 additions & 122 deletions

app/coffeescripts/bundles/account_admin_tools.coffee

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,75 @@ require [
2121
'compiled/views/accounts/admin_tools/RestoreContentPaneView'
2222
'compiled/views/accounts/admin_tools/CourseSearchFormView'
2323
'compiled/views/accounts/admin_tools/CourseSearchResultsView'
24+
'compiled/views/InputFilterView'
25+
'compiled/views/accounts/UserView'
2426
'compiled/views/PaginatedCollectionView'
2527
'compiled/collections/CommMessageCollection'
28+
'compiled/collections/AccountUserCollection'
29+
'compiled/collections/AuthLoggingCollection'
2630
'compiled/views/accounts/admin_tools/CommMessagesContentPaneView'
27-
'compiled/views/accounts/admin_tools/CommMessagesSearchFormView'
31+
'compiled/views/accounts/admin_tools/AuthLoggingContentPaneView'
32+
'compiled/views/accounts/admin_tools/UserDateRangeSearchFormView'
2833
'compiled/views/accounts/admin_tools/CommMessageItemView'
34+
'compiled/views/accounts/admin_tools/AuthLoggingItemView'
2935
'jst/accounts/admin_tools/commMessagesSearchResults'
30-
], (CourseRestoreModel, AdminToolsView, RestoreContentPaneView, CourseSearchFormView, CourseSearchResultsView, PaginatedCollectionView, CommMessageCollection, CommMessagesContentPaneView, CommMessagesSearchFormView, CommMessageItemView, messagesSearchResultsTemplate) ->
36+
'jst/accounts/admin_tools/authLoggingSearchResults'
37+
'jst/accounts/usersList'
38+
], (CourseRestoreModel, AdminToolsView, RestoreContentPaneView, CourseSearchFormView, CourseSearchResultsView, InputFilterView, UserView, PaginatedCollectionView, CommMessageCollection, AccountUserCollection, AuthLoggingCollection, CommMessagesContentPaneView, AuthLoggingContentPaneView, UserDateRangeSearchFormView, CommMessageItemView, AuthLoggingItemView, messagesSearchResultsTemplate, authLoggingResultsTemplate, usersTemplate) ->
3139
# This is used by admin tools to display search results
3240
restoreModel = new CourseRestoreModel account_id: ENV.ACCOUNT_ID
3341

3442
messages = new CommMessageCollection null,
3543
params: {perPage: 10}
36-
formView = new CommMessagesSearchFormView
37-
collection: messages
38-
resultsView = new PaginatedCollectionView
39-
template: messagesSearchResultsTemplate
40-
itemView: CommMessageItemView
41-
collection: messages
44+
users = new AccountUserCollection null,
45+
account_id: ENV.ACCOUNT_ID
4246
messagesContentView = new CommMessagesContentPaneView
43-
searchForm: formView
44-
resultsView: resultsView
47+
searchForm: new UserDateRangeSearchFormView
48+
formName: 'messages'
49+
inputFilterView: new InputFilterView
50+
collection: users
51+
usersView: new PaginatedCollectionView
52+
collection: users
53+
itemView: UserView
54+
buffer: 1000
55+
template: usersTemplate
56+
collection: messages
57+
resultsView: new PaginatedCollectionView
58+
template: messagesSearchResultsTemplate
59+
itemView: CommMessageItemView
60+
collection: messages
4561
collection: messages
62+
loggingEvents = new AuthLoggingCollection null
63+
loggingContentView = new AuthLoggingContentPaneView
64+
searchForm: new UserDateRangeSearchFormView
65+
formName: 'logging'
66+
inputFilterView: new InputFilterView
67+
collection: users
68+
usersView: new PaginatedCollectionView
69+
collection: users
70+
itemView: UserView
71+
buffer: 1000
72+
template: usersTemplate
73+
collection: loggingEvents
74+
resultsView: new PaginatedCollectionView
75+
template: authLoggingResultsTemplate
76+
itemView: AuthLoggingItemView
77+
collection: loggingEvents
78+
collection: loggingEvents
4679

4780
# Render tabs
4881
@app = new AdminToolsView
4982
el: "#content"
5083
tabs:
5184
courseRestore: ENV.PERMISSIONS.restore_course
5285
viewMessages: ENV.PERMISSIONS.view_messages
86+
authLogging: ENV.PERMISSIONS.auth_logging
5387
restoreContentPaneView: new RestoreContentPaneView
5488
courseSearchFormView: new CourseSearchFormView
5589
model: restoreModel
5690
courseSearchResultsView: new CourseSearchResultsView
5791
model: restoreModel
5892
messageContentPaneView: messagesContentView
93+
authLoggingContentPaneView: loggingContentView
5994

6095
@app.render()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define [
2+
'compiled/collections/PaginatedCollection'
3+
'compiled/models/AccountUser'
4+
], (PaginatedCollection, AccountUser) ->
5+
6+
class AccountUserCollection extends PaginatedCollection
7+
8+
model: AccountUser
9+
10+
##
11+
# The account id of this user collection
12+
13+
@optionProperty 'account_id'
14+
15+
url: ->
16+
"/api/v1/accounts/#{@options.account_id}/users"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (C) 2013 Instructure, Inc.
3+
#
4+
# This file is part of Canvas.
5+
#
6+
# Canvas is free software: you can redistribute it and/or modify it under
7+
# the terms of the GNU Affero General Public License as published by the Free
8+
# Software Foundation, version 3 of the License.
9+
#
10+
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12+
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13+
# details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License along
16+
# with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
define [
20+
'compiled/collections/PaginatedCollection'
21+
], (PaginatedCollection) ->
22+
23+
class AuthLoggingCollection extends PaginatedCollection
24+
url: ->
25+
"/api/v1/audit/authentication/users/#{@options.params.user_id}"
26+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define ['compiled/models/User'], (User) ->
2+
3+
class AccountUser extends User
4+
5+
defaults:
6+
avatar_url: '/images/messages/avatar-50.png'
7+

app/coffeescripts/views/CollectionView.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ define [
8888
# @api private
8989

9090
removePreviousItems: (models) =>
91-
@$list.children().each (index, el) =>
91+
@$list?.children().each (index, el) =>
9292
@$(el).data('view')?.remove()
9393

9494
renderOnReset: =>

app/coffeescripts/views/InputView.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define [
2525
@setupElement()
2626

2727
setupElement: ->
28-
@lastValue = @el.value
28+
@lastValue = @el?.value
2929
@modelAttribute = @$el.attr('name') or @options.modelAttribute
3030

3131
attach: ->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
define [
2+
'Backbone'
3+
'jst/accounts/user'
4+
], (Backbone, template) ->
5+
6+
class UserView extends Backbone.View
7+
8+
tagName: 'tr'
9+
10+
className: 'rosterUser al-hover-container'
11+
12+
template: template
13+
14+
events:
15+
'click': 'click'
16+
17+
attach: ->
18+
@model.collection.on 'selectedModelChange', @changeSelection
19+
20+
click: (e) =>
21+
e.preventDefault()
22+
@model.collection.trigger('selectedModelChange', @model)
23+
24+
changeSelection: (u) =>
25+
if u == @model
26+
setTimeout((() => @$el.addClass('selected')), 0)
27+

app/coffeescripts/views/accounts/admin_tools/AdminToolsView.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ define [
1717
# @api custom backbone
1818
@child 'restoreContentPaneView', '#restoreContentPane'
1919
@child 'messageContentPaneView', '#commMessagesPane'
20+
@child 'authLoggingContentPaneView', '#authLoggingPane'
2021
@optionProperty 'tabs'
2122

2223
template: template
@@ -33,5 +34,6 @@ define [
3334
json = super
3435
json.courseRestore = @tabs.courseRestore
3536
json.viewMessages = @tabs.viewMessages
37+
json.authLogging = @tabs.authLogging
3638
json
3739

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
define [
2+
'Backbone'
3+
'jquery'
4+
'jst/accounts/admin_tools/authLoggingContentPane'
5+
], (Backbone, $, template) ->
6+
class AuthLoggingContentPaneView extends Backbone.View
7+
@child 'searchForm', '#authLoggingSearchForm'
8+
@child 'resultsView', '#authLoggingSearchResults'
9+
10+
template: template
11+
12+
attach: ->
13+
@collection.on 'setParams', @fetch
14+
15+
fetch: =>
16+
@collection.fetch().fail @onFail
17+
18+
onFail: =>
19+
# Received a 404, empty the collection and don't let the paginated
20+
# view try to fetch more.
21+
@collection.reset()
22+
@resultsView.detachScroll()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
define [
2+
'Backbone'
3+
'jst/accounts/admin_tools/authLoggingItem'
4+
'i18n!auth_logging'
5+
], (Backbone, template, I18n) ->
6+
7+
class AuthLoggingItemView extends Backbone.View
8+
9+
tagName: 'tr'
10+
11+
className: 'logitem'
12+
13+
template: template
14+
15+
toJSON: ->
16+
json = super
17+
if json.event_type == "login"
18+
json.event = I18n.t("login", "LOGIN")
19+
else if json.event_type == "logout"
20+
json.event = I18n.t("logout", "LOGOUT")
21+
json

0 commit comments

Comments
 (0)