Просмотр исходного кода

Merge pull request #5590 from overleaf/tm-show-current-session-2

Show current session on user sessions page

GitOrigin-RevId: fd748207905f600ca3102db6a208a994b089ca97
Thomas 4 лет назад
Родитель
Сommit
307e151d6d

+ 5 - 0
services/web/app/src/Features/User/UserPagesController.js

@@ -137,6 +137,10 @@ const UserPagesController = {
   sessionsPage(req, res, next) {
     const user = SessionManager.getSessionUser(req.session)
     logger.log({ userId: user._id }, 'loading sessions page')
+    const currentSession = {
+      ip_address: user.ip_address,
+      session_created: user.session_created,
+    }
     UserSessionsManager.getAllUserSessions(
       user,
       [req.sessionID],
@@ -149,6 +153,7 @@ const UserPagesController = {
         }
         res.render('user/sessions', {
           title: 'sessions',
+          currentSession,
           sessions,
         })
       }

+ 13 - 0
services/web/app/views/user/sessions.pug

@@ -9,6 +9,19 @@ block content
 						.page-header
 							h1  #{translate("your_sessions")}
 
+						if currentSession.ip_address && currentSession.session_created
+							h3 #{translate("current_session")}
+							div
+								table.table.table-striped
+									thead
+										tr
+											th #{translate("ip_address")}
+											th #{translate("session_created_at")}
+										tr
+											td #{currentSession.ip_address}
+											td #{moment(currentSession.session_created).utc().format('Do MMM YYYY, h:mm a')} UTC
+
+						h3 #{translate("other_sessions")}
 						div
 							p.small
 								| !{translate("clear_sessions_description")}

+ 2 - 0
services/web/locales/en.json

@@ -625,6 +625,8 @@
   "clear_sessions_success": "Sessions Cleared",
   "sessions": "Sessions",
   "manage_sessions": "Manage Your Sessions",
+  "current_session": "Current Session",
+  "other_sessions": "Other Sessions",
   "syntax_validation": "Code check",
   "history": "History",
   "joining": "Joining",

+ 13 - 0
services/web/test/unit/src/User/UserPagesControllerTests.js

@@ -35,6 +35,8 @@ describe('UserPagesController', function () {
       _id: (this.user_id = 'kwjewkl'),
       features: {},
       email: 'joe@example.com',
+      ip_address: '1.1.1.1',
+      session_created: 'timestamp',
       thirdPartyIdentifiers: [
         {
           providerId: 'google',
@@ -168,6 +170,17 @@ describe('UserPagesController', function () {
       return this.UserPagesController.sessionsPage(this.req, this.res)
     })
 
+    it('should include current session data in the view', function (done) {
+      this.res.render = (page, opts) => {
+        expect(opts.currentSession).to.deep.equal({
+          ip_address: '1.1.1.1',
+          session_created: 'timestamp',
+        })
+        return done()
+      }
+      return this.UserPagesController.sessionsPage(this.req, this.res)
+    })
+
     it('should have called getAllUserSessions', function (done) {
       this.res.render = page => {
         this.UserSessionsManager.getAllUserSessions.callCount.should.equal(1)