-
Notifications
You must be signed in to change notification settings - Fork 0
Dashboard search, display most recent dashboards first, display who created dashboard #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ module.exports = ({ studioConnection }) => async function getDashboards(params) | |
|
|
||
| await authorize('Dashboard.getDashboards', roles); | ||
|
|
||
| const dashboards = await Dashboard.find(); | ||
| const dashboards = await Dashboard.find().sort({ createdAt: -1, _id: -1 }).lean(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For legacy dashboards that do not have Useful? React with 👍 / 👎. |
||
|
|
||
| return { dashboards }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const mongoose = require('mongoose'); | ||
| const { actions, studioConnection } = require('./setup.test'); | ||
| const dashboardSchema = require('../backend/db/dashboardSchema'); | ||
|
|
||
| const Dashboard = studioConnection.model('__Studio_Dashboard', dashboardSchema, 'studio__dashboards'); | ||
|
|
||
| describe('Dashboard.getDashboards()', function() { | ||
| afterEach(async function() { | ||
| await Dashboard.deleteMany(); | ||
| }); | ||
|
|
||
| it('returns newest dashboards first with stored evaluation time', async function() { | ||
| const older = await Dashboard.create({ | ||
| title: 'Older', | ||
| description: 'First dashboard', | ||
| code: 'return 1;', | ||
| createdAt: new Date('2026-01-01T00:00:00.000Z'), | ||
| updatedAt: new Date('2026-01-01T00:00:00.000Z') | ||
| }); | ||
| const newer = await Dashboard.create({ | ||
| title: 'Newer', | ||
| description: 'Second dashboard', | ||
| code: 'return 2;', | ||
| createdAt: new Date('2026-01-02T00:00:00.000Z'), | ||
| updatedAt: new Date('2026-01-02T00:00:00.000Z'), | ||
| lastEvaluatedAt: new Date('2026-01-04T00:00:01.000Z') | ||
| }); | ||
|
|
||
| const res = await actions.Dashboard.getDashboards({ roles: ['dashboards'] }); | ||
|
|
||
| assert.deepStrictEqual(res.dashboards.map(dashboard => dashboard.title), ['Newer', 'Older']); | ||
| assert.strictEqual( | ||
| new Date(res.dashboards[0].lastEvaluatedAt).toISOString(), | ||
| '2026-01-04T00:00:01.000Z' | ||
| ); | ||
| assert.strictEqual(res.dashboards[1].lastEvaluatedAt, undefined); | ||
| assert.strictEqual(older.title, 'Older'); | ||
| }); | ||
|
|
||
| it('derives createdAt from _id for legacy dashboards', async function() { | ||
| const dashboard = await Dashboard.create({ | ||
| title: 'Legacy', | ||
| code: 'return 1;' | ||
| }); | ||
| await Dashboard.collection.updateOne({ _id: dashboard._id }, { $unset: { createdAt: 1 } }); | ||
|
|
||
| const res = await actions.Dashboard.getDashboards({ roles: ['dashboards'] }); | ||
|
|
||
| assert.strictEqual(res.dashboards.length, 1); | ||
| assert.strictEqual( | ||
| new Date(res.dashboards[0].createdAt).toISOString(), | ||
| dashboard._id.getTimestamp().toISOString() | ||
| ); | ||
| }); | ||
|
|
||
| it('stores the creating user id when creating a dashboard', async function() { | ||
| const userId = new mongoose.Types.ObjectId(); | ||
|
|
||
| const res = await actions.Dashboard.createDashboard({ | ||
| title: 'Created By Test', | ||
| code: 'return 1;', | ||
| initiatedById: userId, | ||
| initiatedBy: { | ||
| name: 'Jane Doe', | ||
| email: 'jane@example.com' | ||
| }, | ||
| roles: ['member'] | ||
| }); | ||
|
|
||
| assert.strictEqual(res.dashboard.createdById.toString(), userId.toString()); | ||
| assert.deepStrictEqual(res.dashboard.createdBy.toObject(), { | ||
| name: 'Jane Doe', | ||
| email: 'jane@example.com' | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every dashboard creation now logs the full
paramsobject, which includes the dashboardcodeand the authenticated user's details when running with an API key. In production this can leak proprietary dashboard scripts or user PII into server logs, and the log line appears unrelated to the returned result.Useful? React with 👍 / 👎.