Skip to content

Commit

Permalink
Output active blocks list
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 1, 2025
1 parent 00b3d9a commit 59186c8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
5 changes: 4 additions & 1 deletion app/controllers/api/user_blocks/active_lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class ActiveListsController < ApiController

before_action :set_request_formats

def show; end
def show
@user_blocks = current_user.blocks.active.order(:id => :desc)
@skip_reason = true
end

private

Expand Down
20 changes: 9 additions & 11 deletions app/views/api/user_blocks/_user_block.json.jbuilder
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion app/views/api/user_blocks/_user_block.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions app/views/api/user_blocks/active_lists/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/views/api/user_blocks/active_lists/show.xml.builder
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion app/views/api/user_blocks/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
json.partial! "api/root_attributes"

json.partial! @user_block
json.user_block do
json.partial! @user_block
end
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_show

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
Expand All @@ -63,6 +67,11 @@ def test_show_json

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
Expand Down

0 comments on commit 59186c8

Please sign in to comment.