Commit 1c950250bb0f77c394c6feb87a86306a73a76974
1 parent
c3453051
Exists in
master
and in
29 other branches
Revert part of the last commit in order to not remove the EnvironmentStatisticsBlock
- EnvironmentStatisticsBlock was marked as DEPRECATED, it will be removed in the next Noosfero release, see ActionItem3045 Thanks for the tip Daniela Feitosa ;) (ActionItem2851)
Showing
9 changed files
with
175 additions
and
11 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
... | ... | @@ -3,7 +3,9 @@ class EnvironmentDesignController < BoxOrganizerController |
3 | 3 | protect 'edit_environment_design', :environment |
4 | 4 | |
5 | 5 | def available_blocks |
6 | - @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | |
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, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | |
7 | 9 | @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) |
8 | 10 | end |
9 | 11 | ... | ... |
app/models/box.rb
... | ... | @@ -26,6 +26,9 @@ class Box < ActiveRecord::Base |
26 | 26 | CategoriesBlock, |
27 | 27 | CommunitiesBlock, |
28 | 28 | EnterprisesBlock, |
29 | + # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | |
30 | + # the Noosfero core soon, see ActionItem3045 | |
31 | + EnvironmentStatisticsBlock, | |
29 | 32 | FansBlock, |
30 | 33 | FavoriteEnterprisesBlock, |
31 | 34 | FeedReaderBlock, |
... | ... | @@ -51,6 +54,9 @@ class Box < ActiveRecord::Base |
51 | 54 | CommunitiesBlock, |
52 | 55 | DisabledEnterpriseMessageBlock, |
53 | 56 | EnterprisesBlock, |
57 | + # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | |
58 | + # the Noosfero core soon, see ActionItem3045 | |
59 | + EnvironmentStatisticsBlock, | |
54 | 60 | FansBlock, |
55 | 61 | FavoriteEnterprisesBlock, |
56 | 62 | FeaturedProductsBlock, | ... | ... |
app/models/environment.rb
... | ... | @@ -161,6 +161,9 @@ class Environment < ActiveRecord::Base |
161 | 161 | |
162 | 162 | # "left" area |
163 | 163 | env.boxes[1].blocks << LoginBlock.new |
164 | + # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | |
165 | + # the Noosfero core soon, see ActionItem3045 | |
166 | + env.boxes[1].blocks << EnvironmentStatisticsBlock.new | |
164 | 167 | env.boxes[1].blocks << RecentDocumentsBlock.new |
165 | 168 | |
166 | 169 | # "right" area | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
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,6 +8,9 @@ class ProfileSweeper # < ActiveRecord::Observer |
8 | 8 | end |
9 | 9 | |
10 | 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) | |
11 | 14 | end |
12 | 15 | |
13 | 16 | protected |
... | ... | @@ -28,6 +31,13 @@ protected |
28 | 31 | expire_blogs(profile) if profile.organization? |
29 | 32 | end |
30 | 33 | |
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 | + | |
31 | 41 | def expire_blogs(profile) |
32 | 42 | profile.blogs.select{|b| !b.empty?}.each do |blog| |
33 | 43 | pages = blog.posts.count / blog.posts_per_page + 1 | ... | ... |
db/migrate/20140316171151_remove_environment_statistics_block.rb
test/functional/environment_design_controller_test.rb
... | ... | @@ -6,7 +6,9 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class EnvironmentDesignControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - ALL_BLOCKS = [ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | |
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, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | |
10 | 12 | |
11 | 13 | def setup |
12 | 14 | @controller = EnvironmentDesignController.new |
... | ... | @@ -83,6 +85,18 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
83 | 85 | assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } |
84 | 86 | end |
85 | 87 | |
88 | + # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | |
89 | + # the Noosfero core soon, see ActionItem3045 | |
90 | + should 'be able to edit EnvironmentStatisticsBlock' do | |
91 | + login_as(create_admin_user(Environment.default)) | |
92 | + b = EnvironmentStatisticsBlock.create! | |
93 | + e = Environment.default | |
94 | + e.boxes.create! | |
95 | + e.boxes.first.blocks << b | |
96 | + get :edit, :id => b.id | |
97 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | |
98 | + end | |
99 | + | |
86 | 100 | should 'be able to edit EnterprisesBlock' do |
87 | 101 | login_as(create_admin_user(Environment.default)) |
88 | 102 | b = EnterprisesBlock.create! | ... | ... |
test/unit/box_test.rb
... | ... | @@ -33,6 +33,9 @@ class BoxTest < ActiveSupport::TestCase |
33 | 33 | assert blocks.include?('categories-block') |
34 | 34 | assert blocks.include?('communities-block') |
35 | 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') | |
36 | 39 | assert blocks.include?('fans-block') |
37 | 40 | assert blocks.include?('favorite-enterprises-block') |
38 | 41 | assert blocks.include?('feed-reader-block') |
... | ... | @@ -64,6 +67,9 @@ class BoxTest < ActiveSupport::TestCase |
64 | 67 | assert blocks.include?('communities-block') |
65 | 68 | assert blocks.include?('disabled-enterprise-message-block') |
66 | 69 | assert blocks.include?('enterprises-block') |
70 | + # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from | |
71 | + # the Noosfero core soon, see ActionItem3045 | |
72 | + assert blocks.include?('environment-statistics-block') | |
67 | 73 | assert blocks.include?('fans-block') |
68 | 74 | assert blocks.include?('favorite-enterprises-block') |
69 | 75 | assert blocks.include?('featured-products-block') | ... | ... |
... | ... | @@ -0,0 +1,99 @@ |
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 | ... | ... |