Commit 4b62288d0a6da32636435354b23d2c36833374d8

Authored by Leandro Santos
1 parent ceb06403

updating with rails3 branch

Showing 129 changed files with 2121 additions and 1531 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 129 files displayed.

Gemfile
... ... @@ -26,6 +26,7 @@ end
26 26 group :test do
27 27 gem 'rspec'
28 28 gem 'rspec-rails'
  29 + gem 'mocha', :require => false
29 30 end
30 31  
31 32 group :cucumber do
... ...
Gemfile.lock
... ... @@ -61,7 +61,7 @@ GEM
61 61 database_cleaner (1.2.0)
62 62 diff-lcs (1.1.3)
63 63 erubis (2.7.0)
64   - eventmachine (0.12.11)
  64 + eventmachine (1.0.3)
65 65 fast_gettext (0.6.8)
66 66 ffi (1.0.11)
67 67 gherkin (2.4.21)
... ... @@ -75,7 +75,10 @@ GEM
75 75 i18n (>= 0.4.0)
76 76 mime-types (~> 1.16)
77 77 treetop (~> 1.4.8)
  78 + metaclass (0.0.4)
78 79 mime-types (1.19)
  80 + mocha (0.11.3)
  81 + metaclass (~> 0.0.1)
79 82 multi_json (1.3.6)
80 83 nokogiri (1.5.5)
81 84 pg (0.13.2)
... ... @@ -164,6 +167,7 @@ DEPENDENCIES
164 167 database_cleaner
165 168 fast_gettext
166 169 hpricot
  170 + mocha
167 171 nokogiri
168 172 pg
169 173 prototype-rails
... ...
app/controllers/admin/admin_panel_controller.rb
... ... @@ -7,6 +7,7 @@ class AdminPanelController < AdminController
7 7 end
8 8  
9 9 def site_info
  10 + @no_design_blocks = true
10 11 if request.post?
11 12 if params[:environment][:languages]
12 13 params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact
... ...
app/controllers/admin/environment_design_controller.rb
... ... @@ -5,7 +5,7 @@ class EnvironmentDesignController < BoxOrganizerController
5 5 def available_blocks
6 6 # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from
7 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 ]
  8 + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
9 9 @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment)
10 10 end
11 11  
... ...
app/controllers/my_profile/cms_controller.rb
... ... @@ -144,6 +144,7 @@ class CmsController < MyProfileController
144 144  
145 145 @article.profile = profile
146 146 @article.last_changed_by = user
  147 + @article.created_by = user
147 148  
148 149 translations if @article.translatable?
149 150  
... ...
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -9,14 +9,8 @@ class ProfileDesignController < BoxOrganizerController
9 9  
10 10 blocks += plugins.dispatch(:extra_blocks)
11 11  
12   - # blocks exclusive for organizations
13   - if profile.has_members?
14   - blocks << MembersBlock
15   - end
16   -
17 12 # blocks exclusive to people
18 13 if profile.person?
19   - blocks << FriendsBlock
20 14 blocks << FavoriteEnterprisesBlock
21 15 blocks << CommunitiesBlock
22 16 blocks << EnterprisesBlock
... ...
app/helpers/application_helper.rb
... ... @@ -1034,7 +1034,7 @@ module ApplicationHelper
1034 1034 end
1035 1035  
1036 1036 link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') +
1037   - link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
  1037 + link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
1038 1038 end
1039 1039 alias :browse_contents_menu :search_contents_menu
1040 1040  
... ... @@ -1050,7 +1050,7 @@ module ApplicationHelper
1050 1050 end
1051 1051  
1052 1052 link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') +
1053   - link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
  1053 + link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
1054 1054 end
1055 1055 alias :browse_people_menu :search_people_menu
1056 1056  
... ... @@ -1066,7 +1066,7 @@ module ApplicationHelper
1066 1066 end
1067 1067  
1068 1068 link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') +
1069   - link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
  1069 + link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
1070 1070 end
1071 1071 alias :browse_communities_menu :search_communities_menu
1072 1072  
... ...
app/helpers/sweeper_helper.rb
... ... @@ -18,9 +18,7 @@ module SweeperHelper
18 18 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s))
19 19 end
20 20  
21   - # friends blocks
22   - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}
23   - BlockSweeper.expire_blocks(blocks)
  21 + expire_blocks_cache(profile, [:profile])
24 22 end
25 23  
26 24 def expire_communities(profile)
... ...
app/models/approve_article.rb
... ... @@ -48,7 +48,7 @@ class ApproveArticle &lt; Task
48 48 end
49 49  
50 50 def perform
51   - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author_id)
  51 + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.last_changed_by_id, :created_by_id => article.created_by_id)
52 52 end
53 53  
54 54 def title
... ...
app/models/article.rb
... ... @@ -40,12 +40,6 @@ class Article &lt; ActiveRecord::Base
40 40 # xss_terminate plugin can't sanitize array fields
41 41 before_save :sanitize_tag_list
42 42  
43   - before_create do |article|
44   - if article.last_changed_by_id
45   - article.author_name = Person.find(article.last_changed_by_id).name
46   - end
47   - end
48   -
49 43 belongs_to :profile
50 44 validates_presence_of :profile_id, :name
51 45 validates_presence_of :slug, :path, :if => lambda { |article| !article.name.blank? }
... ... @@ -55,6 +49,7 @@ class Article &lt; ActiveRecord::Base
55 49 validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => N_('The title (article name) is already being used by another article, please use another title.'), :if => lambda { |article| !article.slug.blank? }
56 50  
57 51 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'
  52 + belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id'
58 53  
59 54 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'
60 55  
... ... @@ -89,6 +84,11 @@ class Article &lt; ActiveRecord::Base
89 84 article.parent = article.profile.blog
90 85 end
91 86 end
  87 +
  88 + if article.created_by
  89 + article.author_name = article.created_by.name
  90 + end
  91 +
92 92 end
93 93  
94 94 after_destroy :destroy_activity
... ... @@ -205,6 +205,10 @@ class Article &lt; ActiveRecord::Base
205 205 acts_as_versioned
206 206 self.non_versioned_columns << 'setting'
207 207  
  208 + def version_condition_met?
  209 + (['name', 'body', 'abstract', 'filename', 'start_date', 'end_date', 'image_id', 'license_id'] & changed).length > 0
  210 + end
  211 +
208 212 def comment_data
209 213 comments.map {|item| [item.title, item.body].join(' ') }.join(' ')
210 214 end
... ... @@ -630,17 +634,13 @@ class Article &lt; ActiveRecord::Base
630 634  
631 635 def author(version_number = nil)
632 636 if version_number
633   - version = versions.find_by_version(version_number)
  637 + version = self.versions.find_by_version(version_number)
634 638 author_id = version.last_changed_by_id if version
635   - Person.exists?(author_id) ? Person.find(author_id) : nil
636 639 else
637   - if versions.empty?
638   - last_changed_by
639   - else
640   - author_id = versions.first.last_changed_by_id
641   - Person.exists?(author_id) ? Person.find(author_id) : nil
642   - end
  640 + author_id = self.created_by_id
643 641 end
  642 +
  643 + environment.people.find_by_id(author_id)
644 644 end
645 645  
646 646 def author_name(version_number = nil)
... ...
app/models/box.rb
... ... @@ -34,14 +34,11 @@ class Box &lt; ActiveRecord::Base
34 34 FansBlock,
35 35 FavoriteEnterprisesBlock,
36 36 FeedReaderBlock,
37   - FriendsBlock,
38 37 HighlightsBlock,
39 38 LinkListBlock,
40 39 LoginBlock,
41 40 MainBlock,
42   - MembersBlock,
43 41 MyNetworkBlock,
44   - PeopleBlock,
45 42 ProfileImageBlock,
46 43 RawHTMLBlock,
47 44 RecentDocumentsBlock,
... ... @@ -63,14 +60,11 @@ class Box &lt; ActiveRecord::Base
63 60 FavoriteEnterprisesBlock,
64 61 FeaturedProductsBlock,
65 62 FeedReaderBlock,
66   - FriendsBlock,
67 63 HighlightsBlock,
68 64 LinkListBlock,
69 65 LocationBlock,
70 66 LoginBlock,
71   - MembersBlock,
72 67 MyNetworkBlock,
73   - PeopleBlock,
74 68 ProductsBlock,
75 69 ProductCategoriesBlock,
76 70 ProfileImageBlock,
... ...
app/models/categories_block.rb
... ... @@ -8,6 +8,8 @@ class CategoriesBlock &lt; Block
8 8  
9 9 settings_items :category_types, :type => Array, :default => []
10 10  
  11 + attr_accessible :category_types
  12 +
11 13 def self.description
12 14 _("Categories Menu")
13 15 end
... ...
app/models/community.rb
1 1 class Community < Organization
2 2  
3   - attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
  3 + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type, :address_reference, :district, :tag_list, :language
4 4 after_destroy :check_invite_member_for_destroy
5 5  
6 6 def self.type_name
... ... @@ -85,10 +85,6 @@ class Community &lt; Organization
85 85 recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight])
86 86 end
87 87  
88   - def blocks_to_expire_cache
89   - [MembersBlock]
90   - end
91   -
92 88 def each_member(offset=0)
93 89 while member = self.members.first(:order => :id, :offset => offset)
94 90 yield member
... ...
app/models/enterprise.rb
... ... @@ -2,6 +2,8 @@
2 2 # only enterprises can offer products and services.
3 3 class Enterprise < Organization
4 4  
  5 + attr_accessible :business_name, :address_reference, :district, :tag_list, :organization_website, :historic_and_current_context, :activities_short_description, :products_per_catalog_page
  6 +
5 7 SEARCH_DISPLAYS += %w[map full]
6 8  
7 9 def self.type_name
... ...
app/models/environment.rb
... ... @@ -3,7 +3,7 @@
3 3 # domains.
4 4 class Environment < ActiveRecord::Base
5 5  
6   - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound
  6 + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body
7 7  
8 8 has_many :users
9 9  
... ... @@ -182,7 +182,6 @@ class Environment &lt; ActiveRecord::Base
182 182  
183 183 # "right" area
184 184 env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6)
185   - env.boxes[2].blocks << PeopleBlock.new(:limit => 6)
186 185 end
187 186  
188 187 # One Environment can be reached by many domains
... ... @@ -298,6 +297,12 @@ class Environment &lt; ActiveRecord::Base
298 297 settings_items :access_control_allow_origin, :type => Array, :default => []
299 298 settings_items :access_control_allow_methods, :type => String
300 299  
  300 + settings_items :signup_welcome_screen_body, :type => String
  301 +
  302 + def has_custom_welcome_screen?
  303 + settings[:signup_welcome_screen_body].present?
  304 + end
  305 +
301 306 def news_amount_by_folder=(amount)
302 307 settings[:news_amount_by_folder] = amount.to_i
303 308 end
... ...
app/models/friends_block.rb
... ... @@ -1,26 +0,0 @@
1   -class FriendsBlock < ProfileListBlock
2   -
3   - def self.description
4   - _('Friends')
5   - end
6   -
7   - def default_title
8   - n_('{#} friend', '{#} friends', profile_count)
9   - end
10   -
11   - def help
12   - _('This block displays your friends.')
13   - end
14   -
15   - def footer
16   - owner_id = owner.identifier
17   - proc do
18   - link_to s_('friends|View all'), :profile => owner_id, :controller => 'profile', :action => 'friends'
19   - end
20   - end
21   -
22   - def profiles
23   - owner.friends
24   - end
25   -
26   -end
app/models/members_block.rb
... ... @@ -1,52 +0,0 @@
1   -class MembersBlock < ProfileListBlock
2   - settings_items :show_join_leave_button, :type => :boolean, :default => false
3   -
4   - attr_accessible :show_join_leave_button
5   -
6   - def self.description
7   - _('Members')
8   - end
9   -
10   - def default_title
11   - _('{#} members')
12   - end
13   -
14   - def help
15   - _('This block presents the members of a collective.')
16   - end
17   -
18   - def footer
19   - profile = self.owner
20   - s = show_join_leave_button
21   -
22   - proc do
23   - render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s}
24   - end
25   - end
26   -
27   - def profiles
28   - owner.members
29   - end
30   -
31   - def extra_option
32   - data = {
33   - :human_name => _("Show join leave button"),
34   - :name => 'block[show_join_leave_button]',
35   - :value => true,
36   - :checked => show_join_leave_button,
37   - :options => {}
38   - }
39   - end
40   -
41   - def cache_key(language='en', user=nil)
42   - logged = ''
43   - if user
44   - logged += '-logged-in'
45   - if user.is_member_of? self.owner
46   - logged += '-member'
47   - end
48   - end
49   - super + logged
50   - end
51   -
52   -end
app/models/organization.rb
... ... @@ -123,7 +123,7 @@ class Organization &lt; Profile
123 123 [
124 124 [MainBlock.new],
125 125 [ProfileImageBlock.new, LinkListBlock.new(:links => links)],
126   - [MembersBlock.new, RecentDocumentsBlock.new]
  126 + [RecentDocumentsBlock.new]
127 127 ]
128 128 end
129 129  
... ...
app/models/people_block.rb
... ... @@ -1,25 +0,0 @@
1   -class PeopleBlock < ProfileListBlock
2   -
3   - def default_title
4   - _('People')
5   - end
6   -
7   - def help
8   - _('Clicking a person takes you to his/her homepage')
9   - end
10   -
11   - def self.description
12   - _('Random people')
13   - end
14   -
15   - def profiles
16   - owner.people
17   - end
18   -
19   - def footer
20   - lambda do |context|
21   - link_to _('View all'), :controller => 'search', :action => 'people'
22   - end
23   - end
24   -
25   -end
app/models/person.rb
1 1 # A person is the profile of an user holding all relationships with the rest of the system
2 2 class Person < Profile
3 3  
4   - attr_accessible :organization, :contact_information, :sex, :birth_date
  4 + attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website
5 5  
6 6 SEARCH_FILTERS += %w[
7 7 more_popular
... ... @@ -269,7 +269,7 @@ class Person &lt; Profile
269 269 [
270 270 [MainBlock.new],
271 271 [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new],
272   - [FriendsBlock.new, CommunitiesBlock.new]
  272 + [CommunitiesBlock.new]
273 273 ]
274 274 end
275 275  
... ...
app/models/profile_list_block.rb
... ... @@ -18,9 +18,9 @@ class ProfileListBlock &lt; Block
18 18 result = nil
19 19 visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
20 20 if !prioritize_profiles_with_image
21   - result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand }
  21 + result = visible_profiles.all(:limit => limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
22 22 elsif profiles.visible.with_image.count >= limit
23   - result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  23 + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
24 24 else
25 25 result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
26 26 end
... ...
app/sweepers/friendship_sweeper.rb
... ... @@ -34,8 +34,7 @@ protected
34 34 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s))
35 35 end
36 36  
37   - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}
38   - BlockSweeper.expire_blocks(blocks)
  37 + expire_blocks_cache(profile, [:profile])
39 38 end
40 39  
41 40 end
... ...
app/views/account/signup.html.erb
1 1 <% if @register_pending %>
2   -<div id='thanks-for-signing'>
3   - <h1><%= _("Welcome to %s!") % environment.name %></h1>
4   - <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3>
5   - <p><%= _("Firstly, some tips for getting started:") %></p>
6   - <h4><%= _("Confirm your account!") %></h4>
7   - <p><%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %></p>
8   - <p><%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
9   - <h4><%= _("What to do next?") %></h4>
10   - <p><%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %></p>
11   - <p><%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %></p>
12   - <p><%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %></p>
13   - <p><%= _("Start exploring and have fun!") %></p>
14   -</div>
  2 + <div id='thanks-for-signing'>
  3 + <% if environment.has_custom_welcome_screen? %>
  4 + <%= environment.settings[:signup_welcome_screen_body].html_safe %>
  5 + <% else %>
  6 + <h1><%= _("Welcome to %s!") % environment.name %></h1>
  7 + <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3>
  8 + <p><%= _("Firstly, some tips for getting started:") %></p>
  9 + <h4><%= _("Confirm your account!") %></h4>
  10 + <p><%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %></p>
  11 + <p><%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
  12 + <h4><%= _("What to do next?") %></h4>
  13 + <p><%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %></p>
  14 + <p><%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %></p>
  15 + <p><%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %></p>
  16 + <p><%= _("Start exploring and have fun!") %></p>
  17 + <% end %>
  18 + </div>
15 19 <% else %>
16 20 <h1><%= _('Sign up for %s!') % environment.name %></h1>
17 21 <%= render :partial => 'signup_form' %>
... ...
app/views/admin_panel/_signup_welcome_screen.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<div class='description'>
  2 + <%= _('This text will be showed as a welcome message to users after signup') %><br/><br/>
  3 +</div>
  4 +
  5 +<%= labelled_form_field(_('Body'), text_area(:environment, :signup_welcome_screen_body, :cols => 40, :style => 'width: 100%', :class => 'mceEditor')) %>
... ...
app/views/admin_panel/site_info.html.erb
... ... @@ -12,6 +12,8 @@
12 12 :content => (render :partial => 'terms_of_use', :locals => {:f => f})} %>
13 13 <% tabs << {:title => _('Signup welcome text'), :id => 'signup-welcome-text',
14 14 :content => (render :partial => 'signup_welcome_text', :locals => {:f => f})} %>
  15 + <% tabs << {:title => _('Signup welcome message'), :id => 'signup-welcome-message',
  16 + :content => (render :partial => 'signup_welcome_screen', :locals => {:f => f}) }%>
15 17 <%= render_tabs(tabs) %>
16 18 <% button_bar do %>
17 19 <%= submit_button(:save, _('Save'), :cancel => {:action => 'index'}) %>
... ...
app/views/blocks/members.html.erb
... ... @@ -1,5 +0,0 @@
1   -<%= link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' %>
2   -
3   -<% if show_join_leave_button %>
4   - <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %>
5   -<% end %>
app/views/content_viewer/_article_toolbar.html.erb
... ... @@ -10,7 +10,7 @@
10 10  
11 11 <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) && !remove_content_button(:delete)%>
12 12 <% content = content_tag( 'span', _('Delete') ) %>
13   - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}) %>
  13 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page.id}) %>
14 14 <% options = {:method => :post, :confirm => delete_article_message(@page)} %>
15 15 <%= expirable_button @page, :delete, content, url, options %>
16 16 <% end %>
... ... @@ -19,9 +19,9 @@
19 19 <% content = content_tag( 'span', _('Spread this') ) %>
20 20 <% url = nil %>
21 21 <% if profile.kind_of?(Person) %>
22   - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }) %>
  22 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page.id }) %>
23 23 <% elsif profile.kind_of?(Community) && environment.portal_community %>
24   - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }) %>
  24 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page.id }) %>
25 25 <% end %>
26 26 <%= expirable_button @page, :spread, content, url if url %>
27 27 <% end %>
... ...
app/views/layouts/application-ng.html.erb
... ... @@ -83,5 +83,10 @@
83 83 <%= noosfero_layout_features %>
84 84 <%= theme_javascript_ng %>
85 85 <%= addthis_javascript %>
  86 + <%=
  87 + @plugins.dispatch(:body_ending).map do |content|
  88 + if content.respond_to?(:call) then instance_exec(&content).html_safe else content.html_safe end
  89 + end.join("\n")
  90 + %>
86 91 </body>
87 92 </html>
... ...
app/views/profile_members/_members_list.html.erb
... ... @@ -17,9 +17,9 @@
17 17 <%= button_without_text :edit, _('Edit'), :action => 'change_role', :id => m %>
18 18 <%= button_to_remote_without_text(:remove, _('Remove'),
19 19 :update => 'members-list',
20   - :loading => j('$("members-list").addClassName("loading")'),
21   - :success => j("$('tr-#{m.identifier}').show()"),
22   - :complete => j('$("members-list").removeClassName("loading")'),
  20 + :loading => "$('members-list').addClassName('loading')",
  21 + :success => "$('tr-#{m.identifier}').show()",
  22 + :complete => "$('members-list').removeClassName('loading')",
23 23 :url => { :id => m }.merge(remove_action)) if m != user %>
24 24 </div>
25 25 </td>
... ...
app/views/shared/_change_image.html.erb
1 1 <%= i.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) %>
2   - <%= link_to_function(_('Cancel'), nil, :id => 'cancel-change-image-link', :class => 'button icon-cancel with-text', :style => 'display: none') do |page|
3   - page['change-image-link'].show
4   - page['change-image'].replace_html ''
5   - end %>
  2 + <%= link_to_function(_('Cancel'), "jQuery('#change-image-link').show(); jQuery('#change-image').html('')", :id => 'cancel-change-image-link', :class => 'button icon-cancel with-text', :style => 'display: none') %>
... ...
app/views/shared/_show_thumbnail.html.erb
... ... @@ -2,10 +2,15 @@
2 2  
3 3 <br/>
4 4  
5   - <%= link_to_function(_('Change image'), nil, :id => 'change-image-link', :class => 'button icon-photos with-text') do |page|
6   - page['change-image'].replace_html :partial => 'shared/change_image', :locals => { :i => i, :image => image }
7   - page['change-image-link'].hide
8   - page['cancel-change-image-link'].show
9   - end %>
  5 + <%= link_to_function(_('Change image'), 'display_change_image()', :id => 'change-image-link', :class => 'button icon-photos with-text') %>
  6 +
  7 + <script>
  8 + function display_change_image() {
  9 + var content = "<%= j(render :partial => 'shared/change_image', :locals => { :i => i, :image => image }) %>";
  10 + jQuery('#change-image').html(content);
  11 + jQuery('#change-image-link').hide();
  12 + jQuery('#cancel-change-image-link').show();
  13 + }
  14 + </script>
10 15  
11 16 <div id='change-image'> </div> <br/>
... ...
app/views/user/mailer/activation_code.html.erb
1 1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
2 2  
3   -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection) }) %>
  3 +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
4 4  
5 5 <%= _("Greetings,") %>
6 6  
... ...
config/application.rb
... ... @@ -20,7 +20,7 @@ module Noosfero
20 20 require 'noosfero/plugin'
21 21  
22 22 # Adds custom attributes to the Set of allowed html attributes for the #sanitize helper
23   - config.action_view.sanitized_allowed_attributes = 'align', 'border', 'alt', 'vspace', 'hspace', 'width', 'heigth', 'value', 'type', 'data', 'style', 'target', 'codebase', 'archive', 'classid', 'code', 'flashvars', 'scrolling', 'frameborder', 'controls', 'autoplay'
  23 + config.action_view.sanitized_allowed_attributes = 'align', 'border', 'alt', 'vspace', 'hspace', 'width', 'heigth', 'value', 'type', 'data', 'style', 'target', 'codebase', 'archive', 'classid', 'code', 'flashvars', 'scrolling', 'frameborder', 'controls', 'autoplay', 'colspan', 'rowspan'
24 24  
25 25 # Adds custom tags to the Set of allowed html tags for the #sanitize helper
26 26 config.action_view.sanitized_allowed_tags = 'object', 'embed', 'param', 'table', 'tr', 'th', 'td', 'applet', 'comment', 'iframe', 'audio', 'video', 'source'
... ...
config/plugins/people_block 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../plugins/people_block
0 2 \ No newline at end of file
... ...
db/migrate/20140415125414_add_created_by_to_article.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class AddCreatedByToArticle < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :articles, :created_by_id, :integer
  4 + add_column :article_versions, :created_by_id, :integer
  5 +
  6 + execute("UPDATE article_versions SET created_by_id = last_changed_by_id")
  7 +
  8 + execute("UPDATE articles SET created_by_id = article_versions.created_by_id
  9 +FROM article_versions WHERE article_versions.article_id = articles.id AND
  10 +article_versions.version = 1")
  11 + end
  12 +
  13 + def self.down
  14 + remove_column :articles, :created_by_id
  15 + remove_column :article_versions, :created_by_id
  16 + end
  17 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20140408172149) do
  14 +ActiveRecord::Schema.define(:version => 20140415125414) do
15 15  
16 16 create_table "abuse_reports", :force => true do |t|
17 17 t.integer "reporter_id"
... ... @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version =&gt; 20140408172149) do
95 95 t.integer "license_id"
96 96 t.integer "image_id"
97 97 t.integer "position"
  98 + t.integer "created_by_id"
98 99 end
99 100  
100 101 add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id"
... ... @@ -140,6 +141,7 @@ ActiveRecord::Schema.define(:version =&gt; 20140408172149) do
140 141 t.integer "license_id"
141 142 t.integer "image_id"
142 143 t.integer "position"
  144 + t.integer "created_by_id"
143 145 end
144 146  
145 147 add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count"
... ...
features/categories_block.feature
... ... @@ -28,7 +28,8 @@ Feature: categories_block
28 28  
29 29 @selenium
30 30 Scenario: List just product categories
31   - Given I follow "Edit" within ".categories-block"
  31 + Given display ".button-bar"
  32 + And I follow "Edit" within ".categories-block"
32 33 And I check "Product"
33 34 When I press "Save"
34 35 Then I should see "Food"
... ... @@ -39,7 +40,8 @@ Feature: categories_block
39 40  
40 41 @selenium
41 42 Scenario: Show submenu if it exists
42   - Given I follow "Edit" within ".categories-block"
  43 + Given display ".button-bar"
  44 + And I follow "Edit" within ".categories-block"
43 45 And I check "Product"
44 46 And I press "Save"
45 47 Then I should see "Food"
... ... @@ -56,7 +58,8 @@ Feature: categories_block
56 58  
57 59 @selenium
58 60 Scenario: Show only one submenu per time
59   - Given I follow "Edit" within ".categories-block"
  61 + Given display ".button-bar"
  62 + And I follow "Edit" within ".categories-block"
60 63 And I check "Product"
61 64 And I press "Save"
62 65 Then I should see "Book"
... ... @@ -66,14 +69,16 @@ Feature: categories_block
66 69  
67 70 @selenium
68 71 Scenario: List just general categories
69   - Given I follow "Edit" within ".categories-block"
  72 + Given display ".button-bar"
  73 + And I follow "Edit" within ".categories-block"
70 74 And I check "Generic category"
71 75 When I press "Save"
72 76 Then I should see "Wood"
73 77  
74 78 @selenium
75 79 Scenario: List just regions
76   - Given I follow "Edit" within ".categories-block"
  80 + Given display ".button-bar"
  81 + And I follow "Edit" within ".categories-block"
77 82 And I check "Region"
78 83 When I press "Save"
79 84 Then I should see "Bahia"
... ...
features/edit_profile.feature
... ... @@ -12,7 +12,7 @@ Feature: edit profile
12 12 | birth_date |
13 13 When I go to joao's control panel
14 14 And I follow "Edit Profile"
15   - And I select "1980-11-15" from "profile_data_birth_date"
  15 + And I fill in "Birth date" with "1980-11-15"
16 16 And I press "Save"
17 17 Then I should not see "Birth date is invalid"
18 18 And I should not see "Birth date is mandatory"
... ... @@ -23,7 +23,7 @@ Feature: edit profile
23 23 | birth_date |
24 24 When I go to joao's control panel
25 25 And I follow "Edit Profile"
26   - And I select "1980-11-15" from "profile_data_birth_date"
  26 + And I fill in "Birth date" with "1980-11-15"
27 27 And I press "Save"
28 28 Then I should not see "Birth date is invalid"
29 29 And I should not see "Birth date is mandatory"
... ...
features/my_network_block.feature
... ... @@ -9,9 +9,11 @@ Feature: my_network_block
9 9 And the following blocks
10 10 | owner | type |
11 11 | joaosilva | MyNetworkBlock |
  12 + | joaosilva | FriendsBlock |
12 13 And the following communities
13 14 | identifier | name | public_profile |
14 15 | public-community | Public Community | true |
  16 + And plugin FriendsBlock is enabled on environment
15 17  
16 18 @selenium
17 19 Scenario: display how many public/private communities I am member
... ... @@ -46,6 +48,10 @@ Feature: my_network_block
46 48 | login | name | public_profile |
47 49 | mariasilva | Maria Silva | true |
48 50 | josesilva | Jose Silva | false |
  51 + And the following blocks
  52 + | owner | type |
  53 + | mariasilva | FriendsBlock |
  54 + | josesilva | FriendsBlock |
49 55 And "joaosilva" is friend of "mariasilva"
50 56 And I am logged in as "joaosilva"
51 57 And I am on joaosilva's homepage
... ... @@ -59,6 +65,10 @@ Feature: my_network_block
59 65 | login | name |
60 66 | mariasilva | Maria Silva |
61 67 | josesilva | Jose Silva |
  68 + And the following blocks
  69 + | owner | type |
  70 + | mariasilva | FriendsBlock |
  71 + | josesilva | FriendsBlock |
62 72 And "josesilva" is invisible
63 73 And "joaosilva" is friend of "mariasilva"
64 74 And I am logged in as "joaosilva"
... ...
features/profile_domain.feature
... ... @@ -9,11 +9,11 @@ Feature: domain for profile
9 9 | joaosilva | Joao Silva |
10 10 And the following communities
11 11 | identifier | name | domain |
12   - | sample-community | Sample Community | localhost |
  12 + | sample-community | Sample Community | 127.0.0.1 |
13 13 And the following blocks
14 14 | owner | type |
15 15 | joaosilva | ProfileInfoBlock |
16   - And the environment domain is "127.0.0.1"
  16 + And the environment domain is "localhost"
17 17 And "Joao Silva" is environment admin
18 18 And "Joao Silva" is admin of "Sample Community"
19 19  
... ... @@ -29,8 +29,7 @@ Feature: domain for profile
29 29 @selenium
30 30 Scenario: access user control panel
31 31 Given I am logged in as "joaosilva"
32   - When I go to the homepage
33   - And I follow "joaosilva"
  32 + When I follow "joaosilva"
34 33 And I go to sample-community's homepage
35 34 And I follow "Login"
36 35 And I fill in "joaosilva" for "Username"
... ... @@ -39,18 +38,13 @@ Feature: domain for profile
39 38 And I follow "Control panel" within "div#user"
40 39 Then I should see "Joao Silva" within "span.control-panel-title"
41 40  
42   - # Looking for page title is problematic on selenium since it considers the
43   - # title to be invibible. Checkout some information about this:
44   - # * https://github.com/jnicklas/capybara/issues/863
45   - # * https://github.com/jnicklas/capybara/pull/953
46 41 @selenium
47 42 Scenario: access user page
48 43 Given I am logged in as "joaosilva"
49   - When I go to the homepage
50   - And I follow "joaosilva"
  44 + When I follow "joaosilva"
51 45 Then I should be on joaosilva's profile
52 46 And I should see "Joao Silva" within any "h1"
53   - #And the page title should be "Joao Silva"
  47 + And the page title should be "Joao Silva"
54 48  
55 49 Scenario: access community by domain
56 50 Given I go to the search communities page
... ... @@ -64,7 +58,7 @@ Feature: domain for profile
64 58 Given I am on sample-community's homepage
65 59 When I go to /something-that-does-not-exist
66 60 And I follow "Go to the home page"
67   - Then the page title should be "Sample Community - Colivre.net"
  61 + Then the page title should be "Sample Community"
68 62  
69 63 Scenario: Go to environment homepage after clicking on home button on not found page
70 64 Given I am on the homepage
... ... @@ -72,8 +66,3 @@ Feature: domain for profile
72 66 And I follow "Go to the home page"
73 67 Then I should be on the homepage
74 68 And the page title should be "Colivre.net"
75   -
76   - @selenium
77   - Scenario: Compose link to administration with environment domain
78   - Given I am logged in as "joaosilva"
79   - Then I should see "Administration" linking to "http://127.0.0.1.*/admin"
... ...
features/publish_article.feature
... ... @@ -56,6 +56,7 @@ Feature: publish article
56 56 And I am on mariasilva's control panel
57 57 And I follow "Manage Content"
58 58 And I follow "New content"
  59 + And I should see "Text article with Textile markup language"
59 60 And I follow "Text article with Textile markup language"
60 61 And I fill in the following:
61 62 | Title | Sample Article |
... ...
features/step_definitions/web_steps.rb
... ... @@ -118,9 +118,9 @@ end
118 118  
119 119 Then /^(?:|I )should see "([^"]*)" within any "([^"]*)"?$/ do |text, selector|
120 120 if page.respond_to? :should
121   - page.should have_css(selector, :content => text)
  121 + page.should have_css(selector, :text => text)
122 122 else
123   - assert page.has_css?(selector, :content => text)
  123 + assert page.has_css?(selector, :text => text)
124 124 end
125 125 end
126 126  
... ...
lib/noosfero/plugin.rb
... ... @@ -277,6 +277,12 @@ class Noosfero::Plugin
277 277 nil
278 278 end
279 279  
  280 + # -> Adds content to the ending of the page
  281 + # returns = lambda block that creates html code or raw rhtml/html.erb
  282 + def body_ending
  283 + nil
  284 + end
  285 +
280 286 # -> Adds content to the ending of the page head
281 287 # returns = lambda block that creates html code or raw rhtml/html.erb
282 288 def head_ending
... ...
lib/noosfero/plugin.rb.orig
... ... @@ -1,639 +0,0 @@
1   -require 'noosfero'
2   -
3   -class Noosfero::Plugin
4   -
5   - attr_accessor :context
6   -
7   - def initialize(context=nil)
8   - self.context = context
9   - end
10   -
11   - class << self
12   -
13   - attr_writer :should_load
14   -
15   - def should_load
16   - @should_load.nil? && true || @boot
17   - end
18   -
19   -<<<<<<< HEAD
20   - def initialize!
21   - return if !should_load
22   - enabled.each do |plugin_dir|
23   - plugin_name = File.basename(plugin_dir)
24   - plugin = load_plugin(plugin_name)
25   - load_plugin_extensions(plugin_dir)
26   - load_plugin_filters(plugin)
27   - end
28   - end
29   -
30   - def setup(config)
31   - return if !should_load
32   - enabled.each do |dir|
33   - setup_plugin(dir, config)
34   -=======
35   - def init_system
36   - available_plugins.each do |dir|
37   - load_plugin dir
38   ->>>>>>> rails235
39   - end
40   - end
41   -
42   - def setup_plugin(dir, config)
43   - plugin_name = File.basename(dir)
44   -
45   - plugin_dependencies_ok = true
46   - plugin_dependencies_file = File.join(dir, 'dependencies.rb')
47   - if File.exists?(plugin_dependencies_file)
48   - begin
49   - require plugin_dependencies_file
50   - rescue LoadError => ex
51   - plugin_dependencies_ok = false
52   - $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})"
53   - end
54   - end
55   -
56   - if plugin_dependencies_ok
57   - %w[
58   - controllers
59   - controllers/public
60   - controllers/profile
61   - controllers/myprofile
62   - controllers/admin
63   - ].each do |folder|
64   - config.autoload_paths << File.join(dir, folder)
65   - end
66   - [ config.autoload_paths, $:].each do |path|
67   - path << File.join(dir, 'models')
68   - path << File.join(dir, 'lib')
69   - # load vendor/plugins
70   - Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin|
71   - path << "#{vendor_plugin}/lib"
72   - init = "#{vendor_plugin}/init.rb"
73   - require init.gsub(/.rb$/, '') if File.file? init
74   - end
75   - end
76   -
77   - # add view path
78   - ActionController::Base.view_paths.unshift(File.join(dir, 'views'))
79   - end
80   - end
81   -
82   - def load_plugin(plugin_name)
83   - (plugin_name.to_s.camelize + 'Plugin').constantize
84   - end
85   -
86   - # This is a generic method that initialize any possible filter defined by a
87   - # plugin to a specific controller
88   - def load_plugin_filters(plugin)
89   - plugin_methods = plugin.instance_methods.select {|m| m.to_s.end_with?('_filters')}
90   - plugin_methods.each do |plugin_method|
91   - controller_class = plugin_method.to_s.gsub('_filters', '').camelize.constantize
92   - filters = plugin.new.send(plugin_method)
93   - filters = [filters] if !filters.kind_of?(Array)
94   -
95   - filters.each do |plugin_filter|
96   - filter_method = (plugin.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name]).to_sym
97   - controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {}))
98   - controller_class.send(:define_method, filter_method) do
99   - instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin)
100   - end
101   - end
102   - end
103   - end
104   -
105   - def load_plugin_extensions(dir)
106   - Rails.configuration.to_prepare do
107   - Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
108   - end
109   - end
110   -
111   - def enabled
112   - @enabled ||=
113   - begin
114   - plugins = Dir.glob(Rails.root.join('config', 'plugins', '*'))
115   - if Rails.env.test? && !plugins.include?(Rails.root.join('config', 'plugins', 'foo'))
116   - plugins << Rails.root.join('plugins', 'foo')
117   - end
118   - plugins.select do |entry|
119   - File.directory?(entry)
120   - end
121   - end
122   - end
123   -
124   -<<<<<<< HEAD
125   -
126   - def all
127   - @all ||= []
128   -=======
129   - def available_plugins
130   - unless @available_plugins
131   - path = File.join(Rails.root, 'config', 'plugins', '*')
132   - @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) }
133   - if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo'))
134   - @available_plugins << File.join(Rails.root, 'plugins', 'foo')
135   - end
136   - end
137   - @available_plugins
138   ->>>>>>> rails235
139   - end
140   -
141   - def all
142   - @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize }
143   - end
144   -
145   - def public_name
146   - self.name.underscore.gsub('_plugin','')
147   - end
148   -
149   - def public_path(file = '')
150   - File.join('/plugins', public_name, file)
151   - end
152   -
153   - def root_path
154   - Rails.root.join('plugins', public_name)
155   - end
156   -
157   - def view_path
158   - File.join(root_path,'views')
159   - end
160   -
161   - # Here the developer should specify the meta-informations that the plugin can
162   - # inform.
163   - def plugin_name
164   - self.name.underscore.humanize
165   - end
166   - def plugin_description
167   - _("No description informed.")
168   - end
169   -
170   - def admin_url
171   - {:controller => "#{name.underscore}_admin", :action => 'index'}
172   - end
173   -
174   - def has_admin_url?
175   - File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
176   - end
177   - end
178   -
179   - def expanded_template(file_path, locals = {})
180   - views_path = Rails.root.join('plugins', "#{self.class.public_name}", 'views')
181   - ERB.new(File.read("#{views_path}/#{file_path}")).result(binding)
182   - end
183   -
184   - def extra_blocks(params = {})
185   - return [] if self.class.extra_blocks.nil?
186   - blocks = self.class.extra_blocks.map do |block, options|
187   - type = options[:type]
188   - type = type.is_a?(Array) ? type : [type].compact
189   - type = type.map do |x|
190   - x.is_a?(String) ? x.capitalize.constantize : x
191   - end
192   - raise "This is not a valid type" if !type.empty? && ![Person, Community, Enterprise, Environment].detect{|m| type.include?(m)}
193   -
194   - position = options[:position]
195   - position = position.is_a?(Array) ? position : [position].compact
196   - position = position.map{|p| p.to_i}
197   - raise "This is not a valid position" if !position.empty? && ![1,2,3].detect{|m| position.include?(m)}
198   -
199   - if !type.empty? && (params[:type] != :all)
200   - block = type.include?(params[:type]) ? block : nil
201   - end
202   -
203   - if !position.empty? && !params[:position].nil?
204   - block = position.detect{ |p| [params[:position]].flatten.include?(p)} ? block : nil
205   - end
206   -
207   - block
208   - end
209   - blocks.compact!
210   - blocks || []
211   - end
212   -
213   - def macros
214   - self.class.constants.map do |constant_name|
215   - self.class.const_get(constant_name)
216   - end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro}
217   - end
218   -
219   - # Here the developer may specify the events to which the plugins can
220   - # register and must return true or false. The default value must be false.
221   - # Must also explicitly define its returning variables.
222   -
223   - # -> If true, noosfero will include plugin_dir/public/style.css into
224   - # application
225   - def stylesheet?
226   - false
227   - end
228   -
229   - # -> Adds buttons to the control panel
230   - # returns = { :title => title, :icon => icon, :url => url }
231   - # title = name that will be displayed.
232   - # icon = css class name (for customized icons include them in a css file).
233   - # url = url or route to which the button will redirect.
234   - def control_panel_buttons
235   - nil
236   - end
237   -
238   - # -> Customize profile block design and behavior
239   - # (overwrites profile_image_link function)
240   - # returns = lambda block that creates html code.
241   - def profile_image_link(profile, size, tag, extra_info)
242   - nil
243   - end
244   -
245   - # -> Adds tabs to the profile
246   - # returns = { :title => title, :id => id, :content => content, :start => start }
247   - # title = name that will be displayed.
248   - # id = div id.
249   - # content = lambda block that creates html code.
250   - # start = boolean that specifies if the tab must come before noosfero tabs (optional).
251   - def profile_tabs
252   - nil
253   - end
254   -
255   - # -> Adds plugin-specific content types to CMS
256   - # returns = [ContentClass1, ContentClass2, ...]
257   - def content_types
258   - nil
259   - end
260   -
261   - # -> Adds content to calalog item
262   - # returns = lambda block that creates html code
263   - def catalog_item_extras(item)
264   - nil
265   - end
266   -
267   - # -> Adds content to profile editor info and settings
268   - # returns = lambda block that creates html code or raw rhtml/html.erb
269   - def profile_editor_extras
270   - nil
271   - end
272   -
273   - # -> Adds content to calalog list item
274   - # returns = lambda block that creates html code
275   - def catalog_list_item_extras(item)
276   - nil
277   - end
278   -
279   - # -> Adds content to products info
280   - # returns = lambda block that creates html code
281   - def product_info_extras(product)
282   - nil
283   - end
284   -
285   - # -> Adds content to products on asset list
286   - # returns = lambda block that creates html code
287   - def asset_product_extras(product)
288   - nil
289   - end
290   -
291   - # -> Adds a property to the product on asset products
292   - # returns = {:name => name, :content => content}
293   - # name = Name of the property
294   - # content = lambda block that creates an html
295   - def asset_product_properties(product)
296   - nil
297   - end
298   -
299   - # -> Adds content to the beginning of the page
300   - # returns = lambda block that creates html code or raw rhtml/html.erb
301   - def body_beginning
302   - nil
303   - end
304   -
305   - # -> Adds content to the ending of the page head
306   - # returns = lambda block that creates html code or raw rhtml/html.erb
307   - def head_ending
308   - nil
309   - end
310   -
311   - # -> Adds plugins' javascript files to application
312   - # returns = ['example1.js', 'javascripts/example2.js', 'example3.js']
313   - def js_files
314   - []
315   - end
316   -
317   - # -> Adds stuff in user data hash
318   - # returns = { :some_data => some_value, :another_data => another_value }
319   - def user_data_extras
320   - {}
321   - end
322   -
323   - # -> Parse and possibly make changes of content (article, block, etc) during HTML rendering
324   - # returns = content as string after parser and changes
325   - def parse_content(html, source)
326   - [html, source]
327   - end
328   -
329   - # -> Adds links to the admin panel
330   - # returns = {:title => title, :url => url}
331   - # title = name that will be displayed in the link
332   - # url = url or route to which the link will redirect to.
333   - def admin_panel_links
334   - nil
335   - end
336   -
337   - # -> Adds buttons to manage members page
338   - # returns = { :title => title, :icon => icon, :url => url }
339   - # title = name that will be displayed.
340   - # icon = css class name (for customized icons include them in a css file).
341   - # url = url or route to which the button will redirect.
342   - def manage_members_extra_buttons
343   - nil
344   - end
345   -
346   - # This method will be called just before a comment is saved to the database.
347   - #
348   - # It can modify the comment in several ways. In special, a plugin can call
349   - # reject! on the comment and that will cause the comment to not be saved.
350   - #
351   - # example:
352   - #
353   - # def filter_comment(comment)
354   - # if user_not_logged_in
355   - # comment.reject!
356   - # end
357   - # end
358   - #
359   - def filter_comment(comment)
360   - end
361   -
362   - # Define custom logic to filter loaded comments.
363   - #
364   - # Example:
365   - #
366   - # def unavailable_comments(scope)
367   - # scope.without_spams
368   - # end
369   - #
370   - def unavailable_comments(scope)
371   - scope
372   - end
373   -
374   - # -> Allows plugins to check weather object is a spam
375   - def check_for_spam(object)
376   - end
377   -
378   - # -> Allows plugins to know when an object is marked as a spam
379   - def marked_as_spam(object)
380   - end
381   -
382   - # -> Allows plugins to know when an object is marked as a ham
383   - def marked_as_ham(object)
384   - end
385   -
386   - # Adds extra actions for comments
387   - # returns = list of hashes or lambda block that creates a list of hashes
388   - # example:
389   - #
390   - # def comment_actions(comment)
391   - # [{:link => link_to_function(...)}]
392   - # end
393   - #
394   - def comment_actions(comment)
395   - nil
396   - end
397   -
398   - # This method is called when the user click on comment actions menu.
399   - # returns = list or lambda block that return ids of enabled menu items for comments
400   - # example:
401   - #
402   - # def check_comment_actions(comment)
403   - # ['#action1', '#action2']
404   - # end
405   - #
406   - def check_comment_actions(comment)
407   - []
408   - end
409   -
410   - # -> Adds adicional content to article
411   - # returns = lambda block that creates html code
412   - def article_extra_contents(article)
413   - nil
414   - end
415   -
416   - # -> Adds fields to the signup form
417   - # returns = lambda block that creates html code
418   - def signup_extra_contents
419   - nil
420   - end
421   -
422   - # -> Adds adicional content to profile info
423   - # returns = lambda block that creates html code
424   - def profile_info_extra_contents
425   - nil
426   - end
427   -
428   - # -> Removes the invite friend button from the friends controller
429   - # returns = boolean
430   - def remove_invite_friends_button
431   - nil
432   - end
433   -
434   - # -> Extends organization list of members
435   - # returns = An instance of ActiveRecord::NamedScope::Scope retrieved through
436   - # Person.members_of method.
437   - def organization_members(organization)
438   - nil
439   - end
440   -
441   - # -> Extends person memberships list
442   - # returns = An instance of ActiveRecord::NamedScope::Scope retrived through
443   - # Person.memberships_of method.
444   - def person_memberships(person)
445   - nil
446   - end
447   -
448   - # -> Extends person permission access
449   - # returns = boolean
450   - def has_permission?(person, permission, target)
451   - nil
452   - end
453   -
454   - # -> Adds hidden_fields to the new community view
455   - # returns = {key => value}
456   - def new_community_hidden_fields
457   - nil
458   - end
459   -
460   - # -> Adds hidden_fields to the enterprise registration view
461   - # returns = {key => value}
462   - def enterprise_registration_hidden_fields
463   - nil
464   - end
465   -
466   - # -> Add an alternative authentication method.
467   - # Your plugin have to make the access control and return the logged user.
468   - # returns = User
469   - def alternative_authentication
470   - nil
471   - end
472   -
473   - # -> Adds adicional link to make the user authentication
474   - # returns = lambda block that creates html code
475   - def alternative_authentication_link
476   - nil
477   - end
478   -
479   - # -> Allow or not user registration
480   - # returns = boolean
481   - def allow_user_registration
482   - true
483   - end
484   -
485   - # -> Allow or not password recovery by users
486   - # returns = boolean
487   - def allow_password_recovery
488   - true
489   - end
490   -
491   - # -> Adds fields to the login form
492   - # returns = lambda block that creates html code
493   - def login_extra_contents
494   - nil
495   - end
496   -
497   - # -> Adds adicional content to comment form
498   - # returns = lambda block that creates html code
499   - def comment_form_extra_contents(args)
500   - nil
501   - end
502   -
503   - # -> Adds adicional content to article header
504   - # returns = lambda block that creates html code
505   - def article_header_extra_contents(article)
506   - nil
507   - end
508   -
509   - # -> Adds adittional content to comment visualization
510   - # returns = lambda block that creates html code
511   - def comment_extra_contents(args)
512   - nil
513   - end
514   -
515   - # This method is called when the user clicks to send a comment.
516   - # A plugin can add new content to comment form and this method can process the params sent to avoid creating field on core tables.
517   - # returns = params after processed by plugins
518   - # example:
519   - #
520   - # def process_extra_comment_params(params)
521   - # params.delete(:extra_field)
522   - # end
523   - #
524   - def process_extra_comment_params(params)
525   - params
526   - end
527   -
528   - # -> Finds objects by their contents
529   - # returns = {:results => [a, b, c, ...], ...}
530   - # P.S.: The plugin might add other informations on the return hash for its
531   - # own use in specific views
532   - def find_by_contents(asset, scope, query, paginate_options={}, options={})
533   - end
534   -
535   - # -> Adds aditional fields for change_password
536   - # returns = [{:field => 'field1', :name => 'field 1 name', :model => 'person'}, {...}]
537   - def change_password_fields
538   - nil
539   - end
540   -
541   - # -> Adds additional blocks to profiles and environments.
542   - # Your plugin must implements a class method called 'extra_blocks'
543   - # that returns a hash with the following syntax.
544   - # {
545   - # 'block_name' =>
546   - # {
547   - # :type => 'for which holder the block will be available',
548   - # :position => 'where the block could be displayed'
549   - # }
550   - # }
551   - #
552   - # Where:
553   - #
554   - # - block_name: Name of the new block added to the blocks list
555   - # - type: Might have some of the values
556   - # - 'environment' or Environment: If the block is available only for Environment models
557   - # - 'community' or Community: If the block is available only for Community models
558   - # - 'enterprise' or Enterprise: If the block is available only for Enterprise models
559   - # - 'person' or Person: If the block is available only for Person models
560   - # - nil: If no type parameter is passed the block will be available for all types
561   - # - position: Is the layout position of the block. It should be:
562   - # - '1' or 1: Area 1 of layout
563   - # - '2' or 2: Area 2 of layout
564   - # - '3' or 3: Area 3 of layout
565   - # - nil: If no position parameter is passed the block will be available for all positions
566   - #
567   - # OBS: Area 1 is where stay the main content of layout. Areas 2 and 3 are the sides of layout.
568   - #
569   - # examples:
570   - #
571   - # def self.extra_blocks(params)
572   - # {
573   - # #Display 'CustomBlock1' only for 'Person' on position '1'
574   - # CustomBlock1 => {:type => 'person', :position => '1' },
575   - #
576   - # #Display 'CustomBlock2' only for 'Community' on position '2'
577   - # CustomBlock2 => {:type => Community, :position => '2' },
578   - #
579   - # #Display 'CustomBlock3' only for 'Enterprise' on position '3'
580   - # CustomBlock3 => {:type => 'enterprise', :position => 3 },
581   - #
582   - # #Display 'CustomBlock2' for 'Environment' and 'Person' on positions '1' and '3'
583   - # CustomBlock4 => {:type => ['environment', Person], :position => ['1','3'] },
584   - #
585   - # #Display 'CustomBlock5' for all types and all positions
586   - # CustomBlock5 => {},
587   - # }
588   - # end
589   - #
590   - # OBS: The default value is a empty hash.
591   - def self.extra_blocks
592   - {}
593   - end
594   -
595   - def method_missing(method, *args, &block)
596   - # This is a generic hotspot for all controllers on Noosfero.
597   - # If any plugin wants to define filters to run on any controller, the name of
598   - # the hotspot must be in the following form: <underscored_controller_name>_filters.
599   - # Example: for ProfileController the hotspot is profile_controller_filters
600   - #
601   - # -> Adds a filter to a controller
602   - # returns = { :type => type,
603   - # :method_name => method_name,
604   - # :options => {:opt1 => opt1, :opt2 => opt2},
605   - # :block => Proc or lambda block}
606   - # type = 'before_filter' or 'after_filter'
607   - # method_name = The name of the filter
608   - # option = Filter options, like :only or :except
609   - # block = Block that the filter will call
610   - if method.to_s =~ /^(.+)_controller_filters$/
611   - []
612   - # -> Removes the action button from the content
613   - # returns = boolean
614   - elsif method.to_s =~ /^content_remove_(#{content_actions.join('|')})$/
615   - nil
616   - # -> Expire the action button from the content
617   - # returns = string with reason of expiration
618   - elsif method.to_s =~ /^content_expire_(#{content_actions.join('|')})$/
619   - nil
620   - else
621   - super
622   - end
623   - end
624   -
625   - private
626   -
627   - def content_actions
628   - #FIXME 'new' and 'upload' only works for content_remove. It should work for
629   - #content_expire too.
630   - %w[edit delete spread locale suggest home new upload]
631   - end
632   -
633   -end
634   -
635   -require 'noosfero/plugin/hot_spot'
636   -require 'noosfero/plugin/manager'
637   -require 'noosfero/plugin/active_record'
638   -require 'noosfero/plugin/mailer_base'
639   -require 'noosfero/plugin/settings'
plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
... ... @@ -16,6 +16,9 @@ class CommentGroupPlugin::AllowComment &lt; Noosfero::Plugin::Macro
16 16 article = source
17 17 count = article.group_comments.without_spam.in_group(group_id).count
18 18  
19   - proc {render :partial => 'comment_group_plugin_profile/comment_group', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}
  19 + proc {
  20 + render :partial => 'comment_group_plugin_profile/comment_group',
  21 + :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }
  22 + }
20 23 end
21 24 end
... ...
plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb
... ... @@ -3,7 +3,6 @@
3 3 <div style="float: left">
4 4 <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"),
5 5 :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id},
6   - :loaded => j(visual_effect(:highlight, "comments_list_group_#{group_id}")),
7 6 :method => :post,
8 7 :condition => "!toggleGroup(#{group_id})",
9 8 :complete => "loadCompleted(#{group_id})")%>
... ...
plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +# encoding: UTF-8
  2 +class UpdateDisplayContentSectionsArray < ActiveRecord::Migration
  3 +
  4 + def self.up
  5 + translator = {'Publish date' => 'publish_date', 'Title' => 'title', 'Abstract' => 'abstract', 'Body' => 'body', 'Image' => 'image', 'Tags' => 'tags',
  6 + 'Data de publicação' => 'publish_date', 'Título' => 'title', 'Resumo' => 'abstract', 'Corpo' => 'body', 'Imagem' => 'image'}
  7 +
  8 + DisplayContentBlock.find_each do |block|
  9 + new_sections = []
  10 +
  11 + block.sections.each do |section|
  12 + new_value = translator[section["name"]]
  13 + new_section = new_value.blank? ? section : {:value => new_value, :checked => !section["checked"].blank? }
  14 +
  15 + new_section_to_update = new_sections.select {|s| s[:value] == new_value}.first
  16 + if new_section_to_update.blank?
  17 + new_sections << new_section
  18 + else
  19 + new_section_to_update[:checked] = new_section[:checked]
  20 + end
  21 + end
  22 + block.sections = new_sections
  23 + block.update_attribute(:settings, block.settings)
  24 + end
  25 + end
  26 +
  27 + def self.down
  28 + raise "this migration can't be reverted"
  29 + end
  30 +
  31 +end
... ...
plugins/display_content/lib/display_content_block.rb
... ... @@ -15,16 +15,16 @@ class DisplayContentBlock &lt; Block
15 15 N_('December')
16 16 ]
17 17  
  18 + AVAILABLE_SECTIONS = ['publish_date', 'title', 'abstract', 'body', 'image' ,'tags']
  19 +
18 20 settings_items :nodes, :type => Array, :default => []
19 21 settings_items :sections,
20 22 :type => Array,
21   - :default => [{:name => _('Publish date'), :checked => true},
22   - {:name => _('Title'), :checked => true},
23   - {:name => _('Abstract'), :checked => true},
24   - {:name => _('Body'), :checked => false},
25   - {:name => _('Image'), :checked => false},
26   - {:name => _('Tags'), :checked => false}]
  23 + :default => [{:value => 'publish_date', :checked => true},
  24 + {:value => 'title', :checked => true},
  25 + {:value => 'abstract', :checked => true}]
27 26 settings_items :display_folder_children, :type => :boolean, :default => true
  27 + settings_items :types, :type => Array, :default => ['TextileArticle', 'TinyMceArticle', 'RawHTMLArticle']
28 28  
29 29 attr_accessible :sections, :checked_nodes, :display_folder_children
30 30  
... ... @@ -36,6 +36,50 @@ class DisplayContentBlock &lt; Block
36 36 _('This block displays articles chosen by you. You can edit the block to select which of your articles is going to be displayed in the block.')
37 37 end
38 38  
  39 + def section_name(section)
  40 + {
  41 + 'publish_date' => _('Publish date'),
  42 + 'title' => _('Title'),
  43 + 'abstract' => _('Abstract'),
  44 + 'body' => _('Body'),
  45 + 'image' => _('Image'),
  46 + 'tags' => _('Tags')
  47 + }[section] || section
  48 + end
  49 +
  50 + alias :orig_sections :sections
  51 + def sections
  52 + available_sections = AVAILABLE_SECTIONS
  53 + available_sections = available_sections - orig_sections.map{|e|e[:value]}
  54 + sections = available_sections.map do |section|
  55 + {:value => section, :checked => false}
  56 + end
  57 + sections + orig_sections
  58 + end
  59 +
  60 + def available_content_types
  61 + @available_content_types ||= [TinyMceArticle, RawHTMLArticle, TextileArticle, UploadedFile, Event, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types)
  62 + checked_types = types.map {|t| t.constantize}
  63 + checked_types + (@available_content_types - checked_types)
  64 + end
  65 +
  66 + #FIXME make this test copy of Context Content
  67 + def first_content_types
  68 + available_content_types.first(first_types_count)
  69 + end
  70 +
  71 + def more_content_types
  72 + available_content_types.drop(first_types_count)
  73 + end
  74 +
  75 + def first_types_count
  76 + [2, types.length].max
  77 + end
  78 +
  79 + def types=(new_types)
  80 + settings[:types] = new_types.reject(&:blank?)
  81 + end
  82 +
39 83 def checked_nodes= params
40 84 self.nodes = params.keys
41 85 end
... ... @@ -45,7 +89,7 @@ class DisplayContentBlock &lt; Block
45 89 def expand_nodes
46 90 return self.nodes if self.holder.nil?
47 91  
48   - articles = self.holder.articles.find(nodes)
  92 + articles = self.holder.articles.where(:id => nodes)
49 93 children = articles.map { |article| article.children }.compact.flatten
50 94  
51 95 if display_folder_children
... ... @@ -58,7 +102,7 @@ class DisplayContentBlock &lt; Block
58 102 end
59 103  
60 104 def parent_nodes
61   - @parent_nodes ||= self.holder.articles.find(nodes).map { |article| get_parent(article) }.compact.flatten
  105 + @parent_nodes ||= self.holder.articles.where(:id => nodes).map { |article| get_parent(article) }.compact.flatten
62 106 end
63 107  
64 108 VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum']
... ... @@ -73,9 +117,10 @@ class DisplayContentBlock &lt; Block
73 117  
74 118 def content(args={})
75 119 block = self
76   - extra_condition = display_folder_children ? 'OR articles.parent_id IN(:nodes)':''
77   - docs = nodes.blank? ? [] : owner.articles.find(:all, :conditions => ["(articles.id IN(:nodes) #{extra_condition}) AND articles.type IN(:types)", {:nodes => self.nodes, :types => VALID_CONTENT}])
  120 + nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) "
  121 + nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children
78 122  
  123 + docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}], :include => :profile)
79 124 proc do
80 125 block.block_title(block.title) +
81 126 content_tag('ul', docs.map {|item|
... ... @@ -85,24 +130,24 @@ class DisplayContentBlock &lt; Block
85 130 tags_section = ''
86 131  
87 132 block.sections.select { |section|
88   - case section[:name]
89   - when 'Publish date'
90   - content_sections += (block.display_section?(section) ? (content_tag('div', block.show_date(item.published_at, false), :class => 'published-at') ) : '')
91   - when 'Title'
  133 + case section[:value]
  134 + when 'publish_date'
  135 + content_sections += (block.display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '')
  136 + when 'title'
92 137 content_sections += (block.display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '')
93   - when 'Abstract'
  138 + when 'abstract'
94 139 content_sections += (block.display_section?(section) ? (content_tag('div', item.abstract , :class => 'lead')) : '' )
95 140 if block.display_section?(section)
96 141 read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more')
97 142 end
98   - when 'Body'
  143 + when 'body'
99 144 content_sections += (block.display_section?(section) ? (content_tag('div', item.body ,:class => 'body')) : '' )
100   - when 'Image'
  145 + when 'image'
101 146 image_section = image_tag item.image.public_filename if item.image
102 147 if !image_section.blank?
103 148 content_sections += (block.display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' )
104 149 end
105   - when 'Tags'
  150 + when 'tags'
106 151 if !item.tags.empty?
107 152 tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("")
108 153 content_sections += (block.display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '')
... ... @@ -111,7 +156,7 @@ class DisplayContentBlock &lt; Block
111 156 }
112 157  
113 158 content_sections += read_more_section if !read_more_section.blank?
114   -
  159 +#raise sections.inspect
115 160 content_tag('li', content_sections)
116 161 end
117 162 }.join(" "))
... ...
plugins/display_content/test/unit/display_content_block_test.rb
... ... @@ -370,7 +370,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
370 370 a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2')
371 371  
372 372 block = DisplayContentBlock.new
373   - block.sections = [{:name => 'Abstract', :checked => true}]
  373 + block.sections = [{:value => 'abstract', :checked => true}]
374 374 block.nodes = [a1.id, a2.id]
375 375 box = mock()
376 376 block.stubs(:box).returns(box)
... ... @@ -425,7 +425,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
425 425  
426 426 block = DisplayContentBlock.new
427 427 block.nodes = [a.id]
428   - block.sections = [{:name => 'Title', :checked => true}]
  428 + block.sections = [{:value => 'title', :checked => true}]
429 429 box = mock()
430 430 block.stubs(:box).returns(box)
431 431 box.stubs(:owner).returns(profile)
... ... @@ -439,7 +439,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
439 439  
440 440 block = DisplayContentBlock.new
441 441 block.nodes = [a.id]
442   - block.sections = [{:name => 'Abstract', :checked => true}]
  442 + block.sections = [{:value => 'abstract', :checked => true}]
443 443 box = mock()
444 444 block.stubs(:box).returns(box)
445 445 box.stubs(:owner).returns(profile)
... ... @@ -453,7 +453,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
453 453  
454 454 block = DisplayContentBlock.new
455 455 block.nodes = [a.id]
456   - block.sections = [{:name => 'Body', :checked => true}]
  456 + block.sections = [{:value => 'body', :checked => true}]
457 457 box = mock()
458 458 block.stubs(:box).returns(box)
459 459 box.stubs(:owner).returns(profile)
... ... @@ -466,7 +466,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
466 466  
467 467 block = DisplayContentBlock.new
468 468  
469   - assert block.display_section?({:name => 'Title', :checked => true})
  469 + assert block.display_section?({:value => 'title', :checked => true})
470 470 end
471 471  
472 472 should 'display_attribute be true if the attribute was chosen' do
... ... @@ -474,8 +474,8 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
474 474  
475 475 block = DisplayContentBlock.new
476 476  
477   - block.sections = [{:name => 'Body', :checked => true}]
478   - section = block.sections.first
  477 + section = {:value => 'body', :checked => true}
  478 + block.sections = [section]
479 479  
480 480 assert block.display_section?(section)
481 481 end
... ... @@ -485,7 +485,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
485 485  
486 486 block = DisplayContentBlock.new
487 487  
488   - assert block.display_section?({:name => 'Publish date', :checked => true})
  488 + assert block.display_section?({:value => 'publish_date', :checked => true})
489 489 end
490 490  
491 491 should 'show publishd date if defined by user' do
... ... @@ -494,7 +494,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
494 494  
495 495 block = DisplayContentBlock.new
496 496 block.nodes = [a.id]
497   - block.sections = [{:name => 'Publish date', :checked => true}]
  497 + block.sections = [{:value => 'publish_date', :checked => true}]
498 498 box = mock()
499 499 block.stubs(:box).returns(box)
500 500 box.stubs(:owner).returns(profile)
... ... @@ -547,17 +547,104 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
547 547 profile = create_user('testuser').person
548 548 Article.delete_all
549 549 a1 = fast_create(PluginArticle, :name => 'test article 1', :profile_id => profile.id)
550   -
551 550 Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
552 551 env = fast_create(Environment)
553   - env.enable_plugin(Plugin1)
  552 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new])
554 553  
555 554 block = DisplayContentBlock.new
556 555 box = mock()
557 556 box.stubs(:owner).returns(profile)
  557 + Noosfero::Plugin.stubs(:all).returns(['DisplayContentBlockTest::Plugin1'])
558 558 box.stubs(:environment).returns(env)
559 559 block.stubs(:box).returns(box)
560 560 assert_equal [a1], block.articles_of_parent
561 561 end
562 562  
  563 + should "the section display all available sections" do
  564 + block = DisplayContentBlock.new
  565 + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]}
  566 + end
  567 +
  568 + should "the section display all available sections if the section value has only one key" do
  569 + block = DisplayContentBlock.new
  570 + block.sections = [{:value => 'abstract', :checked => true}]
  571 + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]}
  572 + end
  573 +
  574 + should 'return available content types with checked types first' do
  575 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  576 + block = DisplayContentBlock.create!
  577 + block.types = ['TinyMceArticle']
  578 +
  579 + block.types = ['TinyMceArticle', 'Folder']
  580 + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], block.available_content_types
  581 + end
  582 +
  583 + should 'return available content types' do
  584 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  585 + block = DisplayContentBlock.create!
  586 + block.types = ['TinyMceArticle']
  587 + block.types = []
  588 + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], block.available_content_types
  589 + end
  590 +
  591 + should 'return first 2 content types' do
  592 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  593 + block = DisplayContentBlock.create!
  594 + block.types = ['TinyMceArticle']
  595 + assert_equal 2, block.first_content_types.length
  596 + end
  597 +
  598 + should 'return all but first 2 content types' do
  599 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  600 + block = DisplayContentBlock.create!
  601 + block.types = ['TinyMceArticle']
  602 + assert_equal block.available_content_types.length - 2, block.more_content_types.length
  603 + end
  604 +
  605 + should 'return 2 as default value for first_types_count' do
  606 + block = DisplayContentBlock.create!
  607 + block.types = ['TinyMceArticle']
  608 + assert_equal 2, block.first_types_count
  609 + end
  610 +
  611 + should 'return types length if it has more than 2 selected types' do
  612 + block = DisplayContentBlock.create!
  613 + block.types = ['UploadedFile', 'Event', 'Folder']
  614 + assert_equal 3, block.first_types_count
  615 + end
  616 +
  617 + should 'return selected types at first_content_types' do
  618 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  619 + block = DisplayContentBlock.create!
  620 + block.types = ['UploadedFile', 'Event', 'Folder']
  621 + assert_equal [UploadedFile, Event, Folder], block.first_content_types
  622 + assert_equal block.available_content_types - [UploadedFile, Event, Folder], block.more_content_types
  623 + end
  624 +
  625 + should 'include plugin content at available content types' do
  626 + block = DisplayContentBlock.create!
  627 + class SomePluginContent;end
  628 + class SomePlugin; def content_types; SomePluginContent end end
  629 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
  630 +
  631 + block.types = []
  632 + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], block.available_content_types
  633 + end
  634 +
  635 + should 'do not fail if a selected article was removed' do
  636 + profile = create_user('testuser').person
  637 + Article.delete_all
  638 + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id)
  639 + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id)
  640 +
  641 + checked_articles= {a1.id => true}
  642 +
  643 + block = DisplayContentBlock.new
  644 + block.stubs(:holder).returns(profile)
  645 + block.checked_nodes= checked_articles
  646 + a1.destroy
  647 + assert_equal [], block.parent_nodes
  648 + end
  649 +
563 650 end
... ...
plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<%= label :block, :types, _('Display content types:'), :class => 'formlabel' %>
  2 +<div class="content_types">
  3 + <% @block.first_content_types.each do |type| %>
  4 + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %>
  5 + <% end %>
  6 + <% if !@block.more_content_types.empty? %>
  7 + <a href="#" onclick="jQuery('.content_types .more').toggle(); return false;"><%= _('more') %></a>
  8 + <% end %>
  9 + <div class="more" style="display: none">
  10 + <% @block.more_content_types.each do |type| %>
  11 + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %>
  12 + <% end %>
  13 + </div>
  14 +</div>
  15 +
... ...
plugins/display_content/views/box_organizer/_choose_directly.html.erb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +<div id="display_content">
  2 +</div>
  3 +
  4 +<div class="display_folder_children">
  5 + <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %>
  6 +</div>
  7 +
  8 +<script type="text/javascript" >
  9 +
  10 +jQuery_1_8_3("#display_content").jstree({
  11 + plugins : ["themes","json_data", "checkbox"],
  12 + checkbox : {
  13 + real_checkboxes : true,
  14 + real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; }
  15 + },
  16 + themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"},
  17 + json_data : {
  18 + ajax : {
  19 + url : '<%= url_for @block.url_params %>',
  20 + async: true,
  21 + data : function (m) {
  22 + return m.attr ? {"id" : m.attr("node_id")} : {};
  23 + }
  24 + }
  25 + }
  26 +});
  27 +
  28 +jQuery( "#sortable" ).sortable();
  29 +
  30 +</script>
... ...
plugins/display_content/views/box_organizer/_display_content_block.html.erb
1 1 <div id="display_content_plugin">
2 2  
  3 +<%= javascript_tag 'render_all_jquery_ui_widgets()' %>
  4 +
3 5 <h3> <%= _('Choose which attributes should be displayed and drag to reorder them:') %> </h3>
4 6  
5 7 <table class="sections">
6 8 <tbody id="sortable">
7 9 <% for section in @block.sections do %>
8 10 <tr>
9   - <td><%= hidden_field_tag 'block[sections][][name]', section[:name] %> <%= check_box_tag 'block[sections][][checked]', section[:name], section[:checked] %></td>
10   - <td><%= section[:name]%></td>
  11 + <td>
  12 + <%= hidden_field_tag 'block[sections][][value]', section[:value] %>
  13 + <%= check_box_tag 'block[sections][][checked]', section[:value], section[:checked] %>
  14 + </td>
  15 + <td><%= @block.section_name(section[:value]) %></td>
11 16 </tr>
12 17 <% end %>
13 18 </tbody>
14 19 </table>
15 20  
16 21 <h3> <%= _('Choose which content should be displayed:') %> </h3>
17   -<div id="display_content">
18   -</div>
19   -
20   -<div class="display_folder_children">
21   - <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %>
22   -</div>
  22 +<% tabs = [] %>
  23 +<% tabs << {:title => _('Choose directly'), :id => 'choose-directly', :content => (render :partial => 'choose_directly')} %>
  24 +<% tabs << {:title => _('Choose by Content Type'), :id => 'choose_by_content_type', :content => (render :partial => 'choose_by_content_type')} %>
23 25  
24   -<script type="text/javascript" >
  26 +<%= render_tabs(tabs) %>
25 27  
26   -jQuery_1_8_3("#display_content").jstree({
27   - plugins : ["themes","json_data", "checkbox"],
28   - checkbox : {
29   - real_checkboxes : true,
30   - real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; }
31   - },
32   - themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"},
33   - json_data : {
34   - ajax : {
35   - url : '<%= url_for @block.url_params %>',
36   - async: true,
37   - data : function (m) {
38   - return m.attr ? {"id" : m.attr("node_id")} : {};
39   - }
40   - }
41   - }
42   -});
43   -
44   -jQuery( "#sortable" ).sortable();
45   -
46   -</script>
47 28 </div>
  29 +
... ...
plugins/people_block/before_disable.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +raise "\nPeopleBlockPlugin shouldn't be enabled/disabled by hand, Noosfero" +
  2 + "\ninstallation already comes with it enabled by default!\n"
... ...
plugins/people_block/controllers/people_block_plugin_profile_controller.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class PeopleBlockPluginProfileController < ProfileController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../views')
  4 +
  5 + def members
  6 + if is_cache_expired?(profile.members_cache_key(params))
  7 + if(params[:role_key])
  8 + role = Role.find_by_key_and_environment_id(params[:role_key], profile.environment)
  9 + @members = profile.members.with_role(role.id).includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage])
  10 + @members_title = role.name
  11 + else
  12 + @members = profile.members.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage])
  13 + @members_title = 'members'
  14 + end
  15 + end
  16 + render "profile/members"
  17 + end
  18 +
  19 +end
... ...
plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class EnablePeopleBlockPlugin < ActiveRecord::Migration
  2 + def up
  3 + Environment.all.each do |env|
  4 + env.enabled_plugins << 'PeopleBlockPlugin'
  5 + env.enabled_plugins.uniq!
  6 + env.save!
  7 + end
  8 + end
  9 +
  10 + def down
  11 + Environment.all.each do |env|
  12 + env.enabled_plugins.delete_if {|i| i== 'PeopleBlockPlugin'}
  13 + env.save!
  14 + end
  15 + end
  16 +end
... ...
plugins/people_block/lib/ext/person.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +require_dependency 'person'
  2 +
  3 +class Person
  4 +
  5 + scope :with_role, lambda { |role_id|
  6 + { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ["role_assignments.role_id = #{role_id}"] }
  7 + }
  8 +
  9 +end
... ...
plugins/people_block/lib/friends_block.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +class FriendsBlock < PeopleBlockBase
  2 +
  3 + def self.description
  4 + _('Friends')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a friend takes you to his/her homepage')
  9 + end
  10 +
  11 + def default_title
  12 + n_('{#} friend', '{#} friends', profile_count)
  13 + end
  14 +
  15 + def profiles
  16 + owner.friends
  17 + end
  18 +
  19 + def footer
  20 + profile = self.owner
  21 + proc do
  22 + render :file => 'blocks/friends', :locals => { :profile => profile }
  23 + end
  24 + end
  25 +
  26 + def self.expire_on
  27 + { :profile => [:profile] }
  28 + end
  29 +
  30 +end
... ...
plugins/people_block/lib/members_block.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +class MembersBlock < PeopleBlockBase
  2 + settings_items :show_join_leave_button, :type => :boolean, :default => false
  3 + settings_items :visible_role, :type => :string, :default => nil
  4 + attr_accessible :show_join_leave_button, :visible_role
  5 +
  6 + def self.description
  7 + _('Members')
  8 + end
  9 +
  10 + def help
  11 + _('Clicking a member takes you to his/her homepage')
  12 + end
  13 +
  14 + def default_title
  15 + title = role ? role.name : n_('members')
  16 + _('{#} %s') % title
  17 + end
  18 +
  19 + def profiles
  20 + role ? owner.members.with_role(role.id) : owner.members
  21 + end
  22 +
  23 + def footer
  24 + profile = self.owner
  25 + role_key = visible_role
  26 + s = show_join_leave_button
  27 + proc do
  28 + render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key}
  29 + end
  30 + end
  31 +
  32 + def role
  33 + visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil
  34 + end
  35 +
  36 + def roles
  37 + Profile::Roles.organization_member_roles(owner.environment)
  38 + end
  39 +
  40 + def extra_option
  41 + data = {
  42 + :human_name => _("Show join leave button"),
  43 + :name => 'block[show_join_leave_button]',
  44 + :value => true,
  45 + :checked => show_join_leave_button,
  46 + :options => {}
  47 + }
  48 + end
  49 +
  50 +end
... ...
plugins/people_block/lib/people_block.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +class PeopleBlock < PeopleBlockBase
  2 +
  3 + def self.description
  4 + _('People')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a person takes you to his/her homepage')
  9 + end
  10 +
  11 + def default_title
  12 + _('{#} People')
  13 + end
  14 +
  15 + def profiles
  16 + owner.people
  17 + end
  18 +
  19 + def footer
  20 + proc do
  21 + render :file => 'blocks/people'
  22 + end
  23 + end
  24 +
  25 +end
... ...
plugins/people_block/lib/people_block_base.rb 0 → 100644
... ... @@ -0,0 +1,100 @@
  1 +class PeopleBlockBase < Block
  2 + settings_items :prioritize_profiles_with_image, :type => :boolean, :default => true
  3 + settings_items :limit, :type => :integer, :default => 6
  4 + settings_items :name, :type => String, :default => ""
  5 + settings_items :address, :type => String, :default => ""
  6 + attr_accessible :name, :address, :prioritize_profiles_with_image
  7 +
  8 + def self.description
  9 + _('Random people')
  10 + end
  11 +
  12 + def help
  13 + _('Clicking on the people or groups will take you to their home page.')
  14 + end
  15 +
  16 + def default_title
  17 + _('{#} People')
  18 + end
  19 +
  20 + def view_title
  21 + title.gsub('{#}', profile_count.to_s)
  22 + end
  23 +
  24 + def profiles
  25 + owner.profiles
  26 + end
  27 +
  28 + def profile_list
  29 + result = nil
  30 + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
  31 + if !prioritize_profiles_with_image
  32 + result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand }
  33 + elsif visible_profiles.with_image.count >= limit
  34 + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  35 + else
  36 + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  37 + end
  38 + result.slice(0..limit-1)
  39 + end
  40 +
  41 + def profile_count
  42 + profiles.visible.count
  43 + end
  44 +
  45 + def content(args={})
  46 + profiles = self.profile_list
  47 + title = self.view_title
  48 +
  49 + if !self.name.blank? && !self.address.blank?
  50 + name = self.name
  51 + expanded_address = expand_address(self.address)
  52 + end
  53 +
  54 + proc do
  55 + count = 0
  56 + list = profiles.map {|item|
  57 + count += 1
  58 + send(:profile_image_link, item, :minor )
  59 + }.join("\n")
  60 + if list.empty?
  61 + list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none'
  62 + else
  63 + if !name.blank? && !expanded_address.blank?
  64 + list << content_tag(
  65 + 'div',
  66 + content_tag(
  67 + 'li',
  68 + content_tag(
  69 + 'div',
  70 + link_to(
  71 + content_tag('span', name, :class => 'banner-span' ),
  72 + expanded_address,
  73 + :title => name
  74 + ),
  75 + :class => 'banner-div'
  76 + ),
  77 + :class => 'vcard'
  78 + ),
  79 + :class => 'common-profile-list-block'
  80 + )
  81 + end
  82 + list = content_tag 'ul', list
  83 + end
  84 + block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both'))
  85 + end
  86 + end
  87 +
  88 + def expand_address(address)
  89 + if address !~ /^[a-z]+:\/\// && address !~ /^\//
  90 + 'http://' + address
  91 + else
  92 + address
  93 + end
  94 + end
  95 +
  96 + def extra_option
  97 + { }
  98 + end
  99 +
  100 +end
... ...
plugins/people_block/lib/people_block_plugin.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class PeopleBlockPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "People Block Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that adds a people block")
  9 + end
  10 +
  11 + def self.extra_blocks
  12 + {
  13 + PeopleBlock => {:type => Environment},
  14 + MembersBlock => {:type => Community},
  15 + FriendsBlock => {:type => Person}
  16 + }
  17 + end
  18 +
  19 + def self.has_admin_url?
  20 + false
  21 + end
  22 +
  23 + def stylesheet?
  24 + true
  25 + end
  26 +
  27 +end
... ...
plugins/people_block/public/style.css 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +/*******************************************************************
  2 + * COMMON *
  3 + *******************************************************************/
  4 +.people-block .block-footer-content a {
  5 + position: absolute;
  6 + top: 2px;
  7 + right: 0px;
  8 + font-size: 11px;
  9 + color: #000;
  10 + text-decoration: none;
  11 + padding-right: 15px;
  12 +}
  13 +
  14 +.people-block .banner-span {
  15 + color: #000;
  16 + font-size: 14pt;
  17 + font-weight: bold;
  18 + background-color: #EEE;
  19 +}
  20 +
  21 +
  22 +/*******************************************************************
  23 + * MAIN BOX - 1 *
  24 + *******************************************************************/
  25 +.box-1 .people-block .banner-div {
  26 + line-height: 112px;
  27 +}
  28 +
  29 +.box-1 .people-block .banner-span {
  30 + width: 204px;
  31 +}
  32 +
  33 +
  34 +/*******************************************************************
  35 + * LEFT/RIGHT BOXES *
  36 + *******************************************************************/
  37 +.box-2 .people-block .banner-div,
  38 +.box-3 .people-block .banner-div {
  39 + line-height: 78px;
  40 +}
  41 +
  42 +.box-2 .people-block .banner-div a,
  43 +.box-3 .people-block .banner-div a {
  44 + height: 78px;
  45 +}
  46 +
  47 +.box-2 .people-block .banner-span,
  48 +.box-3 .people-block .banner-span {
  49 + width: 116px;
  50 +}
  51 +
  52 +.box-2 .people-block ul,
  53 +.box-3 .people-block ul {
  54 + min-width: 196px;
  55 + width: 192px;
  56 + margin: 0px 0px 0px -3px;
  57 + padding: 0px;
  58 +}
  59 +
  60 +/*******************************************************************
  61 + * BLOCKs *
  62 + *******************************************************************/
  63 +#content .friends-block ul,
  64 +#content .members-block ul {
  65 + min-width: 196px;
  66 + width: 192px;
  67 + margin: 0px 0px 0px -3px;
  68 + padding: 0px;
  69 +}
  70 +#content .box-1 .people-block ul,
  71 +#content .box-1 .friends-block ul,
  72 +#content .box-1 .members-block ul {
  73 + width: auto;
  74 + display: block;
  75 +}
  76 +#content .people-block .block-footer-content a,
  77 +#content .friends-block .block-footer-content a,
  78 +#content .members-block .block-footer-content a {
  79 + position: absolute;
  80 + top: 2px;
  81 + right: 0px;
  82 + font-size: 11px;
  83 + color: #000;
  84 + text-decoration: none;
  85 + padding-right: 15px;
  86 +}
  87 +#content .members-block .block-footer-content .join-leave-button a {
  88 + position: relative;
  89 + background-color: #EEE;
  90 + border: 1px solid #CCC;
  91 + color: #555;
  92 + padding-right: inherit;
  93 +}
  94 +#content .members-block .block-footer-content .join-leave-button a:hover {
  95 + color: #FFF;
  96 + background-color: #555;
  97 + border: 1px solid #2e3436;
  98 + text-decoration: none;
  99 +}
  100 +#content .people-block .block-footer-content a.view-all,
  101 +#content .friends-block .block-footer-content a.view-all,
  102 +#content .members-block .block-footer-content a.view-all {
  103 + background: url(/designs/themes/base/imgs/arrow-right-p.png) 100% 50% no-repeat;
  104 +}
... ...
plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class EnvironmentDesignController; def rescue_action(e) raise e end; end
  5 +
  6 +class EnvironmentDesignControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = EnvironmentDesignController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new])
  13 + end
  14 +
  15 + should 'be able to edit PeopleBlock' do
  16 + login_as(create_admin_user(Environment.default))
  17 + b = PeopleBlock.create!
  18 + e = Environment.default
  19 + e.boxes.create!
  20 + e.boxes.first.blocks << b
  21 + get :edit, :id => b.id
  22 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  23 + end
  24 +
  25 +end
... ...
plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,76 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/people_block_plugin_profile_controller'
  3 +
  4 +
  5 +# Re-raise errors caught by the controller.
  6 +class PeopleBlockPluginProfileController; def rescue_action(e) raise e end; end
  7 +
  8 +class PeopleBlockPluginProfileControllerTest < ActionController::TestCase
  9 +
  10 + def setup
  11 + @controller = PeopleBlockPluginProfileController.new
  12 + @request = ActionController::TestRequest.new
  13 + @response = ActionController::TestResponse.new
  14 +
  15 + @profile = fast_create(Community)
  16 +
  17 + @environment = @profile.environment
  18 + @environment.enabled_plugins = ['PeopleBlockPlugin']
  19 + @environment.save!
  20 +
  21 + MembersBlock.delete_all
  22 + @block = MembersBlock.new
  23 + @block.box = @profile.boxes.first
  24 + @block.save!
  25 +
  26 + @admin = create_user('adminprofile').person
  27 + @member = create_user('memberprofile').person
  28 + @moderator = create_user('moderatorprofile').person
  29 + @profile.add_moderator(@moderator)
  30 + @profile.add_member(@member)
  31 + @profile.add_admin(@admin)
  32 + end
  33 +
  34 + attr_accessor :profile, :block, :admin, :member, :moderator
  35 +
  36 + should 'list members without role_key' do
  37 + get :members, :profile => profile.identifier
  38 + assert_response :success
  39 + assert_template 'members'
  40 + assert_equivalent [@admin, @member, @moderator], assigns(:members)
  41 + assert_match /adminprofile/, @response.body
  42 + assert_match /memberprofile/, @response.body
  43 + assert_match /moderatorprofile/, @response.body
  44 + end
  45 +
  46 + should 'list members with role_key=nil' do
  47 + get :members, :profile => profile.identifier, :role_key => nil
  48 + assert_response :success
  49 + assert_template 'members'
  50 + assert_equivalent [@admin, @member, @moderator], assigns(:members)
  51 + assert_match /adminprofile/, @response.body
  52 + assert_match /memberprofile/, @response.body
  53 + assert_match /moderatorprofile/, @response.body
  54 + end
  55 +
  56 + should 'list members only' do
  57 + get :members, :profile => profile.identifier, :role_key => Profile::Roles.member(profile.environment.id).key
  58 + assert_response :success
  59 + assert_template 'members'
  60 + assert_equal [@member], assigns(:members)
  61 + assert_no_match /adminprofile/, @response.body
  62 + assert_match /memberprofile/, @response.body
  63 + assert_no_match /moderatorprofile/, @response.body
  64 + end
  65 +
  66 + should 'list moderators only' do
  67 + get :members, :profile => profile.identifier, :role_key => Profile::Roles.moderator(profile.environment.id).key
  68 + assert_response :success
  69 + assert_template 'members'
  70 + assert_equal [@moderator], assigns(:members)
  71 + assert_no_match /adminprofile/, @response.body
  72 + assert_no_match /memberprofile/, @response.body
  73 + assert_match /moderatorprofile/, @response.body
  74 + end
  75 +
  76 +end
... ...
plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class ProfileDesignController; def rescue_action(e) raise e end; end
  5 +
  6 +class ProfileDesignControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = ProfileDesignController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new])
  13 + end
  14 +
  15 + should 'display *block people-block* class at design blocks page' do
  16 + user = create_user('testinguser')
  17 + login_as(user.login)
  18 +
  19 + @profile = user.person
  20 + @environment = @profile.environment
  21 + @environment.save!
  22 +
  23 + FriendsBlock.delete_all
  24 + @box1 = Box.create!(:owner => @profile)
  25 + @profile.boxes = [@box1]
  26 +
  27 + @block = FriendsBlock.new
  28 + @block.box = @box1
  29 + @block.save!
  30 +
  31 + @profile.blocks<<@block
  32 + @profile.save!
  33 +
  34 + get :index, :profile => @profile.identifier
  35 + assert_tag :div, :attributes => {:class => 'block friends-block'}
  36 + end
  37 +
  38 + should 'the people block is available for person profile' do
  39 + profile = mock
  40 + profile.stubs(:has_members?).returns(false)
  41 + profile.stubs(:person?).returns(true)
  42 + profile.stubs(:community?).returns(false)
  43 + profile.stubs(:enterprise?).returns(false)
  44 + profile.stubs(:has_blog?).returns(false)
  45 + profile.stubs(:is_admin?).with(anything).returns(false)
  46 + environment = mock
  47 + profile.stubs(:environment).returns(environment)
  48 + environment.stubs(:enabled?).returns(false)
  49 + @controller.stubs(:profile).returns(profile)
  50 + @controller.stubs(:user).returns(profile)
  51 + assert_includes @controller.available_blocks, FriendsBlock
  52 + end
  53 +
  54 + should 'the people block is available for community profile' do
  55 + profile = mock
  56 + profile.stubs(:has_members?).returns(true)
  57 + profile.stubs(:person?).returns(false)
  58 + profile.stubs(:community?).returns(true)
  59 + profile.stubs(:enterprise?).returns(false)
  60 + profile.stubs(:has_blog?).returns(false)
  61 + profile.stubs(:is_admin?).with(anything).returns(false)
  62 + environment = mock
  63 + profile.stubs(:environment).returns(environment)
  64 + environment.stubs(:enabled?).returns(false)
  65 + @controller.stubs(:profile).returns(profile)
  66 + @controller.stubs(:user).returns(profile)
  67 + assert_includes @controller.available_blocks, MembersBlock
  68 + end
  69 +
  70 +end
... ...
plugins/people_block/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
... ...
plugins/people_block/test/unit/friends_block_test.rb 0 → 100644
... ... @@ -0,0 +1,156 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class FriendsBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, FriendsBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, FriendsBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, FriendsBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = FriendsBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = FriendsBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = FriendsBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = FriendsBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = FriendsBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = FriendsBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = FriendsBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert FriendsBlock.new.prioritize_people_with_image
  64 + end
  65 +
  66 +
  67 + should 'accept a limit of people to be displayed' do
  68 + block = FriendsBlock.new
  69 + block.limit = 20
  70 + assert_equal 20, block.limit
  71 + end
  72 +
  73 +
  74 + should 'list friends from person' do
  75 + owner = fast_create(Person)
  76 + friend1 = fast_create(Person)
  77 + friend2 = fast_create(Person)
  78 + owner.add_friend(friend1)
  79 + owner.add_friend(friend2)
  80 +
  81 + block = FriendsBlock.new
  82 +
  83 + block.expects(:owner).returns(owner).at_least_once
  84 + expects(:profile_image_link).with(friend1, :minor).returns(friend1.name)
  85 + expects(:profile_image_link).with(friend2, :minor).returns(friend2.name)
  86 + expects(:block_title).with(anything).returns('')
  87 +
  88 + content = instance_eval(&block.content)
  89 +
  90 + assert_match(/#{friend1.name}/, content)
  91 + assert_match(/#{friend2.name}/, content)
  92 + end
  93 +
  94 +
  95 + should 'link to "all friends"' do
  96 + person1 = create_user('mytestperson').person
  97 +
  98 + block = FriendsBlock.new
  99 + block.expects(:owner).returns(person1).at_least_once
  100 +
  101 + expects(:_).with('View all').returns('View all')
  102 + expects(:link_to).with('View all', :profile => 'mytestperson', :controller => 'profile', :action => 'friends').returns('link-to-friends')
  103 +
  104 + assert_equal 'link-to-friends', instance_eval(&block.footer)
  105 + end
  106 +
  107 +
  108 + should 'count number of owner friends' do
  109 + owner = fast_create(Person)
  110 + friend1 = fast_create(Person)
  111 + friend2 = fast_create(Person)
  112 + friend3 = fast_create(Person)
  113 + owner.add_friend(friend1)
  114 + owner.add_friend(friend2)
  115 + owner.add_friend(friend3)
  116 +
  117 + block = FriendsBlock.new
  118 + block.expects(:owner).returns(owner).at_least_once
  119 +
  120 + assert_equal 3, block.profile_count
  121 + end
  122 +
  123 +
  124 + should 'count number of public and private friends' do
  125 + owner = fast_create(Person)
  126 + private_p = fast_create(Person, {:public_profile => false})
  127 + public_p = fast_create(Person, {:public_profile => true})
  128 +
  129 + owner.add_friend(private_p)
  130 + owner.add_friend(public_p)
  131 +
  132 + block = FriendsBlock.new
  133 + block.expects(:owner).returns(owner).at_least_once
  134 +
  135 + assert_equal 2, block.profile_count
  136 + end
  137 +
  138 +
  139 + should 'not count number of invisible friends' do
  140 + owner = fast_create(Person)
  141 + private_p = fast_create(Person, {:visible => false})
  142 + public_p = fast_create(Person, {:visible => true})
  143 +
  144 + owner.add_friend(private_p)
  145 + owner.add_friend(public_p)
  146 +
  147 + block = FriendsBlock.new
  148 + block.expects(:owner).returns(owner).at_least_once
  149 +
  150 + assert_equal 1, block.profile_count
  151 + end
  152 +
  153 + protected
  154 + include NoosferoTestHelper
  155 +
  156 +end
... ...
plugins/people_block/test/unit/members_block_test.rb 0 → 100644
... ... @@ -0,0 +1,252 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class MembersBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, MembersBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, MembersBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, MembersBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = MembersBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = MembersBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = MembersBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = MembersBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = MembersBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = MembersBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = MembersBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert MembersBlock.new.prioritize_people_with_image
  64 + end
  65 +
  66 +
  67 + should 'respect limit when listing members' do
  68 + community = fast_create(Community)
  69 + p1 = fast_create(Person)
  70 + p2 = fast_create(Person)
  71 + p3 = fast_create(Person)
  72 + p4 = fast_create(Person)
  73 +
  74 + community.add_member(p1)
  75 + community.add_member(p2)
  76 + community.add_member(p3)
  77 + community.add_member(p4)
  78 +
  79 + block = MembersBlock.new(:limit => 3)
  80 + block.stubs(:owner).returns(community)
  81 +
  82 + assert_equal 3, block.profile_list.size
  83 + end
  84 +
  85 +
  86 + should 'accept a limit of members to be displayed' do
  87 + block = MembersBlock.new
  88 + block.limit = 20
  89 + assert_equal 20, block.limit
  90 + end
  91 +
  92 +
  93 + should 'list members from community' do
  94 + owner = fast_create(Community)
  95 + person1 = fast_create(Person)
  96 + person2 = fast_create(Person)
  97 + owner.add_member(person1)
  98 + owner.add_member(person2)
  99 +
  100 + block = MembersBlock.new
  101 +
  102 + block.expects(:owner).returns(owner).at_least_once
  103 + expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  104 + expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  105 + expects(:block_title).with(anything).returns('')
  106 +
  107 + content = instance_eval(&block.content)
  108 +
  109 + assert_match(/#{person1.name}/, content)
  110 + assert_match(/#{person2.name}/, content)
  111 + end
  112 +
  113 + should 'count number of public and private members' do
  114 + owner = fast_create(Community)
  115 + private_p = fast_create(Person, {:public_profile => false})
  116 + public_p = fast_create(Person, {:public_profile => true})
  117 +
  118 + owner.add_member(private_p)
  119 + owner.add_member(public_p)
  120 +
  121 + block = MembersBlock.new
  122 + block.expects(:owner).returns(owner).at_least_once
  123 +
  124 + assert_equal 2, block.profile_count
  125 + end
  126 +
  127 +
  128 + should 'not count number of invisible members' do
  129 + owner = fast_create(Community)
  130 + private_p = fast_create(Person, {:visible => false})
  131 + public_p = fast_create(Person, {:visible => true})
  132 +
  133 + owner.add_member(private_p)
  134 + owner.add_member(public_p)
  135 +
  136 + block = MembersBlock.new
  137 + block.expects(:owner).returns(owner).at_least_once
  138 +
  139 + assert_equal 1, block.profile_count
  140 + end
  141 +
  142 + should 'provide link to members page without a visible_role selected' do
  143 + profile = create_user('mytestuser').person
  144 + block = MembersBlock.new
  145 + block.box = profile.boxes.first
  146 + block.save!
  147 +
  148 + expects(:_).with('View all').returns('View all')
  149 + expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'people_block_plugin_profile', :action => 'members', :role_key => block.visible_role).returns('link-to-members')
  150 +
  151 + assert_equal 'link-to-members', instance_eval(&block.footer)
  152 + end
  153 +
  154 + should 'provide link to members page with a selected role' do
  155 + profile = create_user('mytestuser').person
  156 + block = MembersBlock.new
  157 + block.box = profile.boxes.first
  158 + block.visible_role = 'profile_member'
  159 + block.save!
  160 +
  161 + expects(:_).with('View all').returns('View all')
  162 + expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'people_block_plugin_profile', :action => 'members', :role_key => block.visible_role).returns('link-to-members')
  163 +
  164 + assert_equal 'link-to-members', instance_eval(&block.footer)
  165 + end
  166 +
  167 + should 'provide a role to be displayed (and default to nil)' do
  168 + env = fast_create(Environment)
  169 + env.boxes << Box.new
  170 + block = MembersBlock.new
  171 + assert_equal nil, block.visible_role
  172 + env.boxes.first.blocks << block
  173 + block.visible_role = 'profile_member'
  174 + block.save!
  175 + assert_equal 'profile_member', block.visible_role
  176 + end
  177 +
  178 + should 'list all members' do
  179 + env = fast_create(Environment)
  180 + env.boxes << Box.new
  181 + profile1 = fast_create(Person, :environment_id => env.id)
  182 + profile2 = fast_create(Person, :environment_id => env.id)
  183 +
  184 + block = MembersBlock.new
  185 + owner = fast_create(Community)
  186 + block.stubs(:owner).returns(owner)
  187 + env.boxes.first.blocks << block
  188 + block.save!
  189 +
  190 + owner.add_member profile1
  191 + owner.add_member profile2
  192 + profiles = block.profiles
  193 +
  194 + assert_includes profiles, profile1
  195 + assert_includes profiles, profile2
  196 + end
  197 +
  198 + should 'list only profiles with moderator role' do
  199 + env = fast_create(Environment)
  200 + env.boxes << Box.new
  201 + profile1 = fast_create(Person, :environment_id => env.id)
  202 + profile2 = fast_create(Person, :environment_id => env.id)
  203 +
  204 + block = MembersBlock.new
  205 + owner = fast_create(Community)
  206 + block.visible_role = Profile::Roles.moderator(owner.environment.id).key
  207 + block.stubs(:owner).returns(owner)
  208 + env.boxes.first.blocks << block
  209 + block.save!
  210 +
  211 + owner.add_member profile2
  212 + owner.add_moderator profile1
  213 + profiles = block.profiles
  214 +
  215 + assert_includes profiles, profile1
  216 + assert_not_includes profiles, profile2
  217 + end
  218 +
  219 + should 'list only profiles with member role' do
  220 + env = fast_create(Environment)
  221 + env.boxes << Box.new
  222 + profile1 = fast_create(Person, :environment_id => env.id)
  223 + profile2 = fast_create(Person, :environment_id => env.id)
  224 +
  225 + block = MembersBlock.new
  226 + owner = fast_create(Community)
  227 + block.visible_role = Profile::Roles.member(owner.environment.id).key
  228 + block.stubs(:owner).returns(owner)
  229 + env.boxes.first.blocks << block
  230 + block.save!
  231 +
  232 + owner.add_member profile2
  233 + owner.add_moderator profile1
  234 + profiles = block.profiles
  235 +
  236 + assert_not_includes profiles, profile1
  237 + assert_includes profiles, profile2
  238 + end
  239 +
  240 + should 'list available roles' do
  241 + block = MembersBlock.new
  242 + owner = fast_create(Community)
  243 + block.stubs(:owner).returns(owner)
  244 + assert_includes block.roles, Profile::Roles.member(owner.environment.id)
  245 + assert_includes block.roles, Profile::Roles.admin(owner.environment.id)
  246 + assert_includes block.roles, Profile::Roles.moderator(owner.environment.id)
  247 + end
  248 +
  249 + protected
  250 + include NoosferoTestHelper
  251 +
  252 +end
... ...
plugins/people_block/test/unit/people_block_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class PeopleBlockPluginTest < ActiveSupport::TestCase
  4 +
  5 + should "return PeopleBlock in extra_blocks class method" do
  6 + assert PeopleBlockPlugin.extra_blocks.keys.include?(PeopleBlock)
  7 + end
  8 +
  9 + should "return MembersBlock in extra_blocks class method" do
  10 + assert PeopleBlockPlugin.extra_blocks.keys.include?(MembersBlock)
  11 + end
  12 +
  13 + should "return FriendsBlock in extra_blocks class method" do
  14 + assert PeopleBlockPlugin.extra_blocks.keys.include?(FriendsBlock)
  15 + end
  16 +
  17 + should "return false for class method has_admin_url?" do
  18 + assert !PeopleBlockPlugin.has_admin_url?
  19 + end
  20 +
  21 + should "return false for class method stylesheet?" do
  22 + assert PeopleBlockPlugin.new.stylesheet?
  23 + end
  24 +
  25 +end
... ...
plugins/people_block/test/unit/people_block_test.rb 0 → 100644
... ... @@ -0,0 +1,146 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class PeopleBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, PeopleBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, PeopleBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, PeopleBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = PeopleBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = PeopleBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = PeopleBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = PeopleBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = PeopleBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = PeopleBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = PeopleBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert PeopleBlock.new.prioritize_profiles_with_image
  64 + end
  65 +
  66 +
  67 + should 'respect limit when listing people' do
  68 + env = fast_create(Environment)
  69 + p1 = fast_create(Person, :environment_id => env.id)
  70 + p2 = fast_create(Person, :environment_id => env.id)
  71 + p3 = fast_create(Person, :environment_id => env.id)
  72 + p4 = fast_create(Person, :environment_id => env.id)
  73 +
  74 + block = PeopleBlock.new(:limit => 3)
  75 + block.stubs(:owner).returns(env)
  76 +
  77 + assert_equal 3, block.profile_list.size
  78 + end
  79 +
  80 +
  81 + should 'accept a limit of people to be displayed' do
  82 + block = PeopleBlock.new
  83 + block.limit = 20
  84 + assert_equal 20, block.limit
  85 + end
  86 +
  87 +
  88 + should 'list people from environment' do
  89 + owner = fast_create(Environment)
  90 + person1 = fast_create(Person, :environment_id => owner.id)
  91 + person2 = fast_create(Person, :environment_id => owner.id)
  92 +
  93 + block = PeopleBlock.new
  94 +
  95 + block.expects(:owner).returns(owner).at_least_once
  96 + expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  97 + expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  98 + expects(:block_title).with(anything).returns('')
  99 +
  100 + content = instance_exec(&block.content)
  101 +
  102 + assert_match(/#{person1.name}/, content)
  103 + assert_match(/#{person2.name}/, content)
  104 + end
  105 +
  106 +
  107 + should 'link to "all people"' do
  108 + env = fast_create(Environment)
  109 +
  110 + block = PeopleBlock.new
  111 +
  112 + stubs(:_).with('View all').returns('View all')
  113 + stubs(:link_to).returns('link-to-people')
  114 + stubs(:url_for).returns(' ')
  115 +
  116 + assert_equal 'link-to-people', instance_exec(&block.footer)
  117 + end
  118 +
  119 +
  120 + should 'count number of public and private people' do
  121 + owner = fast_create(Environment)
  122 + private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id)
  123 + public_p = fast_create(Person, :public_profile => true, :environment_id => owner.id)
  124 +
  125 + block = PeopleBlock.new
  126 + block.expects(:owner).returns(owner).at_least_once
  127 +
  128 + assert_equal 2, block.profile_count
  129 + end
  130 +
  131 +
  132 + should 'not count number of invisible people' do
  133 + owner = fast_create(Environment)
  134 + private_p = fast_create(Person, :visible => false, :environment_id => owner.id)
  135 + public_p = fast_create(Person, :visible => true, :environment_id => owner.id)
  136 +
  137 + block = PeopleBlock.new
  138 + block.expects(:owner).returns(owner).at_least_once
  139 +
  140 + assert_equal 1, block.profile_count
  141 + end
  142 +
  143 + protected
  144 + include NoosferoTestHelper
  145 +
  146 +end
... ...
plugins/people_block/views/blocks/friends.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %>
... ...
plugins/people_block/views/blocks/members.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<%= link_to _('View all'), {:profile => profile.identifier, :controller => 'people_block_plugin_profile', :action => 'members', :role_key => role_key}, :class => 'view-all' %>
  2 +
  3 +<% if show_join_leave_button %>
  4 + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %>
  5 +<% end %>
... ...
plugins/people_block/views/blocks/people.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= link_to _('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %>
... ...
plugins/people_block/views/box_organizer/_people_block_base.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<%= labelled_form_field _('Name:'), text_field(:block, :name) %>
  2 +
  3 +<%= labelled_form_field _('Address:'), text_field(:block, :address) %>
  4 +
  5 +<% if @block.kind_of?(MembersBlock) %>
  6 + <%= labelled_form_field _('Filter by role:'), '' %>
  7 + <%= select_tag 'block[visible_role]', options_for_select(@block.roles.map{|r| [r.name, r.key]}.insert(0,''), @block.visible_role) %>
  8 +<% end %>
  9 +
  10 +<%= render :partial => 'profile_list_block' %>
... ...
plugins/people_block/views/environment_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer
0 2 \ No newline at end of file
... ...
plugins/people_block/views/profile_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer
0 2 \ No newline at end of file
... ...
plugins/piwik/controllers/piwik_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class PiwikPluginAdminController < AdminController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../views')
  4 +
  5 + def index
  6 + if request.post?
  7 + if @environment.update_attributes(params[:environment])
  8 + session[:notice] = _('Piwik plugin settings updated successfully.')
  9 + else
  10 + session[:notice] = _('Piwik plugin settings could not be saved.')
  11 + end
  12 + redirect_to :controller => 'plugins', :action => 'index'
  13 + end
  14 + end
  15 +
  16 +end
... ...
plugins/piwik/lib/ext/environment.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +require_dependency 'environment'
  2 +
  3 +class Environment
  4 + settings_items :piwik_domain
  5 + settings_items :piwik_site_id
  6 + attr_accessible :piwik_domain, :piwik_site_id
  7 +end
... ...
plugins/piwik/lib/piwik_plugin.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +class PiwikPlugin < Noosfero::Plugin
  2 +
  3 + include ActionView::Helpers::JavaScriptHelper
  4 + include ActionView::Helpers::FormHelper
  5 + include ActionView::Helpers::UrlHelper
  6 + include ActionView::Helpers::TagHelper
  7 +
  8 + def self.plugin_name
  9 + "Piwik"
  10 + end
  11 +
  12 + def self.plugin_description
  13 + _("Tracking and web analytics to your Noosfero's environment")
  14 + end
  15 +
  16 + def body_ending
  17 + domain = context.environment.piwik_domain
  18 + site_id = context.environment.piwik_site_id
  19 + unless domain.blank? || site_id.blank?
  20 + expanded_template('tracking-code.rhtml',{:domain => domain, :site_id => site_id})
  21 + end
  22 + end
  23 +
  24 +end
... ...
plugins/piwik/test/functional/piwik_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/piwik_plugin_admin_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class PiwikPluginAdminController; def rescue_action(e) raise e end; end
  6 +
  7 +class PiwikPluginAdminControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @environment = Environment.default
  11 + user_login = create_admin_user(@environment)
  12 + login_as(user_login)
  13 + @environment.enabled_plugins = ['PiwikPlugin']
  14 + @environment.save!
  15 + end
  16 +
  17 + should 'access index action' do
  18 + get :index
  19 + assert_template 'index'
  20 + assert_response :success
  21 + end
  22 +
  23 + should 'update piwik plugin settings' do
  24 + assert_nil @environment.reload.piwik_domain
  25 + assert_nil @environment.reload.piwik_site_id
  26 + post :index, :environment => { :piwik_domain => 'http://something', :piwik_site_id => 10 }
  27 + assert_not_nil @environment.reload.piwik_domain
  28 + assert_not_nil @environment.reload.piwik_site_id
  29 + end
  30 +
  31 +end
... ...
plugins/piwik/test/unit/piwik_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class PiwikPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @plugin = PiwikPlugin.new
  7 + @context = mock()
  8 + @plugin.context = @context
  9 + @environment = Environment.new
  10 + @context.stubs(:environment).returns(@environment)
  11 + end
  12 +
  13 + should 'add content at the body ending unless domain and site_id are blank' do
  14 + @environment.piwik_domain = 'piwik.domain.example.com'
  15 + @environment.piwik_site_id = 5
  16 + @plugin.stubs(:expanded_template).returns('content')
  17 + assert_equal 'content', @plugin.body_ending
  18 + end
  19 +
  20 + should 'not add any content at the body ending if domain is blank' do
  21 + @environment.piwik_domain = nil
  22 + @environment.piwik_site_id = 5
  23 + @plugin.stubs(:expanded_template).returns('content')
  24 + assert_equal nil, @plugin.body_ending
  25 + end
  26 +
  27 + should 'not add any content at the body ending if site_id is blank' do
  28 + @environment.piwik_domain = 'piwik.domain.example.com'
  29 + @environment.piwik_site_id = nil
  30 + @plugin.stubs(:expanded_template).returns('content')
  31 + assert_equal nil, @plugin.body_ending
  32 + end
  33 +
  34 + should 'extends Environment with attr piwik_domain' do
  35 + assert_respond_to Environment.new, :piwik_domain
  36 + end
  37 +
  38 + should 'extends Environment with attr piwik_site_id' do
  39 + assert_respond_to Environment.new, :piwik_site_id
  40 + end
  41 +
  42 +end
... ...
plugins/piwik/views/piwik_plugin_admin/index.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<h1><%= _("Piwik plugin settings") %></h1>
  2 +
  3 +<%= form_for(:environment) do |f| %>
  4 +
  5 + <%= labelled_form_field _('Piwik domain'), f.text_field(:piwik_domain) %>
  6 +
  7 + <%= labelled_form_field _('Piwik site id'), f.text_field(:piwik_site_id) %>
  8 +
  9 + <% button_bar do %>
  10 + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
  11 + <% end %>
  12 +
  13 +<% end %>
... ...
plugins/piwik/views/tracking-code.rhtml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<!-- Piwik -->
  2 +<script type="text/javascript">
  3 + var _paq = _paq || [];
  4 + _paq.push(['trackPageView']);
  5 + _paq.push(['enableLinkTracking']);
  6 + (function() {
  7 + var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= escape_javascript locals[:domain] %>/piwik/";
  8 + _paq.push(['setTrackerUrl', u+'piwik.php']);
  9 + _paq.push(['setSiteId', <%= escape_javascript locals[:site_id] %>]);
  10 + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
  11 + g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  12 + })();
  13 +</script>
  14 +<noscript><p><img src="http://<%= escape_javascript locals[:domain] %>/piwik/piwik.php?idsite=<%= escape_javascript locals[:site_id] %>" style="border:0;" alt="" /></p></noscript>
  15 +<!-- End Piwik Code -->
... ...
plugins/require_auth_to_comment/lib/ext/profile.rb
... ... @@ -2,4 +2,5 @@ require_dependency &#39;profile&#39;
2 2  
3 3 class Profile
4 4 settings_items :allow_unauthenticated_comments, :type => :boolean
  5 + attr_accessible :allow_unauthenticated_comments
5 6 end
... ...
plugins/video/lib/video_block.rb
1 1 class VideoBlock < Block
2 2  
  3 + attr_accessible :url, :width, :height
  4 +
3 5 settings_items :url, :type => :string, :default => ""
4 6 settings_items :width, :type => :integer, :default => 400
5 7 settings_items :height, :type => :integer, :default => 315
6 8  
  9 + YOUTUBE_ID_FORMAT = '\w-'
  10 +
7 11 def is_youtube?
8   - url.match(/.*(youtube.com.*v=[[:alnum:]]+|youtu.be\/[[:alnum:]]+).*/) ? true : false
  12 + url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false
9 13 end
10 14  
11 15 def is_vimeo?
... ... @@ -44,8 +48,8 @@ class VideoBlock &lt; Block
44 48  
45 49 def extract_youtube_id
46 50 return nil unless is_youtube?
47   - youtube_match = url.match('v=([[:alnum:]]*)')
48   - youtube_match ||= url.match('youtu.be\/([[:alnum:]]*)')
  51 + youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)")
  52 + youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)")
49 53 youtube_match[1] unless youtube_match.nil?
50 54 end
51 55  
... ...
plugins/video/test/unit/video_block_test.rb
... ... @@ -70,6 +70,13 @@ class VideoBlockTest &lt; ActiveSupport::TestCase
70 70 assert_equal id, block.send('extract_youtube_id')
71 71 end
72 72  
  73 + should "extract youtube id from youtube video url's if it has underline and hyphen" do
  74 + block = VideoBlock.new
  75 + id = 'oi43_re-d2'
  76 + block.url = "youtube.com/?v=#{id}"
  77 + assert_equal id, block.send('extract_youtube_id')
  78 + end
  79 +
73 80 should "extract youtube id from youtube video url's if it's a valid youtube short url" do
74 81 block = VideoBlock.new
75 82 id = 'oi43jre2d2'
... ...
public/designs/themes/base/style.css
... ... @@ -478,12 +478,9 @@ div#notice {
478 478  
479 479 /************************** Profile List *****************************/
480 480  
481   -#content .people-block ul,
482 481 #content .profile-list-block ul,
483 482 #content .enterprises-block ul,
484   -#content .members-block ul,
485 483 #content .communities-block ul,
486   -#content .friends-block ul,
487 484 #content .fans-block ul {
488 485 min-width: 196px;
489 486 width: 192px;
... ... @@ -491,24 +488,18 @@ div#notice {
491 488 padding: 0px;
492 489 }
493 490  
494   -#content .box-1 .people-block ul,
495 491 #content .box-1 .profile-list-block ul,
496 492 #content .box-1 .enterprises-block ul,
497   -#content .box-1 .members-block ul,
498 493 #content .box-1 .communities-block ul,
499   -#content .box-1 .friends-block ul,
500 494 #content .box-1 .fans-block ul {
501 495 width: auto;
502 496 display: block;
503 497 }
504 498  
505 499 #content .tags-block .block-footer-content a,
506   -#content .people-block .block-footer-content a,
507 500 #content .profile-list-block .block-footer-content a,
508 501 #content .enterprises-block .block-footer-content a,
509   -#content .members-block .block-footer-content a,
510   -#content .communities-block .block-footer-content a,
511   -#content .friends-block .block-footer-content a {
  502 +#content .communities-block .block-footer-content a {
512 503 position: absolute;
513 504 top: 2px;
514 505 right: 0px;
... ... @@ -518,29 +509,12 @@ div#notice {
518 509 padding-right: 15px;
519 510 }
520 511 #content .tags-block .block-footer-content a,
521   -#content .people-block .block-footer-content a,
522 512 #content .profile-list-block .block-footer-content a,
523 513 #content .enterprises-block .block-footer-content a,
524   -#content .communities-block .block-footer-content a,
525   -#content .friends-block .block-footer-content a {
  514 +#content .communities-block .block-footer-content a {
526 515 background: url(imgs/arrow-right-p.png) 100% 50% no-repeat;
527 516 }
528 517  
529   -#content .members-block .block-footer-content .join-leave-button a {
530   - position: relative;
531   - background-color: #EEE;
532   - border: 1px solid #CCC;
533   - color: #555;
534   - padding-right: inherit;
535   -}
536   -
537   -#content .members-block .block-footer-content .join-leave-button a:hover {
538   - color: #FFF;
539   - background-color: #555;
540   - border: 1px solid #2e3436;
541   - text-decoration: none;
542   -}
543   -
544 518 #content .profile-list-block .block-title {
545 519 text-align: left;
546 520 }
... ...
public/plugins/people_block 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../plugins/people_block/public
0 2 \ No newline at end of file
... ...
script/noosfero-plugins
... ... @@ -76,7 +76,8 @@ run(){
76 76  
77 77 _enable(){
78 78 plugin="$1"
79   - source="$available_plugins_dir/$plugin"
  79 + cd $enabled_plugins_dir
  80 + source="../../plugins/$plugin"
80 81 target="$enabled_plugins_dir/$plugin"
81 82 run "$source/before_enable.rb"
82 83 if [ -h "$target" ]; then
... ... @@ -98,11 +99,13 @@ _enable(){
98 99 fi
99 100 fi
100 101 if [ "$installation_ok" = true ] && [ "$dependencies_ok" = true ]; then
101   - ln -s "$source" "$target"
  102 + ln -s "$source" "$plugin"
102 103 plugins_public_dir="$NOOSFERO_DIR/public/plugins"
103 104 plugins_features_dir="$NOOSFERO_DIR/features/plugins"
104   - test -d "$target/public/" && ln -s "$target/public" "$plugins_public_dir/$plugin"
105   - test -d "$NOOSFERO_DIR/features" && test -d "$target/features" && ln -s "$target/features" "$plugins_features_dir/$plugin"
  105 + cd $plugins_public_dir
  106 + test -d "$source/public" && ln -s "$source/public" "$plugin"
  107 + cd $plugins_features_dir
  108 + test -d "$NOOSFERO_DIR/features" && test -d "$source/features" && ln -s "$source/features" "$plugin"
106 109 _say "$plugin enabled"
107 110 run "$source/after_enable.rb"
108 111 needs_migrate=true
... ... @@ -122,15 +125,19 @@ _disable(){
122 125 target="$enabled_plugins_dir/$plugin"
123 126 plugins_public_dir="$NOOSFERO_DIR/public/plugins"
124 127 plugins_features_dir="$NOOSFERO_DIR/features/plugins"
125   - run "$source/before_disable.rb"
126   - if [ -h "$target" ]; then
127   - rm "$target"
128   - test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin"
129   - test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin"
130   - _say "$plugin disabled"
131   - run "$source/after_disable.rb"
  128 + if ! run "$source/before_disable.rb"; then
  129 + echo "W: failed to disabling $plugin"
  130 + echo
132 131 else
133   - _say "$plugin already disabled"
  132 + if [ -h "$target" ]; then
  133 + rm "$target"
  134 + test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin"
  135 + test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin"
  136 + _say "$plugin disabled"
  137 + run "$source/after_disable.rb"
  138 + else
  139 + _say "$plugin already disabled"
  140 + fi
134 141 fi
135 142 }
136 143  
... ...
test/functional/account_controller_test.rb
... ... @@ -21,14 +21,6 @@ class AccountControllerTest &lt; ActionController::TestCase
21 21 disable_signup_bot_check
22 22 end
23 23  
24   - def test_local_files_reference
25   - assert_local_files_reference
26   - end
27   -
28   - def test_valid_xhtml
29   - assert_valid_xhtml
30   - end
31   -
32 24 def test_should_login_and_redirect
33 25 post :login, :user => {:login => 'johndoe', :password => 'test'}
34 26 assert session[:user]
... ...
test/functional/admin_panel_controller_test.rb
... ... @@ -14,14 +14,6 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
14 14 login_as(create_admin_user(Environment.default))
15 15 end
16 16  
17   - def test_local_files_reference
18   - assert_local_files_reference
19   - end
20   -
21   - def test_valid_xhtml
22   - assert_valid_xhtml
23   - end
24   -
25 17 should 'manage the correct environment' do
26 18 current = fast_create(Environment, :name => 'test environment', :is_default => false)
27 19 current.domains.create!(:name => 'example.com')
... ... @@ -73,6 +65,7 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
73 65 assert_tag :tag => 'textarea', :attributes => { :name => 'environment[terms_of_use]'}
74 66 assert_tag :tag => 'input', :attributes => { :name => 'environment[signup_welcome_text_subject]'}
75 67 assert_tag :tag => 'textarea', :attributes => { :name => 'environment[signup_welcome_text_body]'}
  68 + assert_tag :tag => 'textarea', :attributes => { :name => 'environment[signup_welcome_screen_body]'}
76 69 end
77 70  
78 71 should 'display form for editing message for disabled enterprise' do
... ... @@ -381,4 +374,13 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
381 374 assert_not_includes environment.languages, 'en'
382 375 end
383 376  
  377 + should 'save body of signup welcome screen' do
  378 + body = "This is my welcome body"
  379 + post :site_info, :environment => { :signup_welcome_screen_body => body }
  380 + assert_redirected_to :action => 'index'
  381 +
  382 + assert_equal body, Environment.default.signup_welcome_screen_body
  383 + assert !Environment.default.signup_welcome_screen_body.blank?
  384 + end
  385 +
384 386 end
... ...
test/functional/application_controller_test.rb
... ... @@ -60,14 +60,6 @@ class ApplicationControllerTest &lt; ActionController::TestCase
60 60 end
61 61  
62 62  
63   - def test_local_files_reference
64   - assert_local_files_reference
65   - end
66   -
67   - def test_valid_xhtml
68   - assert_valid_xhtml
69   - end
70   -
71 63 def test_exist_environment_variable_to_helper_environment_identification
72 64 get :index
73 65 assert_not_nil assigns(:environment)
... ...
test/functional/catalog_controller_test.rb
... ... @@ -16,14 +16,6 @@ class CatalogControllerTest &lt; ActionController::TestCase
16 16 end
17 17 attr_accessor :enterprise
18 18  
19   - def test_local_files_reference
20   - assert_local_files_reference :get, :index, :profile => @enterprise.identifier
21   - end
22   -
23   - def test_valid_xhtml
24   - assert_valid_xhtml
25   - end
26   -
27 19 should 'not display for non-enterprises' do
28 20 u = create_user('testinguser').person
29 21 get :index, :profile => 'testinguser'
... ...
test/functional/categories_controller_test.rb
... ... @@ -20,14 +20,6 @@ class CategoriesControllerTest &lt; ActionController::TestCase
20 20  
21 21 attr_reader :env, :cat1, :cat2
22 22  
23   - def test_local_files_reference
24   - assert_local_files_reference
25   - end
26   -
27   - def test_valid_xhtml
28   - assert_valid_xhtml
29   - end
30   -
31 23 def test_index
32 24 login_as(create_admin_user(Environment.default))
33 25 get :index
... ...
test/functional/cms_controller_test.rb
... ... @@ -18,14 +18,6 @@ class CmsControllerTest &lt; ActionController::TestCase
18 18  
19 19 attr_reader :profile
20 20  
21   - def test_local_files_reference
22   - assert_local_files_reference :get, :index, :profile => profile.identifier
23   - end
24   -
25   - def test_valid_xhtml
26   - assert_valid_xhtml
27   - end
28   -
29 21 should 'list top level documents on index' do
30 22 get :index, :profile => profile.identifier
31 23  
... ... @@ -1228,7 +1220,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1228 1220 should 'allow user edit article if he is owner and has publish permission' do
1229 1221 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
1230 1222 u = create_user_with_permission('test_user', 'publish_content', c)
1231   - a = create(Article, :profile => c, :name => 'test_article', :last_changed_by => u)
  1223 + a = create(Article, :profile => c, :name => 'test_article', :created_by => u)
1232 1224 login_as :test_user
1233 1225 @controller.stubs(:user).returns(u)
1234 1226  
... ... @@ -1774,6 +1766,31 @@ class CmsControllerTest &lt; ActionController::TestCase
1774 1766 assert_equal 'first version', Article.find(article.id).name
1775 1767 end
1776 1768  
  1769 + should 'set created_by when creating article' do
  1770 + login_as(profile.identifier)
  1771 +
  1772 + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' }
  1773 +
  1774 + a = profile.articles.find_by_path('changed-by-me')
  1775 + assert_not_nil a
  1776 + assert_equal profile, a.created_by
  1777 + end
  1778 +
  1779 + should 'not change created_by when updating article' do
  1780 + other_person = create_user('otherperson').person
  1781 +
  1782 + a = profile.articles.build(:name => 'my article')
  1783 + a.created_by = other_person
  1784 + a.save!
  1785 +
  1786 + login_as(profile.identifier)
  1787 + post :edit, :profile => profile.identifier, :id => a.id, :article => { :body => 'new content for this article' }
  1788 +
  1789 + a.reload
  1790 +
  1791 + assert_equal other_person, a.created_by
  1792 + end
  1793 +
1777 1794 protected
1778 1795  
1779 1796 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -18,16 +18,6 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
18 18 end
19 19 attr_reader :profile, :environment
20 20  
21   - def test_local_files_reference
22   - page = profile.articles.build(:name => 'test')
23   - page.save!
24   - assert_local_files_reference :get, :view_page, :profile => profile.identifier, :page => [ 'test' ]
25   - end
26   -
27   - def test_valid_xhtml
28   - assert_valid_xhtml
29   - end
30   -
31 21 def test_should_display_page
32 22 page = profile.articles.build(:name => 'test')
33 23 page.save!
... ... @@ -743,7 +733,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
743 733 c = Community.create!(:name => 'test_com')
744 734 u = create_user_with_permission('test_user', 'publish_content', c)
745 735 login_as u.identifier
746   - a = create(Article, :profile => c, :name => 'test-article', :last_changed_by => u, :published => false)
  736 + a = create(Article, :profile => c, :name => 'test-article', :created_by => u, :published => false)
747 737  
748 738 get :view_page, :profile => c.identifier, :page => a.path
749 739  
... ...
test/functional/edit_template_controller_test.rb
... ... @@ -15,14 +15,6 @@ class EditTemplateControllerTest &lt; ActionController::TestCase
15 15 login_as 'ze'
16 16 end
17 17  
18   - def test_local_files_reference
19   - assert_local_files_reference
20   - end
21   -
22   - def test_valid_xhtml
23   - assert_valid_xhtml
24   - end
25   -
26 18 def test_redirect_to_design_editor_when_index_action_is_called
27 19 give_permission('ze', 'edit_environment_design', Environment.default)
28 20 get :index
... ...
test/functional/enterprise_registration_controller_test.rb
... ... @@ -17,14 +17,6 @@ class EnterpriseRegistrationControllerTest &lt; ActionController::TestCase
17 17 login_as 'ze'
18 18 end
19 19  
20   - def test_local_files_reference
21   - assert_local_files_reference
22   - end
23   -
24   - def test_valid_xhtml
25   - assert_valid_xhtml
26   - end
27   -
28 20 should 'go to the first step on index' do
29 21 get :index
30 22 assert_response :success
... ...
test/functional/enterprise_validation_controller_test.rb
... ... @@ -19,18 +19,6 @@ class EnterpriseValidationControllerTest &lt; ActionController::TestCase
19 19 Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
20 20 end
21 21  
22   - def test_local_files_reference
23   - assert_local_files_reference :get, :index, :profile => 'myorg'
24   - end
25   -
26   - def test_valid_xhtml
27   -
28   - # FIXME remove this after enable assert_valid_xhtml
29   - Profile.find_by_identifier('myorg')
30   -
31   - assert_valid_xhtml :get, :index, :profile => 'myorg'
32   - end
33   -
34 22 should 'list pending validations on index' do
35 23 empty = []
36 24 @org.expects(:pending_validations).returns(empty)
... ...
test/functional/environment_design_controller_test.rb
... ... @@ -8,7 +8,7 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
8 8  
9 9 # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from
10 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 ]
  11 + ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
12 12  
13 13 def setup
14 14 @controller = EnvironmentDesignController.new
... ... @@ -17,14 +17,6 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
17 17 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
18 18 end
19 19  
20   - def test_local_files_reference
21   - assert_local_files_reference
22   - end
23   -
24   - def test_valid_xhtml
25   - assert_valid_xhtml
26   - end
27   -
28 20 should 'indicate only actual blocks as such' do
29 21 assert(@controller.available_blocks.all? {|item| item.new.is_a? Block})
30 22 end
... ... @@ -107,16 +99,6 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
107 99 assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
108 100 end
109 101  
110   - should 'be able to edit PeopleBlock' do
111   - login_as(create_admin_user(Environment.default))
112   - b = PeopleBlock.create!
113   - e = Environment.default
114   - e.boxes.create!
115   - e.boxes.first.blocks << b
116   - get :edit, :id => b.id
117   - assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
118   - end
119   -
120 102 should 'be able to edit SlideshowBlock' do
121 103 login_as(create_admin_user(Environment.default))
122 104 b = SlideshowBlock.create!
... ...