@teipublisher/pb-components 2.17.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -642,6 +642,12 @@
642
642
  "type": "boolean",
643
643
  "default": "false"
644
644
  },
645
+ {
646
+ "name": "group",
647
+ "description": "A list of space- or comma-separated group names, whose members will be\nallowed to add or edit entries in the local register (if enabled).",
648
+ "type": "string",
649
+ "default": "\"\\\"tei\\\"\""
650
+ },
645
651
  {
646
652
  "name": "subscribe",
647
653
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -698,6 +704,13 @@
698
704
  "type": "boolean",
699
705
  "default": "false"
700
706
  },
707
+ {
708
+ "name": "group",
709
+ "attribute": "group",
710
+ "description": "A list of space- or comma-separated group names, whose members will be\nallowed to add or edit entries in the local register (if enabled).",
711
+ "type": "string",
712
+ "default": "\"\\\"tei\\\"\""
713
+ },
701
714
  {
702
715
  "name": "subscribe",
703
716
  "attribute": "subscribe",
@@ -9465,7 +9478,8 @@
9465
9478
  {
9466
9479
  "name": "login",
9467
9480
  "description": "Id of the pb-login element to connect to",
9468
- "type": "string"
9481
+ "type": "string",
9482
+ "deprecatedMessage": "no longer used"
9469
9483
  },
9470
9484
  {
9471
9485
  "name": "group",
@@ -9514,7 +9528,8 @@
9514
9528
  "name": "login",
9515
9529
  "attribute": "login",
9516
9530
  "description": "Id of the pb-login element to connect to",
9517
- "type": "string"
9531
+ "type": "string",
9532
+ "deprecatedMessage": "no longer used"
9518
9533
  },
9519
9534
  {
9520
9535
  "name": "group",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "description": "Collection of webcomponents underlying TEI Publisher",
5
5
  "repository": "https://github.com/eeditiones/tei-publisher-components.git",
6
6
  "main": "index.html",
package/pb-elements.json CHANGED
@@ -642,6 +642,12 @@
642
642
  "type": "boolean",
643
643
  "default": "false"
644
644
  },
645
+ {
646
+ "name": "group",
647
+ "description": "A list of space- or comma-separated group names, whose members will be\nallowed to add or edit entries in the local register (if enabled).",
648
+ "type": "string",
649
+ "default": "\"\\\"tei\\\"\""
650
+ },
645
651
  {
646
652
  "name": "subscribe",
647
653
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -698,6 +704,13 @@
698
704
  "type": "boolean",
699
705
  "default": "false"
700
706
  },
707
+ {
708
+ "name": "group",
709
+ "attribute": "group",
710
+ "description": "A list of space- or comma-separated group names, whose members will be\nallowed to add or edit entries in the local register (if enabled).",
711
+ "type": "string",
712
+ "default": "\"\\\"tei\\\"\""
713
+ },
701
714
  {
702
715
  "name": "subscribe",
703
716
  "attribute": "subscribe",
@@ -9465,7 +9478,8 @@
9465
9478
  {
9466
9479
  "name": "login",
9467
9480
  "description": "Id of the pb-login element to connect to",
9468
- "type": "string"
9481
+ "type": "string",
9482
+ "deprecatedMessage": "no longer used"
9469
9483
  },
9470
9484
  {
9471
9485
  "name": "group",
@@ -9514,7 +9528,8 @@
9514
9528
  "name": "login",
9515
9529
  "attribute": "login",
9516
9530
  "description": "Id of the pb-login element to connect to",
9517
- "type": "string"
9531
+ "type": "string",
9532
+ "deprecatedMessage": "no longer used"
9518
9533
  },
9519
9534
  {
9520
9535
  "name": "group",
@@ -3,6 +3,7 @@ import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
3
3
  import { pbMixin, waitOnce } from './pb-mixin.js';
4
4
  import { translate } from "./pb-i18n.js";
5
5
  import { createConnectors } from "./authority/connectors.js";
6
+ import "./pb-restricted.js";
6
7
  import '@polymer/paper-input/paper-input';
7
8
  import '@polymer/paper-icon-button';
8
9
 
@@ -41,6 +42,15 @@ export class PbAuthorityLookup extends pbMixin(LitElement) {
41
42
  stopwords: {
42
43
  type: String
43
44
  },
45
+ /**
46
+ * A list of space- or comma-separated group names, whose members will be
47
+ * allowed to add or edit entries in the local register (if enabled).
48
+ *
49
+ * @default "tei"
50
+ */
51
+ group: {
52
+ type: String
53
+ },
44
54
  _results: {
45
55
  type: Array,
46
56
  },
@@ -55,6 +65,7 @@ export class PbAuthorityLookup extends pbMixin(LitElement) {
55
65
  this.sortByLabel = false;
56
66
  this._results = [];
57
67
  this._authorities = {};
68
+ this.group = 'tei';
58
69
  }
59
70
 
60
71
  connectedCallback() {
@@ -92,8 +103,11 @@ export class PbAuthorityLookup extends pbMixin(LitElement) {
92
103
  <iron-icon icon="icons:search" slot="prefix"></iron-icon>
93
104
  ${
94
105
  this._authorities[this.type] && this._authorities[this.type].editable ?
95
- html`<paper-icon-button icon="icons:add" @click="${this._addEntity}" title="${translate('annotations.add-entity')}" slot="suffix"></paper-icon-button>` :
96
- null
106
+ html`
107
+ <pb-restricted group="${this.group}" slot="suffix">
108
+ <paper-icon-button icon="icons:add" @click="${this._addEntity}" title="${translate('annotations.add-entity')}"></paper-icon-button>
109
+ </pb-restricted>
110
+ ` : null
97
111
  }
98
112
  </paper-input>
99
113
  <slot name="authform"></slot>
@@ -144,13 +158,16 @@ export class PbAuthorityLookup extends pbMixin(LitElement) {
144
158
 
145
159
  ${
146
160
  this._authorities[this.type] && this._authorities[this.type].editable ?
147
- html`<div class="icons">
148
- <paper-icon-button
149
- icon="editor:mode-edit"
150
- @click="${() => this._editEntity(item)}"
151
- title="${translate('annotations.edit-entity')}"
152
- ></paper-icon-button>
153
- </div>` : null
161
+ html`
162
+ <pb-restricted group="${this.group}">
163
+ <div class="icons">
164
+ <paper-icon-button
165
+ icon="editor:mode-edit"
166
+ @click="${() => this._editEntity(item)}"
167
+ title="${translate('annotations.edit-entity')}"
168
+ ></paper-icon-button>
169
+ </div>
170
+ </pb-restricted>` : null
154
171
  }
155
172
  ${item.details ? html`<div class="details" part="details">${item.details}</div>` : null}
156
173
 
@@ -260,6 +277,11 @@ export class PbAuthorityLookup extends pbMixin(LitElement) {
260
277
  flex-direction: column;
261
278
  }
262
279
 
280
+ header {
281
+ display: flex;
282
+ align-items: center;
283
+ }
284
+
263
285
  .link {
264
286
  flex-grow: 2;
265
287
  }
package/src/pb-login.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import { pbMixin, waitOnce } from './pb-mixin.js';
3
3
  import { translate } from "./pb-i18n.js";
4
+ import { registry } from "./urls.js";
4
5
  import '@polymer/iron-ajax';
5
6
  import '@polymer/paper-dialog';
6
7
  import '@polymer/paper-dialog-scrollable';
@@ -250,6 +251,15 @@ export class PbLogin extends pbMixin(LitElement) {
250
251
  }
251
252
  }
252
253
  this.emitTo('pb-login', resp);
254
+
255
+ if (this.loggedIn) {
256
+ registry.currentUser = {
257
+ user: this.user,
258
+ groups: this.groups
259
+ }
260
+ } else {
261
+ registry.currentUser = null;
262
+ }
253
263
  }
254
264
 
255
265
  _handleError() {
@@ -266,6 +276,7 @@ export class PbLogin extends pbMixin(LitElement) {
266
276
  this._loginDialog.open();
267
277
  }
268
278
 
279
+ registry.currentUser = null;
269
280
  this.emitTo('pb-login', resp);
270
281
  }
271
282
 
@@ -1,6 +1,41 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import { pbMixin } from './pb-mixin.js';
3
+ import { registry } from './urls.js';
3
4
 
5
+ /**
6
+ *
7
+ * @param {Array<String>} arr array containg string values (name of groups)
8
+ * @param {String} val value to check if it's in the array
9
+ * @returns true if the checked values is in the array
10
+ */
11
+ function _isItemInArray(arr, val) {
12
+ return arr.some((arrVal) => val === arrVal);
13
+ }
14
+
15
+ /**
16
+ *
17
+ * @param {object} user user name returned by login function;
18
+ * @param {object} groups contains groups (an array) the logged user is a member of
19
+ * @param {string} targetGroups string containing (optionally) space separated list of target groups
20
+ * @returns true if user is member of one of the target groups
21
+ */
22
+ export function isLoggedIn(user, groups, targetGroups) {
23
+ if (user == null) {
24
+ return false;
25
+ }
26
+ if (targetGroups) {
27
+ if (!groups) {
28
+ return false;
29
+ }
30
+ const groupArray = targetGroups.split(/[\s+,]+/);
31
+ let exists = false;
32
+ groupArray.forEach(async (oneItem) => {
33
+ exists = _isItemInArray(groups, oneItem) || exists;
34
+ });
35
+ return exists;
36
+ }
37
+ return true;
38
+ }
4
39
 
5
40
  /**
6
41
  * Show content if the user is logged in. Optionally requires the user
@@ -18,7 +53,9 @@ export class PbRestricted extends pbMixin(LitElement) {
18
53
  static get properties() {
19
54
  return {
20
55
  ...super.properties,
21
- /** Id of the pb-login element to connect to */
56
+ /** Id of the pb-login element to connect to
57
+ * @deprecated no longer used
58
+ */
22
59
  login: {
23
60
  type: String
24
61
  },
@@ -50,15 +87,10 @@ export class PbRestricted extends pbMixin(LitElement) {
50
87
  this.classList.add('fallback');
51
88
  }
52
89
 
53
- const login = document.getElementById(this.login);
54
- if (!login) {
55
- console.error('<pb-restricted> connected pb-login element not found!');
56
- return;
57
- }
58
90
  this.subscribeTo('pb-login', (ev) => {
59
91
  this.show = this._loggedIn(ev.detail.user, ev.detail.groups);
60
92
  }, []);
61
- this.show = login.loggedIn && this._loggedIn(login.user, login.groups);
93
+ this.show = registry.currentUser && this._loggedIn(registry.currentUser.user, registry.currentUser.groups);
62
94
  }
63
95
 
64
96
  render() {
@@ -74,43 +106,13 @@ export class PbRestricted extends pbMixin(LitElement) {
74
106
  }
75
107
 
76
108
  :host(.fallback), :host([show]) {
77
- display: block;
109
+ display: inherit;
78
110
  }
79
111
  `;
80
112
  }
81
113
 
82
- /**
83
- *
84
- * @param {Array<String>} arr array containg string values (name of groups)
85
- * @param {String} val value to check if it's in the array
86
- * @returns true if the checked values is in the array
87
- */
88
- _isItemInArray(arr, val) {
89
- return arr.some((arrVal) => val === arrVal);
90
- }
91
-
92
- /**
93
- *
94
- * @param {object} user user name returned by login function;
95
- * @param {object} groups contains groups (an array) the logged user is a member of
96
- * @returns true if user is member of one of defined groups
97
- */
98
114
  _loggedIn(user, groups) {
99
- if (user == null) {
100
- return false;
101
- }
102
- if (this.group) {
103
- if (!groups) {
104
- return false;
105
- }
106
- let groupArray = this.group.split(/[\s+,]+/);
107
- let exists = false;
108
- groupArray.forEach(async (oneItem) => {
109
- exists = this._isItemInArray(groups, oneItem) || exists;
110
- });
111
- return exists;
112
- }
113
- return true;
115
+ return isLoggedIn(user, groups, this.group);
114
116
  }
115
117
  }
116
118
  customElements.define('pb-restricted', PbRestricted);
package/src/urls.js CHANGED
@@ -69,6 +69,12 @@ class Registry {
69
69
 
70
70
  this.urlIgnore = new Set();
71
71
  this.pathParams = new Set();
72
+
73
+ /**
74
+ * Information about the user currently logged in or null. If a user is logged in
75
+ * this will be an object with two properties: `user` and `groups`.
76
+ */
77
+ this.currentUser = null;
72
78
  }
73
79
 
74
80
  configure(usePath = true, idHash = false, rootPath = '', urlPattern, ignoredParams) {