]> git.openstreetmap.org Git - rails.git/commitdiff
Output active blocks list
authorAnton Khorev <tony29@yandex.ru>
Wed, 1 Jan 2025 03:13:54 +0000 (06:13 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 14 Feb 2025 11:16:48 +0000 (14:16 +0300)
app/controllers/api/user_blocks/active_lists_controller.rb
app/views/api/user_blocks/_user_block.json.jbuilder
app/views/api/user_blocks/_user_block.xml.builder
app/views/api/user_blocks/active_lists/show.json.jbuilder [new file with mode: 0644]
app/views/api/user_blocks/active_lists/show.xml.builder [new file with mode: 0644]
app/views/api/user_blocks/show.json.jbuilder
test/controllers/api/user_blocks/active_lists_controller_test.rb

index fd7b768dd90e52de127ea22e577e5f56eb3f5fe9..535d7393a5608d931145f3bce07abf9775b2aaae 100644 (file)
@@ -7,7 +7,10 @@ module Api
 
       before_action :set_request_formats
 
-      def show; end
+      def show
+        @user_blocks = current_user.blocks.active.order(:id => :desc)
+        @skip_reason = true
+      end
     end
   end
 end
index 3288dd6ada031db7f5f3668d7a1f224838326a2c..2e65b52dab8e14a964a4ae948dce2773436bf11e 100644 (file)
@@ -1,13 +1,11 @@
-json.user_block do
-  json.id user_block.id
-  json.created_at user_block.created_at.xmlschema
-  json.updated_at user_block.updated_at.xmlschema
-  json.ends_at user_block.ends_at.xmlschema
-  json.needs_view user_block.needs_view
+json.id user_block.id
+json.created_at user_block.created_at.xmlschema
+json.updated_at user_block.updated_at.xmlschema
+json.ends_at user_block.ends_at.xmlschema
+json.needs_view user_block.needs_view
 
-  json.user :uid => user_block.user_id, :user => user_block.user.display_name
-  json.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
-  json.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
+json.user :uid => user_block.user_id, :user => user_block.user.display_name
+json.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
+json.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
 
-  json.reason user_block.reason
-end
+json.reason user_block.reason unless @skip_reason
index a41dc56d7f4d20a4891833749d8bca9380c46a7b..288e8966363341b36ac2c37418ce1575a9f8522b 100644 (file)
@@ -10,5 +10,6 @@ xml.user_block(attrs) do
   xml.user :uid => user_block.user_id, :user => user_block.user.display_name
   xml.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
   xml.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
-  xml.reason user_block.reason
+
+  xml.reason user_block.reason unless @skip_reason
 end
diff --git a/app/views/api/user_blocks/active_lists/show.json.jbuilder b/app/views/api/user_blocks/active_lists/show.json.jbuilder
new file mode 100644 (file)
index 0000000..aaf1c21
--- /dev/null
@@ -0,0 +1,5 @@
+json.partial! "api/root_attributes"
+
+json.user_blocks do
+  json.array! @user_blocks, :partial => "api/user_blocks/user_block", :as => :user_block
+end
diff --git a/app/views/api/user_blocks/active_lists/show.xml.builder b/app/views/api/user_blocks/active_lists/show.xml.builder
new file mode 100644 (file)
index 0000000..9073926
--- /dev/null
@@ -0,0 +1,5 @@
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+  osm << (render(:partial => "api/user_blocks/user_block", :collection => @user_blocks) || "")
+end
index 6cfc0ded5031835140fefc893eaffa95c7272753..a90b7cd1958569b7c3600425b8be202e9ff828be 100644 (file)
@@ -1,3 +1,5 @@
 json.partial! "api/root_attributes"
 
-json.partial! @user_block
+json.user_block do
+  json.partial! @user_block
+end
index efca9b6c637696e920d06c89d6a4b9c15d03fb67..6856dca8d2cfedc29e78121a48953d0127825ce2 100644 (file)
@@ -50,6 +50,10 @@ module Api
 
         get api_user_blocks_active_list_path, :headers => user_auth_header
         assert_response :success
+        assert_dom "user_block", :count => 2 do |dom_blocks|
+          assert_dom dom_blocks[0], "> @id", block1.id.to_s
+          assert_dom dom_blocks[1], "> @id", block0.id.to_s
+        end
       end
 
       def test_show_json
@@ -63,6 +67,11 @@ module Api
 
         get api_user_blocks_active_list_path(:format => "json"), :headers => user_auth_header
         assert_response :success
+        js = ActiveSupport::JSON.decode(@response.body)
+        assert_not_nil js
+        assert_equal 2, js["user_blocks"].count
+        assert_equal block1.id, js["user_blocks"][0]["id"]
+        assert_equal block0.id, js["user_blocks"][1]["id"]
       end
     end
   end