Skip to content

Commit

Permalink
[fix] Re-introduce beforeUpdateOneObject hook (#5495)
Browse files Browse the repository at this point in the history
... and disable name edition in object edition form. This feature will
be introduced by #5491
  • Loading branch information
ijreilly authored May 21, 2024
1 parent eb78be6 commit 0d16051
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type SettingsDataModelObjectAboutFormValues = z.infer<

type SettingsDataModelObjectAboutFormProps = {
disabled?: boolean;
disableNameEdit?: boolean;
objectMetadataItem?: ObjectMetadataItem;
};

Expand All @@ -46,6 +47,7 @@ const StyledInputContainer = styled.div`

export const SettingsDataModelObjectAboutForm = ({
disabled,
disableNameEdit,
objectMetadataItem,
}: SettingsDataModelObjectAboutFormProps) => {
const { control } = useFormContext<SettingsDataModelObjectAboutFormValues>();
Expand Down Expand Up @@ -93,7 +95,7 @@ export const SettingsDataModelObjectAboutForm = ({
placeholder={placeholder}
value={value}
onChange={onChange}
disabled={disabled}
disabled={disabled || disableNameEdit}
fullWidth
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const SettingsObjectEdit = () => {
/>
<SettingsDataModelObjectAboutForm
disabled={!activeObjectMetadataItem.isCustom}
disableNameEdit
objectMetadataItem={activeObjectMetadataItem}
/>
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ export class BeforeUpdateOneObject<T extends UpdateObjectPayload>
// TODO: this logic could be moved to a policy guard
async run(
instance: UpdateOneInputType<T>,
context: any,
workspaceId: string,
): Promise<UpdateOneInputType<T>> {
const workspaceId = context?.req?.user?.workspace?.id;

if (!workspaceId) {
throw new UnauthorizedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ObjectMetadataResolver } from 'src/engine/metadata-modules/object-metad
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { WorkspaceCacheVersionModule } from 'src/engine/metadata-modules/workspace-cache-version/workspace-cache-version.module';
import { BeforeUpdateOneObject } from 'src/engine/metadata-modules/object-metadata/hooks/before-update-one-object.hook';

import { ObjectMetadataService } from './object-metadata.service';
import { ObjectMetadataEntity } from './object-metadata.entity';
Expand Down Expand Up @@ -65,7 +66,11 @@ import { ObjectMetadataDTO } from './dtos/object-metadata.dto';
],
}),
],
providers: [ObjectMetadataService, ObjectMetadataResolver],
providers: [
ObjectMetadataService,
ObjectMetadataResolver,
BeforeUpdateOneObject,
],
exports: [ObjectMetadataService],
})
export class ObjectMetadataModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
import { ObjectMetadataDTO } from 'src/engine/metadata-modules/object-metadata/dtos/object-metadata.dto';
import { DeleteOneObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/delete-object.input';
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
import { UpdateOneObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
import {
UpdateObjectPayload,
UpdateOneObjectInput,
} from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
import { BeforeUpdateOneObject } from 'src/engine/metadata-modules/object-metadata/hooks/before-update-one-object.hook';

@UseGuards(JwtAuthGuard)
@Resolver(() => ObjectMetadataDTO)
export class ObjectMetadataResolver {
constructor(private readonly objectMetadataService: ObjectMetadataService) {}
constructor(
private readonly objectMetadataService: ObjectMetadataService,
private readonly beforeUpdateOneObject: BeforeUpdateOneObject<UpdateObjectPayload>,
) {}

@Mutation(() => ObjectMetadataDTO)
deleteOneObject(
Expand All @@ -23,10 +30,12 @@ export class ObjectMetadataResolver {
}

@Mutation(() => ObjectMetadataDTO)
updateOneObject(
async updateOneObject(
@Args('input') input: UpdateOneObjectInput,
@AuthWorkspace() { id: workspaceId }: Workspace,
) {
await this.beforeUpdateOneObject.run(input, workspaceId);

return this.objectMetadataService.updateOneObject(input, workspaceId);
}
}

0 comments on commit 0d16051

Please sign in to comment.