]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5162'
authorTom Hughes <tom@compton.nu>
Fri, 6 Sep 2024 16:02:45 +0000 (17:02 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 6 Sep 2024 16:02:45 +0000 (17:02 +0100)
app/views/geocoder/search.html.erb
app/views/site/about.html.erb
config/locales/en.yml
test/controllers/api/changeset_comments_controller_test.rb
test/controllers/api/messages_controller_test.rb
test/controllers/api/old_nodes_controller_test.rb
test/controllers/api/old_relations_controller_test.rb
test/controllers/api/old_ways_controller_test.rb
test/controllers/api/permissions_controller_test.rb
test/controllers/api/user_preferences_controller_test.rb
test/controllers/api/users_controller_test.rb

index f87a4909dd3a4144bdae95a0505fcdc8b5d8817e..56f468f2f655a1303038a237173aca13550d7099 100644 (file)
@@ -4,7 +4,7 @@
 
 <% @sources.each do |source| %>
   <h4>
-    <%= t(".title.results_from_html", :results_link => link_to(t(".title.#{source[:name]}"), source[:url].to_s)) %>
+    <%= link_to t(".title.#{source[:name]}"), source[:url].to_s %>
   </h4>
   <div class="search_results_entry mx-n3" data-href="<%= url_for @params.merge(:action => "search_#{source[:name]}") %>">
     <div class="text-center loader">
index 6cc32edd037dc8817a574252ca6633859c3e813b..56e82f8f8c1472d066cb992c05c0d563c9f87cd1 100644 (file)
@@ -27,9 +27,9 @@
             <circle cx="15" cy="15" r="13" fill="none" stroke="#c0c0c0" stroke-width="4" />
             <path d="m 15,22 c 0,0 5,-4.5199 5,-8 0,-3 -2,-5 -5,-5 -3,0 -5,2 -5,5 0,3.4801 5,8 5,8 z" fill="#c0c0c0" />
           </svg>
-          <h2 class="flex-grow-1 mb-0"><%= t "site.about.local_knowledge_title" %></h2>
+          <h2 class="flex-grow-1 mb-0"><%= t ".local_knowledge_title" %></h2>
         </div>
-        <p><%= t "site.about.local_knowledge_html" %></p>
+        <p><%= t ".local_knowledge_html" %></p>
       </section>
 
       <section>
             <circle cx="15" cy="15" r="13" fill="none" stroke="#c0c0c0" stroke-width="4" />
             <path d="m 15,7 -6,6 0,7 4,0 0,-4 4,0 0,4 4,0 0,-7 z" fill="#c0c0c0" />
           </svg>
-          <h2 class="flex-grow-1 mb-0"><%= t "site.about.community_driven_title" %></h2>
+          <h2 class="flex-grow-1 mb-0"><%= t ".community_driven_title" %></h2>
         </div>
         <p>
-          <%= t "site.about.community_driven_1_html", :osm_blog_link => link_to(t("site.about.community_driven_osm_blog"),
-                                                                                t("site.about.community_driven_osm_blog_url")),
-                                                      :user_diaries_link => link_to(t("site.about.community_driven_user_diaries"),
-                                                                                    diary_entries_path),
-                                                      :community_blogs_link => link_to(t("site.about.community_driven_community_blogs"),
-                                                                                       t("site.about.community_driven_community_blogs_url")),
-                                                      :osm_foundation_link => link_to(t("site.about.community_driven_osm_foundation"),
-                                                                                      t("site.about.community_driven_osm_foundation_url")) %>
+          <%= t ".community_driven_1_html", :osm_blog_link => link_to(t(".community_driven_osm_blog"),
+                                                                      t(".community_driven_osm_blog_url")),
+                                            :user_diaries_link => link_to(t(".community_driven_user_diaries"),
+                                                                          diary_entries_path),
+                                            :community_blogs_link => link_to(t(".community_driven_community_blogs"),
+                                                                             t(".community_driven_community_blogs_url")),
+                                            :osm_foundation_link => link_to(t(".community_driven_osm_foundation"),
+                                                                            t(".community_driven_osm_foundation_url")) %>
         </p>
       </section>
 
             <circle cx="15" cy="15" r="13" fill="none" stroke="#c0c0c0" stroke-width="4" />
             <path d="M20.196 18 a6 6 0 1 1 0 -6" fill="none" stroke="#c0c0c0" stroke-width="3" />
           </svg>
-          <h2 class="flex-grow-1 mb-0"><%= t "site.about.open_data_title" %></h2>
+          <h2 class="flex-grow-1 mb-0"><%= t ".open_data_title" %></h2>
         </div>
         <p>
-          <%= t "site.about.open_data_1_html", :open_data => tag.i(t("site.about.open_data_open_data")),
-                                               :copyright_license_link => link_to(t("site.about.open_data_copyright_license"),
-                                                                                  copyright_path) %></p>
+          <%= t ".open_data_1_html", :open_data => tag.i(t(".open_data_open_data")),
+                                     :copyright_license_link => link_to(t(".open_data_copyright_license"),
+                                                                        copyright_path) %></p>
       </section>
 
       <section id="legal">
                     d="M.5 1 a1 1 0 0 0 0 -2 h-2.5 a1 1 0 0 1 0 -2 h.5" />
             </g>
           </svg>
-          <h2 class="flex-grow-1 mb-0"><%= t "site.about.legal_title" %></h2>
+          <h2 class="flex-grow-1 mb-0"><%= t ".legal_title" %></h2>
         </div>
         <p>
-          <%= t "site.about.legal_1_1_html", :openstreetmap_foundation_link => link_to(t("site.about.legal_1_1_openstreetmap_foundation"),
-                                                                                       t("site.about.legal_1_1_openstreetmap_foundation_url")),
-                                             :terms_of_use_link => link_to(t("site.about.legal_1_1_terms_of_use"),
-                                                                           t("site.about.legal_1_1_terms_of_use_url")),
-                                             :aup_link => link_to(t("site.about.legal_1_1_aup"),
-                                                                  t("site.about.legal_1_1_aup_url")),
-                                             :privacy_policy_link => link_to(t("site.about.legal_1_1_privacy_policy"),
-                                                                             t("site.about.legal_1_1_privacy_policy_url")) %>
+          <%= t ".legal_1_1_html", :openstreetmap_foundation_link => link_to(t(".legal_1_1_openstreetmap_foundation"),
+                                                                             t(".legal_1_1_openstreetmap_foundation_url")),
+                                   :terms_of_use_link => link_to(t(".legal_1_1_terms_of_use"),
+                                                                 t(".legal_1_1_terms_of_use_url")),
+                                   :aup_link => link_to(t(".legal_1_1_aup"),
+                                                        t(".legal_1_1_aup_url")),
+                                   :privacy_policy_link => link_to(t(".legal_1_1_privacy_policy"),
+                                                                   t(".legal_1_1_privacy_policy_url")) %>
         </p>
         <p>
-          <%= t "site.about.legal_2_1_html", :contact_the_osmf_link => link_to(t("site.about.legal_2_1_contact_the_osmf"),
-                                                                               t("site.about.legal_2_1_contact_the_osmf_url")) %>
+          <%= t ".legal_2_1_html", :contact_the_osmf_link => link_to(t(".legal_2_1_contact_the_osmf"),
+                                                                     t(".legal_2_1_contact_the_osmf_url")) %>
         </p>
         <p>
-          <%= t "site.about.legal_2_2_html", :registered_trademarks_link => link_to(t("site.about.legal_2_2_registered_trademarks"),
-                                                                                    t("site.about.legal_2_2_registered_trademarks_url")) %>
+          <%= t ".legal_2_2_html", :registered_trademarks_link => link_to(t(".legal_2_2_registered_trademarks"),
+                                                                          t(".legal_2_2_registered_trademarks_url")) %>
         </p>
       </section>
 
               <line x1="15" y1="11" x2="15" y2="19" />
             </g>
           </svg>
-          <h2 class="flex-grow-1 mb-0"><%= t "site.about.partners_title" %></h2>
+          <h2 class="flex-grow-1 mb-0"><%= t ".partners_title" %></h2>
         </div>
         <p><%= t "layouts.hosting_partners_2024_html", :fastly => link_to(t("layouts.partners_fastly"), "https://www.fastly.com/"),
                                                        :corpmembers => link_to(t("layouts.partners_corpmembers"), "https://osmfoundation.org/wiki/Corporate_Members"),
index 4c7e3f3f7492b5874639757de6d6d421247db861..2634672f18e66667b4ebcd4354d263768be8c4b3 100644 (file)
@@ -668,7 +668,6 @@ en:
   geocoder:
     search:
       title:
-        results_from_html: 'Results from %{results_link}'
         latlon: Internal
         osm_nominatim: OpenStreetMap Nominatim
         osm_nominatim_reverse: OpenStreetMap Nominatim
@@ -1573,16 +1572,12 @@ en:
     history: History
     export: Export
     issues: Issues
-    data: Data
-    export_data: Export Data
     gps_traces: GPS Traces
     gps_traces_tooltip: Manage GPS traces
     user_diaries: User Diaries
     edit_with: Edit with %{editor}
-    tag_line: The Free Wiki World Map
     intro_header: Welcome to OpenStreetMap!
     intro_text: OpenStreetMap is a map of the world, created by people like you and free to use under an open license.
-    intro_2_create_account: "Create a user account"
     hosting_partners_2024_html: "Hosting is supported by %{fastly}, %{corpmembers}, and other %{partners}."
     partners_fastly: "Fastly"
     partners_corpmembers: "OSMF corporate members"
@@ -1596,9 +1591,6 @@ en:
     about: About
     copyright: Copyright
     communities: Communities
-    community: Community
-    community_blogs: "Community Blogs"
-    community_blogs_title: "Blogs from members of the OpenStreetMap community"
     learn_more: "Learn More"
     more: More
   user_mailer:
index ca7fc3407966067c7cc225f0acf9f27caaa4e741..35e45e8c840f4eb2a17d71b6bb01928d3888447b 100644 (file)
@@ -303,11 +303,11 @@ module Api
     # But writing oauth tests is hard, and so it's easier to put in a controller test.)
     def test_api_write_and_terms_agreed_via_token
       user = create(:user, :terms_agreed => nil)
-      token = create(:oauth_access_token, :resource_owner_id => user.id, :scopes => %w[write_api])
+      auth_header = bearer_authorization_header(user, :scopes => %w[write_api])
       changeset = create(:changeset, :closed)
 
       assert_difference "ChangesetComment.count", 0 do
-        post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => bearer_authorization_header(token.token)
+        post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
       end
       assert_response :forbidden
 
@@ -316,7 +316,7 @@ module Api
       user.save!
 
       assert_difference "ChangesetComment.count", 1 do
-        post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => bearer_authorization_header(token.token)
+        post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
       end
       assert_response :success
     end
index 0b54be4dc2051fe33c1c8434d5ced5f823fb45f4..cbf8dc870294fc7362341c2c3700f0e2e6aecc56 100644 (file)
@@ -59,10 +59,7 @@ module Api
       recipient = create(:user)
       sender = create(:user)
 
-      sender_token = create(:oauth_access_token,
-                            :resource_owner_id => sender.id,
-                            :scopes => %w[send_messages consume_messages])
-      sender_auth = bearer_authorization_header(sender_token.token)
+      sender_auth = bearer_authorization_header(sender, :scopes => %w[send_messages consume_messages])
 
       msg = build(:message)
 
@@ -101,10 +98,7 @@ module Api
       recipient = create(:user)
 
       sender = create(:user)
-      sender_token = create(:oauth_access_token,
-                            :resource_owner_id => sender.id,
-                            :scopes => %w[send_messages consume_messages])
-      sender_auth = bearer_authorization_header(sender_token.token)
+      sender_auth = bearer_authorization_header(sender, :scopes => %w[send_messages consume_messages])
 
       assert_no_difference "Message.count" do
         assert_no_difference "ActionMailer::Base.deliveries.size" do
@@ -160,20 +154,9 @@ module Api
       sender = create(:user)
       user3 = create(:user)
 
-      sender_token = create(:oauth_access_token,
-                            :resource_owner_id => sender.id,
-                            :scopes => %w[consume_messages])
-      sender_auth = bearer_authorization_header(sender_token.token)
-
-      recipient_token = create(:oauth_access_token,
-                               :resource_owner_id => recipient.id,
-                               :scopes => %w[consume_messages])
-      recipient_auth = bearer_authorization_header(recipient_token.token)
-
-      user3_token = create(:oauth_access_token,
-                           :resource_owner_id => user3.id,
-                           :scopes => %w[send_messages consume_messages])
-      user3_auth = bearer_authorization_header(user3_token.token)
+      sender_auth = bearer_authorization_header(sender, :scopes => %w[consume_messages])
+      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
+      user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
 
       msg = create(:message, :unread, :sender => sender, :recipient => recipient)
 
@@ -264,15 +247,8 @@ module Api
       sender = create(:user)
       user3 = create(:user)
 
-      recipient_token = create(:oauth_access_token,
-                               :resource_owner_id => recipient.id,
-                               :scopes => %w[consume_messages])
-      recipient_auth = bearer_authorization_header(recipient_token.token)
-
-      user3_token = create(:oauth_access_token,
-                           :resource_owner_id => user3.id,
-                           :scopes => %w[send_messages consume_messages])
-      user3_auth = bearer_authorization_header(user3_token.token)
+      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
+      user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
 
       msg = create(:message, :unread, :sender => sender, :recipient => recipient)
 
@@ -339,22 +315,13 @@ module Api
 
     def test_delete
       recipient = create(:user)
-      recipient_token = create(:oauth_access_token,
-                               :resource_owner_id => recipient.id,
-                               :scopes => %w[consume_messages])
-      recipient_auth = bearer_authorization_header(recipient_token.token)
+      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
 
       sender = create(:user)
-      sender_token = create(:oauth_access_token,
-                            :resource_owner_id => sender.id,
-                            :scopes => %w[send_messages consume_messages])
-      sender_auth = bearer_authorization_header(sender_token.token)
+      sender_auth = bearer_authorization_header(sender, :scopes => %w[send_messages consume_messages])
 
       user3 = create(:user)
-      user3_token = create(:oauth_access_token,
-                           :resource_owner_id => user3.id,
-                           :scopes => %w[send_messages consume_messages])
-      user3_auth = bearer_authorization_header(user3_token.token)
+      user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
 
       msg = create(:message, :read, :sender => sender, :recipient => recipient)
 
@@ -407,22 +374,13 @@ module Api
 
     def test_list_messages
       user1 = create(:user)
-      user1_token = create(:oauth_access_token,
-                           :resource_owner_id => user1.id,
-                           :scopes => %w[send_messages consume_messages])
-      user1_auth = bearer_authorization_header(user1_token.token)
+      user1_auth = bearer_authorization_header(user1, :scopes => %w[send_messages consume_messages])
 
       user2 = create(:user)
-      user2_token = create(:oauth_access_token,
-                           :resource_owner_id => user2.id,
-                           :scopes => %w[send_messages consume_messages])
-      user2_auth = bearer_authorization_header(user2_token.token)
+      user2_auth = bearer_authorization_header(user2, :scopes => %w[send_messages consume_messages])
 
       user3 = create(:user)
-      user3_token = create(:oauth_access_token,
-                           :resource_owner_id => user3.id,
-                           :scopes => %w[send_messages consume_messages])
-      user3_auth = bearer_authorization_header(user3_token.token)
+      user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
 
       # create some messages between users
       # user | inbox | outbox
@@ -523,10 +481,7 @@ module Api
 
     def test_paged_list_messages_asc
       recipient = create(:user)
-      recipient_token = create(:oauth_access_token,
-                               :resource_owner_id => recipient.id,
-                               :scopes => %w[consume_messages])
-      recipient_auth = bearer_authorization_header(recipient_token.token)
+      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
 
       sender = create(:user)
 
@@ -559,10 +514,7 @@ module Api
 
     def test_paged_list_messages_desc
       recipient = create(:user)
-      recipient_token = create(:oauth_access_token,
-                               :resource_owner_id => recipient.id,
-                               :scopes => %w[consume_messages])
-      recipient_auth = bearer_authorization_header(recipient_token.token)
+      recipient_auth = bearer_authorization_header(recipient, :scopes => %w[consume_messages])
 
       sender = create(:user)
 
index 99c4dbb1b317acb8ffd7c2bcf2a2c236ac90fd64..64325fd28c5e4a7e3e4cba4a4301832864942d32 100644 (file)
@@ -239,38 +239,38 @@ module Api
     end
 
     def test_redact_node_by_regular_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[read_prefs])
       do_redact_redactable_node(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_node_by_regular_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_api])
       do_redact_redactable_node(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_node_by_regular_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_redactions])
       do_redact_redactable_node(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_node_by_moderator_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[read_prefs])
       do_redact_redactable_node(auth_header)
       assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_node_by_moderator_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_api])
       do_redact_redactable_node(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_api scope."
       # assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_node_by_moderator_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_redactions])
       do_redact_redactable_node(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
     end
@@ -432,13 +432,6 @@ module Api
 
     private
 
-    def create_bearer_auth_header(user, scopes)
-      token = create(:oauth_access_token,
-                     :resource_owner_id => user.id,
-                     :scopes => scopes)
-      bearer_authorization_header(token.token)
-    end
-
     def do_redact_redactable_node(headers = {})
       node = create(:node, :with_history, :version => 4)
       node_v3 = node.old_nodes.find_by(:version => 3)
index 446fb5f14011464b2380be80109860972b383c6e..8d750542f1ac41505b05e0da314b20b7dec9cce2 100644 (file)
@@ -78,38 +78,38 @@ module Api
     end
 
     def test_redact_relation_by_regular_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[read_prefs])
       do_redact_redactable_relation(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_relation_by_regular_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_api])
       do_redact_redactable_relation(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_relation_by_regular_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_redactions])
       do_redact_redactable_relation(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_relation_by_moderator_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[read_prefs])
       do_redact_redactable_relation(auth_header)
       assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_relation_by_moderator_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_api])
       do_redact_redactable_relation(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_api scope."
       # assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_relation_by_moderator_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_redactions])
       do_redact_redactable_relation(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
     end
@@ -315,13 +315,6 @@ module Api
       end
     end
 
-    def create_bearer_auth_header(user, scopes)
-      token = create(:oauth_access_token,
-                     :resource_owner_id => user.id,
-                     :scopes => scopes)
-      bearer_authorization_header(token.token)
-    end
-
     def do_redact_redactable_relation(headers = {})
       relation = create(:relation, :with_history, :version => 4)
       relation_v3 = relation.old_relations.find_by(:version => 3)
index 48265575459cd4a2e170ccc1e7f8ad6b664e09e4..c6596ec347c984cba560776dfcfe89a6bf63f330 100644 (file)
@@ -119,38 +119,38 @@ module Api
     end
 
     def test_redact_way_by_regular_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[read_prefs])
       do_redact_redactable_way(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_way_by_regular_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_api])
       do_redact_redactable_way(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_way_by_regular_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_redactions])
       do_redact_redactable_way(auth_header)
       assert_response :forbidden, "should need to be moderator to redact."
     end
 
     def test_redact_way_by_moderator_with_read_prefs_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[read_prefs])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[read_prefs])
       do_redact_redactable_way(auth_header)
       assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_way_by_moderator_with_write_api_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_api])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_api])
       do_redact_redactable_way(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_api scope."
       # assert_response :forbidden, "should need to have write_redactions scope to redact."
     end
 
     def test_redact_way_by_moderator_with_write_redactions_scope
-      auth_header = create_bearer_auth_header(create(:moderator_user), %w[write_redactions])
+      auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_redactions])
       do_redact_redactable_way(auth_header)
       assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
     end
@@ -354,13 +354,6 @@ module Api
       end
     end
 
-    def create_bearer_auth_header(user, scopes)
-      token = create(:oauth_access_token,
-                     :resource_owner_id => user.id,
-                     :scopes => scopes)
-      bearer_authorization_header(token.token)
-    end
-
     def do_redact_redactable_way(headers = {})
       way = create(:way, :with_history, :version => 4)
       way_v3 = way.old_ways.find_by(:version => 3)
index 1ee3365e70bd931e6189d547189c5b813054cf48..2a7ac5e121d9113b309fdc890a247852e92515d6 100644 (file)
@@ -34,10 +34,8 @@ module Api
 
     def test_permissions_oauth2
       user = create(:user)
-      token = create(:oauth_access_token,
-                     :resource_owner_id => user.id,
-                     :scopes => %w[read_prefs write_api])
-      get permissions_path, :headers => bearer_authorization_header(token.token)
+      auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs write_api])
+      get permissions_path, :headers => auth_header
       assert_response :success
       assert_select "osm > permissions", :count => 1 do
         assert_select "permission", :count => 2
index e2c573532ecac7e0c0ae8c955de989e639948886..816be9b6e104d5c67aba52b23912079890e00983 100644 (file)
@@ -252,10 +252,10 @@ module Api
     # read preferences
     def test_show_using_token
       user = create(:user)
-      token = create(:oauth_access_token, :resource_owner_id => user.id, :scopes => %w[read_prefs])
+      auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs])
       create(:user_preference, :user => user, :k => "key", :v => "value")
 
-      get user_preference_path(:preference_key => "key"), :headers => bearer_authorization_header(token.token)
+      get user_preference_path(:preference_key => "key"), :headers => auth_header
       assert_response :success
     end
 
@@ -264,10 +264,10 @@ module Api
     # by other methods.
     def test_show_using_token_fail
       user = create(:user)
-      token = create(:oauth_access_token, :resource_owner_id => user.id)
+      auth_header = bearer_authorization_header(user, :scopes => %w[])
       create(:user_preference, :user => user, :k => "key", :v => "value")
 
-      get user_preference_path(:preference_key => "key"), :headers => bearer_authorization_header(token.token)
+      get user_preference_path(:preference_key => "key"), :headers => auth_header
       assert_response :forbidden
     end
   end
index 5086a09b3c217b0010d198c1370d4596c7c656bc..874d9177105b6cba3b20bc7b8aef312914e47671 100644 (file)
@@ -79,18 +79,14 @@ module Api
       user = create(:user,
                     :home_lat => 12.1, :home_lon => 23.4,
                     :languages => ["en"])
-      good_token = create(:oauth_access_token,
-                          :resource_owner_id => user.id,
-                          :scopes => %w[read_prefs])
-      bad_token = create(:oauth_access_token,
-                         :resource_owner_id => user.id,
-                         :scopes => %w[])
+      good_auth = bearer_authorization_header(user, :scopes => %w[read_prefs])
+      bad_auth = bearer_authorization_header(user, :scopes => %w[])
       other_user = create(:user,
                           :home_lat => 12.1, :home_lon => 23.4,
                           :languages => ["en"])
 
       # check that we can fetch our own details as XML with read_prefs
-      get api_user_path(:id => user.id), :headers => bearer_authorization_header(good_token.token)
+      get api_user_path(:id => user.id), :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
 
@@ -98,7 +94,7 @@ module Api
       check_xml_details(user, true, false)
 
       # check that we can fetch a different user's details as XML with read_prefs
-      get api_user_path(:id => other_user.id), :headers => bearer_authorization_header(good_token.token)
+      get api_user_path(:id => other_user.id), :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
 
@@ -106,7 +102,7 @@ module Api
       check_xml_details(other_user, false, false)
 
       # check that we can fetch our own details as XML without read_prefs
-      get api_user_path(:id => user.id), :headers => bearer_authorization_header(bad_token.token)
+      get api_user_path(:id => user.id), :headers => bad_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
 
@@ -114,7 +110,7 @@ module Api
       check_xml_details(user, false, false)
 
       # check that we can fetch our own details as JSON with read_prefs
-      get api_user_path(:id => user.id, :format => "json"), :headers => bearer_authorization_header(good_token.token)
+      get api_user_path(:id => user.id, :format => "json"), :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
 
@@ -126,7 +122,7 @@ module Api
       check_json_details(js, user, true, false)
 
       # check that we can fetch a different user's details as JSON with read_prefs
-      get api_user_path(:id => other_user.id, :format => "json"), :headers => bearer_authorization_header(good_token.token)
+      get api_user_path(:id => other_user.id, :format => "json"), :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
 
@@ -138,7 +134,7 @@ module Api
       check_json_details(js, other_user, false, false)
 
       # check that we can fetch our own details as JSON without read_prefs
-      get api_user_path(:id => user.id, :format => "json"), :headers => bearer_authorization_header(bad_token.token)
+      get api_user_path(:id => user.id, :format => "json"), :headers => bad_auth
       assert_response :success
       assert_equal "application/json", response.media_type
 
@@ -190,21 +186,16 @@ module Api
       user = create(:user,
                     :home_lat => 12.1, :home_lon => 23.4,
                     :languages => ["en"])
-      good_token = create(:oauth_access_token,
-                          :resource_owner_id => user.id,
-                          :scopes => %w[read_prefs])
-      bad_token = create(:oauth_access_token,
-                         :resource_owner_id => user.id)
-      email_token = create(:oauth_access_token,
-                           :resource_owner_id => user.id,
-                           :scopes => %w[read_prefs read_email])
+      good_auth = bearer_authorization_header(user, :scopes => %w[read_prefs])
+      bad_auth = bearer_authorization_header(user, :scopes => %w[])
+      email_auth = bearer_authorization_header(user, :scopes => %w[read_prefs read_email])
 
       # check that we can't fetch details as XML without read_prefs
-      get user_details_path, :headers => bearer_authorization_header(bad_token.token)
+      get user_details_path, :headers => bad_auth
       assert_response :forbidden
 
       # check that we can fetch details as XML without read_email
-      get user_details_path, :headers => bearer_authorization_header(good_token.token)
+      get user_details_path, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
 
@@ -212,7 +203,7 @@ module Api
       check_xml_details(user, true, false)
 
       # check that we can fetch details as XML with read_email
-      get user_details_path, :headers => bearer_authorization_header(email_token.token)
+      get user_details_path, :headers => email_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
 
@@ -220,11 +211,11 @@ module Api
       check_xml_details(user, true, true)
 
       # check that we can't fetch details as JSON without read_prefs
-      get user_details_path(:format => "json"), :headers => bearer_authorization_header(bad_token.token)
+      get user_details_path(:format => "json"), :headers => bad_auth
       assert_response :forbidden
 
       # check that we can fetch details as JSON without read_email
-      get user_details_path(:format => "json"), :headers => bearer_authorization_header(good_token.token)
+      get user_details_path(:format => "json"), :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
 
@@ -236,7 +227,7 @@ module Api
       check_json_details(js, user, true, false)
 
       # check that we can fetch details as JSON with read_email
-      get user_details_path(:format => "json"), :headers => bearer_authorization_header(email_token.token)
+      get user_details_path(:format => "json"), :headers => email_auth
       assert_response :success
       assert_equal "application/json", response.media_type
 
@@ -325,10 +316,10 @@ module Api
       user1 = create(:user, :description => "test1", :terms_agreed => Date.yesterday)
       user2 = create(:user, :description => "test2", :terms_agreed => Date.yesterday)
       user3 = create(:user, :description => "test3", :terms_agreed => Date.yesterday)
-      good_token = create(:oauth_access_token, :resource_owner_id => user1.id, :scopes => %w[read_prefs])
-      bad_token = create(:oauth_access_token, :resource_owner_id => user1.id, :scopes => %w[])
+      good_auth = bearer_authorization_header(user1, :scopes => %w[read_prefs])
+      bad_auth = bearer_authorization_header(user1, :scopes => %w[])
 
-      get api_users_path, :params => { :users => user1.id }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => user1.id }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 1 do
@@ -337,7 +328,7 @@ module Api
         assert_select "user[id='#{user3.id}']", :count => 0
       end
 
-      get api_users_path, :params => { :users => user2.id }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => user2.id }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 1 do
@@ -346,7 +337,7 @@ module Api
         assert_select "user[id='#{user3.id}']", :count => 0
       end
 
-      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 2 do
@@ -355,7 +346,7 @@ module Api
         check_xml_details(user3, false, false)
       end
 
-      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :headers => bearer_authorization_header(bad_token.token)
+      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}" }, :headers => bad_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 2 do
@@ -364,7 +355,7 @@ module Api
         check_xml_details(user3, false, false)
       end
 
-      get api_users_path, :params => { :users => user1.id, :format => "json" }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => user1.id, :format => "json" }, :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
       js = ActiveSupport::JSON.decode(@response.body)
@@ -372,7 +363,7 @@ module Api
       assert_equal 1, js["users"].count
       check_json_details(js["users"][0], user1, true, false)
 
-      get api_users_path, :params => { :users => user2.id, :format => "json" }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => user2.id, :format => "json" }, :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
       js = ActiveSupport::JSON.decode(@response.body)
@@ -380,7 +371,7 @@ module Api
       assert_equal 1, js["users"].count
       check_json_details(js["users"][0], user2, false, false)
 
-      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => good_auth
       assert_response :success
       assert_equal "application/json", response.media_type
       js = ActiveSupport::JSON.decode(@response.body)
@@ -389,7 +380,7 @@ module Api
       check_json_details(js["users"][0], user1, true, false)
       check_json_details(js["users"][1], user3, false, false)
 
-      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => bearer_authorization_header(bad_token.token)
+      get api_users_path, :params => { :users => "#{user1.id},#{user3.id}", :format => "json" }, :headers => bad_auth
       assert_response :success
       assert_equal "application/json", response.media_type
       js = ActiveSupport::JSON.decode(@response.body)
@@ -398,17 +389,17 @@ module Api
       check_json_details(js["users"][0], user1, false, false)
       check_json_details(js["users"][1], user3, false, false)
 
-      get api_users_path, :params => { :users => create(:user, :suspended).id }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => create(:user, :suspended).id }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 0
 
-      get api_users_path, :params => { :users => create(:user, :deleted).id }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => create(:user, :deleted).id }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 0
 
-      get api_users_path, :params => { :users => 0 }, :headers => bearer_authorization_header(good_token.token)
+      get api_users_path, :params => { :users => 0 }, :headers => good_auth
       assert_response :success
       assert_equal "application/xml", response.media_type
       assert_select "user", :count => 0