Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authority relationship #11158

Closed
wants to merge 21 commits into from
Closed

Conversation

xetys
Copy link
Member

@xetys xetys commented Jan 21, 2020

enables relationships to 'Authority' in entity-server and ensures using the correct fields in generated files

fix #11062

@xetys xetys marked this pull request as ready for review February 25, 2020 09:00
@xetys
Copy link
Member Author

xetys commented Feb 25, 2020

hey @jhipster/developers I have finished (IMHO) this feature and I was testing it against this JDL:


entity Alpha
entity Beta
entity Gamma


relationship OneToOne {
    Alpha{authority(name)} to Authority
}

relationship ManyToOne {
    Beta{authority(name)} to Authority
}

relationship ManyToMany {
    Gamma{authority(name)} to Authority
}

and this works fine...

So I wanted to add some meaningful test to cover it, and I'm struggling with the yeoman helper and asking for some hint to make this work:

in entity.spec.js I added a new test case with the following code:

            describe('with authority as relationship', () => {
                before(done => {
                    helpers
                        .run(require.resolve('../generators/entity'))
                        .inTmpDir(dir => {
                            fse.copySync(path.join(__dirname, '../test/templates/default-ng2'), dir);
                        })
                        .withArguments(['foo'])
                        .withPrompts({
                            fieldAdd: false,
                            relationshipAdd: true,
                            otherEntityName: 'authority',
                            relationshipName: 'authority',
                            relationshipType: 'many-to-one',
                            ownerSide: true,
                            otherEntityRelationshipName: 'foo',
                            otherEntityField: 'name'
                        })
                        .withPrompts({
                            relationshipAdd: false,
                            dto: 'no',
                            service: 'no',
                            pagination: 'no'
                        })
                        .on('end', done);
                });

                it('creates expected default files', () => {
                    assert.file(expectedFiles.server);
                    assert.file(expectedFiles.clientNg2);
                    assert.file(expectedFiles.gatling);
                    assert.file(expectedFiles.fakeData);
                });

                it('creates correct entity files for authority', () => {
                    // entity related files exist
                    assert.file(`${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.module.ts`);
                    assert.file(`${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.component.html`);
                    assert.file('.jhipster/Foo.json');
                    assert.fileContent('.jhipster/Foo.json', 'many-to-one');
                    assert.fileContent('.jhipster/Foo.json', {
                        relationships: [
                            {
                                relationshipType: 'many-to-one',
                                otherEntityName: 'authority',
                                otherEntityRelationshipName: 'foo',
                                relationshipName: 'authority',
                                otherEntityField: 'name'
                            }
                        ]
                    });
                    assert.fileContent(
                        `${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.component.html`,
                        "<a [routerLink]=\"['/authority', foo.authority?.name, 'view']\" >{{ foo.authority?.name }}</a>"
                    );
                });
            });

I try to generate an entity with a relationship. From my dumb perspective, this should be the correct usage of Yeomans test helper to answer the prompts. However, this ends up with an entity without a relationship. What am I doing wrong here?

@xetys
Copy link
Member Author

xetys commented Mar 10, 2020

push, I still need some help with the test, then this PR could be merged

@MathieuAA
Copy link
Member

I'll try to see what's wrong this morning

@xetys
Copy link
Member Author

xetys commented Mar 10, 2020

thanks... I dunno what's wrong with the usage of the helper...and it's quite complex because the relationship question is a repeating one....if that's not possible, I'll try to define a .yo-rc.json and entity JSONs and do it this way

@MathieuAA
Copy link
Member

@xetys it may be easier indeed

test/entity.spec.js Outdated Show resolved Hide resolved
generators/client/files-angular.js Outdated Show resolved Hide resolved
generators/generator-base-private.js Outdated Show resolved Hide resolved
Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add authority to warning:

if (relationship.otherEntityName !== 'user') {
this.warning(
`otherEntityRelationshipName is missing in .jhipster/${entityName}.json for relationship ${JSON.stringify(
relationship,
null,
4
)}, using ${_.lowerFirst(entityName)} as fallback`

@CLAassistant
Copy link

CLAassistant commented Apr 20, 2020

CLA assistant check
All committers have signed the CLA.

@mraible
Copy link
Contributor

mraible commented Apr 27, 2020

@xetys FYI... this PR has conflicts that need to be resolved.

@xetys
Copy link
Member Author

xetys commented May 18, 2020

@mraible thx...I didn't forget this one

now I fixed the test as well, and all stuff mentioned in Review (hopefully)

May this PR finally be closed 🙏

Co-authored-by: Marcelo Shima <marceloshima@gmail.com>
@mshima
Copy link
Member

mshima commented May 25, 2020

@xetys have you noticed the failures are related to your PR?

@xetys
Copy link
Member Author

xetys commented May 25, 2020

Yeah, it's now related to react. As I have no react experience I'll need some time to figure out how to fix this. Shouldn't be too hard but I'll need a bit of time for this

@xetys
Copy link
Member Author

xetys commented Jun 11, 2020

still failing because oauth2 is an edge case....I see this is one of the nastiest $100 bug bounties in history :D I'll try to fix that one today >.<

@mshima
Copy link
Member

mshima commented Jun 11, 2020

still failing because oauth2 is an edge case....I see this is one of the nastiest $100 bug bounties in history :D I'll try to fix that one today >.<

I don’t think it is required, just throw an exception at the generator when you detect oauth2.
And blacklist authority from oauth builds, I will think how to do this one.

@mshima
Copy link
Member

mshima commented Jun 15, 2020

The only way I could find is to duplicate the sqlfull

elif [[ "$JHI_ENTITY" == "sqlfull" ]]; then

@xetys it will be hard to add oauth2 support?

@pascalgrimaud pascalgrimaud changed the base branch from master to main October 11, 2020 20:19
@mraible
Copy link
Contributor

mraible commented Dec 29, 2020

@xetys Is this something you're still interested in adding? If so, please fix conflicts.

@mraible
Copy link
Contributor

mraible commented Jan 29, 2021

Closing because this PR is stale.

@Rapster
Copy link
Contributor

Rapster commented Mar 10, 2022

Any news about this? Since #1995 has been closed, I'm thinking to create a custom Authority. If this PR is rejected, then obviously I could do everything manually, but ideally, I would like to design the whole domain with JDL

@DanielFran DanielFran removed this from the 7.0.0 milestone Jul 30, 2022
@DanielFran DanielFran marked this pull request as draft July 30, 2022 12:04
@mraible
Copy link
Contributor

mraible commented Aug 17, 2022

Closing because this PR has become stale. Please re-open if you're able to rebase.

@mraible mraible closed this Aug 17, 2022
@DanielFran DanielFran added this to the 7.9.3 milestone Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adding relationships to Authority
8 participants