Skip to content

Commit

Permalink
Merge branch 'main' into as/add-local-auth-module
Browse files Browse the repository at this point in the history
  • Loading branch information
as1729 authored Mar 1, 2024
2 parents f42561d + a6ce263 commit be48b55
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 86 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
id-token: write
needs:
- validate
- build
uses: ./.github/workflows/aws-auth.yml
with:
aws-region: us-west-2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Warnings:
- You are about to drop the column `certifiedById` on the `Subrecipient` table. All the data in the column will be lost.
- You are about to drop the column `invalidatedById` on the `UploadValidation` table. All the data in the column will be lost.
- You are about to drop the column `validatedById` on the `UploadValidation` table. All the data in the column will be lost.
- You are about to drop the column `organizationId` on the `User` table. All the data in the column will be lost.
- Made the column `name` on table `User` required. This step will fail if there are existing NULL values in that column.
- Made the column `agencyId` on table `User` required. This step will fail if there are existing NULL values in that column.
- Made the column `role` on table `User` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "Subrecipient" DROP CONSTRAINT "Subrecipient_certifiedById_fkey";

-- DropForeignKey
ALTER TABLE "UploadValidation" DROP CONSTRAINT "UploadValidation_invalidatedById_fkey";

-- DropForeignKey
ALTER TABLE "UploadValidation" DROP CONSTRAINT "UploadValidation_validatedById_fkey";

-- DropForeignKey
ALTER TABLE "User" DROP CONSTRAINT "User_agencyId_fkey";

-- DropForeignKey
ALTER TABLE "User" DROP CONSTRAINT "User_organizationId_fkey";

-- AlterTable
ALTER TABLE "Subrecipient" DROP COLUMN "certifiedById";

-- AlterTable
ALTER TABLE "UploadValidation" DROP COLUMN "invalidatedById",
DROP COLUMN "validatedById";

-- AlterTable
ALTER TABLE "User" DROP COLUMN "organizationId",
ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT true,
ALTER COLUMN "name" SET NOT NULL,
ALTER COLUMN "agencyId" SET NOT NULL,
ALTER COLUMN "role" SET NOT NULL;

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_agencyId_fkey" FOREIGN KEY ("agencyId") REFERENCES "Agency"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
23 changes: 6 additions & 17 deletions api/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ model Agency {
model Organization {
id Int @id @default(autoincrement())
agencies Agency[]
users User[]
name String
reportingPeriods ReportingPeriod[]
uploads Upload[]
Expand All @@ -36,20 +35,16 @@ model Organization {

model User {
id Int @id @default(autoincrement())
email String
name String?
agencyId Int?
organizationId Int?
email String @unique
name String
agencyId Int
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6)
role Role?
agency Agency? @relation(fields: [agencyId], references: [id])
organization Organization? @relation(fields: [organizationId], references: [id])
role Role
isActive Boolean @default(true)
agency Agency @relation(fields: [agencyId], references: [id])
certified ReportingPeriod[]
uploaded Upload[]
validated UploadValidation[] @relation("ValidatedUploads")
invalidated UploadValidation[] @relation("InvalidatedUploads")
subrecipients Subrecipient[]
}

enum Role {
Expand Down Expand Up @@ -143,12 +138,8 @@ model UploadValidation {
inputTemplate InputTemplate @relation(fields: [inputTemplateId], references: [id])
validationResults Json? @db.JsonB
validatedAt DateTime? @db.Timestamptz(6)
validatedById Int?
validatedBy User? @relation("ValidatedUploads", fields: [validatedById], references: [id])
invalidationResults Json? @db.JsonB
invalidatedAt DateTime? @db.Timestamptz(6)
invalidatedById Int?
invalidatedBy User? @relation("InvalidatedUploads", fields: [invalidatedById], references: [id])
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6)
}
Expand All @@ -161,8 +152,6 @@ model Subrecipient {
startDate DateTime @db.Date
endDate DateTime @db.Date
certifiedAt DateTime? @db.Timestamptz(6)
certifiedById Int?
certifiedBy User? @relation(fields: [certifiedById], references: [id])
originationUploadId Int
originationUpload Upload @relation(fields: [originationUploadId], references: [id])
createdAt DateTime @default(now()) @db.Timestamptz(6)
Expand Down
6 changes: 0 additions & 6 deletions api/src/graphql/users.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ export const schema = gql`
email: String!
name: String
agencyId: Int
organizationId: Int!
createdAt: DateTime!
updatedAt: DateTime!
agency: Agency
organization: Organization!
role: RoleEnum
certified: [ReportingPeriod]!
uploaded: [Upload]!
validated: [UploadValidation]!
invalidated: [UploadValidation]!
}
type Query {
Expand All @@ -32,15 +28,13 @@ export const schema = gql`
email: String!
name: String
agencyId: Int
organizationId: Int
role: RoleEnum
}
input UpdateUserInput {
email: String
name: String
agencyId: Int
organizationId: Int
role: RoleEnum
}
Expand Down
12 changes: 8 additions & 4 deletions api/src/services/subrecipients/subrecipients.scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const standard = defineScenario<Prisma.SubrecipientCreateArgs>({
updatedAt: '2023-12-09T14:50:18.317Z',
uploadedBy: {
create: {
email: 'String',
name: 'String',
email: '[email protected]',
updatedAt: '2023-12-09T14:50:18.317Z',
organization: { create: { name: 'String' } },
agency: { create: { name: 'String', code: 'String' } },
role: 'USDR_ADMIN',
},
},
agency: { create: { name: 'String', code: 'String' } },
Expand Down Expand Up @@ -73,9 +75,11 @@ export const standard = defineScenario<Prisma.SubrecipientCreateArgs>({
updatedAt: '2023-12-09T14:50:18.317Z',
uploadedBy: {
create: {
email: 'String',
name: 'String',
email: '[email protected]',
updatedAt: '2023-12-09T14:50:18.317Z',
organization: { create: { name: 'String' } },
agency: { create: { name: 'String', code: 'String' } },
role: 'USDR_ADMIN',
},
},
agency: { create: { name: 'String', code: 'String' } },
Expand Down
3 changes: 0 additions & 3 deletions api/src/services/subrecipients/subrecipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export const Subrecipient: SubrecipientRelationResolvers = {
.findUnique({ where: { id: root?.id } })
.organization()
},
certifiedBy: (_obj, { root }) => {
return db.subrecipient.findUnique({ where: { id: root?.id } }).certifiedBy()
},
originationUpload: (_obj, { root }) => {
return db.subrecipient
.findUnique({ where: { id: root?.id } })
Expand Down
18 changes: 16 additions & 2 deletions api/src/services/uploads/uploads.scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export const standard = defineScenario<Prisma.UploadCreateArgs>({
one: {
data: {
filename: 'String',
uploadedBy: { create: { email: 'String' } },
uploadedBy: {
create: {
email: '[email protected]',
name: 'String',
role: 'USDR_ADMIN',
agency: { create: { name: 'String', code: 'String' } },
},
},
agency: { create: { name: 'String', code: 'String' } },
organization: { create: { name: 'String' } },
reportingPeriod: {
Expand Down Expand Up @@ -37,7 +44,14 @@ export const standard = defineScenario<Prisma.UploadCreateArgs>({
two: {
data: {
filename: 'String',
uploadedBy: { create: { email: 'String' } },
uploadedBy: {
create: {
email: '[email protected]',
name: 'String',
role: 'USDR_ADMIN',
agency: { create: { name: 'String', code: 'String' } },
},
},
agency: { create: { name: 'String', code: 'String' } },
organization: { create: { name: 'String' } },
reportingPeriod: {
Expand Down
3 changes: 1 addition & 2 deletions api/src/services/users/users.scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export const standard = defineScenario<
user: {
one: {
data: {
email: 'String',
email: '[email protected]',
name: 'String',
organization: { create: { name: 'String' } },
agency: { create: { name: 'String', code: 'String' } },
role: 'ORGANIZATION_ADMIN',
},
Expand Down
12 changes: 5 additions & 7 deletions api/src/services/users/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ describe('users', () => {
scenario('creates a user', async (scenario: StandardScenario) => {
mockCurrentUser({
id: scenario.user.one.id,
organizationId: scenario.user.one.organizationId,
email: '[email protected]',
email: scenario.user.one.email,
roles: ['USDR_ADMIN'],
})

const result = await createUser({
input: {
name: scenario.user.one.name,
email: scenario.user.one.email,
email: '[email protected]',
name: 'String',
agencyId: scenario.agency.one.id,
role: 'ORGANIZATION_STAFF',
role: 'USDR_ADMIN',
},
})

expect(result.email).toEqual(scenario.user.one.email)
expect(result.organizationId).toEqual(scenario.organization.one.id)
expect(result.email).toEqual('[email protected]')
})

scenario('updates a user', async (scenario: StandardScenario) => {
Expand Down
11 changes: 1 addition & 10 deletions api/src/services/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const createUser: MutationResolvers['createUser'] = async ({
}

return db.user.create({
data: { ...input, organizationId: agency.organizationId },
data: input,
})
} catch (err) {
throw new Error(err)
Expand Down Expand Up @@ -101,19 +101,10 @@ export const User: UserRelationResolvers = {
agency: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).agency()
},
organization: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).organization()
},
certified: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).certified()
},
uploaded: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).uploaded()
},
validated: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).validated()
},
invalidated: (_obj, { root }) => {
return db.user.findUnique({ where: { id: root?.id } }).invalidated()
},
}
14 changes: 0 additions & 14 deletions api/types/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export type CreateUserInput = {
agencyId?: InputMaybe<Scalars['Int']>;
email: Scalars['String'];
name?: InputMaybe<Scalars['String']>;
organizationId?: InputMaybe<Scalars['Int']>;
role?: InputMaybe<RoleEnum>;
};

Expand Down Expand Up @@ -696,7 +695,6 @@ export type UpdateUserInput = {
agencyId?: InputMaybe<Scalars['Int']>;
email?: InputMaybe<Scalars['String']>;
name?: InputMaybe<Scalars['String']>;
organizationId?: InputMaybe<Scalars['Int']>;
role?: InputMaybe<RoleEnum>;
};

Expand Down Expand Up @@ -753,14 +751,10 @@ export type User = {
createdAt: Scalars['DateTime'];
email: Scalars['String'];
id: Scalars['Int'];
invalidated: Array<Maybe<UploadValidation>>;
name?: Maybe<Scalars['String']>;
organization: Organization;
organizationId: Scalars['Int'];
role?: Maybe<RoleEnum>;
updatedAt: Scalars['DateTime'];
uploaded: Array<Maybe<Upload>>;
validated: Array<Maybe<UploadValidation>>;
};

type MaybeOrArrayOfMaybe<T> = T | Maybe<T> | Maybe<T>[];
Expand Down Expand Up @@ -1439,14 +1433,10 @@ export type UserResolvers<ContextType = RedwoodGraphQLContext, ParentType extend
createdAt: OptArgsResolverFn<ResolversTypes['DateTime'], ParentType, ContextType>;
email: OptArgsResolverFn<ResolversTypes['String'], ParentType, ContextType>;
id: OptArgsResolverFn<ResolversTypes['Int'], ParentType, ContextType>;
invalidated: OptArgsResolverFn<Array<Maybe<ResolversTypes['UploadValidation']>>, ParentType, ContextType>;
name: OptArgsResolverFn<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
organization: OptArgsResolverFn<ResolversTypes['Organization'], ParentType, ContextType>;
organizationId: OptArgsResolverFn<ResolversTypes['Int'], ParentType, ContextType>;
role: OptArgsResolverFn<Maybe<ResolversTypes['RoleEnum']>, ParentType, ContextType>;
updatedAt: OptArgsResolverFn<ResolversTypes['DateTime'], ParentType, ContextType>;
uploaded: OptArgsResolverFn<Array<Maybe<ResolversTypes['Upload']>>, ParentType, ContextType>;
validated: OptArgsResolverFn<Array<Maybe<ResolversTypes['UploadValidation']>>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand All @@ -1457,14 +1447,10 @@ export type UserRelationResolvers<ContextType = RedwoodGraphQLContext, ParentTyp
createdAt?: RequiredResolverFn<ResolversTypes['DateTime'], ParentType, ContextType>;
email?: RequiredResolverFn<ResolversTypes['String'], ParentType, ContextType>;
id?: RequiredResolverFn<ResolversTypes['Int'], ParentType, ContextType>;
invalidated?: RequiredResolverFn<Array<Maybe<ResolversTypes['UploadValidation']>>, ParentType, ContextType>;
name?: RequiredResolverFn<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
organization?: RequiredResolverFn<ResolversTypes['Organization'], ParentType, ContextType>;
organizationId?: RequiredResolverFn<ResolversTypes['Int'], ParentType, ContextType>;
role?: RequiredResolverFn<Maybe<ResolversTypes['RoleEnum']>, ParentType, ContextType>;
updatedAt?: RequiredResolverFn<ResolversTypes['DateTime'], ParentType, ContextType>;
uploaded?: RequiredResolverFn<Array<Maybe<ResolversTypes['Upload']>>, ParentType, ContextType>;
validated?: RequiredResolverFn<Array<Maybe<ResolversTypes['UploadValidation']>>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand Down
1 change: 0 additions & 1 deletion scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default async () => {
},
]
const userRecord = await db.user.create({ data: users[0] })

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable userRecord.
console.log(userRecord)

const inputTemplates: Prisma.InputTemplateCreateArgs['data'][] = [
{
Expand Down
2 changes: 0 additions & 2 deletions web/src/components/User/EditUserCell/EditUserCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const QUERY = gql`
email
name
agencyId
organizationId
role
createdAt
updatedAt
Expand All @@ -28,7 +27,6 @@ const UPDATE_USER_MUTATION = gql`
email
name
agencyId
organizationId
role
createdAt
updatedAt
Expand Down
1 change: 0 additions & 1 deletion web/src/components/User/UserCell/UserCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const QUERY = gql`
email
name
agencyId
organizationId
role
createdAt
updatedAt
Expand Down
1 change: 0 additions & 1 deletion web/src/components/User/UsersCell/UsersCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const QUERY = gql`
agency {
name
}
organizationId
role
createdAt
updatedAt
Expand Down
Loading

0 comments on commit be48b55

Please sign in to comment.