ImageEditValidator¶
A FluentValidation AbstractValidator<ImageEdit> used by SAIF.Services.Groups.Imaging.ImageUpdater to authorize and validate a group image edit before it is applied. It depends on IGroupImageRepository and IGroupRepository to confirm the image/group exist, IImageCategoryCodeRepository to confirm the document type is valid, and IGroupImageSecurityProvider to check edit authorization.
Purpose¶
- Blocks the edit entirely if the current user is not authorized to edit images.
- Confirms the target image exists, has not been concurrently updated by another user, and (when found) validates description length, category/type codes, and target group existence.
Context¶
- Namespace:
SAIF.Services.Groups.Imaging.Validators - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| ImageEditValidator(...) | public ImageEditValidator(IGroupImageRepository groupImageRepository, IGroupRepository groupRepository, IImageCategoryCodeRepository imageCategoryCodeRepository, IGroupImageSecurityProvider securityProvider) |
Stores the injected collaborators and registers the full rule chain described in Behavioral notes. |
Behavioral notes¶
RuleFor(n => n.ImageGroupId).Must(UserCanEditImages)fails immediately with "Error: User not authorized to edit images." whensecurityProvider.CanUserEditImages()is false, gating all subsequent rules viaWhen(UserCanEditImages, ...).- Within the authorized branch,
groupImageRepository.ImageFoundmust succeed ("Error: Image could not be found.") before the nestedWhen(ImageFound, ...)rules run. - Nested rules require: no intervening update (
UpdateDatestill matches the stored value — "Error: Image updated by another user."), description text no longer thanImage.MaxDescriptionLength, a non-empty category code, a document-type code that both is non-empty and resolves viaimageCategoryCodeRepository.ImageDocumentTypeFound, and a group ID that resolves viagroupRepository.GroupFound.
Sources¶
- Services/SAIF.Services/Groups/Imaging/Validators/ImageEditValidator.cs