mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Added documentation for types of limits
refs https://github.com/TryGhost/Team/issues/588 refs https://github.com/TryGhost/Team/issues/510 - There's a limited type of limits supported by the limit service and it's worth to have a conceptual description of how they work and how to use them
This commit is contained in:
parent
12b31a7b4b
commit
420ba250a3
1 changed files with 7 additions and 1 deletions
|
@ -120,7 +120,13 @@ if (limitService.isLimited('members')) {
|
|||
}
|
||||
```
|
||||
|
||||
In case the limit check is run without direct access to the database you can override `currentCountQuery` functions for each "max" type of limit. An example usecase would be a frontend client running in a browser. A browser client can check the limit data through HTTP request and then provide that data to the limit service. Example code to do exactly that:
|
||||
### Types of limits
|
||||
At the moment there are four different types of limits that limit service allows to define. These types are:
|
||||
1. `flag` - is an "on/off" switch for certain feature. Example usecase: "disable all emails". It's identified by a `disabled: true` property in the "limits" configuration.
|
||||
2. `max` - checks if the maximum amount of the resource has been used up.Example usecase: "disable creating a staff user when maximum of 5 has been reached". To configure this limit add `max: NUMBER` to the configuration. The limits that support max checks are: `members`, `staff`, and `customIntegrations`
|
||||
3. `maxPeriodic` - it's a variation of `max` type with a difference that the check is done over certain period of time. Example usecase: "disable sending emails when the sent emails count has acceded a limit for last billing period". To enable this limit define `maxPeriodic: NUMBER` in the limit configuration and provide a subscription configuration when initializing the limit service instance. The subscription object comes as a separate parameter and has to contain two properties: `startDate` and `interval`, where `startDate` is a date in ISO 8601 format and period is `'month'` (other values like `'year'` are not supported yet)
|
||||
4. `allowList` - checks if provided value is defined in configured "allowlist". Example usecase: "disable theme activation if it is not an official theme". To configure this limit define ` allowlist: ['VALUE_1', 'VALUE_2', 'VALUE_N']` property in the "limits" parameter.
|
||||
|
||||
```js
|
||||
const limitService = new LimitService();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue