{"action":"created","comment":{"url":"https://api.github.com/repos/tablexi/nucore-open/pulls/comments/47145830","id":47145830,"diff_hunk":"@@ -38,60 +38,82 @@ def price_groups\n     end\n   end\n \n-  def add_or_update_member(user, new_role, session_user)\n-    Account.transaction do\n-      # expire old owner if new\n-      if new_role == AccountUser::ACCOUNT_OWNER\n-        # expire old owner record\n-        @old_owner = self.owner\n-        if @old_owner\n-          @old_owner.deleted_at = Time.zone.now\n-          @old_owner.deleted_by = session_user.id\n-          @old_owner.save!\n-        end\n-      end\n+  # Given an account_type return a param string that can be used as a variable\n+  # name, filename, param, etc. Replaces any backslashes with underscore to\n+  # support namespaced classes.\n+  def self.account_type_to_param(account_type)\n+    account_type.to_s.underscore.gsub(\"/\", \"_\")\n+  end\n \n-      # find non-deleted record for this user and account or init new one\n-      # deleted_at MUST be nil to preserve existing audit trail\n-      @account_user = AccountUser.find_or_initialize_by_account_id_and_user_id_and_deleted_at(\n-        self.id,\n-        user.id,\n-        nil\n-      )\n-      # set (new?) role\n-      @account_user.user_role = new_role\n-      # set creation information\n-      @account_user.created_by = session_user.id\n+  # Returns an array of subclassed Account objects.\n+  # Engines can concat to this on initialization.\n+  def self.account_types\n+    @@account_types ||= [NufsAccount]\n+  end\n \n-      self.account_users << @account_user\n+  # Returns an array of subclassed Account objects available across multiple\n+  # facilities. Engines can concat to this on initialization.\n+  def self.global_account_types\n+    @@global_account_types ||= [NufsAccount]\n+  end\n \n-      raise ActiveRecord::Rollback unless self.save\n-    end\n+  # Returns an array of subclassed Account objects available per facility.\n+  # Engines can concat to this on initialization.\n+  def self.facility_account_types\n+    @@facility_account_types ||= []\n+  end\n \n-    return @account_user\n+  # Returns an array of subclassed Account objects availalbe for statements.\n+  def self.statement_account_types\n+    facility_account_types\n   end\n \n-  def facility\n-    nil\n+  # Returns an array of `creatable` subclassed Account objects given a facility.\n+  def self.creatable_account_types_for_facility(facility)\n+    return account_types.select(&:cross_facility?) if facility.cross_facility?\n+    account_types\n   end\n \n+  # Returns true if multiple account types are available\n+  def self.multiple_account_types?\n+    account_types.size > 1\n+  end\n+\n+  def self.using_statements?\n+    statement_account_types.present?\n+  end\n+\n+  def self.using_affiliates?\n+    using_statements?\n+  end\n \n+  # Returns true if this account type is limited to a single facility.\n+  # TODO: rename to scoped_to_single_facility?\n   def self.limited_to_single_facility?\n-    AccountManager::FACILITY_ACCOUNT_CLASSES.include? self.name\n+    facility_account_types.map(&:to_s).include?(self.name)\n   end\n \n+  # TODO: shouldn't this use `global_account_types.include?(self.name)` instead?\n   def self.cross_facility?\n     !limited_to_single_facility?\n   end","path":"app/models/account.rb","position":100,"original_position":92,"commit_id":"be3c3fe0d60ae086d8c7767a61de46f80de39537","original_commit_id":"d9a37f0813eb7417b8a4070710bb2ea5044aa268","user":{"login":"jhanggi","id":1099111,"avatar_url":"https://avatars.githubusercontent.com/u/1099111?v=3","gravatar_id":"","url":"https://api.github.com/users/jhanggi","html_url":"https://github.com/jhanggi","followers_url":"https://api.github.com/users/jhanggi/followers","following_url":"https://api.github.com/users/jhanggi/following{/other_user}","gists_url":"https://api.github.com/users/jhanggi/gists{/gist_id}","starred_url":"https://api.github.com/users/jhanggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhanggi/subscriptions","organizations_url":"https://api.github.com/users/jhanggi/orgs","repos_url":"https://api.github.com/users/jhanggi/repos","events_url":"https://api.github.com/users/jhanggi/events{/privacy}","received_events_url":"https://api.github.com/users/jhanggi/received_events","type":"User","site_admin":false},"body":"Probably, but there could probably be a few things done to enforce mutual exclusivity. Theoretically, a mischievous developer could add an account type to both lists which could cause come confusion. We probably don't need to worry about that, but it's something to think about. One option would be to maintain a list of all valid account types and a separate list of either global or scoped types, and then compute the other by `valid_account_types - [global_types|scoped_types]`.","created_at":"2015-12-09T20:18:42Z","updated_at":"2015-12-09T20:18:42Z","html_url":"https://github.com/tablexi/nucore-open/pull/410#discussion_r47145830","pull_request_url":"https://api.github.com/repos/tablexi/nucore-open/pulls/410","_links":{"self":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/comments/47145830"},"html":{"href":"https://github.com/tablexi/nucore-open/pull/410#discussion_r47145830"},"pull_request":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/410"}}},"pull_request":{"url":"https://api.github.com/repos/tablexi/nucore-open/pulls/410","id":53076896,"html_url":"https://github.com/tablexi/nucore-open/pull/410","diff_url":"https://github.com/tablexi/nucore-open/pull/410.diff","patch_url":"https://github.com/tablexi/nucore-open/pull/410.patch","issue_url":"https://api.github.com/repos/tablexi/nucore-open/issues/410","number":410,"state":"open","locked":false,"title":"[#120455] Split accounts engine payment source","user":{"login":"benlinton","id":766787,"avatar_url":"https://avatars.githubusercontent.com/u/766787?v=3","gravatar_id":"","url":"https://api.github.com/users/benlinton","html_url":"https://github.com/benlinton","followers_url":"https://api.github.com/users/benlinton/followers","following_url":"https://api.github.com/users/benlinton/following{/other_user}","gists_url":"https://api.github.com/users/benlinton/gists{/gist_id}","starred_url":"https://api.github.com/users/benlinton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benlinton/subscriptions","organizations_url":"https://api.github.com/users/benlinton/orgs","repos_url":"https://api.github.com/users/benlinton/repos","events_url":"https://api.github.com/users/benlinton/events{/privacy}","received_events_url":"https://api.github.com/users/benlinton/received_events","type":"User","site_admin":false},"body":"Support creating, updating, and showing a `split_account` account type as a payment source.\r\n\r\nInstalled the `nested_form_fields` gem to easily add multiple `splits` on a new `split_account`.  \r\n\r\nThe `new` Account views now use a set of nav tabs rather than a select dropdown to choose account type. This means we no longer need to load an generic `Account` object for the `new` action, and can get rid of hacks to support using `Account.new` for the `new` form.  We can now load the specific subclassed account_type (i.e. `NufsAccount`) for new and create which seems like a cleaner approach.\r\n\r\nSince multiple engines are now adding account types, converted the `AccountManager:: GLOBAL_ACCOUNT_CLASSES`-like constants to class variables that are append-able by multiple engines.  Started the process of deprecating `app/support/account_manager.rb` in favor of putting account_type related methods in the `Account` class.  I feel the STI parent should track what it's children are.  Although, some of the non-account_type methods could probably get moved into a service object or etc. outside of the `app/support` directory.  I haven't done this yet.  \r\n\r\nMove `app/support/account_builder.rb` to services folder and refactored it.  Extended the `AccountBuilder` service object within engines that add new account types.  Began removing coupled code and tests from the main app that actually belong in engines.\r\n\r\nI also started refactoring additional legacy code, but removed it from this PR in order to keep the PR more focused/shorter.","created_at":"2015-12-09T04:59:19Z","updated_at":"2015-12-09T20:18:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db277c582d6bf7f5f45aef87cfd2f4090659eb12","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tablexi/nucore-open/pulls/410/commits","review_comments_url":"https://api.github.com/repos/tablexi/nucore-open/pulls/410/comments","review_comment_url":"https://api.github.com/repos/tablexi/nucore-open/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tablexi/nucore-open/issues/410/comments","statuses_url":"https://api.github.com/repos/tablexi/nucore-open/statuses/be3c3fe0d60ae086d8c7767a61de46f80de39537","head":{"label":"tablexi:split-accounts-engine-payment-source","ref":"split-accounts-engine-payment-source","sha":"be3c3fe0d60ae086d8c7767a61de46f80de39537","user":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"repo":{"id":1439473,"name":"nucore-open","full_name":"tablexi/nucore-open","owner":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tablexi/nucore-open","description":"Northwestern University Core Facility Management Software (NUCore)","fork":false,"url":"https://api.github.com/repos/tablexi/nucore-open","forks_url":"https://api.github.com/repos/tablexi/nucore-open/forks","keys_url":"https://api.github.com/repos/tablexi/nucore-open/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tablexi/nucore-open/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tablexi/nucore-open/teams","hooks_url":"https://api.github.com/repos/tablexi/nucore-open/hooks","issue_events_url":"https://api.github.com/repos/tablexi/nucore-open/issues/events{/number}","events_url":"https://api.github.com/repos/tablexi/nucore-open/events","assignees_url":"https://api.github.com/repos/tablexi/nucore-open/assignees{/user}","branches_url":"https://api.github.com/repos/tablexi/nucore-open/branches{/branch}","tags_url":"https://api.github.com/repos/tablexi/nucore-open/tags","blobs_url":"https://api.github.com/repos/tablexi/nucore-open/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tablexi/nucore-open/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tablexi/nucore-open/git/refs{/sha}","trees_url":"https://api.github.com/repos/tablexi/nucore-open/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tablexi/nucore-open/statuses/{sha}","languages_url":"https://api.github.com/repos/tablexi/nucore-open/languages","stargazers_url":"https://api.github.com/repos/tablexi/nucore-open/stargazers","contributors_url":"https://api.github.com/repos/tablexi/nucore-open/contributors","subscribers_url":"https://api.github.com/repos/tablexi/nucore-open/subscribers","subscription_url":"https://api.github.com/repos/tablexi/nucore-open/subscription","commits_url":"https://api.github.com/repos/tablexi/nucore-open/commits{/sha}","git_commits_url":"https://api.github.com/repos/tablexi/nucore-open/git/commits{/sha}","comments_url":"https://api.github.com/repos/tablexi/nucore-open/comments{/number}","issue_comment_url":"https://api.github.com/repos/tablexi/nucore-open/issues/comments{/number}","contents_url":"https://api.github.com/repos/tablexi/nucore-open/contents/{+path}","compare_url":"https://api.github.com/repos/tablexi/nucore-open/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tablexi/nucore-open/merges","archive_url":"https://api.github.com/repos/tablexi/nucore-open/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tablexi/nucore-open/downloads","issues_url":"https://api.github.com/repos/tablexi/nucore-open/issues{/number}","pulls_url":"https://api.github.com/repos/tablexi/nucore-open/pulls{/number}","milestones_url":"https://api.github.com/repos/tablexi/nucore-open/milestones{/number}","notifications_url":"https://api.github.com/repos/tablexi/nucore-open/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tablexi/nucore-open/labels{/name}","releases_url":"https://api.github.com/repos/tablexi/nucore-open/releases{/id}","created_at":"2011-03-04T13:45:37Z","updated_at":"2015-05-07T22:55:09Z","pushed_at":"2015-12-09T20:01:12Z","git_url":"git://github.com/tablexi/nucore-open.git","ssh_url":"git@github.com:tablexi/nucore-open.git","clone_url":"https://github.com/tablexi/nucore-open.git","svn_url":"https://github.com/tablexi/nucore-open","homepage":"","size":60875,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":3,"default_branch":"master"}},"base":{"label":"tablexi:master","ref":"master","sha":"12f510ad655b2ccecbe62b46816e3adbbd2f66d7","user":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"repo":{"id":1439473,"name":"nucore-open","full_name":"tablexi/nucore-open","owner":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tablexi/nucore-open","description":"Northwestern University Core Facility Management Software (NUCore)","fork":false,"url":"https://api.github.com/repos/tablexi/nucore-open","forks_url":"https://api.github.com/repos/tablexi/nucore-open/forks","keys_url":"https://api.github.com/repos/tablexi/nucore-open/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tablexi/nucore-open/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tablexi/nucore-open/teams","hooks_url":"https://api.github.com/repos/tablexi/nucore-open/hooks","issue_events_url":"https://api.github.com/repos/tablexi/nucore-open/issues/events{/number}","events_url":"https://api.github.com/repos/tablexi/nucore-open/events","assignees_url":"https://api.github.com/repos/tablexi/nucore-open/assignees{/user}","branches_url":"https://api.github.com/repos/tablexi/nucore-open/branches{/branch}","tags_url":"https://api.github.com/repos/tablexi/nucore-open/tags","blobs_url":"https://api.github.com/repos/tablexi/nucore-open/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tablexi/nucore-open/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tablexi/nucore-open/git/refs{/sha}","trees_url":"https://api.github.com/repos/tablexi/nucore-open/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tablexi/nucore-open/statuses/{sha}","languages_url":"https://api.github.com/repos/tablexi/nucore-open/languages","stargazers_url":"https://api.github.com/repos/tablexi/nucore-open/stargazers","contributors_url":"https://api.github.com/repos/tablexi/nucore-open/contributors","subscribers_url":"https://api.github.com/repos/tablexi/nucore-open/subscribers","subscription_url":"https://api.github.com/repos/tablexi/nucore-open/subscription","commits_url":"https://api.github.com/repos/tablexi/nucore-open/commits{/sha}","git_commits_url":"https://api.github.com/repos/tablexi/nucore-open/git/commits{/sha}","comments_url":"https://api.github.com/repos/tablexi/nucore-open/comments{/number}","issue_comment_url":"https://api.github.com/repos/tablexi/nucore-open/issues/comments{/number}","contents_url":"https://api.github.com/repos/tablexi/nucore-open/contents/{+path}","compare_url":"https://api.github.com/repos/tablexi/nucore-open/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tablexi/nucore-open/merges","archive_url":"https://api.github.com/repos/tablexi/nucore-open/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tablexi/nucore-open/downloads","issues_url":"https://api.github.com/repos/tablexi/nucore-open/issues{/number}","pulls_url":"https://api.github.com/repos/tablexi/nucore-open/pulls{/number}","milestones_url":"https://api.github.com/repos/tablexi/nucore-open/milestones{/number}","notifications_url":"https://api.github.com/repos/tablexi/nucore-open/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tablexi/nucore-open/labels{/name}","releases_url":"https://api.github.com/repos/tablexi/nucore-open/releases{/id}","created_at":"2011-03-04T13:45:37Z","updated_at":"2015-05-07T22:55:09Z","pushed_at":"2015-12-09T20:01:12Z","git_url":"git://github.com/tablexi/nucore-open.git","ssh_url":"git@github.com:tablexi/nucore-open.git","clone_url":"https://github.com/tablexi/nucore-open.git","svn_url":"https://github.com/tablexi/nucore-open","homepage":"","size":60875,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/410"},"html":{"href":"https://github.com/tablexi/nucore-open/pull/410"},"issue":{"href":"https://api.github.com/repos/tablexi/nucore-open/issues/410"},"comments":{"href":"https://api.github.com/repos/tablexi/nucore-open/issues/410/comments"},"review_comments":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/410/comments"},"review_comment":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tablexi/nucore-open/pulls/410/commits"},"statuses":{"href":"https://api.github.com/repos/tablexi/nucore-open/statuses/be3c3fe0d60ae086d8c7767a61de46f80de39537"}}}}