2021-05-03 10:07:57 +03:00
|
|
|
// NOTE: to support a new config in the limit service add an empty key-object pair in the export below.
|
|
|
|
// Each type of limit has it's own structure:
|
|
|
|
// 1. FlagLimit and AllowlistLimit types are empty objects paired with a key, e.g.: `customThemes: {}`
|
|
|
|
// 2. MaxLimit should contain a `currentCountQuery` function which would count the resources under limit
|
2021-03-03 15:18:51 +03:00
|
|
|
module.exports = {
|
|
|
|
members: {
|
|
|
|
currentCountQuery: async (db) => {
|
|
|
|
let result = await db.knex('members').count('id', {as: 'count'}).first();
|
|
|
|
return result.count;
|
|
|
|
}
|
|
|
|
},
|
2021-05-06 16:37:50 +03:00
|
|
|
emails: {
|
|
|
|
currentCountQuery: async (db, startDate) => {
|
|
|
|
let result = await db.knex('emails')
|
2021-05-07 16:56:30 +03:00
|
|
|
.sum('email_count', {as: 'count'})
|
2021-05-06 16:37:50 +03:00
|
|
|
.where('created_at', '>=', startDate)
|
|
|
|
.first();
|
|
|
|
|
|
|
|
return result.count;
|
|
|
|
}
|
|
|
|
},
|
2021-03-03 15:18:51 +03:00
|
|
|
staff: {
|
|
|
|
currentCountQuery: async (db) => {
|
|
|
|
let result = await db.knex('users')
|
2021-03-04 16:31:41 +03:00
|
|
|
.select('users.id')
|
2021-03-03 15:18:51 +03:00
|
|
|
.leftJoin('roles_users', 'users.id', 'roles_users.user_id')
|
|
|
|
.leftJoin('roles', 'roles_users.role_id', 'roles.id')
|
2021-03-04 16:31:41 +03:00
|
|
|
.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')
|
|
|
|
]);
|
2021-03-03 15:18:51 +03:00
|
|
|
|
2021-03-04 16:31:41 +03:00
|
|
|
return result.length;
|
2021-03-03 15:18:51 +03:00
|
|
|
}
|
|
|
|
},
|
2021-03-04 23:11:54 +03:00
|
|
|
customIntegrations: {
|
2021-03-03 15:18:51 +03:00
|
|
|
currentCountQuery: async (db) => {
|
2021-04-07 09:13:10 +03:00
|
|
|
let result = await db.knex('integrations')
|
|
|
|
.count('id', {as: 'count'})
|
|
|
|
.whereNotIn('type', ['internal', 'builtin'])
|
|
|
|
.first();
|
|
|
|
|
2021-03-03 15:18:51 +03:00
|
|
|
return result.count;
|
|
|
|
}
|
|
|
|
},
|
2021-10-26 14:46:36 +03:00
|
|
|
customThemes: {},
|
|
|
|
uploads: {
|
|
|
|
// NOTE: this function should not ever be used as for uploads we compare the size
|
|
|
|
// of the uploaded file with the configured limit. Noop is here to keep the
|
|
|
|
// MaxLimit constructor happy
|
|
|
|
currentCountQuery: () => {}
|
|
|
|
}
|
2021-03-03 15:18:51 +03:00
|
|
|
};
|