Skip to content

Commit

Permalink
Merge branch 'main' into mygrants
Browse files Browse the repository at this point in the history
  • Loading branch information
mayabose authored Jun 20, 2024
2 parents d80de97 + 84e605a commit ca1389a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 65 deletions.
40 changes: 40 additions & 0 deletions packages/server/__tests__/api/grants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ describe('`/api/grants` endpoint', () => {
context('GET /api/grants/:grantId/assign/agencies', () => {
const assignedEndpoint = `335255/assign/agencies`;
context('by a user with admin role', () => {
const assignedBy = {
NV1: {
assigned_by_name: 'nv.gov Admin User 1',
assigned_by_email: '[email protected]',
assigned_by_avatar_color: '#198754',
},
NV2: {
assigned_by_name: 'nv.gov User 2',
assigned_by_email: '[email protected]',
assigned_by_avatar_color: '#FD7E14',
},
};
let response;
let json;
before(async () => {
Expand Down Expand Up @@ -143,8 +155,28 @@ describe('`/api/grants` endpoint', () => {
const badResponse = await fetchApi(`/grants/${assignedEndpoint}`, agencies.offLimits, fetchOptions.admin);
expect(badResponse.statusText).to.equal('Forbidden');
});
it('includes assigned by information for the grant to an agency', async () => {
expect(json.find((a) => a.assigned_by_name === assignedBy.NV1.assigned_by_name)).to.be.ok;
expect(json.find((a) => a.assigned_by_name === assignedBy.NV2.assigned_by_name)).to.be.ok;
expect(json.find((a) => a.assigned_by_email === assignedBy.NV1.assigned_by_email)).to.be.ok;
expect(json.find((a) => a.assigned_by_email === assignedBy.NV2.assigned_by_email)).to.be.ok;
expect(json.find((a) => a.assigned_by_avatar_color === assignedBy.NV1.assigned_by_avatar_color)).to.be.ok;
expect(json.find((a) => a.assigned_by_avatar_color === assignedBy.NV2.assigned_by_avatar_color)).to.be.ok;
});
});
context('by a user with staff role', () => {
const assignedBy = {
NV1: {
assigned_by_name: 'nv.gov Admin User 1',
assigned_by_email: '[email protected]',
assigned_by_avatar_color: '#198754',
},
NV2: {
assigned_by_name: 'nv.gov User 2',
assigned_by_email: '[email protected]',
assigned_by_avatar_color: '#FD7E14',
},
};
let response;
let json;
before(async () => {
Expand All @@ -167,6 +199,14 @@ describe('`/api/grants` endpoint', () => {
const badResponse = await fetchApi(`/grants/${assignedEndpoint}`, agencies.ownSub, fetchOptions.staff);
expect(badResponse.statusText).to.equal('Forbidden');
});
it('includes assigned by information for the grant to an agency', async () => {
expect(json.find((a) => a.assigned_by_name === assignedBy.NV1.assigned_by_name)).to.be.ok;
expect(json.find((a) => a.assigned_by_name === assignedBy.NV2.assigned_by_name)).to.be.ok;
expect(json.find((a) => a.assigned_by_email === assignedBy.NV1.assigned_by_email)).to.be.ok;
expect(json.find((a) => a.assigned_by_email === assignedBy.NV2.assigned_by_email)).to.be.ok;
expect(json.find((a) => a.assigned_by_avatar_color === assignedBy.NV1.assigned_by_avatar_color)).to.be.ok;
expect(json.find((a) => a.assigned_by_avatar_color === assignedBy.NV2.assigned_by_avatar_color)).to.be.ok;
});
});
context('by a user with admin role in another organization', () => {
it('forbids requests for any agency outside of the main agency hierarchy', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/server/seeds/dev/ref/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,18 +1335,22 @@ const assignedGrantsAgency = [
{
grant_id: grants[0].grant_id,
agency_id: usdr,
assigned_by: 1,
},
{
grant_id: grants[0].grant_id,
agency_id: asd,
assigned_by: 13,
},
{
grant_id: grants[0].grant_id,
agency_id: nevada,
assigned_by: 7,
},
{
grant_id: grants[1].grant_id,
agency_id: nevada,
assigned_by: 6,
},
];

Expand Down
20 changes: 20 additions & 0 deletions packages/server/seeds/dev/ref/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#198754',

},
{
id: 2,
Expand All @@ -34,6 +36,8 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E14',

},
{
id: 3,
Expand All @@ -42,6 +46,7 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E17',
},
{
id: 4,
Expand All @@ -50,6 +55,7 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E15',
},
{
id: 5,
Expand All @@ -58,6 +64,7 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E16',
},
{
id: 6,
Expand All @@ -66,6 +73,7 @@ module.exports = [
agency_id: nevadaAgency.id,
role_id: staffRole.id,
tenant_id: nevadaenant.id,
avatar_color: '#ED7E2F',
},
{
id: 7,
Expand All @@ -74,6 +82,7 @@ module.exports = [
agency_id: nevadaAgency.id,
role_id: staffRole.id,
tenant_id: nevadaenant.id,
avatar_color: '#FD7E14',
},
{
id: 8,
Expand All @@ -82,6 +91,7 @@ module.exports = [
agency_id: nevadaAgency.id,
role_id: staffRole.id,
tenant_id: nevadaenant.id,
avatar_color: '#ED7E19',
},
{
id: 9,
Expand All @@ -90,6 +100,7 @@ module.exports = [
agency_id: procurementAgency.id,
role_id: staffRole.id,
tenant_id: procurementTenant.id,
avatar_color: '#ED7E1A',
},
{
id: 10,
Expand All @@ -98,6 +109,7 @@ module.exports = [
agency_id: procurementAgency.id,
role_id: staffRole.id,
tenant_id: procurementTenant.id,
avatar_color: '#ED7E1B',
},
{
id: 11,
Expand All @@ -106,6 +118,7 @@ module.exports = [
agency_id: procurementAgency.id,
role_id: staffRole.id,
tenant_id: procurementTenant.id,
avatar_color: '#ED7E1C',
},
{
id: 12,
Expand All @@ -114,6 +127,7 @@ module.exports = [
agency_id: dallasAgency.id,
role_id: adminRole.id,
tenant_id: dallasTenant.id,
avatar_color: '#ED7E1D',
},
{
id: 13,
Expand All @@ -122,6 +136,7 @@ module.exports = [
agency_id: nevadaAgency.id,
role_id: adminRole.id,
tenant_id: nevadaenant.id,
avatar_color: '#198754',
},
{
id: 14,
Expand All @@ -130,6 +145,7 @@ module.exports = [
agency_id: usdrSubAgency.id,
role_id: staffRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E1F',
},
{
id: 15,
Expand All @@ -138,6 +154,7 @@ module.exports = [
agency_id: usdrSubAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E20',
},
{
id: 16,
Expand All @@ -146,6 +163,7 @@ module.exports = [
agency_id: usdrSubAgency.id,
role_id: staffRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E21',
},
{
id: 17,
Expand All @@ -154,6 +172,7 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: adminRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E22',
},
{
id: 18,
Expand All @@ -162,5 +181,6 @@ module.exports = [
agency_id: usdrAgency.id,
role_id: staffRole.id,
tenant_id: usdrTenant.id,
avatar_color: '#ED7E23',
},
];
6 changes: 5 additions & 1 deletion packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,12 @@ async function markGrantAsViewed({ grantId, agencyId, userId }) {
function getGrantAssignedAgencies({ grantId, tenantId }) {
return knex(TABLES.assigned_grants_agency)
.join(TABLES.agencies, `${TABLES.agencies}.id`, '=', `${TABLES.assigned_grants_agency}.agency_id`)
.join(TABLES.users, `${TABLES.users}.id`, '=', `${TABLES.assigned_grants_agency}.assigned_by`)
.where({ grant_id: grantId })
.andWhere('tenant_id', tenantId);
.andWhere(`${TABLES.agencies}.tenant_id`, tenantId)
.select(`${TABLES.agencies}.*`)
.select(`${TABLES.assigned_grants_agency}.*`)
.select(`${TABLES.users}.name as assigned_by_name`, `${TABLES.users}.email as assigned_by_email`, `${TABLES.users}.avatar_color as assigned_by_avatar_color`);
}

function assignGrantsToAgencies({ grantId, agencyIds, userId }) {
Expand Down
Loading

0 comments on commit ca1389a

Please sign in to comment.