{"action":"created","comment":{"url":"https://api.github.com/repos/spree/spree/pulls/comments/40330000","id":40330000,"diff_hunk":"@@ -0,0 +1,89 @@\n+module Spree\n+  module Admin\n+    class StoreCreditError < StandardError; end\n+\n+    class StoreCreditsController < Spree::Admin::BaseController\n+      before_filter :load_user\n+      before_filter :load_categories, only: [:new, :edit]\n+      before_filter :load_store_credit, only: [:new, :edit, :update]\n+      before_filter :ensure_unused_store_credit, only: [:update]\n+\n+      def index\n+        @store_credits = @user.store_credits.reverse_order\n+      end\n+\n+      def create\n+        @store_credit = @user.store_credits.build(\n+          permitted_store_credit_params.merge(\n+            created_by: try_spree_current_user,\n+            action_originator: try_spree_current_user,\n+          )\n+        )\n+\n+        if @store_credit.save\n+          flash[:success] = flash_message_for(@store_credit, :successfully_created)\n+          redirect_to admin_user_store_credits_path(@user)\n+        else\n+          load_categories\n+          flash[:error] = Spree.t(\"store_credit.errors.unable_to_create\")\n+          render :new\n+        end\n+      end\n+\n+      def update\n+        @store_credit.assign_attributes(permitted_store_credit_params)\n+        @store_credit.created_by = try_spree_current_user\n+\n+        if @store_credit.save\n+          flash[:success] = flash_message_for(@store_credit, :successfully_updated)\n+          redirect_to admin_user_store_credits_path(@user)\n+        else\n+          load_categories\n+          flash[:error] = Spree.t(\"store_credit.errors.unable_to_update\")\n+          render :edit\n+        end\n+      end\n+\n+      def destroy\n+        @store_credit = @user.store_credits.find(params[:id])\n+        ensure_unused_store_credit\n+\n+        if @store_credit.destroy\n+          respond_with(@store_credit) do |format|\n+            format.html { redirect_to admin_user_store_credits_path(@user) }\n+            format.js { render_js_for_destroy }\n+          end\n+        else\n+          render text: Spree.t(\"store_credit.errors.unable_to_delete\"), status: :unprocessable_entity\n+        end\n+      end\n+\n+      protected\n+\n+      def permitted_store_credit_params\n+        params.require(:store_credit).permit(permitted_store_credit_attributes).\n+          merge(currency: Spree::Config[:currency])\n+      end\n+\n+      private\n+\n+      def load_user\n+        @user = Spree.user_class.find(params[:user_id])\n+      end\n+\n+      def load_categories\n+        @credit_categories = Spree::StoreCreditCategory.all.order(:name)\n+      end\n+\n+      def load_store_credit\n+        @store_credit = Spree::StoreCredit.find_by_id(params[:id]) || Spree::StoreCredit.new\n+      end\n+\n+      def ensure_unused_store_credit","path":"backend/app/controllers/spree/admin/store_credits_controller.rb","position":82,"original_position":82,"commit_id":"b950989913c80d298555e29e4a57ce06ef4e40cf","original_commit_id":"b950989913c80d298555e29e4a57ce06ef4e40cf","user":{"login":"jasonfb","id":59002,"avatar_url":"https://avatars.githubusercontent.com/u/59002?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonfb","html_url":"https://github.com/jasonfb","followers_url":"https://api.github.com/users/jasonfb/followers","following_url":"https://api.github.com/users/jasonfb/following{/other_user}","gists_url":"https://api.github.com/users/jasonfb/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonfb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonfb/subscriptions","organizations_url":"https://api.github.com/users/jasonfb/orgs","repos_url":"https://api.github.com/users/jasonfb/repos","events_url":"https://api.github.com/users/jasonfb/events{/privacy}","received_events_url":"https://api.github.com/users/jasonfb/received_events","type":"User","site_admin":false},"body":"two things: 1) this is domain logic and shouldn't be in a controller. (But that is forgivable)\r\n\r\n2) We actually have a specific need from our Customer Service team that store credits be adjustable after they are created. In our implementation, we enforce that you cannot lower the store credit amount to below the used + authorized amounts. ","created_at":"2015-09-24T15:09:09Z","updated_at":"2015-09-24T15:09:09Z","html_url":"https://github.com/spree/spree/pull/5917#discussion_r40330000","pull_request_url":"https://api.github.com/repos/spree/spree/pulls/5917","_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/comments/40330000"},"html":{"href":"https://github.com/spree/spree/pull/5917#discussion_r40330000"},"pull_request":{"href":"https://api.github.com/repos/spree/spree/pulls/5917"}}},"pull_request":{"url":"https://api.github.com/repos/spree/spree/pulls/5917","id":27772029,"html_url":"https://github.com/spree/spree/pull/5917","diff_url":"https://github.com/spree/spree/pull/5917.diff","patch_url":"https://github.com/spree/spree/pull/5917.patch","issue_url":"https://api.github.com/repos/spree/spree/issues/5917","number":5917,"state":"open","locked":false,"title":"Add store credits","user":{"login":"JDutil","id":25104,"avatar_url":"https://avatars.githubusercontent.com/u/25104?v=3","gravatar_id":"","url":"https://api.github.com/users/JDutil","html_url":"https://github.com/JDutil","followers_url":"https://api.github.com/users/JDutil/followers","following_url":"https://api.github.com/users/JDutil/following{/other_user}","gists_url":"https://api.github.com/users/JDutil/gists{/gist_id}","starred_url":"https://api.github.com/users/JDutil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JDutil/subscriptions","organizations_url":"https://api.github.com/users/JDutil/orgs","repos_url":"https://api.github.com/users/JDutil/repos","events_url":"https://api.github.com/users/JDutil/events{/privacy}","received_events_url":"https://api.github.com/users/JDutil/received_events","type":"User","site_admin":false},"body":"This is an updated branch in favor of https://github.com/spree/spree/pull/5625\r\n\r\n- [x] Frontend UX\r\n- [ ] Frontend UX Feature Specs\r\n- [x] Backend UX for creating credit\r\n- [ ] Backend UX for creating credit reasons\r\n- [ ] Final code review & houndci cleanup.","created_at":"2015-01-21T16:15:51Z","updated_at":"2015-09-24T15:09:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e341f8f886516e41c6abcea6e16d5269e39cceb","assignee":{"login":"peterberkenbosch","id":4252,"avatar_url":"https://avatars.githubusercontent.com/u/4252?v=3","gravatar_id":"","url":"https://api.github.com/users/peterberkenbosch","html_url":"https://github.com/peterberkenbosch","followers_url":"https://api.github.com/users/peterberkenbosch/followers","following_url":"https://api.github.com/users/peterberkenbosch/following{/other_user}","gists_url":"https://api.github.com/users/peterberkenbosch/gists{/gist_id}","starred_url":"https://api.github.com/users/peterberkenbosch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterberkenbosch/subscriptions","organizations_url":"https://api.github.com/users/peterberkenbosch/orgs","repos_url":"https://api.github.com/users/peterberkenbosch/repos","events_url":"https://api.github.com/users/peterberkenbosch/events{/privacy}","received_events_url":"https://api.github.com/users/peterberkenbosch/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/spree/spree/milestones/30","html_url":"https://github.com/spree/spree/milestones/v3.1.x","labels_url":"https://api.github.com/repos/spree/spree/milestones/30/labels","id":984894,"number":30,"title":"v3.1.x","description":"","creator":{"login":"JDutil","id":25104,"avatar_url":"https://avatars.githubusercontent.com/u/25104?v=3","gravatar_id":"","url":"https://api.github.com/users/JDutil","html_url":"https://github.com/JDutil","followers_url":"https://api.github.com/users/JDutil/followers","following_url":"https://api.github.com/users/JDutil/following{/other_user}","gists_url":"https://api.github.com/users/JDutil/gists{/gist_id}","starred_url":"https://api.github.com/users/JDutil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JDutil/subscriptions","organizations_url":"https://api.github.com/users/JDutil/orgs","repos_url":"https://api.github.com/users/JDutil/repos","events_url":"https://api.github.com/users/JDutil/events{/privacy}","received_events_url":"https://api.github.com/users/JDutil/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":3,"state":"open","created_at":"2015-02-18T17:53:10Z","updated_at":"2015-07-25T00:48:43Z","due_on":"2015-03-31T04:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/spree/spree/pulls/5917/commits","review_comments_url":"https://api.github.com/repos/spree/spree/pulls/5917/comments","review_comment_url":"https://api.github.com/repos/spree/spree/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spree/spree/issues/5917/comments","statuses_url":"https://api.github.com/repos/spree/spree/statuses/b950989913c80d298555e29e4a57ce06ef4e40cf","head":{"label":"spree:add-store-credits","ref":"add-store-credits","sha":"b950989913c80d298555e29e4a57ce06ef4e40cf","user":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"repo":{"id":3314,"name":"spree","full_name":"spree/spree","owner":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spree/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":false,"url":"https://api.github.com/repos/spree/spree","forks_url":"https://api.github.com/repos/spree/spree/forks","keys_url":"https://api.github.com/repos/spree/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spree/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spree/spree/teams","hooks_url":"https://api.github.com/repos/spree/spree/hooks","issue_events_url":"https://api.github.com/repos/spree/spree/issues/events{/number}","events_url":"https://api.github.com/repos/spree/spree/events","assignees_url":"https://api.github.com/repos/spree/spree/assignees{/user}","branches_url":"https://api.github.com/repos/spree/spree/branches{/branch}","tags_url":"https://api.github.com/repos/spree/spree/tags","blobs_url":"https://api.github.com/repos/spree/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spree/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spree/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/spree/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spree/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/spree/spree/languages","stargazers_url":"https://api.github.com/repos/spree/spree/stargazers","contributors_url":"https://api.github.com/repos/spree/spree/contributors","subscribers_url":"https://api.github.com/repos/spree/spree/subscribers","subscription_url":"https://api.github.com/repos/spree/spree/subscription","commits_url":"https://api.github.com/repos/spree/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/spree/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/spree/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/spree/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/spree/spree/contents/{+path}","compare_url":"https://api.github.com/repos/spree/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spree/spree/merges","archive_url":"https://api.github.com/repos/spree/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spree/spree/downloads","issues_url":"https://api.github.com/repos/spree/spree/issues{/number}","pulls_url":"https://api.github.com/repos/spree/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/spree/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/spree/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spree/spree/labels{/name}","releases_url":"https://api.github.com/repos/spree/spree/releases{/id}","created_at":"2008-03-10T14:45:35Z","updated_at":"2015-09-24T12:21:42Z","pushed_at":"2015-09-24T15:00:03Z","git_url":"git://github.com/spree/spree.git","ssh_url":"git@github.com:spree/spree.git","clone_url":"https://github.com/spree/spree.git","svn_url":"https://github.com/spree/spree","homepage":"http://spreecommerce.com","size":139743,"stargazers_count":6746,"watchers_count":6746,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3202,"mirror_url":null,"open_issues_count":185,"forks":3202,"open_issues":185,"watchers":6746,"default_branch":"master"}},"base":{"label":"spree:master","ref":"master","sha":"ab9d28e6833cb898998abc72224e65b3c0c22994","user":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"repo":{"id":3314,"name":"spree","full_name":"spree/spree","owner":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spree/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":false,"url":"https://api.github.com/repos/spree/spree","forks_url":"https://api.github.com/repos/spree/spree/forks","keys_url":"https://api.github.com/repos/spree/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spree/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spree/spree/teams","hooks_url":"https://api.github.com/repos/spree/spree/hooks","issue_events_url":"https://api.github.com/repos/spree/spree/issues/events{/number}","events_url":"https://api.github.com/repos/spree/spree/events","assignees_url":"https://api.github.com/repos/spree/spree/assignees{/user}","branches_url":"https://api.github.com/repos/spree/spree/branches{/branch}","tags_url":"https://api.github.com/repos/spree/spree/tags","blobs_url":"https://api.github.com/repos/spree/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spree/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spree/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/spree/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spree/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/spree/spree/languages","stargazers_url":"https://api.github.com/repos/spree/spree/stargazers","contributors_url":"https://api.github.com/repos/spree/spree/contributors","subscribers_url":"https://api.github.com/repos/spree/spree/subscribers","subscription_url":"https://api.github.com/repos/spree/spree/subscription","commits_url":"https://api.github.com/repos/spree/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/spree/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/spree/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/spree/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/spree/spree/contents/{+path}","compare_url":"https://api.github.com/repos/spree/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spree/spree/merges","archive_url":"https://api.github.com/repos/spree/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spree/spree/downloads","issues_url":"https://api.github.com/repos/spree/spree/issues{/number}","pulls_url":"https://api.github.com/repos/spree/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/spree/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/spree/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spree/spree/labels{/name}","releases_url":"https://api.github.com/repos/spree/spree/releases{/id}","created_at":"2008-03-10T14:45:35Z","updated_at":"2015-09-24T12:21:42Z","pushed_at":"2015-09-24T15:00:03Z","git_url":"git://github.com/spree/spree.git","ssh_url":"git@github.com:spree/spree.git","clone_url":"https://github.com/spree/spree.git","svn_url":"https://github.com/spree/spree","homepage":"http://spreecommerce.com","size":139743,"stargazers_count":6746,"watchers_count":6746,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3202,"mirror_url":null,"open_issues_count":185,"forks":3202,"open_issues":185,"watchers":6746,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/5917"},"html":{"href":"https://github.com/spree/spree/pull/5917"},"issue":{"href":"https://api.github.com/repos/spree/spree/issues/5917"},"comments":{"href":"https://api.github.com/repos/spree/spree/issues/5917/comments"},"review_comments":{"href":"https://api.github.com/repos/spree/spree/pulls/5917/comments"},"review_comment":{"href":"https://api.github.com/repos/spree/spree/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spree/spree/pulls/5917/commits"},"statuses":{"href":"https://api.github.com/repos/spree/spree/statuses/b950989913c80d298555e29e4a57ce06ef4e40cf"}}}}