mirror of https://github.com/abpframework/abp.git
23 changed files with 647 additions and 330 deletions
@ -0,0 +1,36 @@ |
|||
{ |
|||
"extends": ["../../.eslintrc.json"], |
|||
"ignorePatterns": ["!**/*"], |
|||
"overrides": [ |
|||
{ |
|||
"files": ["*.ts"], |
|||
"extends": [ |
|||
"plugin:@nrwl/nx/angular", |
|||
"plugin:@angular-eslint/template/process-inline-templates" |
|||
], |
|||
"rules": { |
|||
"@angular-eslint/directive-selector": [ |
|||
"error", |
|||
{ |
|||
"type": "attribute", |
|||
"prefix": "abp", |
|||
"style": "camelCase" |
|||
} |
|||
], |
|||
"@angular-eslint/component-selector": [ |
|||
"error", |
|||
{ |
|||
"type": "element", |
|||
"prefix": "abp", |
|||
"style": "kebab-case" |
|||
} |
|||
] |
|||
} |
|||
}, |
|||
{ |
|||
"files": ["*.html"], |
|||
"extends": ["plugin:@nrwl/nx/angular-template"], |
|||
"rules": {} |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
# @abp/ng.account.core |
|||
|
|||
Visit the [ABP documentation](https://docs.abp.io) |
|||
@ -0,0 +1,20 @@ |
|||
module.exports = { |
|||
displayName: 'account-core', |
|||
preset: '../../jest.preset.js', |
|||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], |
|||
globals: { |
|||
'ts-jest': { |
|||
tsconfig: '<rootDir>/tsconfig.spec.json', |
|||
stringifyContentPathRegex: '\\.(html|svg)$', |
|||
}, |
|||
}, |
|||
coverageDirectory: '../../coverage/packages/account-core', |
|||
transform: { |
|||
'^.+\\.(ts|js|html)$': 'jest-preset-angular', |
|||
}, |
|||
snapshotSerializers: [ |
|||
'jest-preset-angular/build/serializers/no-ng-attributes', |
|||
'jest-preset-angular/build/serializers/ng-snapshot', |
|||
'jest-preset-angular/build/serializers/html-comment', |
|||
], |
|||
}; |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json", |
|||
"dest": "../../dist/packages/account-core", |
|||
"lib": { |
|||
"entryFile": "src/public-api.ts" |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
{ |
|||
"name": "@abp/ng.account.core", |
|||
"version": "4.4.0", |
|||
"homepage": "https://abp.io", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "https://github.com/abpframework/abp.git" |
|||
}, |
|||
"peerDependencies": { |
|||
"@abp/ng.core": "~4.4.0", |
|||
"@abp/ng.theme.shared": "~4.4.0", |
|||
"@angular/common": ">=12.0.0", |
|||
"@angular/core": ">=12.0.0" |
|||
}, |
|||
"dependencies": { |
|||
"tslib": "^2.0.0" |
|||
}, |
|||
"publishConfig": { |
|||
"access": "public" |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
import { TestBed } from '@angular/core/testing'; |
|||
|
|||
import { AuthWrapperService } from './auth-wrapper.service'; |
|||
|
|||
describe('AuthWrapperService', () => { |
|||
let service: AuthWrapperService; |
|||
|
|||
beforeEach(() => { |
|||
TestBed.configureTestingModule({}); |
|||
service = TestBed.inject(AuthWrapperService); |
|||
}); |
|||
|
|||
it('should be created', () => { |
|||
expect(service).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,46 @@ |
|||
import { Injectable, Injector } from '@angular/core'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map } from 'rxjs/operators'; |
|||
import { ActivatedRoute } from '@angular/router'; |
|||
import { ConfigStateService, MultiTenancyService } from '@abp/ng.core'; |
|||
|
|||
@Injectable() |
|||
export class AuthWrapperService { |
|||
isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled'); |
|||
|
|||
get enableLocalLogin$(): Observable<boolean> { |
|||
return this.configState |
|||
.getSetting$('Abp.Account.EnableLocalLogin') |
|||
.pipe(map(value => value?.toLowerCase() !== 'false')); |
|||
} |
|||
|
|||
tenantBoxKey = 'Account.TenantBoxComponent'; |
|||
route: ActivatedRoute; |
|||
|
|||
get isTenantBoxVisibleForCurrentRoute() { |
|||
return this.getMostInnerChild().data.tenantBoxVisible ?? true; |
|||
} |
|||
|
|||
get isTenantBoxVisible() { |
|||
return this.isTenantBoxVisibleForCurrentRoute && this.multiTenancy.isTenantBoxVisible; |
|||
} |
|||
|
|||
constructor( |
|||
public readonly multiTenancy: MultiTenancyService, |
|||
private configState: ConfigStateService, |
|||
injector: Injector, |
|||
) { |
|||
this.route = injector.get(ActivatedRoute); |
|||
} |
|||
|
|||
private getMostInnerChild() { |
|||
let child = this.route.snapshot; |
|||
let depth = 0; |
|||
const depthLimit = 10; |
|||
while (child.firstChild && depth < depthLimit) { |
|||
child = child.firstChild; |
|||
depth++; |
|||
} |
|||
return child; |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
import { TestBed } from '@angular/core/testing'; |
|||
|
|||
import { TenantBoxService } from './tenant-box.service'; |
|||
|
|||
describe('TenantBoxService', () => { |
|||
let service: TenantBoxService; |
|||
|
|||
beforeEach(() => { |
|||
TestBed.configureTestingModule({}); |
|||
service = TestBed.inject(TenantBoxService); |
|||
}); |
|||
|
|||
it('should be created', () => { |
|||
expect(service).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,68 @@ |
|||
import { Injectable } from '@angular/core'; |
|||
import { ToasterService } from '@abp/ng.theme.shared'; |
|||
import { |
|||
AbpApplicationConfigurationService, |
|||
AbpTenantService, |
|||
ConfigStateService, |
|||
CurrentTenantDto, |
|||
SessionStateService, |
|||
} from '@abp/ng.core'; |
|||
import { finalize } from 'rxjs/operators'; |
|||
|
|||
@Injectable() |
|||
export class TenantBoxService { |
|||
currentTenant$ = this.sessionState.getTenant$(); |
|||
|
|||
name: string; |
|||
|
|||
isModalVisible: boolean; |
|||
|
|||
modalBusy: boolean; |
|||
|
|||
constructor( |
|||
private toasterService: ToasterService, |
|||
private tenantService: AbpTenantService, |
|||
private sessionState: SessionStateService, |
|||
private configState: ConfigStateService, |
|||
private appConfigService: AbpApplicationConfigurationService, |
|||
) {} |
|||
|
|||
onSwitch() { |
|||
const tenant = this.sessionState.getTenant(); |
|||
this.name = tenant?.name; |
|||
this.isModalVisible = true; |
|||
} |
|||
|
|||
save() { |
|||
if (!this.name) { |
|||
this.setTenant(null); |
|||
this.isModalVisible = false; |
|||
return; |
|||
} |
|||
|
|||
this.modalBusy = true; |
|||
this.tenantService |
|||
.findTenantByName(this.name, {}) |
|||
.pipe(finalize(() => (this.modalBusy = false))) |
|||
.subscribe(({ success, tenantId: id, ...tenant }) => { |
|||
if (!success) { |
|||
this.showError(); |
|||
return; |
|||
} |
|||
|
|||
this.setTenant({ ...tenant, id, isAvailable: true }); |
|||
this.isModalVisible = false; |
|||
}); |
|||
} |
|||
|
|||
private setTenant(tenant: CurrentTenantDto) { |
|||
this.sessionState.setTenant(tenant); |
|||
this.appConfigService.get().subscribe(res => this.configState.setState(res)); |
|||
} |
|||
|
|||
private showError() { |
|||
this.toasterService.error('AbpUiMultiTenancy::GivenTenantIsNotAvailable', 'AbpUi::Error', { |
|||
messageLocalizationParams: [this.name], |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
/* |
|||
* Public API Surface of account-core |
|||
*/ |
|||
|
|||
export * from './lib/auth-wrapper.service'; |
|||
export * from './lib/tenant-box.service'; |
|||
@ -0,0 +1 @@ |
|||
import 'jest-preset-angular/setup-jest'; |
|||
@ -0,0 +1,13 @@ |
|||
{ |
|||
"extends": "../../tsconfig.base.json", |
|||
"files": [], |
|||
"include": [], |
|||
"references": [ |
|||
{ |
|||
"path": "./tsconfig.lib.json" |
|||
}, |
|||
{ |
|||
"path": "./tsconfig.spec.json" |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
{ |
|||
"extends": "./tsconfig.json", |
|||
"compilerOptions": { |
|||
"outDir": "../../dist/out-tsc", |
|||
"target": "es2015", |
|||
"declaration": true, |
|||
"declarationMap": true, |
|||
"inlineSources": true, |
|||
"types": [], |
|||
"lib": ["dom", "es2018"] |
|||
}, |
|||
"exclude": ["src/test-setup.ts", "**/*.spec.ts"], |
|||
"include": ["**/*.ts"] |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ |
|||
{ |
|||
"extends": "./tsconfig.lib.json", |
|||
"compilerOptions": { |
|||
"declarationMap": false |
|||
}, |
|||
"angularCompilerOptions": { |
|||
"compilationMode": "partial", |
|||
"enableIvy": false |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
{ |
|||
"extends": "./tsconfig.json", |
|||
"compilerOptions": { |
|||
"outDir": "../../dist/out-tsc", |
|||
"module": "commonjs", |
|||
"types": ["jest", "node"] |
|||
}, |
|||
"files": ["src/test-setup.ts"], |
|||
"include": ["**/*.spec.ts", "**/*.d.ts"] |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue