@coolon/angular-ui-powerups 3.7.0-alpha.2 → 3.7.0-alpha.4

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
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.7.0-alpha.4](https://bitbucket.org/coolon/angular-ui-powerups/compare/v3.7.0-alpha.3...v3.7.0-alpha.4) (2020-12-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * routing to not check authorisation for guest places ([f4a7024](https://bitbucket.org/coolon/angular-ui-powerups/commit/f4a70246ecc40a0103dfe1ff8893536bb6efa963))
11
+
12
+ ## [3.7.0-alpha.3](https://bitbucket.org/coolon/angular-ui-powerups/compare/v3.7.0-alpha.2...v3.7.0-alpha.3) (2020-12-16)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * restricted place auth handlers to places/visits to check validity ([5c8d7c9](https://bitbucket.org/coolon/angular-ui-powerups/commit/5c8d7c92f7b85a6d2e971ae13387eef41870d149))
18
+
5
19
  ## [3.7.0-alpha.2](https://bitbucket.org/coolon/angular-ui-powerups/compare/v3.7.0-alpha.1...v3.7.0-alpha.2) (2020-12-16)
6
20
 
7
21
 
@@ -7136,10 +7136,11 @@
7136
7136
 
7137
7137
  var PlaceOutletComponent = /** @class */ (function (_super) {
7138
7138
  __extends(PlaceOutletComponent, _super);
7139
- function PlaceOutletComponent(router, placeRouter, placeConfig, parentOutlet) {
7139
+ function PlaceOutletComponent(router, placeRouter, placeAuthService, placeConfig, parentOutlet) {
7140
7140
  var _this = _super.call(this) || this;
7141
7141
  _this.router = router;
7142
7142
  _this.placeRouter = placeRouter;
7143
+ _this.placeAuthService = placeAuthService;
7143
7144
  _this.placeConfig = placeConfig;
7144
7145
  _this.placeChanged = new i0.EventEmitter();
7145
7146
  _this.outletActivated = new pectin.MutableValueModel(false);
@@ -7184,6 +7185,13 @@
7184
7185
  chain(_this._activePlaceModel)
7185
7186
  .postponeWhile(_this.navigationInProgress)
7186
7187
  .subscribe(function (place) { return _this.placeChanged.emit(place); });
7188
+ when(placeAuthService.authoriserModel).changes(function (isAuthorised) {
7189
+ var activePlace = _this._activePlaceModel.value;
7190
+ if (activePlace && !isAuthorised(activePlace.placeDefinition)) {
7191
+ var visitOrPlace = placeAuthService.handleNotAuthorised(_this._activatedRouteModel.value.snapshot, _this.router.routerState.snapshot);
7192
+ _this.placeRouter.navigate(visitOrPlace instanceof Visit ? visitOrPlace : new Visit(exports.PlaceComponent.getDefinition(visitOrPlace)));
7193
+ }
7194
+ });
7187
7195
  return _this;
7188
7196
  }
7189
7197
  // @Trace()
@@ -7325,6 +7333,7 @@
7325
7333
  PlaceOutletComponent.ctorParameters = function () { return [
7326
7334
  { type: i1$1.Router },
7327
7335
  { type: PlaceRouter },
7336
+ { type: undefined, decorators: [{ type: i0.Inject, args: [PLACE_AUTH_SERVICE,] }] },
7328
7337
  { type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [AUP_PLACE_CONFIG,] }] },
7329
7338
  { type: PlaceOutletComponent, decorators: [{ type: i0.SkipSelf }, { type: i0.Optional }] }
7330
7339
  ]; };
@@ -7954,65 +7963,72 @@
7954
7963
  this.interactionService = interactionService;
7955
7964
  this.injector = injector;
7956
7965
  }
7966
+ // @Trace()
7957
7967
  PlaceGuard.prototype.canActivate = function (activatedRoute, state) {
7958
7968
  return __awaiter(this, void 0, void 0, function () {
7959
- var placeDefinition_1, needsAuth, proceed, _a, result;
7969
+ var placeDefinition_1, redirectLocation, nextPlaceDef, redirectLocation, nextPlaceDef, result;
7960
7970
  var _this = this;
7961
- return __generator(this, function (_b) {
7962
- switch (_b.label) {
7971
+ return __generator(this, function (_a) {
7972
+ switch (_a.label) {
7963
7973
  case 0:
7964
7974
  if (!exports.PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) return [3 /*break*/, 4];
7965
7975
  placeDefinition_1 = exports.PlaceComponent.getDefinition(activatedRoute.component);
7966
- needsAuth = placeDefinition_1.authenticate;
7967
- _a = !needsAuth;
7968
- if (_a) return [3 /*break*/, 2];
7976
+ if (!placeDefinition_1.authenticate) return [3 /*break*/, 2];
7969
7977
  return [4 /*yield*/, this.placeAuthService.isAuthenticated()];
7970
7978
  case 1:
7971
- _a = (_b.sent());
7972
- _b.label = 2;
7973
- case 2:
7974
- proceed = _a;
7975
- if (!proceed) {
7976
- return [2 /*return*/, this.handleGuardResult(this.placeAuthService.handleNotAuthenticated(activatedRoute, state))];
7979
+ if (!(_a.sent())) {
7980
+ redirectLocation = this.placeAuthService.handleNotAuthenticated(activatedRoute, state);
7981
+ nextPlaceDef = this.getPlaceDefinition(redirectLocation);
7982
+ if (nextPlaceDef.authenticate) {
7983
+ pectin.lang.illegalState("handleNotAuthenticated hook returned place " + nextPlaceDef.component.name + " that requires authentication.");
7984
+ }
7985
+ return [2 /*return*/, this.createUrlTree(redirectLocation)];
7977
7986
  }
7978
7987
  if (!this.placeAuthService.isAuthorised(placeDefinition_1)) {
7979
- return [2 /*return*/, this.handleGuardResult(this.placeAuthService.handleNotAuthorised(activatedRoute, state))];
7988
+ redirectLocation = this.placeAuthService.handleNotAuthorised(activatedRoute, state);
7989
+ nextPlaceDef = this.getPlaceDefinition(redirectLocation);
7990
+ if (!this.placeAuthService.isAuthorised(nextPlaceDef)) {
7991
+ pectin.lang.illegalState("handleNotAuthorised hook returned place " + nextPlaceDef.component.name + " that is not authorised for the current user.");
7992
+ }
7993
+ return [2 /*return*/, this.createUrlTree(redirectLocation)];
7980
7994
  }
7981
- return [4 /*yield*/, this.cleanInteractionState(activatedRoute, state, function () { return __awaiter(_this, void 0, void 0, function () {
7982
- var params, parsedParams, navigationSession, initialVisit, sanitiser, sanitisedVisit, urlSnapshot;
7983
- return __generator(this, function (_a) {
7984
- switch (_a.label) {
7985
- case 0:
7986
- params = new ConsolidatedParameterMap(activatedRoute.paramMap, activatedRoute.url);
7987
- parsedParams = placeDefinition_1.parseRouteParams(params);
7988
- navigationSession = this.placeRouter.navigationSession;
7989
- initialVisit = navigationSession.getVisitFor(placeDefinition_1) || new Visit(placeDefinition_1, parsedParams);
7990
- sanitiser = new VisitSanitiser(navigationSession, activatedRoute, this.router, this.placeHistory, this.injector);
7991
- return [4 /*yield*/, sanitiser.sanitise(initialVisit.mergeRouteParameters(parsedParams))];
7992
- case 1:
7993
- sanitisedVisit = _a.sent();
7994
- // Save the visit with any updated parameters. We need to save it so we remember any non route parameters
7995
- navigationSession.storeVisit(sanitisedVisit);
7996
- if (initialVisit.hasRoutingChangedFrom(sanitisedVisit)) {
7997
- urlSnapshot = this.urlService.parseUrl(state.url).updateVisitSegments(sanitisedVisit);
7998
- // console.log('##### Place Guard Redirect', urlSnapshot);
7999
- return [2 /*return*/, urlSnapshot];
8000
- }
8001
- else {
8002
- return [2 /*return*/, true];
8003
- }
8004
- return [2 /*return*/];
8005
- }
8006
- });
8007
- }); })];
7995
+ _a.label = 2;
7996
+ case 2: return [4 /*yield*/, this.cleanInteractionState(activatedRoute, state, function () { return __awaiter(_this, void 0, void 0, function () {
7997
+ var params, parsedParams, navigationSession, initialVisit, sanitiser, sanitisedVisit, urlSnapshot;
7998
+ return __generator(this, function (_a) {
7999
+ switch (_a.label) {
8000
+ case 0:
8001
+ params = new ConsolidatedParameterMap(activatedRoute.paramMap, activatedRoute.url);
8002
+ parsedParams = placeDefinition_1.parseRouteParams(params);
8003
+ navigationSession = this.placeRouter.navigationSession;
8004
+ initialVisit = navigationSession.getVisitFor(placeDefinition_1) || new Visit(placeDefinition_1, parsedParams);
8005
+ sanitiser = new VisitSanitiser(navigationSession, activatedRoute, this.router, this.placeHistory, this.injector);
8006
+ return [4 /*yield*/, sanitiser.sanitise(initialVisit.mergeRouteParameters(parsedParams))];
8007
+ case 1:
8008
+ sanitisedVisit = _a.sent();
8009
+ // Save the visit with any updated parameters. We need to save it so we remember any non route parameters
8010
+ navigationSession.storeVisit(sanitisedVisit);
8011
+ if (initialVisit.hasRoutingChangedFrom(sanitisedVisit)) {
8012
+ urlSnapshot = this.urlService.parseUrl(state.url).updateVisitSegments(sanitisedVisit);
8013
+ // console.log('##### Place Guard Redirect', urlSnapshot);
8014
+ return [2 /*return*/, urlSnapshot];
8015
+ }
8016
+ else {
8017
+ return [2 /*return*/, true];
8018
+ }
8019
+ return [2 /*return*/];
8020
+ }
8021
+ });
8022
+ }); })];
8008
8023
  case 3:
8009
- result = _b.sent();
8024
+ result = _a.sent();
8010
8025
  return [2 /*return*/, result instanceof exports.UrlSnapshot ? result.urlTree : result];
8011
8026
  case 4: return [2 /*return*/, pectin.lang.illegalState("expected component to be an instance of PlaceComponent, got " + activatedRoute.component)];
8012
8027
  }
8013
8028
  });
8014
8029
  });
8015
8030
  };
8031
+ // @Trace()
8016
8032
  PlaceGuard.prototype.canDeactivate = function (component, currentRoute, currentState, nextState) {
8017
8033
  return __awaiter(this, void 0, void 0, function () {
8018
8034
  var currentUrl, nextUrl, result;
@@ -8029,13 +8045,14 @@
8029
8045
  });
8030
8046
  });
8031
8047
  };
8032
- PlaceGuard.prototype.handleGuardResult = function (result) {
8033
- if (result instanceof exports.UrlSnapshot) {
8034
- return result.urlTree;
8035
- }
8036
- else {
8037
- return this.urlService.createUrlSnapshot(result).urlTree;
8038
- }
8048
+ PlaceGuard.prototype.getPlaceDefinition = function (result) {
8049
+ return result instanceof Visit ?
8050
+ result.placeDefinition :
8051
+ exports.PlaceComponent.getDefinition(result);
8052
+ };
8053
+ PlaceGuard.prototype.createUrlTree = function (result) {
8054
+ var visit = result instanceof Visit ? result : new Visit(exports.PlaceComponent.getDefinition(result), {});
8055
+ return this.urlService.createUrlSnapshot(visit).urlTree;
8039
8056
  };
8040
8057
  // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {
8041
8058
  // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;
@@ -8058,6 +8075,7 @@
8058
8075
  // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;
8059
8076
  // }
8060
8077
  // abstract getAuthGuard(injector: Injector): CanActivate;
8078
+ // @Trace()
8061
8079
  PlaceGuard.prototype.cleanInteractionState = function (route, state, next) {
8062
8080
  return __awaiter(this, void 0, void 0, function () {
8063
8081
  var url;
@@ -8090,30 +8108,6 @@
8090
8108
  { type: exports.InteractionService },
8091
8109
  { type: i0.Injector }
8092
8110
  ]; };
8093
- __decorate([
8094
- pectin.Trace(),
8095
- __metadata("design:type", Function),
8096
- __metadata("design:paramtypes", [i1$1.ActivatedRouteSnapshot, i1$1.RouterStateSnapshot]),
8097
- __metadata("design:returntype", Promise)
8098
- ], PlaceGuard.prototype, "canActivate", null);
8099
- __decorate([
8100
- pectin.Trace(),
8101
- __metadata("design:type", Function),
8102
- __metadata("design:paramtypes", [exports.PlaceComponent, i1$1.ActivatedRouteSnapshot, i1$1.RouterStateSnapshot, i1$1.RouterStateSnapshot]),
8103
- __metadata("design:returntype", Promise)
8104
- ], PlaceGuard.prototype, "canDeactivate", null);
8105
- __decorate([
8106
- pectin.Trace(),
8107
- __metadata("design:type", Function),
8108
- __metadata("design:paramtypes", [Object]),
8109
- __metadata("design:returntype", void 0)
8110
- ], PlaceGuard.prototype, "handleGuardResult", null);
8111
- __decorate([
8112
- pectin.Trace(),
8113
- __metadata("design:type", Function),
8114
- __metadata("design:paramtypes", [i1$1.ActivatedRouteSnapshot, i1$1.RouterStateSnapshot, Function]),
8115
- __metadata("design:returntype", Promise)
8116
- ], PlaceGuard.prototype, "cleanInteractionState", null);
8117
8111
 
8118
8112
  (function (Formatter) {
8119
8113
  var StringType = /** @class */ (function () {