Skip to content

Commit

Permalink
Merge pull request #24965 from mshima/authority-entity
Browse files Browse the repository at this point in the history
Add authority angular ui.
  • Loading branch information
DanielFran authored Jan 25, 2024
2 parents c69efeb + df91c1e commit c2f20a7
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 42 deletions.
63 changes: 63 additions & 0 deletions generators/angular/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,69 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(
"src/main/webapp/app/core/util/parse-links.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/authority.model.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/authority.routes.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/authority.test-samples.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/delete/authority-delete-dialog.component.html": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/delete/authority-delete-dialog.component.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/delete/authority-delete-dialog.component.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/detail/authority-detail.component.html": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/detail/authority-detail.component.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/detail/authority-detail.component.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/list/authority.component.html": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/list/authority.component.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/list/authority.component.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/route/authority-routing-resolve.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/route/authority-routing-resolve.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/service/authority.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/service/authority.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/update/authority-form.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/update/authority-form.service.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/update/authority-update.component.html": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/update/authority-update.component.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/authority/update/authority-update.component.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/entities/entity-navbar-items.ts": {
"stateCleared": "modified",
},
Expand Down
14 changes: 7 additions & 7 deletions generators/angular/entity-files-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ export const angularFiles = {

export async function writeEntitiesFiles(this: CoreGenerator, { application, entities }: GeneratorDefinition['writingEntitiesTaskParam']) {
for (const entity of entities.filter(entity => !entity.skipClient)) {
if (!entity.builtIn) {
await this.writeFiles({
sections: angularFiles,
context: { ...application, ...entity },
});
} else if (entity.builtInUser) {
if (entity.builtInUser) {
await this.writeFiles({
sections: builtInFiles,
context: {
Expand All @@ -90,13 +85,18 @@ export async function writeEntitiesFiles(this: CoreGenerator, { application, ent
readOnly: true,
},
});
} else {
await this.writeFiles({
sections: angularFiles,
context: { ...application, ...entity },
});
}
}
}

export async function postWriteEntitiesFiles(this: CoreGenerator, taskParam: GeneratorDefinition['postWritingEntitiesTaskParam']) {
const { source, application } = taskParam;
const entities = taskParam.entities.filter(entity => !entity.skipClient && !entity.builtIn && !entity.embedded);
const entities = taskParam.entities.filter(entity => !entity.skipClient && !entity.builtInUser && !entity.embedded);
source.addEntitiesToClient({ application, entities });
}

Expand Down
21 changes: 20 additions & 1 deletion generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
generateTypescriptTestEntity as generateTestEntity,
} from '../client/support/index.js';
import type { CommonClientServerApplication } from '../base-application/types.js';
import { createNeedleCallback } from '../base/support/index.js';
import { createNeedleCallback, mutateData } from '../base/support/index.js';

const { ANGULAR } = clientFrameworkTypes;

Expand Down Expand Up @@ -141,6 +141,25 @@ export default class AngularGenerator extends BaseApplicationGenerator {
return this.asPreparingTaskGroup(this.delegateTasksToBlueprint(() => this.preparing));
}

get preparingEachEntity() {
return this.asPreparingEachEntityTaskGroup({
prepareEntity({ entity }) {
const asAuthorities = authorities => (authorities.length > 0 ? authorities.map(auth => `'${auth}'`).join(', ') : undefined);
mutateData(entity, {
entityAngularAuthorities: asAuthorities(entity.entityAuthority?.split(',') ?? []),
entityAngularReadAuthorities: asAuthorities([
...(entity.entityAuthority?.split(',') ?? []),
...(entity.entityReadAuthority?.split(',') ?? []),
]),
});
},
});
}

get [BaseApplicationGenerator.PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntity);
}

get default() {
return this.asDefaultTaskGroup({
loadEntities() {
Expand Down
25 changes: 9 additions & 16 deletions generators/angular/support/needles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function addItemToMenu({
<span${enableTranslation ? ` ${jhiPrefix}Translate="${translationKey}"` : ''}>${name}</span>
</a>
</li>`;

return createNeedleCallback({
needle,
contentToAdd,
Expand Down Expand Up @@ -130,22 +131,14 @@ export function addToEntitiesMenu({ application, entities }: { application: Base
const { enableTranslation, jhiPrefix } = application;
return joinCallbacks(
...entities.map(entity => {
const { entityPage, entityTranslationKeyMenu, entityClassHumanized } = entity;
const routerLink = `routerLink="/${entityPage}"`;

// prettier-ignore
const contentToAdd =`
<li>
<a class="dropdown-item" ${routerLink} routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" (click)="collapseNavbar()">
<fa-icon icon="asterisk" [fixedWidth]="true"></fa-icon>
<span${enableTranslation ? ` ${jhiPrefix}Translate="global.menu.entities.${entityTranslationKeyMenu}"` : ''}>${entityClassHumanized}</span>
</a>
</li>`;

return createNeedleCallback({
needle: 'jhipster-needle-add-entity-to-menu',
contentToAdd,
contentToCheck: routerLink,
return addItemToMenu({
needle: entity.adminEntity ? 'jhipster-needle-add-element-to-admin-menu' : 'jhipster-needle-add-entity-to-menu',
enableTranslation,
icon: 'asterisk',
route: entity.entityPage,
translationKey: `global.menu.entities.${entity.entityTranslationKeyMenu}`,
name: entity.entityClassHumanized,
jhiPrefix,
});
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const <%= entityInstance %>Route: Routes = [
component: <%= entityAngularName %>Component,
data: {
defaultSort: '<%- primaryKey.name %>,' + ASC,
<%_ if (entityAngularReadAuthorities) { _%>
authorities: [<%- entityAngularReadAuthorities %>],
<%_ } _%>
},
canActivate: [UserRouteAccessService]
},
Expand All @@ -42,6 +45,11 @@ const <%= entityInstance %>Route: Routes = [
resolve: {
<%= entityInstance %>: <%= entityAngularName %>Resolve
},
<%_ if (entityAngularReadAuthorities) { _%>
data: {
authorities: [<%- entityAngularReadAuthorities %>],
},
<%_ } _%>
canActivate: [UserRouteAccessService]
},
<%_ if (!readOnly) { _%>
Expand All @@ -51,6 +59,11 @@ const <%= entityInstance %>Route: Routes = [
resolve: {
<%= entityInstance %>: <%= entityAngularName %>Resolve
},
<%_ if (entityAngularAuthorities) { _%>
data: {
authorities: [<%- entityAngularAuthorities %>],
},
<%_ } _%>
canActivate: [UserRouteAccessService]
},
<%_ } _%>
Expand All @@ -61,6 +74,11 @@ const <%= entityInstance %>Route: Routes = [
resolve: {
<%= entityInstance %>: <%= entityAngularName %>Resolve
},
<%_ if (entityAngularAuthorities) { _%>
data: {
authorities: [<%- entityAngularAuthorities %>],
},
<%_ } _%>
canActivate: [UserRouteAccessService]
},
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('<%= entityAngularName %> Form Service', () => {
expect(<%= entityInstance %>).toMatchObject(sampleWithRequiredData);
});
});
<%_ if (primaryKey.autoGenerate) { _%>

describe('resetForm', () => {
it('passing I<%= entityAngularName %> should not enable <%= primaryKey.name %> FormControl', () => {
Expand All @@ -106,5 +107,6 @@ describe('<%= entityAngularName %> Form Service', () => {
expect(formGroup.controls.<%= primaryKey.name %>.disabled).toBe(true);
});
});
<%_ } _%>
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ _%>
data-cy="<%= fieldName %>" formControlName="<%= fieldName %>" <% if (readonly) { %> [readonly]="true"<% } %>/>
<%_ } else { _%>
<input type="<%= fieldInputType %>" class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>" data-cy="<%= fieldName %>"
formControlName="<%= fieldName %>"<% if (field.id && !field.autoGenerate) { %> [readonly]="editForm.get('<%= primaryKey.name %>')!.value != null"<% } else if (readonly) { %> [readonly]="true"<% } %>/>
formControlName="<%= fieldName %>"<% if (field.id && !field.autoGenerate) { %> [readonly]="editForm.get('<%= primaryKey.name %>')!.disabled"<% } else if (readonly) { %> [readonly]="true"<% } %>/>
<%_ if (field.fieldTypeBinary && !field.blobContentTypeText) { _%>
<input type="hidden" class="form-control" name="<%= fieldName %>ContentType" id="field_<%= fieldName %>ContentType"
formControlName="<%= fieldName %>ContentType" />
Expand Down
8 changes: 7 additions & 1 deletion generators/base-application/types/entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ export type BaseEntity = {
skipServer?: boolean;
};

type AngularEntity = {
entityAngularAuthorities?: string;
entityAngularReadAuthorities?: string;
};

type Entity = Required<BaseEntity> &
SpringEntity & {
SpringEntity &
AngularEntity & {
builtIn?: boolean;
builtInUser?: boolean;
builtInAuthority?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion generators/bootstrap-application-base/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function createAuthorityEntity(customAuthorityData = {}, application) {
relationships: [],
fields: entityDefinition ? entityDefinition.fields || [] : [],
builtInAuthority: true,
skipClient: true,
skipClient: !application.backendTypeSpringBoot || application.clientFrameworkReact || application.clientFrameworkVue,
searchEngine: 'no',
service: 'no',
dto: 'no',
Expand Down
2 changes: 1 addition & 1 deletion generators/client/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator {
if (!application.webappEnumerationsDir || ![ANGULAR, VUE, REACT].includes(application.clientFramework)) {
return;
}
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
for (const entity of entities.filter(entity => !entity.skipClient)) {
await addEnumerationFiles.call(this, { application, entity });
}
},
Expand Down
6 changes: 6 additions & 0 deletions generators/cypress/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ exports[`generator - cypress jwt-cypressAudit(false)-angular-withAdminUi(false)-
"clientRoot/src/test/javascript/cypress/e2e/administration/administration.cy.ts": {
"stateCleared": "modified",
},
"clientRoot/src/test/javascript/cypress/e2e/entity/authority.cy.ts": {
"stateCleared": "modified",
},
"clientRoot/src/test/javascript/cypress/e2e/entity/entity-a.cy.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -366,6 +369,9 @@ exports[`generator - cypress session-cypressAudit(false)-angular-withAdminUi(fal
"src/test/javascript/cypress/e2e/administration/administration.cy.ts": {
"stateCleared": "modified",
},
"src/test/javascript/cypress/e2e/entity/authority.cy.ts": {
"stateCleared": "modified",
},
"src/test/javascript/cypress/e2e/entity/entity-a.cy.ts": {
"stateCleared": "modified",
},
Expand Down
1 change: 0 additions & 1 deletion generators/cypress/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const cypressFiles: WriteFileSection<CypressGenerator, CommonClientServer
export const cypressEntityFiles: WriteFileSection<CypressGenerator, CypressApplication & Entity> = {
testsCypress: [
{
condition: ctx => !ctx.builtIn && !ctx.embedded,
path: CYPRESS_TEMPLATE_SOURCE_DIR,
renameTo: ctx => `${ctx.cypressDir}e2e/entity/${ctx.entityFileName}.cy.ts`,
templates: ['e2e/entity/_entity_.cy.ts'],
Expand Down
2 changes: 1 addition & 1 deletion generators/cypress/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class CypressGenerator extends BaseApplicationGenerator {
},

async writeCypressEntityFiles({ application, entities }) {
for (const entity of entities) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.embedded && !entity.builtInUser)) {
const context = { ...application, ...entity } as any;
await this.writeFiles({
sections: cypressEntityFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('<%= entityClass %> e2e test', () => {

const <%= entityInstance %>PageUrl = '/<%= entityPage %>';
const <%= entityInstance %>PageUrlPattern = new RegExp('/<%= entityPage %>(\\?.*)?$');
const username = Cypress.env('E2E_USERNAME') ?? 'user';
const password = Cypress.env('E2E_PASSWORD') ?? 'user';
const username = Cypress.env('E2E_USERNAME') ?? '<%- adminEntity ? 'admin' : 'user' %>';
const password = Cypress.env('E2E_PASSWORD') ?? '<%- adminEntity ? 'admin' : 'user' %>';
<% if (skipCreateTest) { %>// <% } %>const <%= entityInstance %>Sample = <%- JSON.stringify(this.generateTestEntity(sampleFields.map(field => field.reference))) %>;
let <%= entityInstance %>;
Expand Down
4 changes: 2 additions & 2 deletions generators/languages/entity-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function writeEntityFiles() {
return {
async writeEnumFiles({ entities, application }) {
if (!application.enableTranslation || application.skipClient) return;
entities = entities.filter(entity => !entity.skipClient && !entity.builtIn);
entities = entities.filter(entity => !entity.skipClient && !entity.builtInUser);
const { clientSrcDir, packageName, frontendAppName } = application;
await Promise.all(
entities
Expand Down Expand Up @@ -81,7 +81,7 @@ export function writeEntityFiles() {

async writeClientFiles({ application, entities }) {
if (application.skipClient) return;
const entitiesToWriteTranslationFor = entities.filter(entity => !entity.skipClient && !entity.builtIn);
const entitiesToWriteTranslationFor = entities.filter(entity => !entity.skipClient && !entity.builtInUser);

// Copy each
const { clientSrcDir, frontendAppName } = application;
Expand Down
2 changes: 1 addition & 1 deletion generators/languages/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export default class LanguagesGenerator extends BaseApplicationGenerator {
addEntities({ application, entities, source }) {
if (application.skipClient) return;
const languagesToApply = application.enableTranslation ? this.languagesToApply : [...new Set([application.nativeLanguage, 'en'])];
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtInUser)) {
for (const language of languagesToApply) {
source.addEntityTranslationKey?.({
language,
Expand Down
6 changes: 3 additions & 3 deletions generators/react/entity-files-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const reactFiles = {
};

export async function writeEntitiesFiles({ application, entities }) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtInUser)) {
await this.writeFiles({
sections: reactFiles,
context: { ...application, ...entity },
Expand All @@ -60,7 +60,7 @@ export async function writeEntitiesFiles({ application, entities }) {
}

export async function postWriteEntitiesFiles({ application, entities }) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtInUser)) {
if (!entity.embedded) {
const { entityInstance, entityClass, entityAngularName, entityFolderName, entityFileName } = entity;

Expand All @@ -75,7 +75,7 @@ export async function postWriteEntitiesFiles({ application, entities }) {
}

export function cleanupEntitiesFiles({ application, entities }) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtInUser)) {
const { entityFolderName, entityFileName } = entity;

if (this.isJhipsterVersionLessThan('7.0.0-beta.1')) {
Expand Down
Loading

0 comments on commit c2f20a7

Please sign in to comment.