-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stark-rbac): update rbac actions style
BREAKING CHANGE: Due to an improvement on how actions are defined, the enum `StarkRBACAuthorizationActionsTypes` became obsolete so it has been removed. As a result, the following actions have been changed: - `StarkUserNavigationUnauthorized(public targetState: string)` -> `StarkRBACAuthorizationActions.userNavigationUnauthorized({ targetState: string })` - `StarkUserNavigationUnauthorizedRedirected(public targetState: string, public redirectionState: string)` -> `StarkRBACAuthorizationActions.userNavigationUnauthorizedRedirected({ targetState: string; redirectionState: string })` And also the previous union type has been replaced: `StarkRBACAuthorizationActions` -> `StarkRBACAuthorizationActions.Types`. Change in effect: ```typescript // Before @effect({ dispatch: false }) public starkRBACNavigationUnauthorized$(): Observable<void> { return this.actions$.pipe( ofType<StarkUserNavigationUnauthorized>( StarkRBACAuthorizationActionsTypes.RBAC_USER_NAVIGATION_UNAUTHORIZED ), map((action: StarkUserNavigationUnauthorized) => { // some logic }) ); } // After public starkRBACNavigationUnauthorizedRedirected$ = createEffect( () => this.actions$.pipe( ofType(StarkRBACAuthorizationActions.userNavigationUnauthorized), map((action) => { // some logic }) ), { dispatch: false } ); ``` Change in `action` usage: ```typescript // Before this.store.dispatch(new StarkUserNavigationUnauthorized(transition.targetState().name())); // After this.store.dispatch(StarkRBACAuthorizationActions.userNavigationUnauthorized({ targetState: transition.targetState().name() })); ```
- Loading branch information
1 parent
3ff099f
commit c4efd6a
Showing
8 changed files
with
88 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./actions/authorization.actions"; | ||
import * as StarkRBACAuthorizationActions from "./actions/authorization.actions"; | ||
export { StarkRBACAuthorizationActions }; |
53 changes: 18 additions & 35 deletions
53
packages/stark-rbac/src/modules/authorization/actions/authorization.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,27 @@ | ||
import { Action } from "@ngrx/store"; | ||
|
||
/** | ||
* Actions related to {@link StarkRBACAuthorizationService} | ||
*/ | ||
export enum StarkRBACAuthorizationActionsTypes { | ||
RBAC_USER_NAVIGATION_UNAUTHORIZED = "[StarkRBAC] User navigation unauthorized", | ||
RBAC_USER_NAVIGATION_UNAUTHORIZED_REDIRECTED = "[StarkRBAC] User navigation unauthorized redirected" | ||
} | ||
import { createAction, props, union } from "@ngrx/store"; | ||
|
||
/** | ||
* Action to be triggered when the user has navigated to a route that he is not authorized to. | ||
* | ||
* Parameter: | ||
* - targetState - The state the user is navigating to | ||
*/ | ||
export class StarkUserNavigationUnauthorized implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkRBACAuthorizationActionsTypes.RBAC_USER_NAVIGATION_UNAUTHORIZED = | ||
StarkRBACAuthorizationActionsTypes.RBAC_USER_NAVIGATION_UNAUTHORIZED; | ||
|
||
/** | ||
* Class constructor | ||
* @param targetState - The state the user is navigating to. | ||
*/ | ||
public constructor(public targetState: string) {} | ||
} | ||
export const userNavigationUnauthorized = createAction("[StarkRBAC] User navigation unauthorized", props<{ targetState: string }>()); | ||
|
||
/** | ||
* Action to be triggered when the user is redirected because he is not authorized to navigate to the original route. | ||
* | ||
* Parameters: | ||
* - targetState - The state the user is navigating to | ||
* - redirectionState - The redirection to be performed instead of the original navigation | ||
*/ | ||
export class StarkUserNavigationUnauthorizedRedirected implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkRBACAuthorizationActionsTypes.RBAC_USER_NAVIGATION_UNAUTHORIZED_REDIRECTED = | ||
StarkRBACAuthorizationActionsTypes.RBAC_USER_NAVIGATION_UNAUTHORIZED_REDIRECTED; | ||
export const userNavigationUnauthorizedRedirected = createAction( | ||
"[StarkRBAC] User navigation unauthorized redirected", | ||
props<{ targetState: string; redirectionState: string }>() | ||
); | ||
|
||
/** | ||
* Class constructor | ||
* @param targetState - The state the user is navigating to | ||
* @param redirectionState - The redirection to be performed instead of the original navigation | ||
*/ | ||
public constructor(public targetState: string, public redirectionState: string) {} | ||
} | ||
/** | ||
* @ignore | ||
*/ | ||
const all = union({ userNavigationUnauthorized, userNavigationUnauthorizedRedirected }); | ||
export type Types = typeof all; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters