{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/23863","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/23863/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/23863/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/23863/events","html_url":"https://github.com/symfony/symfony/issues/23863","id":249561363,"number":23863,"title":"[Workflow] Add a validator to check / enforce state change restrictions","user":{"login":"dkarlovi","id":209225,"avatar_url":"https://avatars3.githubusercontent.com/u/209225?v=4","gravatar_id":"","url":"https://api.github.com/users/dkarlovi","html_url":"https://github.com/dkarlovi","followers_url":"https://api.github.com/users/dkarlovi/followers","following_url":"https://api.github.com/users/dkarlovi/following{/other_user}","gists_url":"https://api.github.com/users/dkarlovi/gists{/gist_id}","starred_url":"https://api.github.com/users/dkarlovi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkarlovi/subscriptions","organizations_url":"https://api.github.com/users/dkarlovi/orgs","repos_url":"https://api.github.com/users/dkarlovi/repos","events_url":"https://api.github.com/users/dkarlovi/events{/privacy}","received_events_url":"https://api.github.com/users/dkarlovi/received_events","type":"User","site_admin":false},"labels":[{"id":100378,"url":"https://api.github.com/repos/symfony/symfony/labels/Feature","name":"Feature","color":"02e10c","default":false},{"id":397995968,"url":"https://api.github.com/repos/symfony/symfony/labels/Workflow","name":"Workflow","color":"dddddd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-08-11T07:50:20Z","updated_at":"2017-08-11T13:42:19Z","closed_at":null,"body":"| Q                | A\r\n| ---------------- | -----\r\n| Bug report?      | no\r\n| Feature request? | yes\r\n| BC Break report? | no\r\n| RFC?             | yes\r\n| Symfony version  | latest\r\n\r\nIf you have an entity with a state machine attached, you can still just set any state as current and save if you're not using `apply()`.\r\n\r\nIt would make sense to add a validator specifically enforcing the attached state machine, it would:\r\n\r\n1. figure out if the state being set is actually a valid state at all\r\n2. figure out if the state being set is a valid state **from current state**\r\n3. (this is debateable) try to apply the state so event listeners are able to block the transition?\r\n\r\nIt would allow for more easier integration of the component into common workflows, IMO.\r\n\r\n**Edit:** if 3) is considered, listeners should probably be able to provide an explanation why they've blocked the transition (`ConstraintViolationInterface` or similar?)\r\n\r\nWDYT?"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/321815060","html_url":"https://github.com/symfony/symfony/issues/23863#issuecomment-321815060","issue_url":"https://api.github.com/repos/symfony/symfony/issues/23863","id":321815060,"user":{"login":"lyrixx","id":408368,"avatar_url":"https://avatars1.githubusercontent.com/u/408368?v=4","gravatar_id":"","url":"https://api.github.com/users/lyrixx","html_url":"https://github.com/lyrixx","followers_url":"https://api.github.com/users/lyrixx/followers","following_url":"https://api.github.com/users/lyrixx/following{/other_user}","gists_url":"https://api.github.com/users/lyrixx/gists{/gist_id}","starred_url":"https://api.github.com/users/lyrixx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyrixx/subscriptions","organizations_url":"https://api.github.com/users/lyrixx/orgs","repos_url":"https://api.github.com/users/lyrixx/repos","events_url":"https://api.github.com/users/lyrixx/events{/privacy}","received_events_url":"https://api.github.com/users/lyrixx/received_events","type":"User","site_admin":false},"created_at":"2017-08-11T13:42:19Z","updated_at":"2017-08-11T13:42:19Z","body":"Ouch. I write my previous message too fast.\r\n\r\nActually the previous configuration I wrote is totally wrong ! It can not work.\r\n\r\nWhat we should test is the transition name, not a marking. So:\r\n\r\n* how could you configure that?\r\n* what does your client send ? (the new marking? (this is wrong), the transition name?)\r\n* how do you map the the value send by your client to your entity?\r\n\r\n---\r\n\r\nI already used API Platform and IMHO the best way to handle this use case is by creating 2 API endpoint.\r\n\r\n* The first one is the classic PUT (or PATCH) method. This one should not modify the `marking` property.\r\n* The second one is a dedicated workflow endpoint. Something like `/image/{id}/transition/{transition}`.\r\n\r\nI think it's better because the CRUD management is really different from the Workflow management.\r\n\r\nFinally, If you are using a DTO, you can mixed theses 2 endpoints together, but I don't think it's a good idea.\r\n\r\n"}}
{"actor":{"display_login":"lyrixx"}}