@coolon/angular-ui-powerups 3.7.0-alpha.2 → 3.7.0-alpha.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
@@ -2,6 +2,13 @@
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.3](https://bitbucket.org/coolon/angular-ui-powerups/compare/v3.7.0-alpha.2...v3.7.0-alpha.3) (2020-12-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * restricted place auth handlers to places/visits to check validity ([5c8d7c9](https://bitbucket.org/coolon/angular-ui-powerups/commit/5c8d7c92f7b85a6d2e971ae13387eef41870d149))
11
+
5
12
  ## [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
13
 
7
14
 
@@ -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,9 +7963,10 @@
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, needsAuth, proceed, _a, redirectLocation, nextPlaceDef, redirectLocation, nextPlaceDef, result;
7960
7970
  var _this = this;
7961
7971
  return __generator(this, function (_b) {
7962
7972
  switch (_b.label) {
@@ -7973,10 +7983,20 @@
7973
7983
  case 2:
7974
7984
  proceed = _a;
7975
7985
  if (!proceed) {
7976
- return [2 /*return*/, this.handleGuardResult(this.placeAuthService.handleNotAuthenticated(activatedRoute, state))];
7986
+ redirectLocation = this.placeAuthService.handleNotAuthenticated(activatedRoute, state);
7987
+ nextPlaceDef = this.getPlaceDefinition(redirectLocation);
7988
+ if (nextPlaceDef.authenticate) {
7989
+ pectin.lang.illegalState("handleNotAuthenticated hook returned place " + nextPlaceDef.component.name + " that requires authentication.");
7990
+ }
7991
+ return [2 /*return*/, this.createUrlTree(redirectLocation)];
7977
7992
  }
7978
7993
  if (!this.placeAuthService.isAuthorised(placeDefinition_1)) {
7979
- return [2 /*return*/, this.handleGuardResult(this.placeAuthService.handleNotAuthorised(activatedRoute, state))];
7994
+ redirectLocation = this.placeAuthService.handleNotAuthorised(activatedRoute, state);
7995
+ nextPlaceDef = this.getPlaceDefinition(redirectLocation);
7996
+ if (!this.placeAuthService.isAuthorised(nextPlaceDef)) {
7997
+ pectin.lang.illegalState("handleNotAuthorised hook returned place " + nextPlaceDef.component.name + " that is not authorised for the current user.");
7998
+ }
7999
+ return [2 /*return*/, this.createUrlTree(redirectLocation)];
7980
8000
  }
7981
8001
  return [4 /*yield*/, this.cleanInteractionState(activatedRoute, state, function () { return __awaiter(_this, void 0, void 0, function () {
7982
8002
  var params, parsedParams, navigationSession, initialVisit, sanitiser, sanitisedVisit, urlSnapshot;
@@ -8013,6 +8033,7 @@
8013
8033
  });
8014
8034
  });
8015
8035
  };
8036
+ // @Trace()
8016
8037
  PlaceGuard.prototype.canDeactivate = function (component, currentRoute, currentState, nextState) {
8017
8038
  return __awaiter(this, void 0, void 0, function () {
8018
8039
  var currentUrl, nextUrl, result;
@@ -8029,13 +8050,14 @@
8029
8050
  });
8030
8051
  });
8031
8052
  };
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
- }
8053
+ PlaceGuard.prototype.getPlaceDefinition = function (result) {
8054
+ return result instanceof Visit ?
8055
+ result.placeDefinition :
8056
+ exports.PlaceComponent.getDefinition(result);
8057
+ };
8058
+ PlaceGuard.prototype.createUrlTree = function (result) {
8059
+ var visit = result instanceof Visit ? result : new Visit(exports.PlaceComponent.getDefinition(result), {});
8060
+ return this.urlService.createUrlSnapshot(visit).urlTree;
8039
8061
  };
8040
8062
  // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {
8041
8063
  // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;
@@ -8058,6 +8080,7 @@
8058
8080
  // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;
8059
8081
  // }
8060
8082
  // abstract getAuthGuard(injector: Injector): CanActivate;
8083
+ // @Trace()
8061
8084
  PlaceGuard.prototype.cleanInteractionState = function (route, state, next) {
8062
8085
  return __awaiter(this, void 0, void 0, function () {
8063
8086
  var url;
@@ -8090,30 +8113,6 @@
8090
8113
  { type: exports.InteractionService },
8091
8114
  { type: i0.Injector }
8092
8115
  ]; };
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
8116
 
8118
8117
  (function (Formatter) {
8119
8118
  var StringType = /** @class */ (function () {