Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

OpenRemote Roles for webcomponents

robindekkers9582c55020c8
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index aa8959ef0..cf9684692 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -717,7 +717,7 @@ export class Manager implements EventProviderFactory {
this._name = this._keycloak.tokenParsed.name;
this._username = this._keycloak.tokenParsed.preferred_username;
- this._roles = this._keycloak.realmAccess.roles;
+ this._roles = this._keycloak.resourceAccess.openremote.roles;
// Update the access token every 10s (note keycloak will only update if expiring within configured
// time period.
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 7cec842af..619585257 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -1,5 +1,5 @@
-import {html, LitElement, property} from 'lit-element';
-
+import {html, LitElement, property, PropertyValues} from 'lit-element';
+import openremote from "@openremote/core";
import {orInputStyle} from './style';
class OrInput extends LitElement {
@@ -13,6 +13,9 @@ class OrInput extends LitElement {
@property({type: Boolean})
public required: boolean = false;
+ @property({type: Boolean})
+ public disabled: boolean = false;
+
@property({type: String})
public value: string = "";
@@ -26,7 +29,7 @@ class OrInput extends LitElement {
protected render() {
return html`
- <input class="or-input" ?required="${this.required}" type="${this.type}" name="${this.name}" @change="${this.onChange}" .value="${this.value}" />
+ <input class="or-input" ?required="${this.required}" type="${this.type}" name="${this.name}" @change="${this.onChange}" .value="${this.value}" ?disabled="${this.disabled} />
`;
}
@@ -50,7 +53,10 @@ class OrInput extends LitElement {
super();
}
-
+ protected firstUpdated(_changedProperties: PropertyValues): void {
+ super.firstUpdated(_changedProperties);
+ this.disabled = !openremote.hasRole("write:assets");
+ }
}
window.customElements.define('or-input', OrInput);
diff --git a/ui/component/or-rules-editor/src/index.ts b/ui/component/or-rules-editor/src/index.ts
index 672ef38d2..c1a937ef3 100644
--- a/ui/component/or-rules-editor/src/index.ts
+++ b/ui/component/or-rules-editor/src/index.ts
@@ -98,8 +98,10 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
<side-menu class="bg-white shadow">
<or-rule-list .rulesets="${this.rulesets}" .ruleset="${this.ruleset}" ></or-rule-list>
<div class="bottom-toolbar">
- <icon class="small-icon" @click="${this.deleteRule}"><or-icon icon="delete"></or-icon></icon>
- <icon style="margin-left: auto;" class="small-icon" @click="${this.createRule}"><or-icon icon="plus"></or-icon></icon>
+ ${openremote.hasRole("write:assets") ? html`
+ <icon class="small-icon" @click="${this.deleteRule}"><or-icon icon="delete"></or-icon></icon>
+ <icon style="margin-left: auto;" class="small-icon" @click="${this.createRule}"><or-icon icon="plus"></or-icon></icon>
+ ` : ``}
</div>
</side-menu>
${this.ruleset ? html`
@@ -118,7 +120,9 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
` : html`
<div class="center-center">
<h3 style="font-weight: normal;">Kies links een profiel of maak een nieuw profiel aan.</h3>
- <button style="margin: auto;" @click="${this.createRule}">profiel aanmaken</button>
+ ${openremote.hasRole("write:assets") ? html`
+ <button style="margin: auto;" @click="${this.createRule}">profiel aanmaken</button>
+ ` : ``}
</div>
`}
</div>
@@ -138,7 +142,6 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
this.rulesets = response.data;
if (this.ruleset && this.rulesets) {
const index = findIndex(this.rulesets, ["id", this.ruleset.id]);
- console.log(index, this.ruleset.id);
let updatedRuleset;
// ID is not found when a new ruleset is added
diff --git a/ui/component/or-rules-editor/src/or-rule-header/index.ts b/ui/component/or-rules-editor/src/or-rule-header/index.ts
index 138bad4ab..5b537f136 100644
--- a/ui/component/or-rules-editor/src/or-rule-header/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-header/index.ts
@@ -6,6 +6,7 @@ import '@openremote/or-input';
import '@openremote/or-select';
import '@openremote/or-icon';
import {TenantRuleset, Rule} from '@openremote/model';
+import openremote from '@openremote/core';
import {style} from './style';
@@ -32,19 +33,22 @@ class OrRuleHeader extends LitElement {
<div class="rule-container">
<div class="layout horizontal">
- <input @change="${this.changeName}" type="text" .value="${this.ruleset ? this.ruleset.name : null}" />
+ <input ?disabled="${!openremote.hasRole("write:assets")}" @change="${this.changeName}" type="text" .value="${this.ruleset ? this.ruleset.name : null}" />
<div class="layout horizontal" style="margin-left: auto;">
<span style="margin: 9px 0;" class="toggle-label" ?data-disabled="${!this.ruleset!.id}">Actief</span>
<label class="switch" ?data-disabled="${!this.ruleset!.id}">
- <input @change="${this.toggleEnabled}" ?disabled="${!this.ruleset!.id}" ?checked="${this.ruleset!.enabled}" type="checkbox">
+ <input @change="${this.toggleEnabled}" ?disabled="${!this.ruleset!.id || !openremote.hasRole("write:assets")}" ?checked="${this.ruleset!.enabled}" type="checkbox">
<span class="slider round"></span>
- </label>
- ${this.ruleset && this.ruleset.id ? html`
- <button ?disabled="${!this.valid}" @click="${this.updateRule}">opslaan</button>
- ` : html`
- <button ?disabled="${!this.valid}" @click="${this.createRule}">opslaan</button>
- `}
+ </label>
+
+ ${openremote.hasRole("write:assets") ? html`
+ ${this.ruleset && this.ruleset.id ? html`
+ <button ?disabled="${!this.valid}" @click="${this.updateRule}">opslaan</button>
+ ` : html`
+ <button ?disabled="${!this.valid}" @click="${this.createRule}">opslaan</button>
+ `}
+ ` : ``}
</div>
</div>
diff --git a/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts b/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
index b578affd7..981fe364d 100644
--- a/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
@@ -5,7 +5,7 @@ import "../selects/or-select-operator";
import "@openremote/or-input";
import "@openremote/or-select";
import "@openremote/or-icon";
-import {AssetModelUtil} from "@openremote/core";
+import openremote, {AssetModelUtil} from "@openremote/core";
import {style} from "./style";
import {AttributeDescriptor, AttributePredicate, AssetDescriptor} from "@openremote/model";
@@ -80,10 +80,14 @@ class OrRuleWhenCondition extends LitElement {
`}
` : ``}
- ${this.predicate.value.value ? html`
- <a style="margin-left: auto;" @click="${this.deleteCondition}">
- <or-icon class="small-icon" icon="close-circle"></or-icon>
- </a>
+ ${openremote.hasRole("write:assets") ? html`
+
+ ${this.predicate.value.value ? html`
+ <a style="margin-left: auto;" @click="${this.deleteCondition}">
+ <or-icon class="small-icon" icon="close-circle"></or-icon>
+ </a>
+ ` : ``}
+
` : ``}
` : ``}
diff --git a/ui/component/or-rules-editor/src/or-rule-when/index.ts b/ui/component/or-rules-editor/src/or-rule-when/index.ts
index 291b1a327..4c89154e9 100644
--- a/ui/component/or-rules-editor/src/or-rule-when/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-when/index.ts
@@ -1,6 +1,7 @@
import {html, LitElement, property, customElement, PropertyValues} from "lit-element";
import {style} from "./style";
+import openremote from "@openremote/core";
import {Rule, AttributePredicate} from "@openremote/model";
import "../or-rule-when-condition";
@@ -43,8 +44,11 @@ class OrRuleWhen extends LitElement {
`; })}
` : ``}
- ${rulesEditorConfig.controls.addWhenCondition ? html`
- <a class="button-add" @click="${this.addWhenCondition}">+ voeg nog een voorwaarde toe</a>
+ ${openremote.hasRole("write:assets") ? html`
+ ${rulesEditorConfig.controls.addWhenCondition ? html`
+ <a class="button-add" @click="${this.addWhenCondition}">+ voeg nog een voorwaarde toe</a>
+ ` : ``}
+
` : ``}
</div>
</div>
diff --git a/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts b/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
index 0a44d37ec..9e7f87776 100644
--- a/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
+++ b/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
@@ -1,4 +1,5 @@
import {html, LitElement, customElement, property, PropertyValues} from "lit-element";
+import openremote from "@openremote/core";
import {AttributeDescriptor, AttributeValueType, AttributeValueDescriptor, ValueType} from "@openremote/model";
import {selectStyle} from "@openremote/or-select/dist/style";
import i18next from "i18next";
@@ -84,6 +85,9 @@ class OrSelectAssetAttribute extends LitElement {
}
});
+
+ this.disabled = !openremote.hasRole("write:assets");
+
}
}
diff --git a/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts b/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
index e042b8eb0..cb0cb3fe0 100644
--- a/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
+++ b/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
@@ -1,4 +1,5 @@
-import {html, LitElement, property, customElement} from "lit-element";
+import {html, LitElement, property, customElement, PropertyValues} from "lit-element";
+import openremote from "@openremote/core";
import {AttributeValueType, BaseAssetQueryMatch, BaseAssetQueryOperator, AttributeValueDescriptor} from "@openremote/model";
import {selectStyle} from "@openremote/or-select/dist/style";
@@ -57,4 +58,8 @@ class OrRuleWhen extends LitElement {
super();
}
+ protected firstUpdated(_changedProperties: PropertyValues): void {
+ super.firstUpdated(_changedProperties);
+ this.disabled = !openremote.hasRole("write:assets");
+ }
}
diff --git a/ui/component/or-select/src/index.ts b/ui/component/or-select/src/index.ts
index 219f14cf3..74551a297 100644
--- a/ui/component/or-select/src/index.ts
+++ b/ui/component/or-select/src/index.ts
@@ -1,4 +1,6 @@
import {html, LitElement, property, PropertyValues} from 'lit-element';
+import openremote from "@openremote/core";
+
import {MDCSelect} from '@material/select';
import i18next from "i18next";
import {selectStyle} from './style';
@@ -13,6 +15,9 @@ class OrSelect extends LitElement {
@property({type: String})
value: string = '';
+ @property({type: Boolean})
+ public disabled: boolean = false;
+
@property({type: Array})
options: string[] = [];
@@ -26,7 +31,7 @@ class OrSelect extends LitElement {
return html`
<div class="mdc-select">
- <select id="or-select" @change="${this.onChange}" name="${this.name}" >
+ <select id="or-select" @change="${this.onChange}" name="${this.name}" ?disabled="${this.disabled}">
${this.options.map((option: string) => {
return html`<option ?selected=${this.value === option} value="${option}">${i18next.t(option || "")}</option>`
})}
@@ -37,6 +42,7 @@ class OrSelect extends LitElement {
protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
+ this.disabled = !openremote.hasRole("write:assets");
}
onChange() {
diff --git a/ui/component/or-smart-notify/src/index.ts b/ui/component/or-smart-notify/src/index.ts
index 8b4a3b00c..23ef9691e 100644
--- a/ui/component/or-smart-notify/src/index.ts
+++ b/ui/component/or-smart-notify/src/index.ts
@@ -1,4 +1,4 @@
-import {html, LitElement, property, customElement} from 'lit-element';
+import {html, LitElement, property, customElement, PropertyValues} from 'lit-element';
import moment from 'moment';
@@ -8,6 +8,7 @@ import {faTimes} from '@fortawesome/free-solid-svg-icons';
import REST from "@openremote/rest";
import {AssetQuery, BaseAssetQueryInclude} from "@openremote/model";
+import openremote from "@openremote/core";
@customElement('or-smart-notify')
class OrSmartNotify extends LitElement {
@@ -248,6 +249,12 @@ class OrSmartNotify extends LitElement {
@property({type: String})
private currentTime: string = '-';
+
+ protected firstUpdated(_changedProperties: PropertyValues): void {
+ super.firstUpdated(_changedProperties);
+ this.isDisabled = !openremote.hasRole("write:assets");
+ }
+
getSmartNotify() {
const self:any = this;
return new Promise(function(resolve: any, reject: any) {
diff --git a/ui/component/or-thermostat/src/index.ts b/ui/component/or-thermostat/src/index.ts
index 074be550e..5b5eaf7bd 100644
--- a/ui/component/or-thermostat/src/index.ts
+++ b/ui/component/or-thermostat/src/index.ts
@@ -38,7 +38,7 @@ class OrThermostat extends LitElement {
}
};
- let subscriptionId = await openremote.events!.subscribeAttributeEvents([this.assetId!], callback);
+ const subscriptionId = await openremote.events!.subscribeAttributeEvents([this.assetId!], false, callback);
this._subscriptionId = subscriptionId;
console.log("Subscribed: " + subscriptionId);
};