]> git.openstreetmap.org Git - rails.git/commitdiff
Update user.consider_pd if confirmed
authorAnton Khorev <tony29@yandex.ru>
Sat, 18 Jan 2025 00:03:13 +0000 (03:03 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 18 Jan 2025 16:16:17 +0000 (19:16 +0300)
app/controllers/accounts/pd_declarations_controller.rb
config/locales/en.yml
test/controllers/accounts/pd_declarations_controller_test.rb
test/system/account_pd_declaration_test.rb

index f6740f77787f1850afaf2690fa67614c391ceb5d..2d2569d62b0adb342a50ce35f53289745b4d3652 100644 (file)
@@ -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
index 83e399fb6709131173543b89307bde3eccc5109b..874ecaa85bbdb7b2479df99a175b395a6ebc7de1 100644 (file)
@@ -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}"
index d2bbd70d2480b4e6f65a0d9d2379aa909bfb2b41..be0d46f1e57d354eb20383b0c29d360ef9cf2aeb 100644 (file)
@@ -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
index 22867c795198fd5718895bb7ff602eddd9adf397..d58484c8c3b81d7d9cb597439628567267636df8 100644 (file)
@@ -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