mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🐛 Fixed Member model removing labels when unset
closes https://github.com/TryGhost/Ghost/issues/12600 The bookshelf-relations plugin which we use will **remove** all relations when they are set to an empty array, but will leave them alone if it's set to undefined. Our logic to deduplicate uppercase & lowercase version of the same label was in advertently always setting the labels to an array, but when the model was saved without passing the labels, this array would be empty. Here we've added a check which will skip all label handling, if there are no labels set.
This commit is contained in:
parent
47843bbfe9
commit
93b1035df5
@ -184,7 +184,7 @@ module.exports = {
|
||||
permissions: true,
|
||||
async query(frame) {
|
||||
try {
|
||||
frame.options.withRelated = ['stripeSubscriptions'];
|
||||
frame.options.withRelated = ['stripeSubscriptions', 'labels'];
|
||||
const member = await membersService.api.members.update(frame.data.members[0], frame.options);
|
||||
|
||||
const hasCompedSubscription = !!member.related('stripeSubscriptions').find(sub => sub.get('plan_nickname') === 'Complimentary' && sub.get('status') === 'active');
|
||||
|
@ -106,6 +106,11 @@ const Member = ghostBookshelf.Model.extend({
|
||||
onSaving: function onSaving(model, attr, options) {
|
||||
let labelsToSave = [];
|
||||
|
||||
if (_.isUndefined(this.get('labels'))) {
|
||||
this.unset('labels');
|
||||
return;
|
||||
}
|
||||
|
||||
// CASE: detect lowercase/uppercase label slugs
|
||||
if (!_.isUndefined(this.get('labels')) && !_.isNull(this.get('labels'))) {
|
||||
labelsToSave = [];
|
||||
|
Loading…
Reference in New Issue
Block a user