Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into feat/replaceable-components

pull/2522/head
mehmet-erim 7 years ago
parent
commit
d7e3a5e95c
  1. 8
      .github/labeler.yml
  2. 2
      .github/workflows/labeler.yml
  3. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  4. 6
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  5. 14
      modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs
  6. 20
      modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs
  7. 17
      modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs
  8. 2
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  9. 207
      npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts
  10. 17
      npm/ng-packs/packages/core/src/lib/tests/date-extensions.spec.ts

8
.github/labeler.yml

@ -1,7 +1,15 @@
ui-angular: ui-angular:
- npm/ng-packs/* - npm/ng-packs/*
- 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/app/angular/**/**/*
- templates/app/angular/**/**/**/*
- templates/module/angular/* - templates/module/angular/*
- templates/module/angular/**/* - templates/module/angular/**/*
- templates/module/angular/**/**/*
- templates/module/angular/**/**/**/*

2
.github/workflows/labeler.yml

@ -1,7 +1,7 @@
name: Pull request labeler name: Pull request labeler
on: on:
schedule: schedule:
- cron: '0 */1 * * *' - cron: '0 */2 * * *'
jobs: jobs:
labeler: labeler:
runs-on: ubuntu-latest runs-on: ubuntu-latest

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -21,9 +21,5 @@ namespace Volo.Abp.Identity
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<long> GetCountAsync(
CancellationToken cancellationToken = default
);
} }
} }

6
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -43,11 +43,5 @@ namespace Volo.Abp.Identity.MongoDB
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount) .PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
} }
} }

14
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IPermissionGrantRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,8 +8,17 @@ namespace Volo.Abp.PermissionManagement
{ {
public interface IPermissionGrantRepository : IBasicRepository<PermissionGrant, Guid> public interface IPermissionGrantRepository : IBasicRepository<PermissionGrant, Guid>
{ {
Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey); Task<PermissionGrant> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default
);
Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey); Task<List<PermissionGrant>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default
);
} }
} }

20
modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -8,7 +9,8 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore namespace Volo.Abp.PermissionManagement.EntityFrameworkCore
{ {
public class EfCorePermissionGrantRepository : EfCoreRepository<IPermissionManagementDbContext, PermissionGrant, Guid>, IPermissionGrantRepository public class EfCorePermissionGrantRepository : EfCoreRepository<IPermissionManagementDbContext, PermissionGrant, Guid>,
IPermissionGrantRepository
{ {
public EfCorePermissionGrantRepository(IDbContextProvider<IPermissionManagementDbContext> dbContextProvider) public EfCorePermissionGrantRepository(IDbContextProvider<IPermissionManagementDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
@ -16,23 +18,31 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore
} }
public async Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey) public async Task<PermissionGrant> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.FirstOrDefaultAsync(s => .FirstOrDefaultAsync(s =>
s.Name == name && s.Name == name &&
s.ProviderName == providerName && s.ProviderName == providerName &&
s.ProviderKey == providerKey s.ProviderKey == providerKey,
GetCancellationToken(cancellationToken)
); );
} }
public async Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey) public async Task<List<PermissionGrant>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.Where(s => .Where(s =>
s.ProviderName == providerName && s.ProviderName == providerName &&
s.ProviderKey == providerKey s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

17
modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -16,23 +17,31 @@ namespace Volo.Abp.PermissionManagement.MongoDB
} }
public async Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey) public async Task<PermissionGrant> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.FirstOrDefaultAsync(s => .FirstOrDefaultAsync(s =>
s.Name == name && s.Name == name &&
s.ProviderName == providerName && s.ProviderName == providerName &&
s.ProviderKey == providerKey s.ProviderKey == providerKey,
GetCancellationToken(cancellationToken)
); );
} }
public async Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey) public async Task<List<PermissionGrant>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(s => .Where(s =>
s.ProviderName == providerName && s.ProviderName == providerName &&
s.ProviderKey == providerKey s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

2
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); const index = flattedRoutes.findIndex(route => route.name === name);
if (index > -1) { if (index > -1) {
flattedRoutes[index] = newValue as ABP.FullRoute; flattedRoutes[index] = { ...flattedRoutes[index], ...newValue } as ABP.FullRoute;
} }
return patchState({ return patchState({

207
npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts

@ -1,17 +1,12 @@
import { import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest';
createServiceFactory,
SpectatorService,
SpyObject,
} from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { ReplaySubject, timer, Subject, of } from 'rxjs'; import { ReplaySubject, timer, Subject, of } from 'rxjs';
import { Config } from '../models/config'; import { Config } from '../models/config';
import { import { ApplicationConfigurationService, ConfigStateService } from '../services';
ApplicationConfigurationService,
ConfigStateService,
} from '../services';
import { ConfigState } from '../states'; 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 = { export const CONFIG_STATE_DATA = {
environment: { environment: {
@ -55,6 +50,7 @@ export const CONFIG_STATE_DATA = {
name: 'AbpAccount::Login', name: 'AbpAccount::Login',
order: 1, order: 1,
url: '/account/login', url: '/account/login',
parentName: 'AbpAccount::Menu:Account',
}, },
], ],
url: '/account', url: '/account',
@ -68,10 +64,27 @@ export const CONFIG_STATE_DATA = {
url: '/', url: '/',
}, },
{ {
name: '::Menu:Identity', name: 'AbpAccount::Menu:Account',
path: 'identity', path: 'account',
children: [], invisible: true,
url: '/identity', 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: { localization: {
@ -134,10 +147,7 @@ describe('ConfigState', () => {
store = spectator.get(Store); store = spectator.get(Store);
service = spectator.service; service = spectator.service;
appConfigService = spectator.get(ApplicationConfigurationService); appConfigService = spectator.get(ApplicationConfigurationService);
state = new ConfigState( state = new ConfigState(spectator.get(ApplicationConfigurationService), store);
spectator.get(ApplicationConfigurationService),
store,
);
}); });
describe('#getAll', () => { describe('#getAll', () => {
@ -165,16 +175,12 @@ describe('ConfigState', () => {
describe('#getDeep', () => { describe('#getDeep', () => {
it('should return deeper', () => { it('should return deeper', () => {
expect( expect(
ConfigState.getDeep('environment.localization.defaultResourceName')( ConfigState.getDeep('environment.localization.defaultResourceName')(CONFIG_STATE_DATA),
CONFIG_STATE_DATA,
),
).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName); ).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName);
expect( expect(
ConfigState.getDeep([ ConfigState.getDeep(['environment', 'localization', 'defaultResourceName'])(
'environment', CONFIG_STATE_DATA,
'localization', ),
'defaultResourceName',
])(CONFIG_STATE_DATA),
).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName); ).toEqual(CONFIG_STATE_DATA.environment.localization.defaultResourceName);
expect(ConfigState.getDeep('test')(null)).toBeFalsy(); expect(ConfigState.getDeep('test')(null)).toBeFalsy();
@ -183,10 +189,10 @@ describe('ConfigState', () => {
describe('#getRoute', () => { describe('#getRoute', () => {
it('should return route', () => { it('should return route', () => {
expect( expect(ConfigState.getRoute(null, '::Menu:Home')(CONFIG_STATE_DATA)).toEqual(
ConfigState.getRoute(null, '::Menu:Home')(CONFIG_STATE_DATA), CONFIG_STATE_DATA.flattedRoutes[0],
).toEqual(CONFIG_STATE_DATA.flattedRoutes[0]); );
expect(ConfigState.getRoute('identity')(CONFIG_STATE_DATA)).toEqual( expect(ConfigState.getRoute('account')(CONFIG_STATE_DATA)).toEqual(
CONFIG_STATE_DATA.flattedRoutes[1], CONFIG_STATE_DATA.flattedRoutes[1],
); );
}); });
@ -205,11 +211,7 @@ describe('ConfigState', () => {
describe('#getSetting', () => { describe('#getSetting', () => {
it('should return a setting', () => { it('should return a setting', () => {
expect( expect(ConfigState.getSetting('Abp.Localization.DefaultLanguage')(CONFIG_STATE_DATA)).toEqual(
ConfigState.getSetting('Abp.Localization.DefaultLanguage')(
CONFIG_STATE_DATA,
),
).toEqual(
CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage'], CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage'],
); );
}); });
@ -217,9 +219,7 @@ describe('ConfigState', () => {
describe('#getSettings', () => { describe('#getSettings', () => {
it('should return settings', () => { it('should return settings', () => {
expect( expect(ConfigState.getSettings('Localization')(CONFIG_STATE_DATA)).toEqual({
ConfigState.getSettings('Localization')(CONFIG_STATE_DATA),
).toEqual({
'Abp.Localization.DefaultLanguage': 'en', 'Abp.Localization.DefaultLanguage': 'en',
}); });
@ -231,45 +231,31 @@ describe('ConfigState', () => {
describe('#getGrantedPolicy', () => { describe('#getGrantedPolicy', () => {
it('should return a granted policy', () => { it('should return a granted policy', () => {
expect( expect(ConfigState.getGrantedPolicy('Abp.Identity')(CONFIG_STATE_DATA)).toBe(false);
ConfigState.getGrantedPolicy('Abp.Identity')(CONFIG_STATE_DATA), expect(ConfigState.getGrantedPolicy('Abp.Identity || Abp.Account')(CONFIG_STATE_DATA)).toBe(
).toBe(false); true,
expect( );
ConfigState.getGrantedPolicy('Abp.Identity || Abp.Account')( expect(ConfigState.getGrantedPolicy('Abp.Account && Abp.Identity')(CONFIG_STATE_DATA)).toBe(
CONFIG_STATE_DATA, false,
), );
).toBe(true); expect(ConfigState.getGrantedPolicy('Abp.Account &&')(CONFIG_STATE_DATA)).toBe(false);
expect( expect(ConfigState.getGrantedPolicy('|| Abp.Account')(CONFIG_STATE_DATA)).toBe(false);
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); expect(ConfigState.getGrantedPolicy('')(CONFIG_STATE_DATA)).toBe(true);
}); });
}); });
describe('#getLocalization', () => { describe('#getLocalization', () => {
it('should return a localization', () => { it('should return a localization', () => {
expect( expect(ConfigState.getLocalization('AbpIdentity::Identity')(CONFIG_STATE_DATA)).toBe(
ConfigState.getLocalization('AbpIdentity::Identity')(CONFIG_STATE_DATA), 'identity',
).toBe('identity'); );
expect( expect(ConfigState.getLocalization('AbpIdentity::NoIdentity')(CONFIG_STATE_DATA)).toBe(
ConfigState.getLocalization('AbpIdentity::NoIdentity')( 'AbpIdentity::NoIdentity',
CONFIG_STATE_DATA, );
),
).toBe('AbpIdentity::NoIdentity');
expect( expect(
ConfigState.getLocalization({ key: '', defaultValue: 'default' })( ConfigState.getLocalization({ key: '', defaultValue: 'default' })(CONFIG_STATE_DATA),
CONFIG_STATE_DATA,
),
).toBe('default'); ).toBe('default');
expect( expect(
@ -290,9 +276,7 @@ describe('ConfigState', () => {
}); });
expect(false).toBeTruthy(); // fail expect(false).toBeTruthy(); // fail
} catch (error) { } catch (error) {
expect((error as Error).message).toContain( expect((error as Error).message).toContain('Please check your environment');
'Please check your environment',
);
} }
}); });
}); });
@ -328,11 +312,11 @@ describe('ConfigState', () => {
}); });
describe('#PatchRouteByName', () => { describe('#PatchRouteByName', () => {
it('should should patch the route', () => { it('should patch the route', () => {
let patchStateArg; let patchStateArg;
const patchState = jest.fn(s => (patchStateArg = s)); const patchState = jest.fn(s => (patchStateArg = s));
const getState = jest.fn(() => CONFIG_STATE_DATA); const getState = jest.fn(() => clone(CONFIG_STATE_DATA));
state.patchRoute( state.patchRoute(
{ patchState, getState } as any, { patchState, getState } as any,
@ -347,17 +331,21 @@ describe('ConfigState', () => {
name: 'Home', name: 'Home',
path: 'home', path: 'home',
url: '/home', url: '/home',
children: [ children: [{ path: 'dashboard', name: 'Dashboard', url: '/home/dashboard' }],
{ 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; let patchStateArg;
const patchState = jest.fn(s => (patchStateArg = s)); const patchState = jest.fn(s => (patchStateArg = s));
const getState = jest.fn(() => CONFIG_STATE_DATA); const getState = jest.fn(() => clone(CONFIG_STATE_DATA));
state.patchRoute( state.patchRoute(
{ patchState, getState } as any, { patchState, getState } as any,
@ -373,6 +361,69 @@ describe('ConfigState', () => {
url: '/', url: '/',
children: [{ path: 'dashboard', name: 'Dashboard', url: '/dashboard' }], 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<ABP.Route, 'children'>;
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]);
}); });
}); });
}); });

17
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(),
);
});
});
});
Loading…
Cancel
Save