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

Restrict Clan creation #108

Closed
IDragonfire opened this issue Jun 2, 2017 · 8 comments
Closed

Restrict Clan creation #108

IDragonfire opened this issue Jun 2, 2017 · 8 comments

Comments

@IDragonfire
Copy link
Contributor

IDragonfire commented Jun 2, 2017

It should not be possible to create Clan Entities over the JSON API.
Instead the ClanController should be used ...
https://github.com/FAForever/faf-java-api/blob/develop/src/main/java/com/faforever/api/clan/ClansController.java#L59


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@Brutus5000
Copy link
Member

What exactly happens? Maybe we can handle adding the clan leader by adding a @OnCreatePostCommit as described here?

@IDragonfire
Copy link
Contributor Author

We have a invalid clan... I think the validation will fail... The elide annotations looks new... Did you test them? Because jpa annotation have some restrictions http://www.objectdb.com/java/jpa/persistence/event e. G. Is it not allowed to use an Entity manager or Query.
I am also not sure if this is against the rest principle... You request the creation of one Ressource and two are created...

@Brutus5000
Copy link
Member

No I did not test it, I just saw it in the docs.

You can't have a clan without a clan leader and you can't have a clan leader without a clan. I see no problem there. Furthermore even if it against the REST principle, moving it to a controller URL does not change anything about the semantics.

@IDragonfire
Copy link
Contributor Author

The clan leader is not the problem... The clan leader must be member of a clan and every clan need at least one member... The validation of the clan will fail because no members exists and you can not add members because the clan doesn't exist

@Brutus5000
Copy link
Member

Yeah so? That is a basic problem with referential integrity across all databases and need to be done inside a transaction. Sounds like a job for @OnCreatePreCommit This annotation executes after the object is created and all security checks are evaluated on the server-side but before it is committed/persisted in the backend.

@IDragonfire
Copy link
Contributor Author

IDragonfire commented Jun 5, 2017

Any idea how I can get the player and clan repository? It looks like a bad idea to include the repository in every entitiy ...
The clan repository is needed to check if the tag and name is unique.
The player repository is needed to get the player out of the request scope.

Test Branch https://github.com/FAForever/faf-java-api/tree/feature/108-clan-commit
Commit 7a884bc#diff-b1ca2e9e0e3deff624edda7e40f83888R111

@Brutus5000
Copy link
Member

After intense research I come to the conclusion that the Elide extensions are not suited for this use case. We could use Hibernate's extensions like PreCommit instead.

@Brutus5000
Copy link
Member

Brutus5000 commented Nov 15, 2019

Using Hibernate entity listeners works and I will move clan creation back to the Elide route. See #362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants