{"action":"created","comment":{"url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/comments/43859127","id":43859127,"diff_hunk":"@@ -0,0 +1,56 @@\n+class Visit\n+  module IntegrityChecker\n+    def ensure_visit_integrity\n+      return if required_information?\n+      log_any_missing_information\n+      flash[:notice] = I18n.t(\n+        :ensure_visit_integrity,\n+        scope: 'controllers.shared'\n+      )\n+      redirect_to edit_prisoner_details_path\n+    end\n+\n+    def required_information?\n+      return false unless visit\n+      return false unless visit.prisoner?\n+      return false unless visit.prison_name?\n+      true\n+    end\n+\n+    def log_any_missing_information\n+      prefix = \"Visit #{visit.visit_id} is missing a\"\n+      log_missing_prisoner(prefix)\n+      log_missing_prisoner_number(prefix)\n+      log_missing_prison_name(prefix)\n+      log_missing_prison(prefix)\n+      log_missing_prison_slots(prefix)\n+    end\n+\n+    private\n+\n+    def log_missing_prisoner(prefix)\n+      return if visit.prisoner?\n+      Rails.logger.info(\"#{prefix} prisoner\")\n+    end\n+\n+    def log_missing_prisoner_number(prefix)\n+      return if !visit.prisoner? || visit.prisoner_number?\n+      Rails.logger.info(\"#{prefix} prisoner number\")","path":"app/services/visit/integrity_checker.rb","position":38,"original_position":38,"commit_id":"8f58c331482938b1585d5f8785b3be9e9e638ae5","original_commit_id":"8f58c331482938b1585d5f8785b3be9e9e638ae5","user":{"login":"SteveMarshall","id":2210,"avatar_url":"https://avatars.githubusercontent.com/u/2210?v=3","gravatar_id":"","url":"https://api.github.com/users/SteveMarshall","html_url":"https://github.com/SteveMarshall","followers_url":"https://api.github.com/users/SteveMarshall/followers","following_url":"https://api.github.com/users/SteveMarshall/following{/other_user}","gists_url":"https://api.github.com/users/SteveMarshall/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveMarshall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveMarshall/subscriptions","organizations_url":"https://api.github.com/users/SteveMarshall/orgs","repos_url":"https://api.github.com/users/SteveMarshall/repos","events_url":"https://api.github.com/users/SteveMarshall/events{/privacy}","received_events_url":"https://api.github.com/users/SteveMarshall/received_events","type":"User","site_admin":false},"body":"As above, I think the inversion of logic here (and in all the siblings of this) is a bit confusing (but that could be because it's early and I'm pre-:coffee:). When does this log? When there's a prisoner but no prisoner number? It might be clearer to wrap the if around the logger, or to make it a conditional line?","created_at":"2015-11-04T09:42:27Z","updated_at":"2015-11-04T09:42:27Z","html_url":"https://github.com/ministryofjustice/prison-visits/pull/385#discussion_r43859127","pull_request_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385","_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/comments/43859127"},"html":{"href":"https://github.com/ministryofjustice/prison-visits/pull/385#discussion_r43859127"},"pull_request":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385"}}},"pull_request":{"url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385","id":48744961,"html_url":"https://github.com/ministryofjustice/prison-visits/pull/385","diff_url":"https://github.com/ministryofjustice/prison-visits/pull/385.diff","patch_url":"https://github.com/ministryofjustice/prison-visits/pull/385.patch","issue_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/385","number":385,"state":"open","locked":false,"title":"Move validity check to model and log missing info","user":{"login":"tatyree","id":20921,"avatar_url":"https://avatars.githubusercontent.com/u/20921?v=3","gravatar_id":"","url":"https://api.github.com/users/tatyree","html_url":"https://github.com/tatyree","followers_url":"https://api.github.com/users/tatyree/followers","following_url":"https://api.github.com/users/tatyree/following{/other_user}","gists_url":"https://api.github.com/users/tatyree/gists{/gist_id}","starred_url":"https://api.github.com/users/tatyree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatyree/subscriptions","organizations_url":"https://api.github.com/users/tatyree/orgs","repos_url":"https://api.github.com/users/tatyree/repos","events_url":"https://api.github.com/users/tatyree/events{/privacy}","received_events_url":"https://api.github.com/users/tatyree/received_events","type":"User","site_admin":false},"body":"We are experiencing 500 errors on the live service that *appear* to be\r\nhappening when existing visits are deserialised. Visits lose their\r\nprisoner_name and prison.slots attributes.  This commit removes the\r\nbulk of the Visit integrity checking logic to the model and uses\r\nthat method, `required_information?`, to call a series of logging methods\r\nthat look for missing prisoner and prison associations.  Hopefully, this\r\nwill give us some insight on where these errors are coming from.","created_at":"2015-10-26T14:21:31Z","updated_at":"2015-11-04T09:42:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ade03a230f20687392a8c9f3ad658b40fe040b54","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385/commits","review_comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385/comments","review_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/385/comments","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits/statuses/8f58c331482938b1585d5f8785b3be9e9e638ae5","head":{"label":"ministryofjustice:log-more-visit-information","ref":"log-more-visit-information","sha":"8f58c331482938b1585d5f8785b3be9e9e638ae5","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":20570322,"name":"prison-visits","full_name":"ministryofjustice/prison-visits","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/prison-visits","description":"","fork":false,"url":"https://api.github.com/repos/ministryofjustice/prison-visits","forks_url":"https://api.github.com/repos/ministryofjustice/prison-visits/forks","keys_url":"https://api.github.com/repos/ministryofjustice/prison-visits/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/prison-visits/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/prison-visits/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/prison-visits/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/prison-visits/events","assignees_url":"https://api.github.com/repos/ministryofjustice/prison-visits/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/prison-visits/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/prison-visits/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/prison-visits/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/prison-visits/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/prison-visits/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/prison-visits/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/prison-visits/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/prison-visits/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/prison-visits/merges","archive_url":"https://api.github.com/repos/ministryofjustice/prison-visits/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/prison-visits/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/prison-visits/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/prison-visits/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/prison-visits/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/prison-visits/releases{/id}","created_at":"2014-06-06T16:24:26Z","updated_at":"2015-08-04T17:02:13Z","pushed_at":"2015-11-03T15:24:40Z","git_url":"git://github.com/ministryofjustice/prison-visits.git","ssh_url":"git@github.com:ministryofjustice/prison-visits.git","clone_url":"https://github.com/ministryofjustice/prison-visits.git","svn_url":"https://github.com/ministryofjustice/prison-visits","homepage":"https://www.prisonvisits.service.gov.uk","size":12040,"stargazers_count":5,"watchers_count":5,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":5,"default_branch":"master"}},"base":{"label":"ministryofjustice:master","ref":"master","sha":"9940212f14df0ca4e87eee66093f7d06ade9f215","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":20570322,"name":"prison-visits","full_name":"ministryofjustice/prison-visits","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/prison-visits","description":"","fork":false,"url":"https://api.github.com/repos/ministryofjustice/prison-visits","forks_url":"https://api.github.com/repos/ministryofjustice/prison-visits/forks","keys_url":"https://api.github.com/repos/ministryofjustice/prison-visits/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/prison-visits/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/prison-visits/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/prison-visits/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/prison-visits/events","assignees_url":"https://api.github.com/repos/ministryofjustice/prison-visits/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/prison-visits/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/prison-visits/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/prison-visits/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/prison-visits/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/prison-visits/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/prison-visits/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/prison-visits/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/prison-visits/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/prison-visits/merges","archive_url":"https://api.github.com/repos/ministryofjustice/prison-visits/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/prison-visits/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/prison-visits/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/prison-visits/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/prison-visits/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/prison-visits/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/prison-visits/releases{/id}","created_at":"2014-06-06T16:24:26Z","updated_at":"2015-08-04T17:02:13Z","pushed_at":"2015-11-03T15:24:40Z","git_url":"git://github.com/ministryofjustice/prison-visits.git","ssh_url":"git@github.com:ministryofjustice/prison-visits.git","clone_url":"https://github.com/ministryofjustice/prison-visits.git","svn_url":"https://github.com/ministryofjustice/prison-visits","homepage":"https://www.prisonvisits.service.gov.uk","size":12040,"stargazers_count":5,"watchers_count":5,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385"},"html":{"href":"https://github.com/ministryofjustice/prison-visits/pull/385"},"issue":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/385"},"comments":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/issues/385/comments"},"review_comments":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385/comments"},"review_comment":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/pulls/385/commits"},"statuses":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits/statuses/8f58c331482938b1585d5f8785b3be9e9e638ae5"}}}}