Skip to content

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 the SAIF.SAIFCode.Core NuGet 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." when securityProvider.CanUserEditImages() is false, gating all subsequent rules via When(UserCanEditImages, ...).
  • Within the authorized branch, groupImageRepository.ImageFound must succeed ("Error: Image could not be found.") before the nested When(ImageFound, ...) rules run.
  • Nested rules require: no intervening update (UpdateDate still matches the stored value — "Error: Image updated by another user."), description text no longer than Image.MaxDescriptionLength, a non-empty category code, a document-type code that both is non-empty and resolves via imageCategoryCodeRepository.ImageDocumentTypeFound, and a group ID that resolves via groupRepository.GroupFound.

Sources

  • Services/SAIF.Services/Groups/Imaging/Validators/ImageEditValidator.cs