Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
TuvalSimha committed Sep 3, 2024
1 parent 95baa17 commit 533ef67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const UserRemovedAuditLogSchema = z.object({
});

const OrganizationSettingsUpdatedAuditLogSchema = z.object({
updatedFields: z.record(z.unknown()),
updatedFields: z.string(),
readableMessage: z.string(),
});

Expand All @@ -34,7 +34,7 @@ const ProjectCreatedAuditLogSchema = z.object({

const ProjectSettingsUpdatedAuditLogSchema = z.object({
projectId: z.string(),
updatedFields: z.record(z.unknown()),
updatedFields: z.string(),
readableMessage: z.string(),
});

Expand All @@ -54,7 +54,7 @@ const TargetCreatedAuditLogSchema = z.object({
const TargetSettingsUpdatedAuditLogSchema = z.object({
projectId: z.string(),
targetId: z.string(),
updatedFields: z.record(z.unknown()),
updatedFields: z.string(),
readableMessage: z.string(),
});

Expand All @@ -67,7 +67,7 @@ const TargetDeletedAuditLogSchema = z.object({

const SchemaPolicySettingsUpdatedAuditLogSchema = z.object({
projectId: z.string(),
updatedFields: z.record(z.unknown()),
updatedFields: z.string(),
readableMessage: z.string(),
});

Expand Down Expand Up @@ -191,7 +191,7 @@ export const auditLogSchema = z.discriminatedUnion('eventType', [
]);

export type AuditLogEvent = z.infer<typeof auditLogSchema> & {
id: string;
id?: string | null;
eventTime: string;
userId: string,
userEmail: string,
Expand Down
18 changes: 18 additions & 0 deletions packages/services/api/src/modules/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IdTranslator } from '../shared/providers/id-translator';
import { Logger } from '../shared/providers/logger';
import type { OrganizationModule } from './__generated__/types';
import { OrganizationManager } from './providers/organization-manager';
import { AuditLogManager } from '../audit-logs/providers/audit-logs-manager';

const OrganizationNameModel = NameModel.min(2).max(50);
const OrganizationSlugModel = z
Expand Down Expand Up @@ -234,6 +235,7 @@ export const resolvers: OrganizationModule.Resolvers = {
async updateOrganizationName(_, { input }, { injector }) {
const result = OrganizationNameModel.safeParse(input.name?.trim());


if (!result.success) {
return {
error: {
Expand All @@ -251,6 +253,22 @@ export const resolvers: OrganizationModule.Resolvers = {
organization: organizationId,
});

const currentUser = await injector.get(AuthManager).getCurrentUser();
const jsonUpdatedFields = JSON.stringify({
name: input.name
});
await injector.get(AuditLogManager).createLogAuditEvent({
eventType: 'ORGANIZATION_SETTINGS_UPDATED',
eventTime: new Date().toISOString(),
organizationId: organizationId,
userEmail: currentUser.email,
userId: currentUser.id,
metadata: {
readableMessage: `${currentUser.email} updated the organization name to ${input.name}`,
updatedFields: jsonUpdatedFields,
},
})

return {
ok: {
updatedOrganizationPayload: {
Expand Down

0 comments on commit 533ef67

Please sign in to comment.