Skip to content

Commit

Permalink
feat(stark-rbac): implement new Stark-RBAC package including StarkRBA…
Browse files Browse the repository at this point in the history
…CAuthorization module. Add demos for RBAC features in Showcase

ISSUES CLOSED: #105
  • Loading branch information
christophercr committed Apr 1, 2019
1 parent c5c34c6 commit 53d3f33
Show file tree
Hide file tree
Showing 91 changed files with 2,846 additions and 213 deletions.
4 changes: 2 additions & 2 deletions build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ logTrace "Executing function: ${FUNCNAME[0]}" 1
logTrace "SHA-512: $SHA"
logTrace "SHA-512 escaped: $ESCAPED_SHA"

local PATTERN="\\\"\@nationalbankbelgium\/$PACKAGE\\\": \\{(\s*)\\\"version\\\": \\\"(\S*)\\\"(,(\s*)\\\"resolved\\\": \\\"(.*))?,(\s*)\\\"integrity\\\": \\\"sha512-(.*)\\\","
local REPLACEMENT='"\@nationalbankbelgium\/'$PACKAGE'": {$1"version": "'$TGZ_PATH'",$4"integrity": "sha512-'$ESCAPED_SHA'",'
local PATTERN="\\\"\@nationalbankbelgium\/$PACKAGE\\\": \\{(\s*)\\\"version\\\": \\\"(\S*)\\\"(,(\s*)\\\"resolved\\\": \\\"(.*))?,(\s*)\\\"integrity\\\": \\\"sha512-(.*)\\\""
local REPLACEMENT='"\@nationalbankbelgium\/'$PACKAGE'": {$1"version": "'$TGZ_PATH'",$4"integrity": "sha512-'$ESCAPED_SHA'"'

logTrace "PATTERN: $PATTERN"
logTrace "REPLACEMENT: $REPLACEMENT"
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cd ${currentDir}

# List of all packages, separated by a space
# Packages will be transpiled using NGC (unless if also part of NODE_PACKAGES like the build package)
PACKAGES=(stark-core stark-ui)
PACKAGES=(stark-core stark-ui stark-rbac)

# Packages that should not be compiled by NGC but just with TSC
TSC_PACKAGES=()
Expand Down
6 changes: 5 additions & 1 deletion combine-packages-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const fs = require("fs");
const StreamConcat = require("stream-concat");

// add the reports of all the different Stark packages to be combined
const fileNames = ["packages/stark-core/reports/coverage/packages/lcov.info", "packages/stark-ui/reports/coverage/packages/lcov.info"];
const fileNames = [
"packages/stark-core/reports/coverage/packages/lcov.info",
"packages/stark-ui/reports/coverage/packages/lcov.info",
"packages/stark-rbac/reports/coverage/packages/lcov.info"
];
let fileIndex = 0;

const nextStream = function() {
Expand Down
8 changes: 8 additions & 0 deletions gh-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SSH_KEY_CLEARTEXT_FILE="stark-ssh"

STARK_CORE="stark-core"
STARK_UI="stark-ui"
STARK_RBAC="stark-rbac"
SHOWCASE="showcase"
API_DOCS_DIR_NAME="api-docs"
LATEST_DIR_NAME="latest"
Expand Down Expand Up @@ -287,6 +288,9 @@ API_DOCS_TARGET_DIR_STARK_CORE_LATEST=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${ST
API_DOCS_TARGET_DIR_STARK_UI=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_UI}/${DOCS_VERSION}
API_DOCS_TARGET_DIR_STARK_UI_LATEST=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_UI}/${LATEST_DIR_NAME}

API_DOCS_TARGET_DIR_STARK_RBAC=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_RBAC}/${DOCS_VERSION}
API_DOCS_TARGET_DIR_STARK_RBAC_LATEST=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_RBAC}/${LATEST_DIR_NAME}

SHOWCASE_TARGET_DIR=${DOCS_WORK_DIR}/${SHOWCASE}/${DOCS_VERSION}
SHOWCASE_TARGET_DIR_LATEST=${DOCS_WORK_DIR}/${SHOWCASE}/${LATEST_DIR_NAME}

Expand All @@ -312,6 +316,10 @@ logTrace "Copying ${STARK_UI} API docs"
syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_UI} ${API_DOCS_TARGET_DIR_STARK_UI} "${syncOptions[@]}"
syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_UI} ${API_DOCS_TARGET_DIR_STARK_UI_LATEST} "${syncOptions[@]}"

logTrace "Copying ${STARK_RBAC} API docs"
syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_RBAC} ${API_DOCS_TARGET_DIR_STARK_RBAC} "${syncOptions[@]}"
syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_RBAC} ${API_DOCS_TARGET_DIR_STARK_RBAC_LATEST} "${syncOptions[@]}"

logTrace "Copying ${SHOWCASE}"

NODE_REPLACE_URLS="node ${PROJECT_ROOT_DIR}/${SHOWCASE}/ghpages-adapt-bundle-urls.js"
Expand Down
14 changes: 3 additions & 11 deletions greenkeeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@
"package.json",
"packages/stark-build/package.json",
"packages/stark-core/package.json",
"packages/stark-rbac/package.json",
"packages/stark-testing/package.json",
"packages/stark-ui/package.json"
]
},
"stark-apps": {
"packages": [
"showcase/package.json",
"starter/package.json"
]
"packages": ["showcase/package.json", "starter/package.json"]
}
},
"ignore": [
"@angular/flex-layout",
"@compodoc/compodoc",
"@types/node",
"class-validator",
"typescript"
]
"ignore": ["@angular/flex-layout", "@compodoc/compodoc", "@types/node", "class-validator", "typescript"]
}
1 change: 1 addition & 0 deletions modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ stark-build
stark-testing
stark-core
stark-ui
stark-rbac
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"build:trace": "npm run build -- --trace",
"build:stark-build": "npm run build -- --packages=stark-build",
"build:stark-core": "npm run build -- --packages=stark-core",
"build:stark-rbac": "npm run build -- --packages=stark-rbac",
"build:stark-testing": "npm run build -- --packages=stark-testing",
"build:stark-ui": "npm run build -- --packages=stark-ui",
"build:showcase": "cd showcase && npm run build:prod && cd ..",
Expand All @@ -73,31 +74,36 @@
"check:starter:stark-versions": "node ./check-stark-versions.js ./starter/package.json latest",
"check:nightly:stark-versions": "node ./check-nightly-version.js ./package.json",
"clean": "npx rimraf ./dist",
"clean:all": "npm run clean && npm run clean:stark-build && npm run clean:stark-core && npm run clean:stark-ui && npm run clean:stark-testing && npm run clean:starter && npm run clean:showcase",
"clean:all": "npm run clean && npm run clean:stark-build && npm run clean:stark-testing && npm run clean:stark-core && npm run clean:stark-ui && npm run clean:stark-rbac && npm run clean:starter && npm run clean:showcase",
"clean:stark-build": "cd packages/stark-build && npm run clean && cd ../..",
"clean:stark-core": "cd packages/stark-core && npm run clean && cd ../..",
"clean:stark-rbac": "cd packages/stark-rbac && npm run clean && cd ../..",
"clean:stark-testing": "cd packages/stark-testing && npm run clean && cd ../..",
"clean:stark-ui": "cd packages/stark-ui && npm run clean && cd ../..",
"clean:showcase": "cd showcase && npx rimraf ./dist && npx rimraf ./node_modules/@nationalbankbelgium && cd ..",
"clean:slate": "npm run clean:all && npm run clean:modules:all && npm install && npm run install:all",
"clean:starter": "cd starter && npx rimraf ./dist && npx rimraf ./node_modules/@nationalbankbelgium && cd ..",
"clean:modules": "npx rimraf ./node_modules package-lock.json",
"clean:modules:all": "npm run clean:modules && npm run clean:modules:stark-build && npm run clean:modules:stark-core && npm run clean:modules:stark-testing && npm run clean:modules:stark-ui && npm run clean:modules:starter && npm run clean:modules:showcase",
"clean:modules:all": "npm run clean:modules && npm run clean:modules:stark-build && npm run clean:modules:stark-testing && npm run clean:modules:stark-core && npm run clean:modules:stark-ui && npm run clean:modules:stark-rbac && npm run clean:modules:starter && npm run clean:modules:showcase",
"clean:modules:stark-build": "cd packages/stark-build && npm run clean:modules && cd ../..",
"clean:modules:stark-core": "cd packages/stark-core && npm run clean:modules && cd ../..",
"clean:modules:stark-rbac": "cd packages/stark-rbac && npm run clean:modules && cd ../..",
"clean:modules:stark-testing": "cd packages/stark-testing && npm run clean:modules && cd ../..",
"clean:modules:stark-ui": "cd packages/stark-ui && npm run clean:modules dist && cd ../..",
"clean:modules:showcase": "cd showcase && npm run clean:modules && cd ..",
"clean:modules:starter": "cd starter && npm run clean:modules && cd ..",
"commit": "./node_modules/.bin/git-cz",
"docs": "npm run docs:clean && npm run docs:all",
"docs:all": "npm run docs:stark-core:generate && npm run docs:stark-ui:generate && npm run docs:starter:generate",
"docs:all": "npm run docs:stark-core:generate && npm run docs:stark-ui:generate && npm run docs:stark-rbac:generate && npm run docs:starter:generate",
"docs:clean": "npx rimraf reports/api-docs",
"docs:coverage": "npm run docs:stark-core:coverage && npm run docs:stark-ui:coverage && npm run docs:starter:coverage",
"docs:coverage": "npm run docs:stark-core:coverage && npm run docs:stark-ui:coverage && npm run docs:stark-rbac:coverage && npm run docs:starter:coverage",
"docs:publish": "bash ./gh-deploy.sh --trace",
"docs:stark-core:coverage": "cd packages/stark-core && npm run docs:coverage && cd ../..",
"docs:stark-core:generate": "cd packages/stark-core && npm run docs && cd ../..",
"docs:stark-core:serve": "cd packages/stark-core && npm run docs:serve && cd ../..",
"docs:stark-rbac:coverage": "cd packages/stark-rbac && npm run docs:coverage && cd ../..",
"docs:stark-rbac:generate": "cd packages/stark-rbac && npm run docs && cd ../..",
"docs:stark-rbac:serve": "cd packages/stark-rbac && npm run docs:serve && cd ../..",
"docs:stark-ui:coverage": "cd packages/stark-ui && npm run docs:coverage && cd ../..",
"docs:stark-ui:generate": "cd packages/stark-ui && npm run docs && cd ../..",
"docs:stark-ui:serve": "cd packages/stark-ui && npm run docs:serve && cd ../..",
Expand All @@ -108,24 +114,27 @@
"generate:changelog-recent": "conventional-changelog -p angular | tail -n +3",
"lint": "tslint --config ./tslint.json --project ./packages/tsconfig.json --format codeFrame",
"lint:stark-core": "cd packages/stark-core && npm run lint && cd ../..",
"lint:stark-rbac": "cd packages/stark-rbac && npm run lint && cd ../..",
"lint:stark-ui": "cd packages/stark-ui && npm run lint && cd ../..",
"lint:showcase": "cd showcase && npm run lint && cd ..",
"lint:starter": "cd starter && npm run lint && cd ..",
"lint:all": "npm run lint:stark-core && npm run lint:stark-ui && npm run lint:starter && npm run lint:showcase",
"install:all": "npm run install:stark-build && npm run install:stark-testing && npm run install:stark-core && npm run install:stark-ui && npm run build && npm run install:starter && npm run install:showcase",
"lint:all": "npm run lint:stark-core && npm run lint:stark-ui && npm run lint:stark-rbac && npm run lint:starter && npm run lint:showcase",
"install:all": "npm run install:stark-build && npm run install:stark-testing && npm run install:stark-core && npm run install:stark-ui && npm run install:stark-rbac && npm run build && npm run install:starter && npm run install:showcase",
"install:stark-build": "cd packages/stark-build && npm install && cd ../..",
"install:stark-core": "cd packages/stark-core && npm install && cd ../..",
"install:stark-rbac": "cd packages/stark-rbac && npm install && cd ../..",
"install:stark-testing": "cd packages/stark-testing && npm install && cd ../..",
"install:stark-ui": "cd packages/stark-ui && npm install && cd ../..",
"install:showcase": "cd showcase && npm install && cd ..",
"install:starter": "cd starter && npm install && cd ..",
"install:ci:all": "npm run install:ci:stark-build && npm run install:ci:stark-testing && npm run install:ci:stark-core && npm run install:ci:stark-ui && npm run build:trace && npm run install:starter && npm run install:ci:showcase",
"install:ci:all": "npm run install:ci:stark-build && npm run install:ci:stark-testing && npm run install:ci:stark-core && npm run install:ci:stark-ui && npm run install:ci:stark-rbac && npm run build:trace && npm run install:starter && npm run install:ci:showcase",
"install:ci:stark-build": "cd packages/stark-build && npm ci && cd ../..",
"install:ci:stark-core": "cd packages/stark-core && npm ci && cd ../..",
"install:ci:stark-rbac": "cd packages/stark-rbac && npm ci && cd ../..",
"install:ci:stark-testing": "cd packages/stark-testing && npm ci && cd ../..",
"install:ci:stark-ui": "cd packages/stark-ui && npm ci && cd ../..",
"install:ci:showcase": "cd showcase && npm ci && cd ..",
"install:travis:all": "npm run install:stark-build && npm run install:stark-testing && npm run install:stark-core && npm run install:stark-ui && npm run build:trace && npm run update:starter && npm run update:showcase",
"install:travis:all": "npm run install:stark-build && npm run install:stark-testing && npm run install:stark-core && npm run install:stark-ui && npm run install:stark-rbac && npm run build:trace && npm run update:starter && npm run update:showcase",
"ngc": "ngc",
"prettier-check": "prettier \"**/*.{css,html,js,json,md,pcss,scss,ts,yml}\" --write --html-whitespace-sensitivity strict",
"preupdate:showcase": "npm run clean:showcase",
Expand All @@ -136,8 +145,9 @@
"starter": "cd starter && npm start && cd ..",
"stylelint-check": "stylelint-config-prettier-check",
"test": "npm run test:ci:all",
"test:all": "npm run test:stark-core && npm run test:stark-ui && npm run test:starter && npm run test:showcase",
"test:all": "npm run test:stark-core && npm run test:stark-ui && npm run test:stark-rbac && npm run test:starter && npm run test:showcase",
"test:stark-core": "cd packages/stark-core && npm run test-fast && cd ../..",
"test:stark-rbac": "cd packages/stark-rbac && npm run test-fast && cd ../..",
"test:stark-ui": "cd packages/stark-ui && npm run test-fast && cd ../..",
"test:showcase": "cd showcase && npm run test-fast && cd ../..",
"test:showcase:e2e": "cd showcase && npm run e2e && cd ../..",
Expand All @@ -146,6 +156,7 @@
"test:starter:e2e": "cd starter && npm run e2e && cd ../..",
"test:ci:all": "npm run test:ci:stark-core && npm run test:ci:stark-ui && npm run test:ci:starter && npm run test:ci:showcase",
"test:ci:stark-core": "cd packages/stark-core && npm run test-fast:ci && cd ../..",
"test:ci:stark-rbac": "cd packages/stark-rbac && npm run test-fast:ci && cd ../..",
"test:ci:stark-ui": "cd packages/stark-ui && npm run test-fast:ci && cd ../..",
"test:ci:showcase": "cd showcase && npm run test-fast:ci && cd ../..",
"test:ci:starter": "cd starter && npm run test-fast:ci && cd ../..",
Expand Down
6 changes: 6 additions & 0 deletions packages/stark-rbac/.compodocrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../node_modules/@compodoc/compodoc/src/config/schema.json",
"theme": "material",
"tsconfig": "../tsconfig.json",
"output": "../../reports/api-docs/stark-rbac"
}
1 change: 1 addition & 0 deletions packages/stark-rbac/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org
16 changes: 16 additions & 0 deletions packages/stark-rbac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[![NPM version](https://img.shields.io/npm/v/@nationalbankbelgium/stark-rbac.svg)](https://www.npmjs.com/package/@nationalbankbelgium/stark-rbac)
[![npm](https://img.shields.io/npm/dm/@nationalbankbelgium/stark-rbac.svg)](https://www.npmjs.com/package/@nationalbankbelgium/stark-rbac)
[![Build Status](https://travis-ci.org/NationalBankBelgium/stark.svg?branch=master)](https://travis-ci.org/NationalBankBelgium/stark)
[![Dependency Status](https://david-dm.org/NationalBankBelgium/stark-rbac.svg)](https://david-dm.org/NationalBankBelgium/stark-rbac)
[![devDependency Status](https://david-dm.org/NationalBankBelgium/stark-rbac/dev-status.svg)](https://david-dm.org/NationalBankBelgium/stark-rbac#info=devDependencies)
[![License](https://img.shields.io/cocoapods/l/AFNetworking.svg)](LICENSE)

# Stark RBAC

Stark's RBAC module (aka stark-rbac) is a separate module in Stark that can be optionally included in any Stark based application in order to provide different elements
(directives, services and components) to support Role Based Access Control (RBAC) mechanism.

The Stark-RBAC module depends on some functionalities provided by the Stark-Core module such as services. However you can use this module without Stark-Core
as long as you provide the same functionalities/services yourself.

**[Getting Started](https://stark.nbb.be/api-docs/stark-rbac/latest/additional-documentation/getting-started.html)**
30 changes: 30 additions & 0 deletions packages/stark-rbac/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoots": "projects",
"projects": {
"stark-rbac": {
"root": "",
"sourceRoot": "src",
"projectType": "library",
"architect": {
"build": {
"options": {
"outputPath": "dist",
"tsConfig": "tsconfig-build.json",
"assets": []
}
},
"test": {
"options": {
"main": "base.spec.ts",
"outputPath": "dist",
"tsConfig": "tsconfig.spec.json",
"assets": []
}
}
}
}
},
"defaultProject": "stark-rbac"
}
41 changes: 41 additions & 0 deletions packages/stark-rbac/base.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

import "core-js/es6";
import "core-js/es7/reflect";
import "core-js/es7/string";
import "core-js/stage/4";

// IE polyfills

// See https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
if (!Element.prototype.matches) {
// @ts-ignore
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}

// See: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill
// @ts-ignore: Window.NodeList
if (window.NodeList && !NodeList.prototype.forEach) {
// @ts-ignore: forEach mismatching types
NodeList.prototype.forEach = Array.prototype.forEach;
}

/* tslint:disable:no-import-side-effect */
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy"; // since zone.js 0.6.15
import "zone.js/dist/sync-test";
import "zone.js/dist/jasmine-patch"; // put here since zone.js 0.6.14
import "zone.js/dist/async-test";
import "zone.js/dist/fake-async-test";
import "zone.js/dist/zone-patch-rxjs";
import "zone.js/dist/zone-patch-rxjs-fake-async";
/* tslint:enable:no-import-side-effect */

import { TestBed } from "@angular/core/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";

TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

// define global environment variable (used in some places in stark-ui)
global["ENV"] = "development";
6 changes: 6 additions & 0 deletions packages/stark-rbac/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is not used to build this module. It is only used during editing
// by the TypeScript language service and during build for verification. `ngc`
// replaces this file with production index.ts when it rewrites private symbol
// names.

export * from "./public_api";
36 changes: 36 additions & 0 deletions packages/stark-rbac/karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
*/
const defaultKarmaCIConfig = require("../stark-testing/karma.conf.ci.js").rawKarmaConfig;
const karmaTypescriptBundlerAliasResolution = require("./karma.conf").karmaTypescriptBundlerAliasResolution;
const karmaTypescriptFiles = require("./karma.conf").karmaTypescriptFiles;

// start customizing the KarmaCI configuration from stark-testing
const starkRBACSpecificConfiguration = {
...defaultKarmaCIConfig,
// change the module resolution for the KarmaTypescript bundler
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
...karmaTypescriptBundlerAliasResolution,
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
},
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: { ...defaultKarmaCIConfig.coverageIstanbulReporter, dir: helpers.root("reports/coverage/packages") },
// add missing files due to "@nationalbankbelgium/stark-rbac" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles]
};

// export the configuration function that karma expects and simply return the stark configuration
module.exports = config => {
return config.set(starkRBACSpecificConfiguration);
};
Loading

0 comments on commit 53d3f33

Please sign in to comment.