mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 22:01:49 +03:00
298599ce91
refs https://github.com/TryGhost/Team/issues/1532 - Added before the migration in https://github.com/TryGhost/Ghost/pull/14468 to populate the default newsletter - The fixture for the default newsletter has a different value than the model and schema default - This is because by default the newsletter name is the same as the site title, and the site title is already shown
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const Newsletter = ghostBookshelf.Model.extend({
|
|
tableName: 'newsletters',
|
|
|
|
defaults: {
|
|
sender_reply_to: 'newsletter',
|
|
status: 'active',
|
|
visibility: 'members',
|
|
subscribe_on_signup: true,
|
|
sort_order: 0,
|
|
title_font_category: 'sans_serif',
|
|
title_alignment: 'center',
|
|
show_feature_image: true,
|
|
body_font_category: 'sans_serif',
|
|
show_badge: true,
|
|
show_header_icon: true,
|
|
show_header_title: true,
|
|
show_header_name: true
|
|
},
|
|
|
|
async onSaving(model, _attr, options) {
|
|
ghostBookshelf.Model.prototype.onSaving.apply(this, arguments);
|
|
|
|
if (model.get('name')) {
|
|
model.set('name', model.get('name').trim());
|
|
}
|
|
|
|
if (model.hasChanged('slug') || !model.get('slug')) {
|
|
const slug = model.get('slug') || model.get('name');
|
|
|
|
if (slug) {
|
|
const cleanSlug = await ghostBookshelf.Model.generateSlug(Newsletter, slug, {
|
|
transacting: options.transacting
|
|
});
|
|
|
|
model.set({slug: cleanSlug});
|
|
}
|
|
}
|
|
}
|
|
}, {
|
|
orderDefaultOptions: function orderDefaultOptions() {
|
|
return {
|
|
sort_order: 'ASC'
|
|
};
|
|
}
|
|
});
|
|
|
|
module.exports = {
|
|
Newsletter: ghostBookshelf.model('Newsletter', Newsletter)
|
|
};
|