From: Anton Khorev Date: Sat, 18 Jan 2025 00:03:13 +0000 (+0300) Subject: Update user.consider_pd if confirmed X-Git-Tag: live~176^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/6a75db52e44a587f1b96cdd0ca2b8b327f11958e?ds=inline Update user.consider_pd if confirmed --- diff --git a/app/controllers/accounts/pd_declarations_controller.rb b/app/controllers/accounts/pd_declarations_controller.rb index f6740f777..2d2569d62 100644 --- a/app/controllers/accounts/pd_declarations_controller.rb +++ b/app/controllers/accounts/pd_declarations_controller.rb @@ -10,6 +10,18 @@ module Accounts def show; end def create + if current_user.consider_pd + flash[:warning] = t(".already_declared") + else + current_user.consider_pd = params[:consider_pd] + + if current_user.consider_pd + flash[:notice] = t(".successfully_declared") if current_user.save + else + flash[:warning] = t(".did_not_confirm") + end + end + redirect_to edit_account_path end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 83e399fb6..874ecaa85 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -331,6 +331,10 @@ en: consider_pd_why: "Why would I want my contributions to be Public Domain?" consider_pd_why_url: https://osmfoundation.org/wiki/Licence_and_Legal_FAQ/Why_would_I_want_my_contributions_to_be_public_domain confirm: Confirm + create: + successfully_declared: "You have successfully declared that you consider your edits to be in the Public Domain." + already_declared: "You have already declared that you consider your edits to be in the Public Domain." + did_not_confirm: "You didn't confirm that you consider your edits to be in the Public Domain." browse: deleted_ago_by_html: "Deleted %{time_ago} by %{user}" edited_ago_by_html: "Edited %{time_ago} by %{user}" diff --git a/test/controllers/accounts/pd_declarations_controller_test.rb b/test/controllers/accounts/pd_declarations_controller_test.rb index d2bbd70d2..be0d46f1e 100644 --- a/test/controllers/accounts/pd_declarations_controller_test.rb +++ b/test/controllers/accounts/pd_declarations_controller_test.rb @@ -36,13 +36,57 @@ module Accounts assert_response :forbidden end - def test_create + def test_create_unconfirmed user = create(:user) session_for(user) post account_pd_declaration_path assert_redirected_to edit_account_path + assert_nil flash[:notice] + assert_equal "You didn't confirm that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_not_predicate user, :consider_pd + end + + def test_create_confirmed + user = create(:user) + session_for(user) + + post account_pd_declaration_path, :params => { :consider_pd => true } + + assert_equal "You have successfully declared that you consider your edits to be in the Public Domain.", flash[:notice] + assert_nil flash[:warning] + + user.reload + assert_predicate user, :consider_pd + end + + def test_create_already_declared_unconfirmed + user = create(:user, :consider_pd => true) + session_for(user) + + post account_pd_declaration_path + + assert_nil flash[:notice] + assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_predicate user, :consider_pd + end + + def test_create_already_declared_confirmed + user = create(:user, :consider_pd => true) + session_for(user) + + post account_pd_declaration_path, :params => { :consider_pd => true } + + assert_nil flash[:notice] + assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_predicate user, :consider_pd end end end diff --git a/test/system/account_pd_declaration_test.rb b/test/system/account_pd_declaration_test.rb index 22867c795..d58484c8c 100644 --- a/test/system/account_pd_declaration_test.rb +++ b/test/system/account_pd_declaration_test.rb @@ -6,12 +6,30 @@ class AccountPdDeclarationTest < ApplicationSystemTestCase sign_in_as(@user) end - test "show checkbox if no declaration was made" do + test "can decline declaration if no declaration was made" do visit account_pd_declaration_path within_content_body do assert_unchecked_field "I consider my contributions to be in the Public Domain" assert_button "Confirm" + + click_on "Confirm" + + assert_no_text "You have also declared that you consider your edits to be in the Public Domain." + end + end + + test "can confirm declaration if no declaration was made" do + visit account_pd_declaration_path + + within_content_body do + assert_unchecked_field "I consider my contributions to be in the Public Domain" + assert_button "Confirm" + + check "I consider my contributions to be in the Public Domain" + click_on "Confirm" + + assert_text "You have also declared that you consider your edits to be in the Public Domain." end end