Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123315
D3374.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Subscribers
None
D3374.diff
View Options
diff --git a/cypress/integration/deposit-admin.spec.js b/cypress/integration/deposit-admin.spec.js
--- a/cypress/integration/deposit-admin.spec.js
+++ b/cypress/integration/deposit-admin.spec.js
@@ -49,151 +49,6 @@
});
- it('Should filter out deposits matching excluding pattern from display', function() {
- cy.adminLogin();
- cy.visit(this.Urls.admin_deposit());
-
- cy.server();
-
- // entry supposed to be excluded from the display by default
- let extraDeposit = {
- 'id': 10,
- 'external_id': 'check-deposit-3',
- 'reception_date': '2020-05-18T11:20:16Z',
- 'status': 'done',
- 'status_detail': null,
- 'swh_id': 'swh:1:dir:fb234417',
- 'swh_id_context': 'swh:1:dir:fb234417;origin=https://w.s.o/c-d-3;visit=swh:1:snp:181417fb;anchor=swh:1:rev:3d166604;path=/'
- };
-
- // of course, that's how to copy a list (an "array")
- let testDeposits = responseDeposits.slice();
- // and add a new element to that array by mutating it...
- testDeposits.push(extraDeposit);
- expectedOrigins[10] = 'https://w.s.o/c-d-3';
-
- // ensure we don't touch the original reference
- expect(responseDeposits.length).to.be.equal(3);
- expect(testDeposits.length).to.be.equal(4);
-
- cy.route({
- method: 'GET',
- url: `${this.Urls.admin_deposit_list()}**`,
- response: {
- 'draw': 10,
- 'recordsTotal': testDeposits.length,
- 'recordsFiltered': testDeposits.length,
- 'data': testDeposits
- }
- }).as('listDeposits');
-
- cy.location('pathname')
- .should('be.equal', this.Urls.admin_deposit());
- cy.url().should('include', '/admin/deposit');
-
- cy.get('#swh-admin-deposit-list')
- .should('exist');
-
- cy.wait('@listDeposits').then((xhr) => {
- let deposits = xhr.response.body.data;
- expect(deposits.length).to.equal(testDeposits.length);
-
- cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows');
-
- // only 2 entries
- cy.get('@rows').each((row, idx, collection) => {
- let deposit = deposits[idx];
- let responseDeposit = testDeposits[idx];
- cy.log('deposit', deposit);
- cy.log('responseDeposit', responseDeposit);
- expect(deposit.id).to.be.equal(responseDeposit['id']);
- expect(deposit.external_id).to.be.equal(responseDeposit['external_id']);
- expect(deposit.status).to.be.equal(responseDeposit['status']);
- expect(deposit.status_detail).to.be.equal(responseDeposit['status_detail']);
- expect(deposit.swh_id).to.be.equal(responseDeposit['swh_id']);
- expect(deposit.swh_id_context).to.be.equal(responseDeposit['swh_id_context']);
-
- let expectedOrigin = expectedOrigins[deposit.id];
-
- // part of the data, but it should not be displayed (got filtered out)
- if (deposit.external_id === 'check-deposit-3') {
- cy.contains(deposit.status).should('not.be.visible');
- cy.contains(deposit.status_detail).should('not.be.visible');
- cy.contains(deposit.external_id).should('not.be.visible');
- cy.contains(expectedOrigin).should('not.be.visible');
- cy.contains(deposit.swh_id).should('not.be.visible');
- cy.contains(deposit.swh_id_context).should('not.be.visible');
- } else {
- expect(deposit.external_id).to.be.not.equal('check-deposit-3');
- cy.contains(deposit.id).should('be.visible');
- if (deposit.status !== 'rejected') {
- cy.contains(deposit.external_id).should('not.be.visible');
- cy.contains(expectedOrigin).should('be.visible');
- // ensure it's in the dom
- }
- cy.contains(deposit.status).should('be.visible');
- // those are hidden by default, so now visible
- if (deposit.status_detail !== null) {
- cy.contains(deposit.status_detail).should('not.be.visible');
- }
-
- // those are hidden by default
- if (deposit.swh_id !== null) {
- cy.contains(deposit.swh_id).should('not.be.visible');
- cy.contains(deposit.swh_id_context).should('not.be.visible');
- }
- }
- });
-
- // toggling all links and ensure, the previous checks are inverted
- cy.get('a.toggle-col').click({'multiple': true}).then(() => {
- cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows');
-
- cy.get('@rows').should('have.length', 3);
-
- cy.get('@rows').each((row, idx, collection) => {
- let deposit = deposits[idx];
- let expectedOrigin = expectedOrigins[deposit.id];
-
- // filtered out deposit
- if (deposit.external_id === 'check-deposit-3') {
- cy.contains(deposit.status).should('not.be.visible');
- cy.contains(deposit.status_detail).should('not.be.visible');
- cy.contains(deposit.external_id).should('not.be.visible');
- cy.contains(expectedOrigin).should('not.be.visible');
- cy.contains(deposit.swh_id).should('not.be.visible');
- cy.contains(deposit.swh_id_context).should('not.be.visible');
- } else {
- expect(deposit.external_id).to.be.not.equal('check-deposit-3');
- // ensure it's in the dom
- cy.contains(deposit.id).should('not.be.visible');
- if (deposit.status !== 'rejected') {
- cy.contains(deposit.external_id).should('not.be.visible');
- expect(row).to.contain(expectedOrigin);
- }
-
- expect(row).to.not.contain(deposit.status);
- // those are hidden by default, so now visible
- if (deposit.status_detail !== null) {
- cy.contains(deposit.status_detail).should('be.visible');
- }
-
- // those are hidden by default, so now they should be visible
- if (deposit.swh_id !== null) {
- cy.contains(deposit.swh_id).should('be.visible');
- cy.contains(deposit.swh_id_context).should('be.visible');
- }
- }
- });
- });
-
- cy.get('#swh-admin-deposit-list-error')
- .should('not.contain',
- 'An error occurred while retrieving the list of deposits');
- });
-
- });
-
it('Should display properly entries', function() {
cy.adminLogin();
cy.visit(this.Urls.admin_deposit());
diff --git a/swh/web/admin/deposit.py b/swh/web/admin/deposit.py
--- a/swh/web/admin/deposit.py
+++ b/swh/web/admin/deposit.py
@@ -37,7 +37,6 @@
deposits_list_auth = HTTPBasicAuth(
config["private_api_user"], config["private_api_password"]
)
-
try:
nb_deposits = requests.get(
"%s?page_size=1" % deposits_list_url, auth=deposits_list_auth, timeout=30
@@ -65,6 +64,17 @@
)
]
+ exclude_pattern = request.GET.get("excludePattern")
+ if exclude_pattern:
+ deposits = [
+ d
+ for d in deposits
+ if all(
+ exclude_pattern.lower() not in val
+ for val in [str(v).lower() for v in d.values()]
+ )
+ ]
+
column_order = request.GET["order[0][column]"]
field_order = request.GET["columns[%s][name]" % column_order]
order_dir = request.GET["order[0][dir]"]
diff --git a/swh/web/assets/src/bundles/admin/deposit.js b/swh/web/assets/src/bundles/admin/deposit.js
--- a/swh/web/assets/src/bundles/admin/deposit.js
+++ b/swh/web/assets/src/bundles/admin/deposit.js
@@ -15,30 +15,6 @@
return data;
}
-function filterDataWithExcludePattern(data, excludePattern) {
- /* Return true if the data is to be filtered, false otherwise.
-
- Args:
- data (dict): row dict data
- excludePattern (str): pattern to lookup in data columns
-
- Returns:
- true if the data is to be excluded (because it matches), false otherwise
-
- */
- if (excludePattern === '') {
- return false; // otherwise, everything gets excluded
- }
- for (const key in data) {
- let value = data[key];
- if ((typeof value === 'string' || value instanceof String) &&
- value.search(excludePattern) !== -1) {
- return true; // exclude the data from filtering
- }
- }
- return false;
-}
-
export function initDepositAdmin() {
let depositsTable;
$(document).ready(() => {
@@ -58,39 +34,15 @@
// i: (i)nfo
// p: (p)agination
// see https://datatables.net/examples/basic_init/dom.html
- dom: '<<f<"#list-exclude">l>rt<"bottom"ip>>',
+ dom: '<<"d-flex justify-content-between align-items-center"f' +
+ '<"#list-exclude">l>rt<"bottom"ip>>',
// div#list-exclude is a custom filter added next to dataTable
// initialization below through js dom manipulation, see
// https://datatables.net/examples/advanced_init/dom_toolbar.html
ajax: {
url: Urls.admin_deposit_list(),
- // filtering data set depending on the exclude search input
- dataFilter: function(dataResponse) {
- /* Filter out data returned by the server to exclude entries
- matching the exclude pattern.
-
- Args
- dataResponse (str): the json response in string
-
- Returns:
- json response altered (in string)
- */
- //
- let data = jQuery.parseJSON(dataResponse);
- let excludePattern = $('#swh-admin-deposit-list-exclude-filter').val();
- let recordsFiltered = 0;
- let filteredData = [];
- for (const row of data.data) {
- if (filterDataWithExcludePattern(row, excludePattern)) {
- recordsFiltered += 1;
- } else {
- filteredData.push(row);
- }
- }
- // update data values
- data['recordsFiltered'] = recordsFiltered;
- data['data'] = filteredData;
- return JSON.stringify(data);
+ data: d => {
+ d.excludePattern = $('#swh-admin-deposit-list-exclude-filter').val();
}
},
columns: [
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 18 2024, 5:22 PM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215868
Attached To
D3374: admin/deposit: Filter out deposit entries server side
Event Timeline
Log In to Comment