Commit 914ea967ce52bf2ea6f8973ab7b433c396cd3acd
1 parent
5a4f284e
Exists in
master
and in
8 other branches
Removing EnvironmentStatisticsBlock from core
PeopleBlock plugin overrides the EnvironmentStatisticsBlock (ActionItem3045)
Showing
11 changed files
with
13 additions
and
176 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
@@ -3,9 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController | @@ -3,9 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController | ||
3 | protect 'edit_environment_design', :environment | 3 | protect 'edit_environment_design', :environment |
4 | 4 | ||
5 | def available_blocks | 5 | def available_blocks |
6 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
7 | - # the Noosfero core soon, see ActionItem3045 | ||
8 | - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | 6 | + @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] |
9 | @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) | 7 | @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) |
10 | end | 8 | end |
11 | 9 |
app/models/box.rb
@@ -28,9 +28,6 @@ class Box < ActiveRecord::Base | @@ -28,9 +28,6 @@ class Box < ActiveRecord::Base | ||
28 | CategoriesBlock, | 28 | CategoriesBlock, |
29 | CommunitiesBlock, | 29 | CommunitiesBlock, |
30 | EnterprisesBlock, | 30 | EnterprisesBlock, |
31 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
32 | - # the Noosfero core soon, see ActionItem3045 | ||
33 | - EnvironmentStatisticsBlock, | ||
34 | FansBlock, | 31 | FansBlock, |
35 | FavoriteEnterprisesBlock, | 32 | FavoriteEnterprisesBlock, |
36 | FeedReaderBlock, | 33 | FeedReaderBlock, |
@@ -53,9 +50,6 @@ class Box < ActiveRecord::Base | @@ -53,9 +50,6 @@ class Box < ActiveRecord::Base | ||
53 | CommunitiesBlock, | 50 | CommunitiesBlock, |
54 | DisabledEnterpriseMessageBlock, | 51 | DisabledEnterpriseMessageBlock, |
55 | EnterprisesBlock, | 52 | EnterprisesBlock, |
56 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
57 | - # the Noosfero core soon, see ActionItem3045 | ||
58 | - EnvironmentStatisticsBlock, | ||
59 | FansBlock, | 53 | FansBlock, |
60 | FavoriteEnterprisesBlock, | 54 | FavoriteEnterprisesBlock, |
61 | FeaturedProductsBlock, | 55 | FeaturedProductsBlock, |
app/models/environment.rb
@@ -177,9 +177,6 @@ class Environment < ActiveRecord::Base | @@ -177,9 +177,6 @@ class Environment < ActiveRecord::Base | ||
177 | 177 | ||
178 | # "left" area | 178 | # "left" area |
179 | env.boxes[1].blocks << LoginBlock.new | 179 | env.boxes[1].blocks << LoginBlock.new |
180 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
181 | - # the Noosfero core soon, see ActionItem3045 | ||
182 | - env.boxes[1].blocks << EnvironmentStatisticsBlock.new | ||
183 | env.boxes[1].blocks << RecentDocumentsBlock.new | 180 | env.boxes[1].blocks << RecentDocumentsBlock.new |
184 | 181 | ||
185 | # "right" area | 182 | # "right" area |
app/models/environment_statistics_block.rb
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -# TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
2 | -# the Noosfero core soon, see ActionItem3045 | ||
3 | - | ||
4 | -class EnvironmentStatisticsBlock < Block | ||
5 | - | ||
6 | - def self.description | ||
7 | - _('Environment stastistics (DEPRECATED)') | ||
8 | - end | ||
9 | - | ||
10 | - def default_title | ||
11 | - _('Statistics for %s') % owner.name | ||
12 | - end | ||
13 | - | ||
14 | - def help | ||
15 | - _('This block presents some statistics about your environment.') | ||
16 | - end | ||
17 | - | ||
18 | - def content(args={}) | ||
19 | - users = owner.people.visible.count | ||
20 | - enterprises = owner.enterprises.visible.count | ||
21 | - communities = owner.communities.visible.count | ||
22 | - | ||
23 | - info = [] | ||
24 | - info << (n_('One user', '%{num} users', users) % { :num => users }) | ||
25 | - unless owner.enabled?('disable_asset_enterprises') | ||
26 | - info << (n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }) | ||
27 | - end | ||
28 | - info << (n_('One community', '%{num} communities', communities) % { :num => communities }) | ||
29 | - | ||
30 | - block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) | ||
31 | - end | ||
32 | - | ||
33 | -end |
app/sweepers/profile_sweeper.rb
@@ -8,9 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer | @@ -8,9 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer | ||
8 | end | 8 | end |
9 | 9 | ||
10 | def after_create(profile) | 10 | def after_create(profile) |
11 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
12 | - # the Noosfero core soon, see ActionItem3045 | ||
13 | - expire_statistics_block_cache(profile) | ||
14 | end | 11 | end |
15 | 12 | ||
16 | protected | 13 | protected |
@@ -31,13 +28,6 @@ protected | @@ -31,13 +28,6 @@ protected | ||
31 | expire_blogs(profile) if profile.organization? | 28 | expire_blogs(profile) if profile.organization? |
32 | end | 29 | end |
33 | 30 | ||
34 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
35 | - # the Noosfero core soon, see ActionItem3045 | ||
36 | - def expire_statistics_block_cache(profile) | ||
37 | - blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } | ||
38 | - BlockSweeper.expire_blocks(blocks) | ||
39 | - end | ||
40 | - | ||
41 | def expire_blogs(profile) | 31 | def expire_blogs(profile) |
42 | profile.blogs.select{|b| !b.empty?}.each do |blog| | 32 | profile.blogs.select{|b| !b.empty?}.each do |blog| |
43 | pages = blog.posts.count / blog.posts_per_page + 1 | 33 | pages = blog.posts.count / blog.posts_per_page + 1 |
db/migrate/20140827191326_remove_environment_statistics_block.rb
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +class RemoveEnvironmentStatisticsBlock < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + update("UPDATE blocks SET type = 'StatisticsBlock' WHERE type = 'EnvironmentStatisticsBlock'") | ||
4 | + end | ||
5 | + | ||
6 | + def self.down | ||
7 | + say("Nothing to undo (cannot recover the data)") | ||
8 | + end | ||
9 | +end |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(:version => 20140808185510) do | 14 | +ActiveRecord::Schema.define(:version => 20140827191326) do |
15 | 15 | ||
16 | create_table "abuse_reports", :force => true do |t| | 16 | create_table "abuse_reports", :force => true do |t| |
17 | t.integer "reporter_id" | 17 | t.integer "reporter_id" |
test/functional/environment_design_controller_test.rb
@@ -6,9 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end | @@ -6,9 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class EnvironmentDesignControllerTest < ActionController::TestCase | 7 | class EnvironmentDesignControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
10 | - # the Noosfero core soon, see ActionItem3045 | ||
11 | - ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | 9 | + ALL_BLOCKS = [ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] |
12 | 10 | ||
13 | def setup | 11 | def setup |
14 | @controller = EnvironmentDesignController.new | 12 | @controller = EnvironmentDesignController.new |
@@ -77,18 +75,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -77,18 +75,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
77 | assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } | 75 | assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } |
78 | end | 76 | end |
79 | 77 | ||
80 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
81 | - # the Noosfero core soon, see ActionItem3045 | ||
82 | - should 'be able to edit EnvironmentStatisticsBlock' do | ||
83 | - login_as(create_admin_user(Environment.default)) | ||
84 | - b = EnvironmentStatisticsBlock.create! | ||
85 | - e = Environment.default | ||
86 | - e.boxes.create! | ||
87 | - e.boxes.first.blocks << b | ||
88 | - get :edit, :id => b.id | ||
89 | - assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
90 | - end | ||
91 | - | ||
92 | should 'be able to edit EnterprisesBlock' do | 78 | should 'be able to edit EnterprisesBlock' do |
93 | login_as(create_admin_user(Environment.default)) | 79 | login_as(create_admin_user(Environment.default)) |
94 | b = EnterprisesBlock.create! | 80 | b = EnterprisesBlock.create! |
test/unit/box_test.rb
@@ -33,9 +33,6 @@ class BoxTest < ActiveSupport::TestCase | @@ -33,9 +33,6 @@ class BoxTest < ActiveSupport::TestCase | ||
33 | assert blocks.include?('categories-block') | 33 | assert blocks.include?('categories-block') |
34 | assert blocks.include?('communities-block') | 34 | assert blocks.include?('communities-block') |
35 | assert blocks.include?('enterprises-block') | 35 | assert blocks.include?('enterprises-block') |
36 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
37 | - # the Noosfero core soon, see ActionItem3045 | ||
38 | - assert blocks.include?('environment-statistics-block') | ||
39 | assert blocks.include?('fans-block') | 36 | assert blocks.include?('fans-block') |
40 | assert blocks.include?('favorite-enterprises-block') | 37 | assert blocks.include?('favorite-enterprises-block') |
41 | assert blocks.include?('feed-reader-block') | 38 | assert blocks.include?('feed-reader-block') |
@@ -64,9 +61,6 @@ class BoxTest < ActiveSupport::TestCase | @@ -64,9 +61,6 @@ class BoxTest < ActiveSupport::TestCase | ||
64 | assert blocks.include?('communities-block') | 61 | assert blocks.include?('communities-block') |
65 | assert blocks.include?('disabled-enterprise-message-block') | 62 | assert blocks.include?('disabled-enterprise-message-block') |
66 | assert blocks.include?('enterprises-block') | 63 | assert blocks.include?('enterprises-block') |
67 | - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
68 | - # the Noosfero core soon, see ActionItem3045 | ||
69 | - assert blocks.include?('environment-statistics-block') | ||
70 | assert blocks.include?('fans-block') | 64 | assert blocks.include?('fans-block') |
71 | assert blocks.include?('favorite-enterprises-block') | 65 | assert blocks.include?('favorite-enterprises-block') |
72 | assert blocks.include?('featured-products-block') | 66 | assert blocks.include?('featured-products-block') |
test/unit/environment_statistics_block_test.rb
@@ -1,99 +0,0 @@ | @@ -1,99 +0,0 @@ | ||
1 | -# TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | ||
2 | -# the Noosfero core soon, see ActionItem3045 | ||
3 | - | ||
4 | -require File.dirname(__FILE__) + '/../test_helper' | ||
5 | - | ||
6 | -class EnvironmentStatisticsBlockTest < ActiveSupport::TestCase | ||
7 | - | ||
8 | - should 'inherit from Block' do | ||
9 | - assert_kind_of Block, EnvironmentStatisticsBlock.new | ||
10 | - end | ||
11 | - | ||
12 | - should 'describe itself' do | ||
13 | - assert_not_equal Block.description, EnvironmentStatisticsBlock.description | ||
14 | - end | ||
15 | - | ||
16 | - should 'provide a default title' do | ||
17 | - owner = mock | ||
18 | - owner.expects(:name).returns('my environment') | ||
19 | - | ||
20 | - block = EnvironmentStatisticsBlock.new | ||
21 | - block.expects(:owner).returns(owner) | ||
22 | - assert_equal 'Statistics for my environment', block.title | ||
23 | - end | ||
24 | - | ||
25 | - should 'generate statistics' do | ||
26 | - env = create(Environment) | ||
27 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
28 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
29 | - | ||
30 | - fast_create(Enterprise, :environment_id => env.id) | ||
31 | - fast_create(Community, :environment_id => env.id) | ||
32 | - | ||
33 | - block = EnvironmentStatisticsBlock.new | ||
34 | - env.boxes.first.blocks << block | ||
35 | - | ||
36 | - content = block.content | ||
37 | - | ||
38 | - assert_match(/One enterprise/, content) | ||
39 | - assert_match(/2 users/, content) | ||
40 | - assert_match(/One community/, content) | ||
41 | - end | ||
42 | - | ||
43 | - should 'generate statistics including private profiles' do | ||
44 | - env = create(Environment) | ||
45 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
46 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
47 | - user3 = create_user('testuser3', :environment_id => env.id) | ||
48 | - p = user3.person; p.public_profile = false; p.save! | ||
49 | - | ||
50 | - fast_create(Enterprise, :environment_id => env.id) | ||
51 | - fast_create(Enterprise, :environment_id => env.id, :public_profile => false) | ||
52 | - | ||
53 | - fast_create(Community, :environment_id => env.id) | ||
54 | - fast_create(Community, :environment_id => env.id, :public_profile => false) | ||
55 | - | ||
56 | - block = EnvironmentStatisticsBlock.new | ||
57 | - env.boxes.first.blocks << block | ||
58 | - | ||
59 | - content = block.content | ||
60 | - | ||
61 | - assert_match /2 enterprises/, content | ||
62 | - assert_match /3 users/, content | ||
63 | - assert_match /2 communities/, content | ||
64 | - end | ||
65 | - | ||
66 | - should 'generate statistics but not for not visible profiles' do | ||
67 | - env = create(Environment) | ||
68 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
69 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
70 | - user3 = create_user('testuser3', :environment_id => env.id) | ||
71 | - p = user3.person; p.visible = false; p.save! | ||
72 | - | ||
73 | - fast_create(Enterprise, :environment_id => env.id) | ||
74 | - fast_create(Enterprise, :environment_id => env.id, :visible => false) | ||
75 | - | ||
76 | - fast_create(Community, :environment_id => env.id) | ||
77 | - fast_create(Community, :environment_id => env.id, :visible => false) | ||
78 | - | ||
79 | - block = EnvironmentStatisticsBlock.new | ||
80 | - env.boxes.first.blocks << block | ||
81 | - | ||
82 | - content = block.content | ||
83 | - | ||
84 | - assert_match /One enterprise/, content | ||
85 | - assert_match /2 users/, content | ||
86 | - assert_match /One community/, content | ||
87 | - end | ||
88 | - | ||
89 | - should 'not display enterprises if disabled' do | ||
90 | - env = fast_create(Environment) | ||
91 | - env.enable('disable_asset_enterprises', false) | ||
92 | - | ||
93 | - block = EnvironmentStatisticsBlock.new | ||
94 | - block.stubs(:owner).returns(env) | ||
95 | - | ||
96 | - assert_no_match /enterprises/i, block.content | ||
97 | - end | ||
98 | - | ||
99 | -end |