mirror of https://github.com/abpframework/abp.git
committed by
GitHub
20 changed files with 574 additions and 320 deletions
@ -0,0 +1,31 @@ |
|||
import { EntityAction } from '@abp/ng.theme.shared/extensions'; |
|||
import { RolesComponent } from '../components/roles/roles.component'; |
|||
import { IdentityRoleDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_ROLES_ENTITY_ACTIONS = EntityAction.createMany<IdentityRoleDto>([ |
|||
{ |
|||
text: 'AbpIdentity::Edit', |
|||
action: data => { |
|||
const component = data.getInjected(RolesComponent); |
|||
component.edit(data.record.id); |
|||
}, |
|||
permission: 'AbpIdentity.Roles.Update', |
|||
}, |
|||
{ |
|||
text: 'AbpIdentity::Permissions', |
|||
action: data => { |
|||
const component = data.getInjected(RolesComponent); |
|||
component.openPermissionsModal(data.record.name); |
|||
}, |
|||
permission: 'AbpIdentity.Roles.ManagePermissions', |
|||
}, |
|||
{ |
|||
text: 'AbpIdentity::Delete', |
|||
action: data => { |
|||
const component = data.getInjected(RolesComponent); |
|||
component.delete(data.record.id, data.record.name); |
|||
}, |
|||
permission: 'AbpIdentity.Roles.Delete', |
|||
visible: data => !data.record.isStatic, |
|||
}, |
|||
]); |
|||
@ -0,0 +1,32 @@ |
|||
import { LocalizationService } from '@abp/ng.core'; |
|||
import { EntityProp, ePropType } from '@abp/ng.theme.shared/extensions'; |
|||
import { of } from 'rxjs'; |
|||
import { IdentityRoleDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_ROLES_ENTITY_PROPS = EntityProp.createMany<IdentityRoleDto>([ |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'name', |
|||
displayName: 'AbpIdentity::RoleName', |
|||
sortable: true, |
|||
valueResolver: data => { |
|||
const l10n = data.getInjected(LocalizationService); |
|||
const t = l10n.instant.bind(l10n); |
|||
const { isDefault, isPublic, name } = data.record; |
|||
|
|||
return of( |
|||
name + |
|||
(isDefault |
|||
? `<span class="badge badge-pill badge-success ml-1">${t( |
|||
'AbpIdentity::DisplayName:IsDefault', |
|||
)}</span>` |
|||
: '') + |
|||
(isPublic |
|||
? `<span class="badge badge-pill badge-info ml-1">${t( |
|||
'AbpIdentity::DisplayName:IsPublic', |
|||
)}</span>` |
|||
: ''), |
|||
); |
|||
}, |
|||
}, |
|||
]); |
|||
@ -0,0 +1,30 @@ |
|||
import { ePropType, FormProp, PropData } from '@abp/ng.theme.shared/extensions'; |
|||
import { Validators } from '@angular/forms'; |
|||
import { IdentityRoleDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_ROLES_CREATE_FORM_PROPS = FormProp.createMany<IdentityRoleDto>([ |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'name', |
|||
displayName: 'AbpIdentity::RoleName', |
|||
id: 'role-name', |
|||
disabled: (data: PropData<IdentityRoleDto>) => data.record && data.record.isStatic, |
|||
validators: () => [Validators.required], |
|||
}, |
|||
{ |
|||
type: ePropType.Boolean, |
|||
name: 'isDefault', |
|||
displayName: 'AbpIdentity::DisplayName:IsDefault', |
|||
id: 'role-is-default', |
|||
defaultValue: false, |
|||
}, |
|||
{ |
|||
type: ePropType.Boolean, |
|||
name: 'isPublic', |
|||
displayName: 'AbpIdentity::DisplayName:IsPublic', |
|||
id: 'role-is-public', |
|||
defaultValue: false, |
|||
}, |
|||
]); |
|||
|
|||
export const DEFAULT_ROLES_EDIT_FORM_PROPS = DEFAULT_ROLES_CREATE_FORM_PROPS; |
|||
@ -0,0 +1,15 @@ |
|||
import { ToolbarAction } from '@abp/ng.theme.shared/extensions'; |
|||
import { RolesComponent } from '../components/roles/roles.component'; |
|||
import { IdentityRoleDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_ROLES_TOOLBAR_ACTIONS = ToolbarAction.createMany<IdentityRoleDto[]>([ |
|||
{ |
|||
text: 'AbpIdentity::NewRole', |
|||
action: data => { |
|||
const component = data.getInjected(RolesComponent); |
|||
component.add(); |
|||
}, |
|||
permission: 'AbpIdentity.Roles.Create', |
|||
icon: 'fa fa-plus', |
|||
}, |
|||
]); |
|||
@ -0,0 +1,30 @@ |
|||
import { EntityAction } from '@abp/ng.theme.shared/extensions'; |
|||
import { UsersComponent } from '../components/users/users.component'; |
|||
import { IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_USERS_ENTITY_ACTIONS = EntityAction.createMany<IdentityUserDto>([ |
|||
{ |
|||
text: 'AbpIdentity::Edit', |
|||
action: data => { |
|||
const component = data.getInjected(UsersComponent); |
|||
component.edit(data.record.id); |
|||
}, |
|||
permission: 'AbpIdentity.Users.Update', |
|||
}, |
|||
{ |
|||
text: 'AbpIdentity::Permissions', |
|||
action: data => { |
|||
const component = data.getInjected(UsersComponent); |
|||
component.openPermissionsModal(data.record.id); |
|||
}, |
|||
permission: 'AbpIdentity.Users.ManagePermissions', |
|||
}, |
|||
{ |
|||
text: 'AbpIdentity::Delete', |
|||
action: data => { |
|||
const component = data.getInjected(UsersComponent); |
|||
component.delete(data.record.id, data.record.name || data.record.userName); |
|||
}, |
|||
permission: 'AbpIdentity.Users.Delete', |
|||
}, |
|||
]); |
|||
@ -0,0 +1,26 @@ |
|||
import { EntityProp, ePropType } from '@abp/ng.theme.shared/extensions'; |
|||
import { IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_USERS_ENTITY_PROPS = EntityProp.createMany<IdentityUserDto>([ |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'userName', |
|||
displayName: 'AbpIdentity::UserName', |
|||
sortable: true, |
|||
columnWidth: 250, |
|||
}, |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'email', |
|||
displayName: 'AbpIdentity::EmailAddress', |
|||
sortable: true, |
|||
columnWidth: 250, |
|||
}, |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'phoneNumber', |
|||
displayName: 'AbpIdentity::PhoneNumber', |
|||
sortable: true, |
|||
columnWidth: 250, |
|||
}, |
|||
]); |
|||
@ -0,0 +1,61 @@ |
|||
import { getPasswordValidators } from '@abp/ng.theme.shared'; |
|||
import { ePropType, FormProp } from '@abp/ng.theme.shared/extensions'; |
|||
import { Validators } from '@angular/forms'; |
|||
import { IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_USERS_CREATE_FORM_PROPS = FormProp.createMany<IdentityUserDto>([ |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'userName', |
|||
displayName: 'AbpIdentity::UserName', |
|||
id: 'user-name', |
|||
validators: () => [Validators.required, Validators.maxLength(256)], |
|||
}, |
|||
{ |
|||
type: ePropType.Password, |
|||
name: 'password', |
|||
displayName: 'AbpIdentity::Password', |
|||
id: 'password', |
|||
autocomplete: 'new-password', |
|||
validators: data => [Validators.required, ...getPasswordValidators({ get: data.getInjected })], |
|||
}, |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'name', |
|||
displayName: 'AbpIdentity::DisplayName:Name', |
|||
id: 'name', |
|||
validators: () => [Validators.maxLength(64)], |
|||
}, |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'surname', |
|||
displayName: 'AbpIdentity::DisplayName:Surname', |
|||
id: 'surname', |
|||
validators: () => [Validators.maxLength(64)], |
|||
}, |
|||
{ |
|||
type: ePropType.Email, |
|||
name: 'email', |
|||
displayName: 'AbpIdentity::EmailAddress', |
|||
id: 'email', |
|||
validators: () => [Validators.required, Validators.maxLength(256), Validators.email], |
|||
}, |
|||
{ |
|||
type: ePropType.String, |
|||
name: 'phoneNumber', |
|||
displayName: 'AbpIdentity::PhoneNumber', |
|||
id: 'phone-number', |
|||
validators: () => [Validators.maxLength(16)], |
|||
}, |
|||
{ |
|||
type: ePropType.Boolean, |
|||
name: 'lockoutEnabled', |
|||
displayName: 'AbpIdentity::DisplayName:LockoutEnabled', |
|||
id: 'lockout-checkbox', |
|||
defaultValue: true, |
|||
}, |
|||
]); |
|||
|
|||
export const DEFAULT_USERS_EDIT_FORM_PROPS = DEFAULT_USERS_CREATE_FORM_PROPS.filter( |
|||
prop => prop.name !== 'password', |
|||
); |
|||
@ -0,0 +1,15 @@ |
|||
import { ToolbarAction } from '@abp/ng.theme.shared/extensions'; |
|||
import { UsersComponent } from '../components/users/users.component'; |
|||
import { IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_USERS_TOOLBAR_ACTIONS = ToolbarAction.createMany<IdentityUserDto[]>([ |
|||
{ |
|||
text: 'AbpIdentity::NewUser', |
|||
action: data => { |
|||
const component = data.getInjected(UsersComponent); |
|||
component.add(); |
|||
}, |
|||
permission: 'AbpIdentity.Users.Create', |
|||
icon: 'fa fa-plus', |
|||
}, |
|||
]); |
|||
@ -0,0 +1,91 @@ |
|||
import { ConfigStateService } from '@abp/ng.core'; |
|||
import { |
|||
ExtensionsService, |
|||
getObjectExtensionEntitiesFromStore, |
|||
mapEntitiesToContributors, |
|||
mergeWithDefaultActions, |
|||
mergeWithDefaultProps, |
|||
} from '@abp/ng.theme.shared/extensions'; |
|||
import { Injectable, Injector } from '@angular/core'; |
|||
import { CanActivate } from '@angular/router'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map, mapTo, tap } from 'rxjs/operators'; |
|||
import { eIdentityComponents } from '../enums/components'; |
|||
import { |
|||
IdentityCreateFormPropContributors, |
|||
IdentityEditFormPropContributors, |
|||
IdentityEntityActionContributors, |
|||
IdentityEntityPropContributors, |
|||
IdentityToolbarActionContributors, |
|||
} from '../models/config-options'; |
|||
import { |
|||
DEFAULT_IDENTITY_CREATE_FORM_PROPS, |
|||
DEFAULT_IDENTITY_EDIT_FORM_PROPS, |
|||
DEFAULT_IDENTITY_ENTITY_ACTIONS, |
|||
DEFAULT_IDENTITY_ENTITY_PROPS, |
|||
DEFAULT_IDENTITY_TOOLBAR_ACTIONS, |
|||
IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS, |
|||
IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS, |
|||
IDENTITY_ENTITY_ACTION_CONTRIBUTORS, |
|||
IDENTITY_ENTITY_PROP_CONTRIBUTORS, |
|||
IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS, |
|||
} from '../tokens/extensions.token'; |
|||
|
|||
@Injectable() |
|||
export class IdentityExtensionsGuard implements CanActivate { |
|||
constructor(private injector: Injector) {} |
|||
|
|||
canActivate(): Observable<boolean> { |
|||
const extensions: ExtensionsService = this.injector.get(ExtensionsService); |
|||
const actionContributors: IdentityEntityActionContributors = |
|||
this.injector.get(IDENTITY_ENTITY_ACTION_CONTRIBUTORS, null) || {}; |
|||
const toolbarContributors: IdentityToolbarActionContributors = |
|||
this.injector.get(IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS, null) || {}; |
|||
const propContributors: IdentityEntityPropContributors = |
|||
this.injector.get(IDENTITY_ENTITY_PROP_CONTRIBUTORS, null) || {}; |
|||
const createFormContributors: IdentityCreateFormPropContributors = |
|||
this.injector.get(IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS, null) || {}; |
|||
const editFormContributors: IdentityEditFormPropContributors = |
|||
this.injector.get(IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS, null) || {}; |
|||
|
|||
const configState = this.injector.get(ConfigStateService); |
|||
return getObjectExtensionEntitiesFromStore(configState, 'Identity').pipe( |
|||
map(entities => ({ |
|||
[eIdentityComponents.Roles]: entities.Role, |
|||
[eIdentityComponents.Users]: entities.User, |
|||
})), |
|||
mapEntitiesToContributors(configState, 'AbpIdentity'), |
|||
tap(objectExtensionContributors => { |
|||
mergeWithDefaultActions( |
|||
extensions.entityActions, |
|||
DEFAULT_IDENTITY_ENTITY_ACTIONS, |
|||
actionContributors, |
|||
); |
|||
mergeWithDefaultActions( |
|||
extensions.toolbarActions, |
|||
DEFAULT_IDENTITY_TOOLBAR_ACTIONS, |
|||
toolbarContributors, |
|||
); |
|||
mergeWithDefaultProps( |
|||
extensions.entityProps, |
|||
DEFAULT_IDENTITY_ENTITY_PROPS, |
|||
objectExtensionContributors.prop, |
|||
propContributors, |
|||
); |
|||
mergeWithDefaultProps( |
|||
extensions.createFormProps, |
|||
DEFAULT_IDENTITY_CREATE_FORM_PROPS, |
|||
objectExtensionContributors.createForm, |
|||
createFormContributors, |
|||
); |
|||
mergeWithDefaultProps( |
|||
extensions.editFormProps, |
|||
DEFAULT_IDENTITY_EDIT_FORM_PROPS, |
|||
objectExtensionContributors.editForm, |
|||
editFormContributors, |
|||
); |
|||
}), |
|||
mapTo(true), |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
export * from './extensions.guard'; |
|||
@ -0,0 +1,42 @@ |
|||
import { |
|||
CreateFormPropContributorCallback, |
|||
EditFormPropContributorCallback, |
|||
EntityActionContributorCallback, |
|||
EntityPropContributorCallback, |
|||
ToolbarActionContributorCallback, |
|||
} from '@abp/ng.theme.shared/extensions'; |
|||
import { eIdentityComponents } from '../enums/components'; |
|||
import { IdentityRoleDto, IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export type IdentityEntityActionContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EntityActionContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EntityActionContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
|
|||
export type IdentityToolbarActionContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: ToolbarActionContributorCallback<IdentityRoleDto[]>[]; |
|||
[eIdentityComponents.Users]: ToolbarActionContributorCallback<IdentityUserDto[]>[]; |
|||
}>; |
|||
|
|||
export type IdentityEntityPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EntityPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EntityPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
|
|||
export type IdentityCreateFormPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: CreateFormPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: CreateFormPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
|
|||
export type IdentityEditFormPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EditFormPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EditFormPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
|
|||
export interface IdentityConfigOptions { |
|||
entityActionContributors?: IdentityEntityActionContributors; |
|||
toolbarActionContributors?: IdentityToolbarActionContributors; |
|||
entityPropContributors?: IdentityEntityPropContributors; |
|||
createFormPropContributors?: IdentityCreateFormPropContributors; |
|||
editFormPropContributors?: IdentityEditFormPropContributors; |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
export * from './config-options'; |
|||
export * from './identity'; |
|||
@ -0,0 +1,91 @@ |
|||
import { |
|||
CreateFormPropContributorCallback, |
|||
EditFormPropContributorCallback, |
|||
EntityActionContributorCallback, |
|||
EntityPropContributorCallback, |
|||
ToolbarActionContributorCallback, |
|||
} from '@abp/ng.theme.shared/extensions'; |
|||
import { InjectionToken } from '@angular/core'; |
|||
import { DEFAULT_ROLES_ENTITY_ACTIONS } from '../defaults/default-roles-entity-actions'; |
|||
import { DEFAULT_ROLES_ENTITY_PROPS } from '../defaults/default-roles-entity-props'; |
|||
import { |
|||
DEFAULT_ROLES_CREATE_FORM_PROPS, |
|||
DEFAULT_ROLES_EDIT_FORM_PROPS, |
|||
} from '../defaults/default-roles-form-props'; |
|||
import { DEFAULT_ROLES_TOOLBAR_ACTIONS } from '../defaults/default-roles-toolbar-actions'; |
|||
import { DEFAULT_USERS_ENTITY_ACTIONS } from '../defaults/default-users-entity-actions'; |
|||
import { DEFAULT_USERS_ENTITY_PROPS } from '../defaults/default-users-entity-props'; |
|||
import { |
|||
DEFAULT_USERS_CREATE_FORM_PROPS, |
|||
DEFAULT_USERS_EDIT_FORM_PROPS, |
|||
} from '../defaults/default-users-form-props'; |
|||
import { DEFAULT_USERS_TOOLBAR_ACTIONS } from '../defaults/default-users-toolbar-actions'; |
|||
import { eIdentityComponents } from '../enums/components'; |
|||
import { IdentityRoleDto, IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export const DEFAULT_IDENTITY_ENTITY_ACTIONS = { |
|||
[eIdentityComponents.Roles]: DEFAULT_ROLES_ENTITY_ACTIONS, |
|||
[eIdentityComponents.Users]: DEFAULT_USERS_ENTITY_ACTIONS, |
|||
}; |
|||
|
|||
export const DEFAULT_IDENTITY_TOOLBAR_ACTIONS = { |
|||
[eIdentityComponents.Roles]: DEFAULT_ROLES_TOOLBAR_ACTIONS, |
|||
[eIdentityComponents.Users]: DEFAULT_USERS_TOOLBAR_ACTIONS, |
|||
}; |
|||
|
|||
export const DEFAULT_IDENTITY_ENTITY_PROPS = { |
|||
[eIdentityComponents.Roles]: DEFAULT_ROLES_ENTITY_PROPS, |
|||
[eIdentityComponents.Users]: DEFAULT_USERS_ENTITY_PROPS, |
|||
}; |
|||
|
|||
export const DEFAULT_IDENTITY_CREATE_FORM_PROPS = { |
|||
[eIdentityComponents.Roles]: DEFAULT_ROLES_CREATE_FORM_PROPS, |
|||
[eIdentityComponents.Users]: DEFAULT_USERS_CREATE_FORM_PROPS, |
|||
}; |
|||
|
|||
export const DEFAULT_IDENTITY_EDIT_FORM_PROPS = { |
|||
[eIdentityComponents.Roles]: DEFAULT_ROLES_EDIT_FORM_PROPS, |
|||
[eIdentityComponents.Users]: DEFAULT_USERS_EDIT_FORM_PROPS, |
|||
}; |
|||
|
|||
export const IDENTITY_ENTITY_ACTION_CONTRIBUTORS = new InjectionToken<EntityActionContributors>( |
|||
'IDENTITY_ENTITY_ACTION_CONTRIBUTORS', |
|||
); |
|||
|
|||
export const IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS = new InjectionToken<ToolbarActionContributors>( |
|||
'IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS', |
|||
); |
|||
|
|||
export const IDENTITY_ENTITY_PROP_CONTRIBUTORS = new InjectionToken<EntityPropContributors>( |
|||
'IDENTITY_ENTITY_PROP_CONTRIBUTORS', |
|||
); |
|||
|
|||
export const IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS = new InjectionToken<CreateFormPropContributors>( |
|||
'IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS', |
|||
); |
|||
|
|||
export const IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS = new InjectionToken<EditFormPropContributors>( |
|||
'IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS', |
|||
); |
|||
|
|||
// Fix for TS4023 -> https://github.com/microsoft/TypeScript/issues/9944#issuecomment-254693497
|
|||
type EntityActionContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EntityActionContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EntityActionContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
type ToolbarActionContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: ToolbarActionContributorCallback<IdentityRoleDto[]>[]; |
|||
[eIdentityComponents.Users]: ToolbarActionContributorCallback<IdentityUserDto[]>[]; |
|||
}>; |
|||
type EntityPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EntityPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EntityPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
type CreateFormPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: CreateFormPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: CreateFormPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
type EditFormPropContributors = Partial<{ |
|||
[eIdentityComponents.Roles]: EditFormPropContributorCallback<IdentityRoleDto>[]; |
|||
[eIdentityComponents.Users]: EditFormPropContributorCallback<IdentityUserDto>[]; |
|||
}>; |
|||
@ -0,0 +1 @@ |
|||
export * from './extensions.token'; |
|||
Loading…
Reference in new issue