diff --git a/.github/labeler.yml b/.github/labeler.yml index 2dded9549b..cb0c9cddbd 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,7 +1,15 @@ ui-angular: - npm/ng-packs/* - npm/ng-packs/**/* + - npm/ng-packs/**/**/* + - npm/ng-packs/**/**/**/* + - npm/ng-packs/**/**/**/**/* + - npm/ng-packs/**/**/**/**/**/* - templates/app/angular/* - templates/app/angular/**/* + - templates/app/angular/**/**/* + - templates/app/angular/**/**/**/* - templates/module/angular/* - templates/module/angular/**/* + - templates/module/angular/**/**/* + - templates/module/angular/**/**/**/* diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 2796d177d1..b1ab143f46 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,7 +1,7 @@ name: Pull request labeler on: schedule: - - cron: '0 */1 * * *' + - cron: '0 */2 * * *' jobs: labeler: runs-on: ubuntu-latest diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index d27de75865..6ce3ce3c0c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -21,9 +21,5 @@ namespace Volo.Abp.Identity bool includeDetails = false, CancellationToken cancellationToken = default ); - - Task GetCountAsync( - CancellationToken cancellationToken = default - ); } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index 81c6106b7d..50c1403a03 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -43,11 +43,5 @@ namespace Volo.Abp.Identity.MongoDB .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } - - public async Task GetCountAsync(CancellationToken cancellationToken = default) - { - return await GetMongoQueryable() - .LongCountAsync(GetCancellationToken(cancellationToken)); - } } } \ No newline at end of file diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs index 886d546073..8c0beffd1a 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -7,8 +8,17 @@ namespace Volo.Abp.PermissionManagement { public interface IPermissionGrantRepository : IBasicRepository { - Task FindAsync(string name, string providerName, string providerKey); + Task FindAsync( + string name, + string providerName, + string providerKey, + CancellationToken cancellationToken = default + ); - Task> GetListAsync(string providerName, string providerKey); + Task> GetListAsync( + string providerName, + string providerKey, + CancellationToken cancellationToken = default + ); } } \ No newline at end of file diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs index 413a960c7c..d8241d6f8f 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -8,7 +9,8 @@ using Volo.Abp.EntityFrameworkCore; namespace Volo.Abp.PermissionManagement.EntityFrameworkCore { - public class EfCorePermissionGrantRepository : EfCoreRepository, IPermissionGrantRepository + public class EfCorePermissionGrantRepository : EfCoreRepository, + IPermissionGrantRepository { public EfCorePermissionGrantRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) @@ -16,23 +18,31 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore } - public async Task FindAsync(string name, string providerName, string providerKey) + public async Task FindAsync( + string name, + string providerName, + string providerKey, + CancellationToken cancellationToken = default) { return await DbSet .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && - s.ProviderKey == providerKey + s.ProviderKey == providerKey, + GetCancellationToken(cancellationToken) ); } - public async Task> GetListAsync(string providerName, string providerKey) + public async Task> GetListAsync( + string providerName, + string providerKey, + CancellationToken cancellationToken = default) { return await DbSet .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey - ).ToListAsync(); + ).ToListAsync(GetCancellationToken(cancellationToken)); } } } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs index 70614c890d..67befaa717 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -16,23 +17,31 @@ namespace Volo.Abp.PermissionManagement.MongoDB } - public async Task FindAsync(string name, string providerName, string providerKey) + public async Task FindAsync( + string name, + string providerName, + string providerKey, + CancellationToken cancellationToken = default) { return await GetMongoQueryable() .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && - s.ProviderKey == providerKey + s.ProviderKey == providerKey, + GetCancellationToken(cancellationToken) ); } - public async Task> GetListAsync(string providerName, string providerKey) + public async Task> GetListAsync( + string providerName, + string providerKey, + CancellationToken cancellationToken = default) { return await GetMongoQueryable() .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey - ).ToListAsync(); + ).ToListAsync(GetCancellationToken(cancellationToken)); } } } \ No newline at end of file diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index a32a101de2..1e959b3e54 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -229,7 +229,7 @@ export class ConfigState { const index = flattedRoutes.findIndex(route => route.name === name); if (index > -1) { - flattedRoutes[index] = newValue as ABP.FullRoute; + flattedRoutes[index] = { ...flattedRoutes[index], ...newValue } as ABP.FullRoute; } return patchState({ diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index 1fd2e45b35..635ca1d8b1 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -1,17 +1,12 @@ -import { - createServiceFactory, - SpectatorService, - SpyObject, -} from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { Store } from '@ngxs/store'; import { ReplaySubject, timer, Subject, of } from 'rxjs'; import { Config } from '../models/config'; -import { - ApplicationConfigurationService, - ConfigStateService, -} from '../services'; +import { ApplicationConfigurationService, ConfigStateService } from '../services'; import { ConfigState } from '../states'; -import { SetLanguage, PatchRouteByName } from '../actions'; +import { SetLanguage, PatchRouteByName, AddRoute } from '../actions'; +import clone from 'just-clone'; +import { ABP } from '../models'; export const CONFIG_STATE_DATA = { environment: { @@ -55,6 +50,7 @@ export const CONFIG_STATE_DATA = { name: 'AbpAccount::Login', order: 1, url: '/account/login', + parentName: 'AbpAccount::Menu:Account', }, ], url: '/account', @@ -68,10 +64,27 @@ export const CONFIG_STATE_DATA = { url: '/', }, { - name: '::Menu:Identity', - path: 'identity', - children: [], - url: '/identity', + name: 'AbpAccount::Menu:Account', + path: 'account', + invisible: true, + layout: 'application', + children: [ + { + path: 'login', + name: 'AbpAccount::Login', + order: 1, + url: '/account/login', + parentName: 'AbpAccount::Menu:Account', + }, + ], + url: '/account', + }, + { + path: 'login', + name: 'AbpAccount::Login', + order: 1, + url: '/account/login', + parentName: 'AbpAccount::Menu:Account', }, ], localization: { @@ -134,10 +147,7 @@ describe('ConfigState', () => { store = spectator.get(Store); service = spectator.service; appConfigService = spectator.get(ApplicationConfigurationService); - state = new ConfigState( - spectator.get(ApplicationConfigurationService), - store, - ); + state = new ConfigState(spectator.get(ApplicationConfigurationService), store); }); describe('#getAll', () => { @@ -165,16 +175,12 @@ describe('ConfigState', () => { describe('#getDeep', () => { it('should return deeper', () => { expect( - ConfigState.getDeep('environment.localization.defaultResourceName')( - CONFIG_STATE_DATA, - ), + ConfigState.getDeep('environment.localization.defaultResourceName')(CONFIG_STATE_DATA), ).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName); expect( - ConfigState.getDeep([ - 'environment', - 'localization', - 'defaultResourceName', - ])(CONFIG_STATE_DATA), + ConfigState.getDeep(['environment', 'localization', 'defaultResourceName'])( + CONFIG_STATE_DATA, + ), ).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName); expect(ConfigState.getDeep('test')(null)).toBeFalsy(); @@ -183,10 +189,10 @@ describe('ConfigState', () => { describe('#getRoute', () => { it('should return route', () => { - expect( - ConfigState.getRoute(null, '::Menu:Home')(CONFIG_STATE_DATA), - ).toEqual(CONFIG_STATE_DATA.flattedRoutes[0]); - expect(ConfigState.getRoute('identity')(CONFIG_STATE_DATA)).toEqual( + expect(ConfigState.getRoute(null, '::Menu:Home')(CONFIG_STATE_DATA)).toEqual( + CONFIG_STATE_DATA.flattedRoutes[0], + ); + expect(ConfigState.getRoute('account')(CONFIG_STATE_DATA)).toEqual( CONFIG_STATE_DATA.flattedRoutes[1], ); }); @@ -205,11 +211,7 @@ describe('ConfigState', () => { describe('#getSetting', () => { it('should return a setting', () => { - expect( - ConfigState.getSetting('Abp.Localization.DefaultLanguage')( - CONFIG_STATE_DATA, - ), - ).toEqual( + expect(ConfigState.getSetting('Abp.Localization.DefaultLanguage')(CONFIG_STATE_DATA)).toEqual( CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage'], ); }); @@ -217,9 +219,7 @@ describe('ConfigState', () => { describe('#getSettings', () => { it('should return settings', () => { - expect( - ConfigState.getSettings('Localization')(CONFIG_STATE_DATA), - ).toEqual({ + expect(ConfigState.getSettings('Localization')(CONFIG_STATE_DATA)).toEqual({ 'Abp.Localization.DefaultLanguage': 'en', }); @@ -231,45 +231,31 @@ describe('ConfigState', () => { describe('#getGrantedPolicy', () => { it('should return a granted policy', () => { - expect( - ConfigState.getGrantedPolicy('Abp.Identity')(CONFIG_STATE_DATA), - ).toBe(false); - expect( - ConfigState.getGrantedPolicy('Abp.Identity || Abp.Account')( - CONFIG_STATE_DATA, - ), - ).toBe(true); - expect( - ConfigState.getGrantedPolicy('Abp.Account && Abp.Identity')( - CONFIG_STATE_DATA, - ), - ).toBe(false); - expect( - ConfigState.getGrantedPolicy('Abp.Account &&')(CONFIG_STATE_DATA), - ).toBe(false); - expect( - ConfigState.getGrantedPolicy('|| Abp.Account')(CONFIG_STATE_DATA), - ).toBe(false); + expect(ConfigState.getGrantedPolicy('Abp.Identity')(CONFIG_STATE_DATA)).toBe(false); + expect(ConfigState.getGrantedPolicy('Abp.Identity || Abp.Account')(CONFIG_STATE_DATA)).toBe( + true, + ); + expect(ConfigState.getGrantedPolicy('Abp.Account && Abp.Identity')(CONFIG_STATE_DATA)).toBe( + false, + ); + expect(ConfigState.getGrantedPolicy('Abp.Account &&')(CONFIG_STATE_DATA)).toBe(false); + expect(ConfigState.getGrantedPolicy('|| Abp.Account')(CONFIG_STATE_DATA)).toBe(false); expect(ConfigState.getGrantedPolicy('')(CONFIG_STATE_DATA)).toBe(true); }); }); describe('#getLocalization', () => { it('should return a localization', () => { - expect( - ConfigState.getLocalization('AbpIdentity::Identity')(CONFIG_STATE_DATA), - ).toBe('identity'); + expect(ConfigState.getLocalization('AbpIdentity::Identity')(CONFIG_STATE_DATA)).toBe( + 'identity', + ); - expect( - ConfigState.getLocalization('AbpIdentity::NoIdentity')( - CONFIG_STATE_DATA, - ), - ).toBe('AbpIdentity::NoIdentity'); + expect(ConfigState.getLocalization('AbpIdentity::NoIdentity')(CONFIG_STATE_DATA)).toBe( + 'AbpIdentity::NoIdentity', + ); expect( - ConfigState.getLocalization({ key: '', defaultValue: 'default' })( - CONFIG_STATE_DATA, - ), + ConfigState.getLocalization({ key: '', defaultValue: 'default' })(CONFIG_STATE_DATA), ).toBe('default'); expect( @@ -290,9 +276,7 @@ describe('ConfigState', () => { }); expect(false).toBeTruthy(); // fail } catch (error) { - expect((error as Error).message).toContain( - 'Please check your environment', - ); + expect((error as Error).message).toContain('Please check your environment'); } }); }); @@ -328,11 +312,11 @@ describe('ConfigState', () => { }); describe('#PatchRouteByName', () => { - it('should should patch the route', () => { + it('should patch the route', () => { let patchStateArg; const patchState = jest.fn(s => (patchStateArg = s)); - const getState = jest.fn(() => CONFIG_STATE_DATA); + const getState = jest.fn(() => clone(CONFIG_STATE_DATA)); state.patchRoute( { patchState, getState } as any, @@ -347,17 +331,21 @@ describe('ConfigState', () => { name: 'Home', path: 'home', url: '/home', - children: [ - { path: 'dashboard', name: 'Dashboard', url: '/home/dashboard' }, - ], + children: [{ path: 'dashboard', name: 'Dashboard', url: '/home/dashboard' }], + }); + expect(patchStateArg.flattedRoutes[0]).toEqual({ + name: 'Home', + path: 'home', + url: '/home', + children: [{ path: 'dashboard', name: 'Dashboard', url: '/home/dashboard' }], }); }); - it('should should patch the route without path', () => { + it('should patch the route without path', () => { let patchStateArg; const patchState = jest.fn(s => (patchStateArg = s)); - const getState = jest.fn(() => CONFIG_STATE_DATA); + const getState = jest.fn(() => clone(CONFIG_STATE_DATA)); state.patchRoute( { patchState, getState } as any, @@ -373,6 +361,69 @@ describe('ConfigState', () => { url: '/', children: [{ path: 'dashboard', name: 'Dashboard', url: '/dashboard' }], }); + + expect(patchStateArg.flattedRoutes[0]).toEqual({ + name: 'Main', + path: '', + url: '/', + children: [{ path: 'dashboard', name: 'Dashboard', url: '/dashboard' }], + }); + }); + }); + + describe('#AddRoute', () => { + const newRoute = { + name: 'My new page', + iconClass: 'fa fa-dashboard', + path: 'page', + invisible: false, + order: 2, + requiredPolicy: 'MyProjectName::MyNewPage', + } as Omit; + + test('should add a new route', () => { + let patchStateArg; + + const patchState = jest.fn(s => (patchStateArg = s)); + const getState = jest.fn(() => clone(CONFIG_STATE_DATA)); + + state.addRoute({ patchState, getState } as any, new AddRoute(newRoute)); + + expect(patchStateArg.routes[CONFIG_STATE_DATA.routes.length]).toEqual({ + ...newRoute, + url: '/page', + }); + expect(patchStateArg.flattedRoutes[CONFIG_STATE_DATA.flattedRoutes.length]).toEqual( + patchStateArg.routes[CONFIG_STATE_DATA.routes.length], + ); + }); + + it('should add a new child route', () => { + let patchStateArg; + + const patchState = jest.fn(s => (patchStateArg = s)); + const getState = jest.fn(() => clone(CONFIG_STATE_DATA)); + + state.addRoute( + { patchState, getState } as any, + new AddRoute({ ...newRoute, parentName: 'AbpAccount::Login' }), + ); + + expect(patchStateArg.routes[1].children[0].children[0]).toEqual({ + ...newRoute, + parentName: 'AbpAccount::Login', + url: '/account/login/page', + }); + + expect(patchStateArg.flattedRoutes[CONFIG_STATE_DATA.flattedRoutes.length]).toEqual( + patchStateArg.routes[1].children[0].children[0], + ); + + expect( + patchStateArg.flattedRoutes[ + CONFIG_STATE_DATA.flattedRoutes.findIndex(route => route.name === 'AbpAccount::Login') + ], + ).toEqual(patchStateArg.routes[1].children[0]); }); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/date-extensions.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/date-extensions.spec.ts new file mode 100644 index 0000000000..3d743ae003 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/date-extensions.spec.ts @@ -0,0 +1,17 @@ +import '../utils/date-extensions'; + +describe('DateExtensions', () => { + describe('#toLocalISOString', () => { + test('should able to use as date prototype', () => { + new Date().toLocalISOString(); + }); + + test('should return correct value', () => { + const now = new Date(); + const timezoneOffset = now.getTimezoneOffset(); + expect(now.toLocalISOString()).toEqual( + new Date(now.getTime() - timezoneOffset * 60000).toISOString(), + ); + }); + }); +});