@telia-ace/alliance-portal 1.0.5-next.2 → 1.0.5-next.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @telia-ace/alliance-portal
2
2
 
3
+ ## 1.0.5-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7a0e643: Show 401 unauthorized page for users without access to the workspace.
8
+
3
9
  ## 1.0.5-next.2
4
10
 
5
11
  ### Patch Changes
@@ -17,7 +17,9 @@ const axios_1 = require("@nestjs/axios");
17
17
  const common_1 = require("@nestjs/common");
18
18
  const config_1 = require("@nestjs/config");
19
19
  const alliance_internal_node_utilities_1 = require("@telia-ace/alliance-internal-node-utilities");
20
+ const graphql_request_1 = require("graphql-request");
20
21
  const config_2 = require("./config");
22
+ const graphql_1 = require("./graphql");
21
23
  let AppController = exports.AppController = class AppController {
22
24
  logger;
23
25
  configService;
@@ -36,7 +38,19 @@ let AppController = exports.AppController = class AppController {
36
38
  const { data } = await this.httpService.axiosRef.get(policyUrl);
37
39
  return data;
38
40
  }
39
- index(req) {
41
+ async index(req, workspaceSlug) {
42
+ let userHasAccess = false;
43
+ try {
44
+ const objectId = req.oidc.user.sub;
45
+ const { user } = await (0, graphql_request_1.request)(this.configService.getOrThrow(alliance_internal_node_utilities_1.SharedConfigKeys.DbEndpoint), graphql_1.GetUserDocument, { objectId, workspaceSlug }, {
46
+ authorization: (0, alliance_internal_node_utilities_1.createSystemUserToken)(this.configService),
47
+ });
48
+ userHasAccess = !!user.id;
49
+ }
50
+ catch { }
51
+ if (!userHasAccess) {
52
+ return htmlTemplate(unauthorizedPortalBody());
53
+ }
40
54
  const distributionOptions = {};
41
55
  const distributionUrl = this.configService.getOrThrow(config_2.ConfigKeys.WebprovisionsDistributionUrl);
42
56
  if (!req.query['wp-tag'] && !req.query['wp-version']) {
@@ -48,7 +62,7 @@ let AppController = exports.AppController = class AppController {
48
62
  distributionOptions,
49
63
  distributionUrl,
50
64
  });
51
- return htmlTemplate(distributionUrl, distributionOptions);
65
+ return htmlTemplate(portalBody(distributionUrl, distributionOptions));
52
66
  }
53
67
  };
54
68
  __decorate([
@@ -72,9 +86,10 @@ __decorate([
72
86
  __decorate([
73
87
  (0, common_1.Get)(['/:workspace', '/:workspace/*']),
74
88
  __param(0, (0, common_1.Req)()),
89
+ __param(1, (0, common_1.Param)('workspace')),
75
90
  __metadata("design:type", Function),
76
- __metadata("design:paramtypes", [Object]),
77
- __metadata("design:returntype", void 0)
91
+ __metadata("design:paramtypes", [Object, String]),
92
+ __metadata("design:returntype", Promise)
78
93
  ], AppController.prototype, "index", null);
79
94
  exports.AppController = AppController = __decorate([
80
95
  (0, common_1.Controller)(),
@@ -190,7 +205,59 @@ const loader = `
190
205
  </div>
191
206
  </div>
192
207
  `;
193
- function htmlTemplate(distributionUrl, distributionOpts) {
208
+ function portalBody(distributionUrl, distributionOpts) {
209
+ return `
210
+ <script>
211
+ /* WEBPROVISIONS */
212
+ !function(e,n){var o=n||{},c=document,t=window,s=function(n,o){e+=(e.indexOf("?")>-1?"&":"?")+encodeURIComponent(n)+"="
213
+ +encodeURIComponent(o)},i=/[?&]{1}(wp[^=]*)=([^&#]*)/g,r=c.getElementsByTagName("script")[0],p=c.createElement("script");p.type="module";e=e+"/index.js";
214
+ for(t.webprovisions=t.webprovisions||{_c:[],configure:function(){t.webprovisions._c.push(arguments)}};matches=i.exec(t.location.search);)
215
+ s(matches[1],matches[2]);Object.keys(o).forEach((function(e){s("wp-"+e,o[e])})),p.async=!0,p.src=e,r.parentNode.insertBefore(p,r)}
216
+ /**
217
+ * Configure the implementation by specifying a remote endpoint with optional arguments.
218
+ * url - The url to the remote endpoint for the implementation.
219
+ * args - Object containing optional arguments for the implementation.
220
+ */
221
+ ("${distributionUrl}", ${JSON.stringify(distributionOpts)})
222
+ </script>
223
+
224
+ ${loader}
225
+ `;
226
+ }
227
+ function unauthorizedPortalBody() {
228
+ return `
229
+ <div class="unauthorized">
230
+ <h1>401</h1>
231
+ <p>Your user does access to this workspace</p>
232
+ </div>
233
+ <style>
234
+ @import 'https://cdn.voca.teliacompany.com/fonts/TeliaSansV10/TeliaSans.css';
235
+ .unauthorized {
236
+ position: absolute;
237
+ inset: 0;
238
+ display: flex;
239
+ flex-direction: column;
240
+ gap: 1em;
241
+ justify-content: center;
242
+ align-items: center;
243
+ }
244
+
245
+ h1 {
246
+ font-family: TeliaSansHeading, TeliaSans, HelveticaNeue, Helvetica, Arial, sans-serif;
247
+ color: #e4175c;
248
+ font-size: 4em;
249
+ margin: 0;
250
+ }
251
+
252
+ p {
253
+ font-family: TeliaSans, Helvetica, Arial, Lucida Grande, sans-serif;
254
+ font-size: 2em;
255
+ margin: 0;
256
+ }
257
+ </style>
258
+ `;
259
+ }
260
+ function htmlTemplate(body) {
194
261
  return `
195
262
  <!DOCTYPE html>
196
263
  <html lang="en">
@@ -204,22 +271,7 @@ function htmlTemplate(distributionUrl, distributionOpts) {
204
271
  </head>
205
272
 
206
273
  <body>
207
- <script>
208
- /* WEBPROVISIONS */
209
- !function(e,n){var o=n||{},c=document,t=window,s=function(n,o){e+=(e.indexOf("?")>-1?"&":"?")+encodeURIComponent(n)+"="
210
- +encodeURIComponent(o)},i=/[?&]{1}(wp[^=]*)=([^&#]*)/g,r=c.getElementsByTagName("script")[0],p=c.createElement("script");p.type="module";e=e+"/index.js";
211
- for(t.webprovisions=t.webprovisions||{_c:[],configure:function(){t.webprovisions._c.push(arguments)}};matches=i.exec(t.location.search);)
212
- s(matches[1],matches[2]);Object.keys(o).forEach((function(e){s("wp-"+e,o[e])})),p.async=!0,p.src=e,r.parentNode.insertBefore(p,r)}
213
- /**
214
- * Configure the implementation by specifying a remote endpoint with optional arguments.
215
- * url - The url to the remote endpoint for the implementation.
216
- * args - Object containing optional arguments for the implementation.
217
- */
218
- ("${distributionUrl}", ${JSON.stringify(distributionOpts)})
219
- </script>
220
-
221
- ${loader}
222
-
274
+ ${body}
223
275
  </body>
224
276
 
225
277
  </html>
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOrCreateUserDocument = void 0;
3
+ exports.GetUserDocument = exports.GetOrCreateUserDocument = void 0;
4
4
  exports.GetOrCreateUserDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "GetOrCreateUser" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "GetOrCreateUserInput" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "getOrCreateUser" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "objectId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" } }, { "kind": "Field", "name": { "kind": "Name", "value": "type" } }] } }] } }] };
5
+ exports.GetUserDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetUser" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "objectId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "workspaceSlug" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "user" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "objectId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "objectId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "workspaceSlug" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "workspaceSlug" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" } }] } }] } }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/alliance-portal",
3
- "version": "1.0.5-next.2",
3
+ "version": "1.0.5-next.3",
4
4
  "description": "ACE Alliance portal",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",