From bec06fe12b9175e0b9af9f344aa811c68e22dc37 Mon Sep 17 00:00:00 2001 From: Cesar Varela Date: Tue, 6 Feb 2024 18:25:29 -0300 Subject: [PATCH 1/9] Display largest count on classifications filter --- .../src/components/discover/filterTypes/Classifications.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/gatsby-site/src/components/discover/filterTypes/Classifications.js b/site/gatsby-site/src/components/discover/filterTypes/Classifications.js index 837523484c..2e0476cb89 100644 --- a/site/gatsby-site/src/components/discover/filterTypes/Classifications.js +++ b/site/gatsby-site/src/components/discover/filterTypes/Classifications.js @@ -29,7 +29,8 @@ function Attribute({ name, refinement, searchResults }) { tabIndex={0} onClick={() => setCollapsed((c) => !c)} > - {name} ({refinement.items.length}){' '} + {name} (~ + {refinement.items.reduce((a, c) => Math.max(a, c.count), refinement.items[0].count)}){' '}
{collapsed ? <>+ : <>-}
From 038639404ecdc277c2e7213fbc7704a5bd301ef0 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Fri, 15 Mar 2024 19:52:16 -0300 Subject: [PATCH 2/9] Disable Previous and Next incident buttons on first and last incidents --- .../cypress/e2e/integration/cite.cy.js | 34 +++++++++++++++++-- .../gatsby-site/src/templates/citeTemplate.js | 4 +-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/site/gatsby-site/cypress/e2e/integration/cite.cy.js b/site/gatsby-site/cypress/e2e/integration/cite.cy.js index 3699c3a130..2372f8dc80 100644 --- a/site/gatsby-site/cypress/e2e/integration/cite.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/cite.cy.js @@ -20,6 +20,8 @@ describe('Cite pages', () => { let user; + let lastIncidentId; + before('before', function () { // Skip all tests if the environment is empty since /cite/{incident_id} is not available Cypress.env('isEmptyEnvironment') && this.skip(); @@ -32,10 +34,14 @@ describe('Cite pages', () => { first_name last_name } + incidents(limit: 1, sortBy: INCIDENT_ID_DESC) { + incident_id + } } `, - }).then(({ data: { user: userData } }) => { + }).then(({ data: { user: userData, incidents: incidentsData } }) => { user = userData; + lastIncidentId = incidentsData[0].incident_id; }); }); @@ -323,7 +329,7 @@ describe('Cite pages', () => { cy.get(`.incident-ids-field [data-cy="token"]`).contains('10').should('be.visible'); }); - it('should render Next and Previous incident buttons', () => { + it('Should render Next and Previous incident buttons', () => { cy.visit(url); cy.contains('Next Incident').should('be.visible').should('have.attr', 'href', '/cite/11'); @@ -331,6 +337,30 @@ describe('Cite pages', () => { cy.contains('Previous Incident').should('be.visible').should('have.attr', 'href', '/cite/9'); }); + it('Should disable Previous and Next incident buttons on first and last incidents', () => { + cy.visit('/cite/1'); + + cy.contains('Previous Incident').within(($button) => { + cy.wrap($button).should('be.visible'); + cy.wrap($button).should('have.attr', 'disabled'); + cy.wrap($button).should('not.have.attr', 'href'); + }); + + cy.contains('Next Incident').should('be.visible').should('have.attr', 'href', '/cite/2'); + + cy.visit(`/cite/${lastIncidentId}`); + + cy.contains('Previous Incident') + .should('be.visible') + .should('have.attr', 'href', `/cite/${lastIncidentId - 1}`); + + cy.contains('Next Incident').within(($button) => { + cy.wrap($button).should('be.visible'); + cy.wrap($button).should('have.attr', 'disabled'); + cy.wrap($button).should('not.have.attr', 'href'); + }); + }); + maybeIt('Should show the edit incident form', () => { cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword')); diff --git a/site/gatsby-site/src/templates/citeTemplate.js b/site/gatsby-site/src/templates/citeTemplate.js index 76641c73a8..f94ddbafe3 100644 --- a/site/gatsby-site/src/templates/citeTemplate.js +++ b/site/gatsby-site/src/templates/citeTemplate.js @@ -352,7 +352,7 @@ function CiteTemplate({
)} - {i == footerContent.length - 1 && process.env.GATSBY_COMMIT_SHA && ( -
  • -
    - {process.env.GATSBY_COMMIT_SHA.toString().substring(0, 7)} -
    -
  • - )} + {i == footerContent.length - 1 && + allPrismicFooter.edges.length > 0 && + process.env.GATSBY_COMMIT_SHA && ( +
  • + +
  • + )} ); @@ -298,6 +306,7 @@ export default function Footer() { /> + )} From 9138d4e7fd0f228a31b357cd942264ecc18c620d Mon Sep 17 00:00:00 2001 From: Cesar Varela Date: Wed, 10 Apr 2024 15:51:11 -0300 Subject: [PATCH 7/9] Tighter user admin data permissions (#2726) --- .../e2e/unit/functions/getUserAdminData.cy.js | 63 +++++++++++++++++++ site/realm/functions/getUserAdminData.js | 21 +++++-- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js diff --git a/site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js b/site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js new file mode 100644 index 0000000000..1aec958d8e --- /dev/null +++ b/site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js @@ -0,0 +1,63 @@ +const getUserAdminData = require('../../../../../realm/functions/getUserAdminData'); + +describe('getUserAdminData', () => { + it('Should not return data if different user id and no permissions', () => { + global.context = { + // @ts-ignore + functions: { + execute: cy.stub().resolves({}), + }, + user: { + id: '2', + custom_data: { + roles: ['subscriber'], + }, + }, + }; + + cy.wrap(getUserAdminData({ userId: '1' })).then((response) => { + expect(global.context.functions.execute).to.not.called; + expect(response.email).to.be.null; + }); + }); + + it('Should return data if user id is the same as current user', () => { + global.context = { + // @ts-ignore + functions: { + execute: cy.stub().resolves({ data: { email: 'test@test.com' } }), + }, + user: { + id: '1', + custom_data: { + roles: ['subscriber'], + }, + }, + }; + + cy.wrap(getUserAdminData({ userId: '1' })).then((response) => { + expect(global.context.functions.execute).to.have.been.calledOnce; + expect(response.email).to.equal('test@test.com'); + }); + }); + + it('Should return data if user is admin', () => { + global.context = { + // @ts-ignore + functions: { + execute: cy.stub().resolves({ data: { email: 'test@test.com' } }), + }, + user: { + id: '1', + custom_data: { + roles: ['admin'], + }, + }, + }; + + cy.wrap(getUserAdminData({ userId: '3211231' })).then((response) => { + expect(global.context.functions.execute).to.have.been.calledOnce; + expect(response.email).to.equal('test@test.com'); + }); + }); +}); diff --git a/site/realm/functions/getUserAdminData.js b/site/realm/functions/getUserAdminData.js index 08e31dcd85..e72d8a2fd4 100644 --- a/site/realm/functions/getUserAdminData.js +++ b/site/realm/functions/getUserAdminData.js @@ -1,6 +1,6 @@ exports = async (source) => { - const userApiResponse = await context.functions.execute('apiRequest', { method: 'GET', path: `/users/${source.userId}` }); + const { user } = context; const response = { email: null, @@ -9,13 +9,22 @@ exports = async (source) => { disabled: null, }; - if (userApiResponse.data) { + if (user.id === source.userId || user.custom_data.roles.includes('admin')) { - response.email = userApiResponse.data.email; - response.creationDate = new Date(userApiResponse.creation_date * 1000); - response.lastAuthenticationDate = new Date(userApiResponse.last_authentication_date * 1000); - response.disabled = userApiResponse.disabled; + const userApiResponse = await context.functions.execute('apiRequest', { method: 'GET', path: `/users/${source.userId}` }); + + if (userApiResponse.data) { + + response.email = userApiResponse.data.email; + response.creationDate = new Date(userApiResponse.creation_date * 1000); + response.lastAuthenticationDate = new Date(userApiResponse.last_authentication_date * 1000); + response.disabled = userApiResponse.disabled; + } } return response; }; + +if (typeof module === 'object') { + module.exports = exports; +} \ No newline at end of file From bdf947707fb80e152524e5dd877fb0a80265df10 Mon Sep 17 00:00:00 2001 From: Cesar Varela Date: Tue, 16 Apr 2024 17:20:04 -0300 Subject: [PATCH 8/9] Delete dummy translations --- ...4.16T20.04.34.delete-dummy-translations.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 site/gatsby-site/migrations/2024.04.16T20.04.34.delete-dummy-translations.js diff --git a/site/gatsby-site/migrations/2024.04.16T20.04.34.delete-dummy-translations.js b/site/gatsby-site/migrations/2024.04.16T20.04.34.delete-dummy-translations.js new file mode 100644 index 0000000000..3c31d0ba36 --- /dev/null +++ b/site/gatsby-site/migrations/2024.04.16T20.04.34.delete-dummy-translations.js @@ -0,0 +1,24 @@ +const languages = require('../i18n/config.json'); + +/** + * + * @param {{context: {client: import('mongodb').MongoClient}}} context + */ + +exports.up = async ({ context: { client } }) => { + const db = client.db('translations'); + + for (const language of languages) { + const name = `reports_${language.code}`; + + console.log(`Deleting dummy translations from ${name}`); + + const translations = db.collection(name); + + const result = await translations.deleteMany({ + text: /^translated-/, + }); + + console.log(`Deleted ${result.deletedCount} dummy translations for ${language.code}`); + } +}; From e10e44078755439e6fe8e67f66b8023490a2dc2e Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Wed, 17 Apr 2024 19:32:45 -0300 Subject: [PATCH 9/9] Fix Facebook share test --- .../cypress/e2e/integration/socialShareButtons.cy.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/site/gatsby-site/cypress/e2e/integration/socialShareButtons.cy.js b/site/gatsby-site/cypress/e2e/integration/socialShareButtons.cy.js index 815c784dff..3f960c0c42 100644 --- a/site/gatsby-site/cypress/e2e/integration/socialShareButtons.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/socialShareButtons.cy.js @@ -116,7 +116,14 @@ describe('Social Share buttons on pages', { retries: { runMode: 4 } }, () => { cy.get('[data-cy=btn-share-facebook]').first().click(); cy.get('@popup_facebook', { timeout: 8000 }).should('be.called'); - cy.url().should('contain', `https://www.facebook.com/sharer/sharer.php?u=${canonicalUrl}`); + // Take into consideration that the Facebook share button can open a new window with two different URLs depending on the environment + cy.url().should( + 'satisfy', + (url) => + (url.includes('https://www.facebook.com/login.php') && + url.includes('next=https%3A%2F%2Fwww.facebook.com%2Fsharer%2Fsharer.php')) || + url.includes(`https://www.facebook.com/sharer/sharer.php?u=${canonicalUrl}`) + ); }); }); });