asab_webui_shell 27.5.2 → 27.5.4-alpha.1

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.
@@ -11,21 +11,25 @@ var _locationReplace = require("../../components/locationReplace");
11
11
  class SeaCatAuthApi {
12
12
  /*
13
13
  SeaCat Auth Open ID Connect / OAuth2.0
14
-
15
- From config.js:
16
- module.exports = {
17
- app: {
18
- BASE_URL: 'http://localhost:3000',
19
- API_PATH: 'api',
20
- SERVICES: {openidconnect: 'openidconnect'},
21
- ...
14
+ From webpack.common.js:
15
+ To change a Client ID, set the seacat.auth.client_id configuration variable in the webpack.common.js file:
16
+ const { DefinePlugin } = require('webpack');
17
+ ...
18
+ new DefinePlugin({
19
+ 'LOCAL_CONFIG': JSON.stringify({
20
+ "seacat.auth.scope": "openid tenant userinfo:*",
21
+ "seacat.auth.client_id": "llm-microlink-webui",
22
+ }),
23
+ })
22
24
  */
23
25
 
24
26
  constructor(app) {
25
27
  this.App = app;
26
- var scope = this.App.Config.get('seacat.auth.scope');
27
- this.Scope = scope ? scope : "openid tenant userinfo:* batman";
28
- this.ClientId = "asab-webui-auth";
28
+ this.Scope = this.App.Config.get('seacat.auth.scope') || "openid tenant userinfo:* batman";
29
+ this.ClientId = this.App.Config.get('seacat.auth.client_id') || "asab-webui-auth";
30
+
31
+ // The console log is intentionally left here so that we can see the Client ID in the console
32
+ console.log('OpenID Connect Client ID:', this.ClientId);
29
33
  this.SeaCatAuthAPI = this.App.axiosCreate('seacat-auth');
30
34
  this.OidcAPI = this.App.axiosCreate('openidconnect');
31
35
  }
@@ -331,6 +331,11 @@ class AuthModule extends _asab_webui_components.Module {
331
331
  if (this.UserInfo !== null) {
332
332
  resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
333
333
  tenants = this.UserInfo.tenants ? this.UserInfo.tenants : [];
334
+ if (tenants == null || tenants.length === 0) {
335
+ var _this$UserInfo$resour;
336
+ // Fallback to tenant from resources if tenants list is not available
337
+ tenants = Object.keys((_this$UserInfo$resour = this.UserInfo.resources) !== null && _this$UserInfo$resour !== void 0 ? _this$UserInfo$resour : {}).filter(tenant => tenant !== '*');
338
+ }
334
339
  }
335
340
  var valid = tenants ? tenants.indexOf(currentTenant) !== -1 : false;
336
341
  // If user is superuser, then tenant access is granted
@@ -342,6 +347,7 @@ class AuthModule extends _asab_webui_components.Module {
342
347
  updateUserInfo() {
343
348
  var _this3 = this;
344
349
  return (0, _asyncToGenerator2.default)(function* () {
350
+ var _this3$UserInfo;
345
351
  var internal = _this3.OAuthTokens.internal || false;
346
352
  if (!internal) {
347
353
  var _response$data;
@@ -412,10 +418,20 @@ class AuthModule extends _asab_webui_components.Module {
412
418
  });
413
419
  }
414
420
 
415
- /** Check for TenantService and pass tenants list obtained from userinfo */
421
+ // Check for TenantService and pass tenants list obtained from userinfo resources
416
422
  var availableTenants = _this3.UserInfo.tenants;
423
+ if (availableTenants == null || availableTenants.length === 0) {
424
+ var _this3$UserInfo$resou;
425
+ // Fallback to tenant from resources if tenants list is not available
426
+ availableTenants = Object.keys((_this3$UserInfo$resou = _this3.UserInfo.resources) !== null && _this3$UserInfo$resou !== void 0 ? _this3$UserInfo$resou : {}).filter(tenant => tenant !== '*');
427
+ }
428
+ if (((_this3$UserInfo = _this3.UserInfo) === null || _this3$UserInfo === void 0 ? void 0 : _this3$UserInfo.tenants) == null) {
429
+ // This is a monkey patch to add the tenants list to the userinfo if missing
430
+ _this3.UserInfo['tenants'] = availableTenants;
431
+ }
417
432
  if (_this3.App.Services.TenantService) {
418
- yield _this3.App.Services.TenantService.setTenants(availableTenants, _this3._getAuthorizedTenant(_this3.UserInfo));
433
+ yield _this3.App.Services.TenantService.setTenants(availableTenants, _this3._getAuthorizedTenant(_this3.UserInfo) // Get the authorized tenant
434
+ );
419
435
  }
420
436
  return true;
421
437
  })();
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = TenantDropdown;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
7
9
  var _react = _interopRequireWildcard(require("react"));
8
10
  var _asab_webui_components = require("asab_webui_components");
9
11
  var _reactI18next = require("react-i18next");
@@ -12,6 +14,10 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
12
14
  function TenantDropdown() {
13
15
  var _useTranslation = (0, _reactI18next.useTranslation)(),
14
16
  t = _useTranslation.t;
17
+ var _useState = (0, _react.useState)(false),
18
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
19
+ isOpen = _useState2[0],
20
+ setIsOpen = _useState2[1];
15
21
  var current = (0, _asab_webui_components.useAppSelector)(state => {
16
22
  var _state$tenant;
17
23
  return state === null || state === void 0 || (_state$tenant = state.tenant) === null || _state$tenant === void 0 ? void 0 : _state$tenant.current;
@@ -20,9 +26,12 @@ function TenantDropdown() {
20
26
  var _state$tenant2;
21
27
  return state === null || state === void 0 || (_state$tenant2 = state.tenant) === null || _state$tenant2 === void 0 ? void 0 : _state$tenant2.tenants;
22
28
  });
23
- return /*#__PURE__*/_react.default.createElement(_reactstrap.UncontrolledDropdown, {
29
+ var toggle = () => setIsOpen(prev => !prev);
30
+ return /*#__PURE__*/_react.default.createElement(_reactstrap.Dropdown, {
31
+ isOpen: isOpen,
32
+ toggle: toggle,
24
33
  direction: "down",
25
- title: t('tenant|Tenant')
34
+ title: t('General|Tenant')
26
35
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownToggle, {
27
36
  nav: true,
28
37
  caret: true
@@ -30,17 +39,20 @@ function TenantDropdown() {
30
39
  className: "bi bi-house-lock pe-2"
31
40
  }), /*#__PURE__*/_react.default.createElement(TenantLabel, {
32
41
  tenant: current
33
- })), tenants && tenants.length > 0 ? /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownMenu, {
34
- className: "shadow"
42
+ })), isOpen && (tenants === null || tenants === void 0 ? void 0 : tenants.length) > 0 && /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownMenu, {
43
+ className: "shadow overflow-y-auto",
44
+ style: {
45
+ maxHeight: '20em'
46
+ }
35
47
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
36
48
  header: true
37
- }, "Tenants"), tenants.map((tenant, i) => /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
49
+ }, t('General|Tenants')), tenants.map((tenant, i) => /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
38
50
  key: i,
39
51
  tag: "a",
40
52
  href: '?tenant=' + tenant + '#/'
41
53
  }, /*#__PURE__*/_react.default.createElement(TenantLabel, {
42
54
  tenant: tenant
43
- })))) : null);
55
+ })))));
44
56
  }
45
57
  function TenantLabel(_ref) {
46
58
  var tenant = _ref.tenant;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_shell",
3
- "version": "27.5.2",
3
+ "version": "27.5.4-alpha.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Shell Application",
6
6
  "contributors": [