{"action":"created","comment":{"url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/comments/63772135","id":63772135,"diff_hunk":"@@ -50,17 +53,101 @@ class Person < ActiveRecord::Base\n   has_many :secondary_agent_loans, class_name: 'Loan', foreign_key: :secondary_agent_id\n   has_many :representative_loans,  class_name: 'Loan', foreign_key: :representative_id\n \n-  has_one :user, foreign_key: :profile_id\n+  has_one :user, foreign_key: :profile_id, autosave: true\n \n   validates :division_id, presence: true\n   validates :first_name, presence: true\n \n+  validate :division_role_valid\n+  validate :user_valid\n+\n+  # Transient attributes to fascilitate user managment\n+  attr_writer :owning_division_role\n+  attr_accessor :password, :password_confirmation\n+\n+  before_save :update_full_name\n+  before_save :update_user\n+  after_save :handle_roles\n+  after_save :clean_up_passwords\n+\n+  def update_full_name\n+    self.name = \"#{first_name} #{last_name}\"\n+  end\n+\n+  # Lazy evaluation getter\n+  def owning_division_role\n+    @owning_division_role = resolve_owning_division_role unless defined? @owning_division_role\n+    @owning_division_role\n+  end\n+\n+  def owning_division_role_label\n+    label_key = owning_division_role || 'none'\n+    I18n.t(\"people.roles.#{label_key}\")\n+  end\n+\n+  def resolve_owning_division_role\n+    if user\n+      role = user.roles.find_by(resource_type: 'Division', resource_id: division_id)\n+      return role.name.to_sym if role\n+    end\n+    nil\n+  end\n+\n+  def user_required?\n+    has_system_access","path":"app/models/person.rb","position":76,"original_position":76,"commit_id":"4cd7c3742da69348808dcc0253537c94ed299a43","original_commit_id":"4cd7c3742da69348808dcc0253537c94ed299a43","user":{"login":"hooverlunch","id":702320,"avatar_url":"https://avatars.githubusercontent.com/u/702320?v=3","gravatar_id":"","url":"https://api.github.com/users/hooverlunch","html_url":"https://github.com/hooverlunch","followers_url":"https://api.github.com/users/hooverlunch/followers","following_url":"https://api.github.com/users/hooverlunch/following{/other_user}","gists_url":"https://api.github.com/users/hooverlunch/gists{/gist_id}","starred_url":"https://api.github.com/users/hooverlunch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hooverlunch/subscriptions","organizations_url":"https://api.github.com/users/hooverlunch/orgs","repos_url":"https://api.github.com/users/hooverlunch/repos","events_url":"https://api.github.com/users/hooverlunch/events{/privacy}","received_events_url":"https://api.github.com/users/hooverlunch/received_events","type":"User","site_admin":false},"body":"Can/should add `?` at end of this line by convention. Rails supports automatically.","created_at":"2016-05-18T20:04:58Z","updated_at":"2016-05-18T20:04:58Z","html_url":"https://github.com/sassafrastech/madeline_system/pull/84#discussion_r63772135","pull_request_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84","_links":{"self":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/comments/63772135"},"html":{"href":"https://github.com/sassafrastech/madeline_system/pull/84#discussion_r63772135"},"pull_request":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84"}}},"pull_request":{"url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84","id":70535283,"html_url":"https://github.com/sassafrastech/madeline_system/pull/84","diff_url":"https://github.com/sassafrastech/madeline_system/pull/84.diff","patch_url":"https://github.com/sassafrastech/madeline_system/pull/84.patch","issue_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/84","number":84,"state":"open","locked":false,"title":"3776 manage people / users","user":{"login":"elliottjf","id":1640599,"avatar_url":"https://avatars.githubusercontent.com/u/1640599?v=3","gravatar_id":"","url":"https://api.github.com/users/elliottjf","html_url":"https://github.com/elliottjf","followers_url":"https://api.github.com/users/elliottjf/followers","following_url":"https://api.github.com/users/elliottjf/following{/other_user}","gists_url":"https://api.github.com/users/elliottjf/gists{/gist_id}","starred_url":"https://api.github.com/users/elliottjf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elliottjf/subscriptions","organizations_url":"https://api.github.com/users/elliottjf/orgs","repos_url":"https://api.github.com/users/elliottjf/repos","events_url":"https://api.github.com/users/elliottjf/events{/privacy}","received_events_url":"https://api.github.com/users/elliottjf/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-18T14:14:02Z","updated_at":"2016-05-18T20:04:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49f06af335a4560f97b44cc9230ab72c279aeed8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84/commits","review_comments_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84/comments","review_comment_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/84/comments","statuses_url":"https://api.github.com/repos/sassafrastech/madeline_system/statuses/4cd7c3742da69348808dcc0253537c94ed299a43","head":{"label":"sassafrastech:3776_manage_users","ref":"3776_manage_users","sha":"4cd7c3742da69348808dcc0253537c94ed299a43","user":{"login":"sassafrastech","id":5033102,"avatar_url":"https://avatars.githubusercontent.com/u/5033102?v=3","gravatar_id":"","url":"https://api.github.com/users/sassafrastech","html_url":"https://github.com/sassafrastech","followers_url":"https://api.github.com/users/sassafrastech/followers","following_url":"https://api.github.com/users/sassafrastech/following{/other_user}","gists_url":"https://api.github.com/users/sassafrastech/gists{/gist_id}","starred_url":"https://api.github.com/users/sassafrastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sassafrastech/subscriptions","organizations_url":"https://api.github.com/users/sassafrastech/orgs","repos_url":"https://api.github.com/users/sassafrastech/repos","events_url":"https://api.github.com/users/sassafrastech/events{/privacy}","received_events_url":"https://api.github.com/users/sassafrastech/received_events","type":"Organization","site_admin":false},"repo":{"id":48768255,"name":"madeline_system","full_name":"sassafrastech/madeline_system","owner":{"login":"sassafrastech","id":5033102,"avatar_url":"https://avatars.githubusercontent.com/u/5033102?v=3","gravatar_id":"","url":"https://api.github.com/users/sassafrastech","html_url":"https://github.com/sassafrastech","followers_url":"https://api.github.com/users/sassafrastech/followers","following_url":"https://api.github.com/users/sassafrastech/following{/other_user}","gists_url":"https://api.github.com/users/sassafrastech/gists{/gist_id}","starred_url":"https://api.github.com/users/sassafrastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sassafrastech/subscriptions","organizations_url":"https://api.github.com/users/sassafrastech/orgs","repos_url":"https://api.github.com/users/sassafrastech/repos","events_url":"https://api.github.com/users/sassafrastech/events{/privacy}","received_events_url":"https://api.github.com/users/sassafrastech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sassafrastech/madeline_system","description":"","fork":false,"url":"https://api.github.com/repos/sassafrastech/madeline_system","forks_url":"https://api.github.com/repos/sassafrastech/madeline_system/forks","keys_url":"https://api.github.com/repos/sassafrastech/madeline_system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sassafrastech/madeline_system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sassafrastech/madeline_system/teams","hooks_url":"https://api.github.com/repos/sassafrastech/madeline_system/hooks","issue_events_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/events{/number}","events_url":"https://api.github.com/repos/sassafrastech/madeline_system/events","assignees_url":"https://api.github.com/repos/sassafrastech/madeline_system/assignees{/user}","branches_url":"https://api.github.com/repos/sassafrastech/madeline_system/branches{/branch}","tags_url":"https://api.github.com/repos/sassafrastech/madeline_system/tags","blobs_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/refs{/sha}","trees_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sassafrastech/madeline_system/statuses/{sha}","languages_url":"https://api.github.com/repos/sassafrastech/madeline_system/languages","stargazers_url":"https://api.github.com/repos/sassafrastech/madeline_system/stargazers","contributors_url":"https://api.github.com/repos/sassafrastech/madeline_system/contributors","subscribers_url":"https://api.github.com/repos/sassafrastech/madeline_system/subscribers","subscription_url":"https://api.github.com/repos/sassafrastech/madeline_system/subscription","commits_url":"https://api.github.com/repos/sassafrastech/madeline_system/commits{/sha}","git_commits_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/commits{/sha}","comments_url":"https://api.github.com/repos/sassafrastech/madeline_system/comments{/number}","issue_comment_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/comments{/number}","contents_url":"https://api.github.com/repos/sassafrastech/madeline_system/contents/{+path}","compare_url":"https://api.github.com/repos/sassafrastech/madeline_system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sassafrastech/madeline_system/merges","archive_url":"https://api.github.com/repos/sassafrastech/madeline_system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sassafrastech/madeline_system/downloads","issues_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues{/number}","pulls_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls{/number}","milestones_url":"https://api.github.com/repos/sassafrastech/madeline_system/milestones{/number}","notifications_url":"https://api.github.com/repos/sassafrastech/madeline_system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sassafrastech/madeline_system/labels{/name}","releases_url":"https://api.github.com/repos/sassafrastech/madeline_system/releases{/id}","deployments_url":"https://api.github.com/repos/sassafrastech/madeline_system/deployments","created_at":"2015-12-29T21:38:53Z","updated_at":"2016-01-12T00:19:27Z","pushed_at":"2016-05-18T19:16:32Z","git_url":"git://github.com/sassafrastech/madeline_system.git","ssh_url":"git@github.com:sassafrastech/madeline_system.git","clone_url":"https://github.com/sassafrastech/madeline_system.git","svn_url":"https://github.com/sassafrastech/madeline_system","homepage":null,"size":2837,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"develop"}},"base":{"label":"sassafrastech:develop","ref":"develop","sha":"b479bb9d1f1619a3772c29a040f3a488fa5bf990","user":{"login":"sassafrastech","id":5033102,"avatar_url":"https://avatars.githubusercontent.com/u/5033102?v=3","gravatar_id":"","url":"https://api.github.com/users/sassafrastech","html_url":"https://github.com/sassafrastech","followers_url":"https://api.github.com/users/sassafrastech/followers","following_url":"https://api.github.com/users/sassafrastech/following{/other_user}","gists_url":"https://api.github.com/users/sassafrastech/gists{/gist_id}","starred_url":"https://api.github.com/users/sassafrastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sassafrastech/subscriptions","organizations_url":"https://api.github.com/users/sassafrastech/orgs","repos_url":"https://api.github.com/users/sassafrastech/repos","events_url":"https://api.github.com/users/sassafrastech/events{/privacy}","received_events_url":"https://api.github.com/users/sassafrastech/received_events","type":"Organization","site_admin":false},"repo":{"id":48768255,"name":"madeline_system","full_name":"sassafrastech/madeline_system","owner":{"login":"sassafrastech","id":5033102,"avatar_url":"https://avatars.githubusercontent.com/u/5033102?v=3","gravatar_id":"","url":"https://api.github.com/users/sassafrastech","html_url":"https://github.com/sassafrastech","followers_url":"https://api.github.com/users/sassafrastech/followers","following_url":"https://api.github.com/users/sassafrastech/following{/other_user}","gists_url":"https://api.github.com/users/sassafrastech/gists{/gist_id}","starred_url":"https://api.github.com/users/sassafrastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sassafrastech/subscriptions","organizations_url":"https://api.github.com/users/sassafrastech/orgs","repos_url":"https://api.github.com/users/sassafrastech/repos","events_url":"https://api.github.com/users/sassafrastech/events{/privacy}","received_events_url":"https://api.github.com/users/sassafrastech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sassafrastech/madeline_system","description":"","fork":false,"url":"https://api.github.com/repos/sassafrastech/madeline_system","forks_url":"https://api.github.com/repos/sassafrastech/madeline_system/forks","keys_url":"https://api.github.com/repos/sassafrastech/madeline_system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sassafrastech/madeline_system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sassafrastech/madeline_system/teams","hooks_url":"https://api.github.com/repos/sassafrastech/madeline_system/hooks","issue_events_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/events{/number}","events_url":"https://api.github.com/repos/sassafrastech/madeline_system/events","assignees_url":"https://api.github.com/repos/sassafrastech/madeline_system/assignees{/user}","branches_url":"https://api.github.com/repos/sassafrastech/madeline_system/branches{/branch}","tags_url":"https://api.github.com/repos/sassafrastech/madeline_system/tags","blobs_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/refs{/sha}","trees_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sassafrastech/madeline_system/statuses/{sha}","languages_url":"https://api.github.com/repos/sassafrastech/madeline_system/languages","stargazers_url":"https://api.github.com/repos/sassafrastech/madeline_system/stargazers","contributors_url":"https://api.github.com/repos/sassafrastech/madeline_system/contributors","subscribers_url":"https://api.github.com/repos/sassafrastech/madeline_system/subscribers","subscription_url":"https://api.github.com/repos/sassafrastech/madeline_system/subscription","commits_url":"https://api.github.com/repos/sassafrastech/madeline_system/commits{/sha}","git_commits_url":"https://api.github.com/repos/sassafrastech/madeline_system/git/commits{/sha}","comments_url":"https://api.github.com/repos/sassafrastech/madeline_system/comments{/number}","issue_comment_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues/comments{/number}","contents_url":"https://api.github.com/repos/sassafrastech/madeline_system/contents/{+path}","compare_url":"https://api.github.com/repos/sassafrastech/madeline_system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sassafrastech/madeline_system/merges","archive_url":"https://api.github.com/repos/sassafrastech/madeline_system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sassafrastech/madeline_system/downloads","issues_url":"https://api.github.com/repos/sassafrastech/madeline_system/issues{/number}","pulls_url":"https://api.github.com/repos/sassafrastech/madeline_system/pulls{/number}","milestones_url":"https://api.github.com/repos/sassafrastech/madeline_system/milestones{/number}","notifications_url":"https://api.github.com/repos/sassafrastech/madeline_system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sassafrastech/madeline_system/labels{/name}","releases_url":"https://api.github.com/repos/sassafrastech/madeline_system/releases{/id}","deployments_url":"https://api.github.com/repos/sassafrastech/madeline_system/deployments","created_at":"2015-12-29T21:38:53Z","updated_at":"2016-01-12T00:19:27Z","pushed_at":"2016-05-18T19:16:32Z","git_url":"git://github.com/sassafrastech/madeline_system.git","ssh_url":"git@github.com:sassafrastech/madeline_system.git","clone_url":"https://github.com/sassafrastech/madeline_system.git","svn_url":"https://github.com/sassafrastech/madeline_system","homepage":null,"size":2837,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84"},"html":{"href":"https://github.com/sassafrastech/madeline_system/pull/84"},"issue":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/issues/84"},"comments":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/issues/84/comments"},"review_comments":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84/comments"},"review_comment":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/pulls/84/commits"},"statuses":{"href":"https://api.github.com/repos/sassafrastech/madeline_system/statuses/4cd7c3742da69348808dcc0253537c94ed299a43"}}}}