diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6f4e8627..8f17e192 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController - before_action except: [:show, :login, :index, :send_email_address_request, :set_password_and_address, :suggestions] do + before_action except: [:show, :login, :index, :set_password_and_address, :suggestions] do @user = User.enabled.where(id: params[:id]).first if current_user if current_user != @user @@ -48,14 +48,6 @@ def send_tips_back redirect_to @user, notice: 'All your tips have been refunded to their project' end - def send_email_address_request - tip = Tip.find(params[:tip_id]) - authorize! :update, tip.distribution - tip.user.reset_confirmation_token! - UserMailer.address_request(tip, current_user).deliver - redirect_to params[:return_url], notice: "Request sent" - end - def set_password_and_address @user = User.enabled.find(params[:id]) raise "Blank token" if params[:token].blank? diff --git a/app/models/project.rb b/app/models/project.rb index ee6a495e..84d0fd13 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -103,25 +103,9 @@ def tip_for commit end user ||= User.enabled.find_by(email: email) - if (next_tip_amount > 0) && - Tip.find_by(commit: commit.sha).nil? - - # create user - unless user - generated_password = Devise.friendly_token.first(8) - user = User.new( - email: email, - password: generated_password, - name: commit.commit.author.name, - ) - user.skip_confirmation_notification! - end - - if nickname.present? and user.nickname.blank? - user.nickname = nickname - end - - user.save! + if (next_tip_amount > 0) and + Tip.find_by(commit: commit.sha).nil? and + user if hold_tips amount = nil diff --git a/app/views/distributions/show.html.haml b/app/views/distributions/show.html.haml index b0a4f9a0..bf99a0f8 100644 --- a/app/views/distributions/show.html.haml +++ b/app/views/distributions/show.html.haml @@ -23,9 +23,6 @@ %td.address - if tip.user.try(:bitcoin_address).present? = tip.user.bitcoin_address - - else - - if tip.user.try(:email).present? and can? :update, @distribution - = button_to "Send email request to provide an address", send_email_address_request_user_path(tip_id: tip.id, return_url: request.url), class: "btn btn-default" %td.amount - if tip.amount = btc_human tip.amount diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index f1d65160..8fd3c9d1 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -7,6 +7,6 @@ = fields.text_area :text, rows: 10, label: "Tipping policies" = f.text_field :full_name, label: "GitHub URL (optional)" = f.form_group do - = f.check_box :auto_tip_commits, {label: "Automatically send 1% of the balance to each commit added to the default branch of the GitHub project"} + = f.check_box :auto_tip_commits, {label: "Automatically send 1% of the balance to each commit added to the default branch of the GitHub project. It only works if the user has registered an account on this site."} = f.form_group do = f.primary "Save" diff --git a/config/routes.rb b/config/routes.rb index 3bc617e1..1c64af15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,6 @@ end member do post :send_tips_back - post :send_email_address_request get :set_password_and_address patch :set_password_and_address end diff --git a/features/change_github.feature b/features/change_github.feature index e34d0fae..401be459 100644 --- a/features/change_github.feature +++ b/features/change_github.feature @@ -11,6 +11,7 @@ Feature: Fundraiser can change the GitHub repository linked to a project And our fee is "0" And a deposit of "500" Given a GitHub user "bob" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "alice" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" When the project tips are built from commits Then the project should have these tips: diff --git a/features/distribute_to_commits.feature b/features/distribute_to_commits.feature index 627d6aa0..8a2ff98e 100644 --- a/features/distribute_to_commits.feature +++ b/features/distribute_to_commits.feature @@ -13,6 +13,8 @@ Feature: A project collaborator distribute to commit authors And the author of commit "BBB" is "yugo" And the message of commit "BBB" is "Tiny change" And the author of commit "CCC" is "gaal" + And a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" Given I'm logged in as "seldon" And I go to the project page @@ -36,14 +38,9 @@ Feature: A project collaborator distribute to commit authors And I click on "Save" Then I should see these distribution lines: - | recipient | reason | address | amount | percentage | - | yugo | Commit BBB: Tiny change | | 0.5 | 100 | + | recipient | reason | address | amount | percentage | + | yugo | Commit BBB: Tiny change | mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1 | 0.5 | 100 | And I should see "Total amount: 0.50 PPC" - When I click on "Send email request to provide an address" - Then I should see "Request sent" - And there should be 1 email sent - And an email should have been sent to "yugo@example.com" - When the new commits are read When I go to the project page @@ -84,6 +81,8 @@ Feature: A project collaborator distribute to commit authors And the author of commit "170ed604f287b9fec397389d0b1b3f7d15b82276" is "yugo" And the message of commit "170ed604f287b9fec397389d0b1b3f7d15b82276" is "Tiny change" And the author of commit "1329394df2595739d652528d48fe6db66c67e1e8" is "gaal" + And a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" Given I'm logged in as "seldon" When the new commits are read @@ -103,6 +102,6 @@ Feature: A project collaborator distribute to commit authors And I click on "Save" Then I should see these distribution lines: - | recipient | reason | address | amount | percentage | - | yugo | Commit 170ed604f2: Tiny change | | 0.5 | | - | gaal | Commit 1329394df2: Some changes | | Undecided | | + | recipient | reason | address | amount | percentage | + | yugo | Commit 170ed604f2: Tiny change | mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1 | 0.5 | | + | gaal | Commit 1329394df2: Some changes | mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n | Undecided | | diff --git a/features/step_definitions/common.rb b/features/step_definitions/common.rb index 865bd95e..f4553ec7 100644 --- a/features/step_definitions/common.rb +++ b/features/step_definitions/common.rb @@ -87,10 +87,20 @@ def find_new_commit(id) end end +Given(/^(\d+) new commits by "([^"]*)"$/) do |arg1, arg2| + arg1.to_i.times do + add_new_commit(Digest::SHA1.hexdigest(SecureRandom.hex), author: {login: arg2}, commit: {author: {email: "#{arg2}@example.com"}}) + end +end + Given(/^a new commit "([^"]*?)"$/) do |arg1| add_new_commit(arg1) end +Given(/^a new commit "([^"]*?)" by "([^"]*)"$/) do |arg1, arg2| + add_new_commit(arg1, author: {login: arg2}, commit: {author: {email: "#{arg2}@example.com"}}) +end + Given(/^the project holds tips$/) do @project.update(hold_tips: true) end diff --git a/features/tip_for_commit.feature b/features/tip_for_commit.feature index 0b544ef6..221494aa 100644 --- a/features/tip_for_commit.feature +++ b/features/tip_for_commit.feature @@ -16,48 +16,32 @@ Feature: On projects not holding tips, a tip is created for each new commit Then the project should have these tips: | commit | amount | | 123 | 5.0 | - | abc | 4.95 | - | 333 | 4.9005 | + | 333 | 4.95 | When the tipper is started Then these amounts should have been sent from the account of the project: | address | amount | - | mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1 | 9.9005 | + | mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1 | 9.95 | - And an email should have been sent to "alicia@example.com" - When I click on the "Set your password and Peercoin address" link in the email - And I fill "Password" with "password" - And I fill "Password confirmation" with "password" - And I fill "Peercoin address" with "mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK" - And I click on "Save" - Then I should see "Information saved" - And the user with email "alicia@example.com" should have "password" as password - And the user with email "alicia@example.com" should have "mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK" as peercoin address - And the user with email "alicia@example.com" should have his email confirmed - - When the transaction history is cleared - And the tipper is started - Then these amounts should have been sent from the account of the project: - | address | amount | - | mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK | 4.95 | + And no email should have been sent Scenario: A project holding tips Given a project And the project holds tips And the project GitHub name is "foo/bar" And the commits on GitHub for project "foo/bar" are - | sha | - | 123 | - | abc | - | 333 | + | sha | author | email | + | 123 | bob | bobby@example.com | + | abc | alice | alicia@example.com | + | 333 | bob | bobby@example.com | And our fee is "0" And a deposit of "500" + And a GitHub user "bob" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" When the project tips are built from commits Then the project should have these tips: | commit | amount | | 123 | | - | abc | | | 333 | | When the tipper is started diff --git a/features/tip_modifier_interface.feature b/features/tip_modifier_interface.feature index 87a42071..51589c0d 100644 --- a/features/tip_modifier_interface.feature +++ b/features/tip_modifier_interface.feature @@ -13,11 +13,18 @@ Feature: A project collaborator can change the tips of commits And the message of commit "BBB" is "Tiny change" And the author of commit "CCC" is "gaal" - Scenario: Without anything modified + Scenario: Without anything modified and known users + Given a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" When the new commits are read Then there should be a tip of "5" for commit "BBB" And there should be a tip of "4.95" for commit "CCC" - And there should be 2 email sent + And there should be 0 email sent + + Scenario: Without anything modified and unknown users + When the new commits are read + Then there should be 0 tip + And there should be 0 email sent Scenario: A collaborator wants to alter the tips Given I'm logged in as "seldon" @@ -27,6 +34,9 @@ Feature: A project collaborator can change the tips of commits And I click on "Save" Then I should see "The project has been updated" + Given a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" + When the new commits are read Then the tip amount for commit "BBB" should be undecided And the tip amount for commit "CCC" should be undecided @@ -43,7 +53,7 @@ Feature: A project collaborator can change the tips of commits And I click on "Send the selected tip amounts" Then there should be a tip of "0.5" for commit "BBB" And the tip amount for commit "CCC" should be undecided - And there should be 1 email sent + And there should be 0 email sent When the email counters are reset And I choose the amount "Free: 0%" on commit "CCC" @@ -52,6 +62,21 @@ Feature: A project collaborator can change the tips of commits And there should be a tip of "0" for commit "CCC" And there should be 0 email sent + Scenario: A collaborator wants to alter the tips without known users + Given I'm logged in as "seldon" + And I go to the project page + And I click on "Edit project" + And I uncheck "Automatically send 1% of the balance to each commit added to the default branch of the GitHub project" + And I click on "Save" + Then I should see "The project has been updated" + + When the new commits are read + Then there should be 0 tip + And there should be 0 email sent + + When I go to the project page + And I should not see "Decide tip amounts" + Scenario: A non collaborator does not see the settings button Given I'm logged in as "yugo" And I go to the project page @@ -92,8 +117,9 @@ Feature: A project collaborator can change the tips of commits | yugo | 1 | Scenario: A collaborator sends large amounts in tips - Given 20 new commits - And a new commit "last" + Given a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + Given 20 new commits by "yugo" + And a new commit "last" by "yugo" And the project holds tips When the new commits are read And I'm logged in as "seldon" @@ -102,10 +128,11 @@ Feature: A project collaborator can change the tips of commits And I choose the amount "Huge: 5%" on all commits And I click on "Send the selected tip amounts" Then there should be a tip of "25" for commit "BBB" - And there should be a tip of "8.088338" for commit "last" + And there should be a tip of "8.51404" for commit "last" Scenario Outline: A collaborator changes the amount of a tip on another project Given the project holds tips + Given a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" And the new commits are read And a project "fake" And a deposit of "500" @@ -125,6 +152,8 @@ Feature: A project collaborator can change the tips of commits Scenario: A collaborator sends a free amount as tip Given the project holds tips + And a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" And the new commits are read And I'm logged in as "seldon" And I go to the project page @@ -136,6 +165,8 @@ Feature: A project collaborator can change the tips of commits Scenario: A collaborator sends too big free amounts Given the project holds tips + And a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" And the new commits are read And I'm logged in as "seldon" And I go to the project page @@ -155,6 +186,8 @@ Feature: A project collaborator can change the tips of commits Scenario: A collaborator changes the amount of an already decided tip Given the project holds tips + And a GitHub user "yugo" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1" + And a GitHub user "gaal" who has set his address to "mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n" And the new commits are read And I'm logged in as "seldon" And I go to the project page