Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 7b2caad

Browse files
committed
webui: Ensure Save/Delete buttons are only shown to database owner
We probably want to allow anyone with write access to see and use them, but this is a reasonable starting point
1 parent 80d81d6 commit 7b2caad

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

cypress/e2e/1-webui/visualisation.cy.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,40 @@ describe('visualisation', () => {
322322
// Switch back to the default user
323323
cy.request('/x/test/switchdefault')
324324
})
325+
326+
// Ensure the save and delete buttons are only shown to the database owner
327+
it('Ensure save/delete buttons are only shown to database owner', () => {
328+
// Switch to a different user
329+
cy.request('/x/test/switchfirst')
330+
331+
// Load a public page
332+
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
333+
334+
// Test if the Save and Delete fields are visible. They shouldn't be
335+
cy.get('[data-cy="savebtn"').should('not.exist')
336+
cy.get('[data-cy="nameinput"').should('not.exist')
337+
cy.get('[data-cy="delvisbtn"').should('not.exist')
338+
339+
// Log out
340+
cy.request('/x/test/logout')
341+
342+
// Reload the page
343+
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
344+
345+
// Test if the Save and Delete fields are visible. They shouldn't be
346+
cy.get('[data-cy="savebtn"').should('not.exist')
347+
cy.get('[data-cy="nameinput"').should('not.exist')
348+
cy.get('[data-cy="delvisbtn"').should('not.exist')
349+
350+
// Switch back to the default user
351+
cy.request('/x/test/switchdefault')
352+
353+
// Reload the page again
354+
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
355+
356+
// Ensure the Save and Delete fields are visible. They should be this time
357+
cy.get('[data-cy="savebtn"').should('exist')
358+
cy.get('[data-cy="nameinput"').should('exist')
359+
cy.get('[data-cy="delvisbtn"').should('exist')
360+
})
325361
})

webui/templates/visualise.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@
166166
<input type="submit" class="btn" value="Download as CSV" ng-click="downloadResults()" data-cy="downcsvbtn">
167167
<input type="submit" class="btn" value="Format SQL" ng-click="formatSQL()" data-cy="formatsqlbtn">
168168
<input type="submit" class="btn btn-success" value="Run SQL" ng-click="execSQL()" data-cy="runsqlbtn">
169-
<input type="submit" class="btn btn-primary" value="Save as:" ng-click="saveAs()" data-cy="savebtn">
170-
<input type="text" id="savename" value="default" data-cy="nameinput">
171-
<input type="submit" class="btn btn-danger" value="Delete" ng-click="deleteVis()" data-cy="delvisbtn">
169+
[[ if eq .PageMeta.LoggedInUser .DB.Info.Owner ]]
170+
<input type="submit" class="btn btn-primary" value="Save as:" ng-click="saveAs()" data-cy="savebtn">
171+
<input type="text" id="savename" value="default" data-cy="nameinput">
172+
<input type="submit" class="btn btn-danger" value="Delete" ng-click="deleteVis()" data-cy="delvisbtn">
173+
[[ end ]]
172174
</div>
173175
<div class="row">
174176
<div class="col-md-2">&nbsp;</div>

0 commit comments

Comments
 (0)