Skip to content

Commit

Permalink
Merge pull request #2727 from responsible-ai-collaborative/staging
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
kepae authored Apr 18, 2024
2 parents 7d8a4b7 + e834df1 commit 492efaf
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 24 deletions.
25 changes: 25 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ describe('Checklists App Form', () => {
});
});

maybeIt('Should trigger UI update on adding and removing tag', () => {
withLogin(({ user }) => {
interceptFindChecklist({
...defaultChecklist,
owner_id: user.userId,
});
interceptUpsertChecklist({});

cy.visit(url);

cy.get('#tags_methods_input').type('Transformer');
cy.get('#tags_methods').contains('Transformer').click();

cy.waitForStableDOM();

cy.get('details').should('exist');

cy.get('.rbt-close').click();

cy.waitForStableDOM();

cy.get('details').should('not.exist');
});
});

it('Should change sort order of risk items', () => {
cy.viewport(1920, 1080);

Expand Down
34 changes: 32 additions & 2 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
});
});

Expand Down Expand Up @@ -323,14 +329,38 @@ 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');

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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
);
});
});
});
63 changes: 63 additions & 0 deletions site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]' } }),
},
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('[email protected]');
});
});

it('Should return data if user is admin', () => {
global.context = {
// @ts-ignore
functions: {
execute: cy.stub().resolves({ data: { email: '[email protected]' } }),
},
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('[email protected]');
});
});
});
4 changes: 3 additions & 1 deletion site/gatsby-site/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,7 @@
"Name": "Nombre",
"Creation Date": "Fecha de Creación",
"Last modified": "Última modificación",
"Save": "Guardar"
"Save": "Guardar",
"Language": "Idioma",
"Read the Source": "Leer la Fuente"
}
3 changes: 2 additions & 1 deletion site/gatsby-site/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,6 @@
"Name": "Nom",
"Creation Date": "Date de création",
"Last modified": "Dernière modification",
"Save": "Enregistrer"
"Save": "Enregistrer",
"Read the Source": "Lire la source"
}
8 changes: 7 additions & 1 deletion site/gatsby-site/i18n/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,11 @@
"Name": "名前",
"Creation Date": "作成日",
"Last modified": "最終更新",
"Save": "保存"
"Save": "保存",
"results found": "件の結果が見つかりました",
"More filters": "さらにフィルタ",
"Fewer filters": "フィルタを減らす",
"Tags": "タグ",
"Language": "言語",
"Read the Source": "情報源を読む"
}
Original file line number Diff line number Diff line change
@@ -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}`);
}
};
4 changes: 2 additions & 2 deletions site/gatsby-site/src/components/discover/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function Actions({ item, toggleFilterByIncidentId = null }) {
titleId="report-source"
icon={faNewspaper}
className="fa-newspaper"
title="Read the Source"
title={t('Read the Source')}
/>
</WebArchiveLink>

Expand Down Expand Up @@ -203,7 +203,7 @@ export default function Actions({ item, toggleFilterByIncidentId = null }) {
titleId="report-hashtag"
icon={faHashtag}
className="fa-hashtag"
title="Incident ID"
title={t('Incident ID')}
/>
{item.incident_id}
</CustomButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}){' '}
<div className="inline-block">{collapsed ? <>+</> : <>-</>} </div>
</div>

Expand Down
23 changes: 16 additions & 7 deletions site/gatsby-site/src/components/layout/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import config from '../../../config';
import { LocalizedLink } from 'plugins/gatsby-theme-i18n';
import { Trans, useTranslation } from 'react-i18next';

function CommitSHA() {
return (
<div className="text-muted-gray text-xs" data-cy="commit-sha">
{process.env.GATSBY_COMMIT_SHA.toString().substring(0, 7)}
</div>
);
}

export default function Footer() {
const data = useStaticQuery(graphql`
query FooterQuery {
Expand Down Expand Up @@ -204,13 +212,13 @@ export default function Footer() {
</div>
)}

{i == footerContent.length - 1 && process.env.GATSBY_COMMIT_SHA && (
<li>
<div className="text-muted-gray text-xs" data-cy="commit-sha">
{process.env.GATSBY_COMMIT_SHA.toString().substring(0, 7)}
</div>
</li>
)}
{i == footerContent.length - 1 &&
allPrismicFooter.edges.length > 0 &&
process.env.GATSBY_COMMIT_SHA && (
<li>
<CommitSHA />
</li>
)}
</ul>
</div>
);
Expand Down Expand Up @@ -298,6 +306,7 @@ export default function Footer() {
/>
</a>
</div>
<CommitSHA />
</div>
)}
</footer>
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function CiteTemplate({
<div className="flex justify-between">
<Button
color={'gray'}
href={localizePath({ path: `/cite/${prevIncident}` })}
href={prevIncident && localizePath({ path: `/cite/${prevIncident}` })}
disabled={!prevIncident}
className="hover:no-underline"
>
Expand All @@ -361,7 +361,7 @@ function CiteTemplate({
</Button>
<Button
color={'gray'}
href={localizePath({ path: `/cite/${nextIncident}` })}
href={nextIncident && localizePath({ path: `/cite/${nextIncident}` })}
disabled={!nextIncident}
className="hover:no-underline"
>
Expand Down
21 changes: 15 additions & 6 deletions site/realm/functions/getUserAdminData.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}

0 comments on commit 492efaf

Please sign in to comment.