Ghost/ghost/limit-service/lib/config.js
Hannah Wolfe 75e857b76b Updated staff count query to include invites
refs: https://github.com/TryGhost/Team/issues/510

- we need to make sure we take into account any invites that could be accepted at any time
- this counts all invites for non-contributor roles as well as all users who aren't contributors
- this should stop there being loop holes to inviting staff users
2021-03-04 13:31:41 +00:00

32 lines
1.1 KiB
JavaScript

module.exports = {
members: {
currentCountQuery: async (db) => {
let result = await db.knex('members').count('id', {as: 'count'}).first();
return result.count;
}
},
staff: {
currentCountQuery: async (db) => {
let result = await db.knex('users')
.select('users.id')
.leftJoin('roles_users', 'users.id', 'roles_users.user_id')
.leftJoin('roles', 'roles_users.role_id', 'roles.id')
.whereNot('roles.name', 'Contributor').andWhereNot('users.status', 'inactive').union([
db.knex('invites')
.select('invites.id')
.leftJoin('roles', 'invites.role_id', 'roles.id')
.whereNot('roles.name', 'Contributor')
]);
return result.length;
}
},
custom_integrations: {
currentCountQuery: async (db) => {
let result = await db.knex('integrations').count('id', {as: 'count'}).whereNotIn('type', ['internal', 'builtin']).first();
return result.count;
}
},
custom_themes: {}
};