Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user rights check for getHistory #3018

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/adapter/src/lib/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9230,7 +9230,16 @@ export class AdapterClass extends EventEmitter {
options.instance = this.defaultHistory;
}

this.sendTo(options.instance || 'history.0', 'getHistory', { id: id, options: options }, res => {
if (options?.user && options.user !== SYSTEM_ADMIN_USER) {
try {
await this._checkStates(id, options, 'getState');
} catch (e) {
// @ts-expect-error
return tools.maybeCallbackWithError(callback, e);
}
}

this.sendTo(options.instance || 'history.0', 'getHistory', { id, options }, res => {
// @ts-expect-error
tools.maybeCallbackWithError(callback, res.error, res.result, res.step, res.sessionId);
});
Expand Down Expand Up @@ -9574,7 +9583,7 @@ export class AdapterClass extends EventEmitter {
return tools.maybeCallbackWithError(callback, tools.ERRORS.ERROR_DB_CLOSED);
}

// if pattern is array
// if the pattern is an array
if (Array.isArray(pattern)) {
if (options.user && options.user !== SYSTEM_ADMIN_USER) {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/common-db/src/lib/common/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ export interface AdapterInformation {
platform: 'Javascript/Node.js';
/** keywords of the adapter */
keywords: string[];
/** path to readme file */
/** path to the readme file */
readme: string;
/** The installed adapter version, not existing on controller */
runningVersion?: string;
Expand Down
6 changes: 4 additions & 2 deletions packages/types-dev/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,18 @@ declare global {
| 'integralTotal';
/** Returned data is normally sorted ascending by date, this option lets you return the newest instead of the oldest values if the number of returned points is limited */
returnNewestEntries?: boolean;
/** By default, the additional border values are returned to optimize charting. Set this option to true if this is not wanted (e.g. for script data processing) */
/** By default, the additional border values are returned to optimize charting. Set this option to true if this is not wanted (e.g., for script data processing) */
removeBorderValues?: boolean;
/** when using aggregate method `percentile` defines the percentile level (0..100)(defaults to 50) */
percentile?: number;
/** when using aggregate method `quantile` defines the quantile level (0..1)(defaults to 0.5) */
quantile?: number;
/** when using aggregate method `integral` defines the unit in seconds (defaults to 60s). e.g. to get integral in hours for Wh or such, set to 3600. */
/** when using aggregate method `integral` defines the unit in seconds (defaults to 60 seconds). E.g., to get integral in hours for Wh or such, set to 3600. */
integralUnit?: number;
/** when using aggregate method `integral` defines the interpolation method (defaults to `none`). */
integralInterpolation?: 'none' | 'linear';
/** If user is set, it will be checked if this user may read the variable */
user?: `system.user.${string}`;
}

interface DelObjectOptions {
Expand Down
Loading