Commit 51549bab authored by ale's avatar ale

Create a custom validator for newsletters

Now that we're no longer reusing the List metadata field in the
Resource, we have to adapt the validators.
parent f2a3ab80
Pipeline #4856 passed with stages
in 4 minutes and 32 seconds
......@@ -582,6 +582,26 @@ func (v *validationContext) validListResource() ResourceValidatorFunc {
}
}
func (v *validationContext) validNewsletterResource() ResourceValidatorFunc {
listValidator := v.validHostedMailingList()
return func(ctx context.Context, r *Resource, user *User) error {
if err := v.validateShardedResource(ctx, r, user); err != nil {
return err
}
if r.Newsletter == nil {
return errors.New("resource has no newsletter metadata")
}
if err := listValidator(ctx, r.Name); err != nil {
return err
}
if len(r.Newsletter.Admins) < 1 {
return errors.New("can't create a newsletter without admins")
}
return nil
}
}
func findMatchingDAVAccount(user *User, r *Resource) *Resource {
for _, dav := range user.GetResourcesByType(ResourceTypeDAV) {
if isSubdir(dav.DAV.Homedir, r.Website.DocumentRoot) {
......@@ -762,7 +782,7 @@ func newResourceValidator(v *validationContext) *resourceValidator {
rvs: map[string]ResourceValidatorFunc{
ResourceTypeEmail: v.validEmailResource(),
ResourceTypeMailingList: v.validListResource(),
ResourceTypeNewsletter: v.validListResource(),
ResourceTypeNewsletter: v.validNewsletterResource(),
ResourceTypeDomain: v.validDomainResource(),
ResourceTypeWebsite: v.validWebsiteResource(),
ResourceTypeDAV: v.validDAVResource(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment