Skip to content

Commit 7093f8e

Browse files
Merge branch 'remove-any-from-activypub' of https://github.com/PedroMarianoAlmeida/Ghost into remove-any-from-activypub
2 parents a5744da + b76361b commit 7093f8e

17 files changed

Lines changed: 288 additions & 140 deletions

File tree

apps/portal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tryghost/portal",
3-
"version": "2.69.3",
3+
"version": "2.69.4",
44
"license": "MIT",
55
"repository": "https://github.com/TryGhost/Ghost",
66
"author": "Ghost Foundation",

apps/portal/src/components/frame.styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ html[dir="rtl"] .gh-portal-closeicon-container {
534534
}
535535
536536
.gh-portal-closeicon {
537-
color: var(--grey10);
537+
color: var(--grey6);
538538
cursor: pointer;
539539
width: 20px;
540540
height: 20px;

ghost/admin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ghost-admin",
3-
"version": "6.45.0-rc.0",
3+
"version": "6.45.1-rc.0",
44
"description": "Ember.js admin client for Ghost",
55
"author": "Ghost Foundation",
66
"homepage": "http://ghost.org",

ghost/core/core/frontend/helpers/date.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,20 @@ module.exports = function (...attrs) {
4646
// Documentation: http://momentjs.com/docs/#/i18n/
4747
// Locales: https://github.com/moment/moment/tree/develop/locale
4848
if (locale && locale.match('^[^/\\\\]*$') !== null) {
49-
dateMoment.locale(locale);
49+
// Moment ships region-specific locales (e.g. zh-cn, zh-tw, pa-in) for some
50+
// languages where Ghost's i18n uses a bare or script-tagged code (zh, zh-Hant, pa).
51+
// Maximize the locale to find the most likely regional variant, and let moment
52+
// pick the first candidate it has a locale for.
53+
const candidates = [locale];
54+
try {
55+
const maximized = new Intl.Locale(locale).maximize();
56+
if (maximized.region) {
57+
candidates.push(`${maximized.language}-${maximized.region}`, maximized.language);
58+
}
59+
} catch (e) {
60+
// Invalid locale tag - moment will fall back to the default locale
61+
}
62+
dateMoment.locale(candidates);
5063
}
5164

5265
if (timeago) {

ghost/core/core/server/api/endpoints/utils/serializers/input/members.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
const _ = require('lodash');
2-
const errors = require('@tryghost/errors');
32
const debug = require('@tryghost/debug')('api:endpoints:utils:serializers:input:members');
43
const mapNQLKeyValues = require('@tryghost/nql').utils.mapKeyValues;
54

6-
const ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER = 'count.active_stripe_customers';
7-
const MULTIPLE_ACTIVE_STRIPE_CUSTOMERS_FILTER = `${ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER}:>1`;
8-
const ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER_PATTERN = /(^|[+(,])count\.active_stripe_customers(?=:)/;
9-
105
function defaultRelations(frame) {
116
if (frame.options.withRelated) {
127
return;
@@ -36,27 +31,6 @@ function mapSubscribedFlagToNewsletterRelation(frame) {
3631
});
3732
}
3833

39-
function extractActiveStripeCustomersCountFilter(frame) {
40-
const filterString = frame.options.filter;
41-
42-
if (!filterString || !filterString.includes(ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER)) {
43-
return;
44-
}
45-
46-
if (!ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER_PATTERN.test(filterString)) {
47-
return;
48-
}
49-
50-
if (filterString !== MULTIPLE_ACTIVE_STRIPE_CUSTOMERS_FILTER) {
51-
throw new errors.BadRequestError({
52-
message: `The ${ACTIVE_STRIPE_CUSTOMERS_COUNT_FILTER} filter only supports ${MULTIPLE_ACTIVE_STRIPE_CUSTOMERS_FILTER}.`
53-
});
54-
}
55-
56-
frame.options.activeStripeCustomersCount = true;
57-
delete frame.options.filter;
58-
}
59-
6034
module.exports = {
6135
all(_apiConfig, frame) {
6236
if (!frame.options.withRelated) {
@@ -74,7 +48,6 @@ module.exports = {
7448
browse(apiConfig, frame) {
7549
debug('browse');
7650
defaultRelations(frame);
77-
extractActiveStripeCustomersCountFilter(frame);
7851
mapSubscribedFlagToNewsletterRelation(frame);
7952

8053
if (!frame.options.order) {
@@ -136,7 +109,6 @@ module.exports = {
136109

137110
bulkEdit(apiConfig, frame) {
138111
debug('bulkEdit');
139-
extractActiveStripeCustomersCountFilter(frame);
140112
mapSubscribedFlagToNewsletterRelation(frame);
141113
},
142114

ghost/core/core/server/models/member.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const Member = ghostBookshelf.Model.extend({
9696
}, {
9797
key: 'offer_redemptions',
9898
replacement: 'offer_redemptions.offer_id'
99+
}, {
100+
key: 'count.active_stripe_customers',
101+
replacement: 'active_stripe_customers_count'
99102
}];
100103
},
101104

@@ -169,6 +172,21 @@ const Member = ghostBookshelf.Model.extend({
169172
tableName: 'offer_redemptions',
170173
type: 'oneToOne',
171174
joinFrom: 'member_id'
175+
},
176+
active_stripe_customers_count: {
177+
type: 'aggregate',
178+
aggregate: {fn: 'countDistinct', column: 'members_stripe_customers_subscriptions.customer_id'},
179+
tableName: 'members_stripe_customers',
180+
joinFrom: 'member_id',
181+
joins: [{
182+
tableName: 'members_stripe_customers_subscriptions',
183+
from: 'customer_id',
184+
to: 'customer_id'
185+
}],
186+
wheres: {
187+
'members_stripe_customers_subscriptions.status': 'active',
188+
'members_stripe_customers_subscriptions.cancel_at_period_end': false
189+
}
172190
}
173191
};
174192
},
@@ -198,26 +216,6 @@ const Member = ghostBookshelf.Model.extend({
198216
offers: 'offers'
199217
},
200218

201-
applyCustomQuery(options) {
202-
if (!options.activeStripeCustomersCount) {
203-
return;
204-
}
205-
206-
this.query((qb) => {
207-
qb.innerJoin(function () {
208-
this
209-
.select('members_stripe_customers.member_id')
210-
.from('members_stripe_customers')
211-
.innerJoin('members_stripe_customers_subscriptions', 'members_stripe_customers_subscriptions.customer_id', 'members_stripe_customers.customer_id')
212-
.where('members_stripe_customers_subscriptions.status', 'active')
213-
.where('members_stripe_customers_subscriptions.cancel_at_period_end', false)
214-
.groupBy('members_stripe_customers.member_id')
215-
.havingRaw('COUNT(DISTINCT members_stripe_customers_subscriptions.customer_id) > 1')
216-
.as('multiple_active_stripe_customers');
217-
}, 'multiple_active_stripe_customers.member_id', 'members.id');
218-
});
219-
},
220-
221219
productEvents() {
222220
return this.hasMany('MemberProductEvent', 'member_id', 'id')
223221
.query('orderBy', 'created_at', 'DESC');
@@ -516,7 +514,7 @@ const Member = ghostBookshelf.Model.extend({
516514
let options = ghostBookshelf.Model.permittedOptions.call(this, methodName);
517515

518516
if (['findPage', 'findAll'].includes(methodName)) {
519-
options = options.concat(['search', 'activeStripeCustomersCount']);
517+
options = options.concat(['search']);
520518
}
521519

522520
return options;

ghost/core/core/server/models/post.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,9 @@ Post = ghostBookshelf.Model.extend({
932932
columns: ['id', 'lexical', 'created_at', 'author_id', 'title', 'reason', 'post_status', 'created_at_ts', 'feature_image']
933933
}, _.pick(options, 'transacting')));
934934

935-
const revisions = revisionModels.toJSON();
935+
// PostRevisions expects revisions in ascending order (latest last)
936+
const revisions = revisionModels.toJSON()
937+
.sort((a, b) => a.created_at_ts - b.created_at_ts);
936938

937939
const current = {
938940
id: model.id,

ghost/core/core/server/services/members/members-api/repositories/member-repository.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const messages = {
2323
memberNotFound: 'Could not find Member {id}',
2424
subscriptionNotFound: 'Could not find Subscription {id}',
2525
productNotFound: 'Could not find Product {id}',
26-
bulkActionRequiresFilter: 'Cannot perform {action} without a filter or all=true',
26+
bulkActionRequiresFilter: 'Cannot perform {action} without a filter, search, or all=true',
2727
tierArchived: 'Cannot use archived Tiers',
2828
invalidEmail: 'Invalid Email',
2929
offerNotFound: 'Could not find Offer {id}',
@@ -955,15 +955,15 @@ module.exports = class MemberRepository {
955955
}
956956

957957
async bulkEdit(data, options) {
958-
const {activeStripeCustomersCount, all, filter, search} = options;
958+
const {all, filter, search} = options;
959959

960960
if (!['unsubscribe', 'addLabel', 'removeLabel'].includes(data.action)) {
961961
throw new errors.IncorrectUsageError({
962962
message: 'Unsupported bulk action'
963963
});
964964
}
965965

966-
if (!filter && !search && !activeStripeCustomersCount && (!all || all !== true)) {
966+
if (!filter && !search && (!all || all !== true)) {
967967
throw new errors.IncorrectUsageError({
968968
message: tpl(messages.bulkActionRequiresFilter, {action: 'bulk edit'})
969969
});
@@ -973,7 +973,7 @@ module.exports = class MemberRepository {
973973

974974
if (all !== true) {
975975
// Include mongoTransformer to apply subscribed:{true|false} => newsletter relation mapping
976-
Object.assign(filterOptions, _.pick(options, ['filter', 'search', 'mongoTransformer', 'activeStripeCustomersCount']));
976+
Object.assign(filterOptions, _.pick(options, ['filter', 'search', 'mongoTransformer']));
977977
}
978978
const memberRows = await this._Member.getFilteredCollectionQuery(filterOptions)
979979
.select('members.id')

0 commit comments

Comments
 (0)