Ghost/ghost/admin/app/models/newsletter.js

56 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-04-04 21:26:49 +03:00
import Model, {attr} from '@ember-data/model';
import ValidationEngine from '../mixins/validation-engine';
export default class Newsletter extends Model.extend(ValidationEngine) {
validationType = 'newsletter';
@attr name;
@attr slug;
2022-04-04 21:26:49 +03:00
@attr description;
@attr senderName;
@attr senderEmail;
@attr({defaultValue: 'newsletter'}) senderReplyTo;
2022-04-04 21:26:49 +03:00
@attr({defaultValue: 'active'}) status;
@attr({defaultValue: true}) subscribeOnSignup;
@attr({defaultValue: 'members'}) visibility;
2022-04-04 21:26:49 +03:00
@attr({defaultValue: 0}) sortOrder;
@attr({defaultValue: true}) feedbackEnabled;
2022-04-04 21:26:49 +03:00
// Design-related properties
2022-04-04 21:26:49 +03:00
@attr headerImage;
@attr({defaultValue: true}) showHeaderIcon;
@attr({defaultValue: true}) showHeaderTitle;
@attr({defaultValue: true}) showHeaderName;
@attr({defaultValue: true}) showPostTitleSection;
@attr({defaultValue: true}) showCommentCta;
@attr({defaultValue: false}) showSubscriptionDetails;
@attr({defaultValue: false}) showLatestPosts;
2022-04-04 21:26:49 +03:00
@attr({defaultValue: 'sans_serif'}) titleFontCategory;
@attr({defaultValue: 'center'}) titleAlignment;
@attr({defaultValue: true}) showFeatureImage;
@attr({defaultValue: 'sans_serif'}) bodyFontCategory;
@attr({defaultValue: 'light'}) backgroundColor;
@attr({defaultValue: null}) borderColor;
@attr({defaultValue: null}) titleColor;
@attr footerContent;
2022-04-04 21:26:49 +03:00
@attr({defaultValue: true}) showBadge;
@attr count;
Added sender email verification flow for newsletters refs https://github.com/TryGhost/Team/issues/584 refs https://github.com/TryGhost/Team/issues/1498 - updated newsletter save routine in `edit-newsletter` modal to open an email confirmation modal if the API indicates one was sent - modal indicates that the previously set or default email will continue to be used until verified - response from API when saving looks like `{newsletters: [{...}], meta: {sent_email_verification: ['sender_name]}}` - added custom newsletter serializer and updated model so that the `meta` property returned in the response when saving posts is exposed - Ember Data only exposes meta on array-response find/query methods - https://github.com/emberjs/data/issues/2905 - added `/settings/members-email-labs/?verifyEmail=xyz` query param handling - opens email verification modal if param is set and instantly clears the query param to avoid problems with sticky params - when the modal opens it makes a `PUT /newsletters/verify-email/` request with the token in the body params, on the API side this works the same as a newsletter update request returning the fully updated newsletter record which is then pushed into the store - removed unused from/reply address code from `<Settings::MembersEmailLabs>` component and controller - setting the values now handled per-newsletter in the edit-newsletter modal - verifying email change is handled in the members-email-labs controller - fixed mirage not outputting pluralized root for "singular" endpoints such as POST/PUT requests to better match our API behaviour
2022-04-13 21:34:48 +03:00
// HACK - not a real model attribute but a workaround for Ember Data not
// exposing meta from save responses
@attr _meta;
/**
* The filter that we should use to filter out members that are subscribed to this newsletter
*/
get recipientFilter() {
const idFilter = 'newsletters.slug:' + this.slug;
if (this.visibility === 'paid') {
return idFilter + '+status:-free';
}
return idFilter;
}
2022-04-04 21:26:49 +03:00
}