{"action":"created","issue":{"url":"https://api.github.com/repos/chaps-io/access-granted/issues/50","repository_url":"https://api.github.com/repos/chaps-io/access-granted","labels_url":"https://api.github.com/repos/chaps-io/access-granted/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/chaps-io/access-granted/issues/50/comments","events_url":"https://api.github.com/repos/chaps-io/access-granted/issues/50/events","html_url":"https://github.com/chaps-io/access-granted/pull/50","id":359011273,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0NjA2MTAy","number":50,"title":"Allow passing custom exception message for authorize!","user":{"login":"lokeshdevnani","id":7446748,"node_id":"MDQ6VXNlcjc0NDY3NDg=","avatar_url":"https://avatars0.githubusercontent.com/u/7446748?v=4","gravatar_id":"","url":"https://api.github.com/users/lokeshdevnani","html_url":"https://github.com/lokeshdevnani","followers_url":"https://api.github.com/users/lokeshdevnani/followers","following_url":"https://api.github.com/users/lokeshdevnani/following{/other_user}","gists_url":"https://api.github.com/users/lokeshdevnani/gists{/gist_id}","starred_url":"https://api.github.com/users/lokeshdevnani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lokeshdevnani/subscriptions","organizations_url":"https://api.github.com/users/lokeshdevnani/orgs","repos_url":"https://api.github.com/users/lokeshdevnani/repos","events_url":"https://api.github.com/users/lokeshdevnani/events{/privacy}","received_events_url":"https://api.github.com/users/lokeshdevnani/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-11T11:52:20Z","updated_at":"2018-09-11T12:41:44Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/chaps-io/access-granted/pulls/50","html_url":"https://github.com/chaps-io/access-granted/pull/50","diff_url":"https://github.com/chaps-io/access-granted/pull/50.diff","patch_url":"https://github.com/chaps-io/access-granted/pull/50.patch"},"body":"Sometimes, there is a need for specifying a message along with the authorization of an action. This message is useful as it provides some feedback to the consumer of the action. In some cases, it also acts as a documentation which makes it clear as to why this authorization was introduced.\r\n\r\n### Usage\r\n\r\nThe message passed along with `authorize!` will be accessible on the exception object thrown if the authorization fails.\r\n\r\n```ruby\r\nclass PostsController\r\n  def show\r\n    @post = Post.find(params[:id])\r\n    authorize! :read, @post, 'You do not have access to this post'\r\n    render json: { post: @post }\r\n  rescue AccessGranted::AccessDenied => e\r\n    render json: { error: e.message }, status: :forbidden\r\n  end\r\nend\r\n```\r\n\r\nThis PR allows `authorize!` method to optionally take a third argument specifying the custom exception message"},"comment":{"url":"https://api.github.com/repos/chaps-io/access-granted/issues/comments/420260108","html_url":"https://github.com/chaps-io/access-granted/pull/50#issuecomment-420260108","issue_url":"https://api.github.com/repos/chaps-io/access-granted/issues/50","id":420260108,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDI2MDEwOA==","user":{"login":"pokonski","id":135402,"node_id":"MDQ6VXNlcjEzNTQwMg==","avatar_url":"https://avatars3.githubusercontent.com/u/135402?v=4","gravatar_id":"","url":"https://api.github.com/users/pokonski","html_url":"https://github.com/pokonski","followers_url":"https://api.github.com/users/pokonski/followers","following_url":"https://api.github.com/users/pokonski/following{/other_user}","gists_url":"https://api.github.com/users/pokonski/gists{/gist_id}","starred_url":"https://api.github.com/users/pokonski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pokonski/subscriptions","organizations_url":"https://api.github.com/users/pokonski/orgs","repos_url":"https://api.github.com/users/pokonski/repos","events_url":"https://api.github.com/users/pokonski/events{/privacy}","received_events_url":"https://api.github.com/users/pokonski/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T12:41:44Z","updated_at":"2018-09-11T12:41:44Z","author_association":"MEMBER","body":"Hey @lokeshdevnani, thanks for the contribution! This is a good addition :)\r\n\r\n@jrochkind it looks like you already can pass anything as `message`, not necessarily a string. So you could pass a custom object/hash that has i18n key and additional options (for interpolation etc)."}}
{"actor":{"display_login":"pokonski"}}