Commit 099313773408999b45f37f7e9af66d99a52dfade

Authored by Daniela Feitosa
2 parents 011db1bb ed2a58fd

Merge commit 'refs/merge-requests/167' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/167
app/controllers/my_profile/cms_controller.rb
@@ -15,42 +15,21 @@ class CmsController < MyProfileController @@ -15,42 +15,21 @@ class CmsController < MyProfileController
15 end 15 end
16 16
17 before_filter :login_required, :except => [:suggest_an_article] 17 before_filter :login_required, :except => [:suggest_an_article]
  18 +
18 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile| 19 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile|
19 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) 20 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))
20 end 21 end
21 22
22 - protect_if :only => [:edit, :destroy, :publish] do |c, user, profile| 23 + protect_if :only => [:destroy, :publish] do |c, user, profile|
23 profile.articles.find(c.params[:id]).allow_post_content?(user) 24 profile.articles.find(c.params[:id]).allow_post_content?(user)
24 end 25 end
25 26
26 - def boxes_holder  
27 - profile  
28 - end  
29 -  
30 - include CmsHelper  
31 -  
32 - def available_article_types  
33 - articles = [  
34 - TinyMceArticle,  
35 - TextileArticle,  
36 - Event  
37 - ]  
38 - articles += special_article_types if params && params[:cms]  
39 - parent_id = params ? params[:parent_id] : nil  
40 - if profile.enterprise?  
41 - articles << EnterpriseHomepage  
42 - end  
43 - if @parent && @parent.blog?  
44 - articles -= Article.folder_types.map(&:constantize)  
45 - end  
46 - if user.is_admin?(profile.environment)  
47 - articles << RawHTMLArticle  
48 - end  
49 - articles 27 + protect_if :only => :edit do |c,user,profile|
  28 + profile.articles.find(c.params[:id]).allow_edit?(user)
50 end 29 end
51 30
52 - def special_article_types  
53 - [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types) 31 + def boxes_holder
  32 + profile
54 end 33 end
55 34
56 def view 35 def view
@@ -303,6 +282,33 @@ class CmsController &lt; MyProfileController @@ -303,6 +282,33 @@ class CmsController &lt; MyProfileController
303 282
304 protected 283 protected
305 284
  285 + include CmsHelper
  286 +
  287 + def available_article_types
  288 + articles = [
  289 + TinyMceArticle,
  290 + TextileArticle,
  291 + Event
  292 + ]
  293 + articles += special_article_types if params && params[:cms]
  294 + parent_id = params ? params[:parent_id] : nil
  295 + if profile.enterprise?
  296 + articles << EnterpriseHomepage
  297 + end
  298 + if @parent && @parent.blog?
  299 + articles -= Article.folder_types.map(&:constantize)
  300 + end
  301 + if user.is_admin?(profile.environment)
  302 + articles << RawHTMLArticle
  303 + end
  304 + articles
  305 + end
  306 +
  307 + def special_article_types
  308 + [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types)
  309 + end
  310 +
  311 +
306 def record_coming 312 def record_coming
307 if request.post? 313 if request.post?
308 @back_to = params[:back_to] 314 @back_to = params[:back_to]
app/controllers/public/account_controller.rb
@@ -78,7 +78,12 @@ class AccountController &lt; ApplicationController @@ -78,7 +78,12 @@ class AccountController &lt; ApplicationController
78 invitation.update_attributes!({:friend => @user.person}) 78 invitation.update_attributes!({:friend => @user.person})
79 invitation.finish 79 invitation.finish
80 end 80 end
81 - @register_pending = true 81 + if @user.activated?
  82 + self.current_user = @user
  83 + redirect_to '/'
  84 + else
  85 + @register_pending = true
  86 + end
82 end 87 end
83 rescue ActiveRecord::RecordInvalid 88 rescue ActiveRecord::RecordInvalid
84 @person.valid? 89 @person.valid?
app/helpers/article_helper.rb
@@ -8,19 +8,32 @@ module ArticleHelper @@ -8,19 +8,32 @@ module ArticleHelper
8 'div', 8 'div',
9 check_box(:article, :published) + 9 check_box(:article, :published) +
10 content_tag('label', _('This article must be published (visible to other people)'), :for => 'article_published') 10 content_tag('label', _('This article must be published (visible to other people)'), :for => 'article_published')
11 - ) + (article.parent && article.parent.forum? && controller.action_name == 'new' ? 11 + ) +
  12 +
  13 + (article.profile.has_members? ?
  14 + content_tag(
  15 + 'div',
  16 + check_box(:article, :allow_members_to_edit) +
  17 + content_tag('label', _('Allow all members to edit this article'), :for => 'article_allow_members_to_edit')
  18 + ) :
  19 + '') +
  20 +
  21 + (article.parent && article.parent.forum? && controller.action_name == 'new' ?
12 hidden_field_tag('article[accept_comments]', 1) : 22 hidden_field_tag('article[accept_comments]', 1) :
13 content_tag( 23 content_tag(
14 'div', 24 'div',
15 check_box(:article, :accept_comments) + 25 check_box(:article, :accept_comments) +
16 content_tag('label', (article.parent && article.parent.forum? ? _('This topic is opened for replies') : _('I want to receive comments about this article')), :for => 'article_accept_comments') 26 content_tag('label', (article.parent && article.parent.forum? ? _('This topic is opened for replies') : _('I want to receive comments about this article')), :for => 'article_accept_comments')
17 )) + 27 )) +
  28 +
18 content_tag( 29 content_tag(
19 'div', 30 'div',
20 check_box(:article, :notify_comments) + 31 check_box(:article, :notify_comments) +
21 content_tag('label', _('I want to receive a notification of each comment written by e-mail'), :for => 'article_notify_comments') + 32 content_tag('label', _('I want to receive a notification of each comment written by e-mail'), :for => 'article_notify_comments') +
22 observe_field(:article_accept_comments, :function => "$('article_notify_comments').disabled = ! $('article_accept_comments').checked") 33 observe_field(:article_accept_comments, :function => "$('article_notify_comments').disabled = ! $('article_accept_comments').checked")
23 - ) + (article.can_display_hits? ? 34 + ) +
  35 +
  36 + (article.can_display_hits? ?
24 content_tag( 37 content_tag(
25 'div', 38 'div',
26 check_box(:article, :display_hits) + 39 check_box(:article, :display_hits) +
app/models/article.rb
@@ -26,6 +26,7 @@ class Article &lt; ActiveRecord::Base @@ -26,6 +26,7 @@ class Article &lt; ActiveRecord::Base
26 26
27 settings_items :display_hits, :type => :boolean, :default => true 27 settings_items :display_hits, :type => :boolean, :default => true
28 settings_items :author_name, :type => :string, :default => "" 28 settings_items :author_name, :type => :string, :default => ""
  29 + settings_items :allow_members_to_edit, :type => :boolean, :default => false
29 30
30 belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' 31 belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id'
31 32
@@ -408,6 +409,17 @@ class Article &lt; ActiveRecord::Base @@ -408,6 +409,17 @@ class Article &lt; ActiveRecord::Base
408 user && user.has_permission?('view_private_content', profile) 409 user && user.has_permission?('view_private_content', profile)
409 end 410 end
410 411
  412 + alias :allow_delete? :allow_post_content?
  413 + alias :allow_spread? :allow_post_content?
  414 +
  415 + def allow_create?(user)
  416 + allow_post_content?(user) || allow_publish_content?(user)
  417 + end
  418 +
  419 + def allow_edit?(user)
  420 + allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile)
  421 + end
  422 +
411 def comments_updated 423 def comments_updated
412 ferret_update 424 ferret_update
413 end 425 end
app/models/environment.rb
@@ -94,7 +94,6 @@ class Environment &lt; ActiveRecord::Base @@ -94,7 +94,6 @@ class Environment &lt; ActiveRecord::Base
94 'disable_asset_events' => _('Disable search for events'), 94 'disable_asset_events' => _('Disable search for events'),
95 'disable_products_for_enterprises' => __('Disable products for enterprises'), 95 'disable_products_for_enterprises' => __('Disable products for enterprises'),
96 'disable_categories' => _('Disable categories'), 96 'disable_categories' => _('Disable categories'),
97 - 'disable_cms' => _('Disable CMS'),  
98 'disable_header_and_footer' => _('Disable header/footer editing by users'), 97 'disable_header_and_footer' => _('Disable header/footer editing by users'),
99 'disable_gender_icon' => _('Disable gender icon'), 98 'disable_gender_icon' => _('Disable gender icon'),
100 'disable_categories_menu' => _('Disable the categories menu'), 99 'disable_categories_menu' => _('Disable the categories menu'),
@@ -122,6 +121,7 @@ class Environment &lt; ActiveRecord::Base @@ -122,6 +121,7 @@ class Environment &lt; ActiveRecord::Base
122 'xmpp_chat' => _('XMPP/Jabber based chat'), 121 'xmpp_chat' => _('XMPP/Jabber based chat'),
123 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), 122 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'),
124 'captcha_for_logged_users' => _('Ask captcha when a logged user comments too'), 123 'captcha_for_logged_users' => _('Ask captcha when a logged user comments too'),
  124 + 'skip_new_user_email_confirmation' => _('Skip e-mail confirmation for new users')
125 } 125 }
126 end 126 end
127 127
app/models/user.rb
@@ -35,6 +35,9 @@ class User &lt; ActiveRecord::Base @@ -35,6 +35,9 @@ class User &lt; ActiveRecord::Base
35 user.person.name ||= user.login 35 user.person.name ||= user.login
36 user.person.visible = false unless user.activated? 36 user.person.visible = false unless user.activated?
37 user.person.save! 37 user.person.save!
  38 + if user.environment && user.environment.enabled?('skip_new_user_email_confirmation')
  39 + user.activate
  40 + end
38 end 41 end
39 after_create :deliver_activation_code 42 after_create :deliver_activation_code
40 after_create :delay_activation_check 43 after_create :delay_activation_check
app/views/cms/_tiny_mce_article.rhtml
@@ -3,13 +3,7 @@ @@ -3,13 +3,7 @@
3 <%= render :file => 'shared/tiny_mce' %> 3 <%= render :file => 'shared/tiny_mce' %>
4 4
5 <div> 5 <div>
6 - <% if profile.enterprise? && environment.enabled?('disable_cms') && !@article.name.blank? %>  
7 - <div>  
8 - <%= _('Title') %>: <%= @article.name %>  
9 - </div>  
10 - <% else %>  
11 - <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>  
12 - <% end %> 6 + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
13 7
14 <%= render :partial => 'translatable' %> 8 <%= render :partial => 'translatable' %>
15 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> 9 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %>
app/views/content_viewer/_article_toolbar.rhtml
1 -<div<%= " class='logged-in'" if user %>> 1 +<div<%= user && " class='logged-in'" %>>
2 <div id="article-actions"> 2 <div id="article-actions">
3 - <% if @page.allow_post_content?(user) || @page.allow_publish_content?(user) %>  
4 - <% if @page.allow_post_content?(user) %>  
5 - <%= link_to content_tag( 'span', label_for_edit_article(@page) ),  
6 - profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }),  
7 - :class => 'button with-text icon-edit' %>  
8 - <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %>  
9 - <% if @page != profile.home_page && !@page.has_posts? %>  
10 - <%= link_to content_tag( 'span', _('Delete') ),  
11 - profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}),  
12 - :method => :post,  
13 - :class => 'button with-text icon-delete',  
14 - :confirm => delete_article_message(@page) %>  
15 - <% end %>  
16 - <% if !environment.enabled?('disable_cms') && !@page.folder? %>  
17 - <% if profile.kind_of?(Person) %>  
18 - <%= link_to content_tag( 'span', _('Spread this') ),  
19 - profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }),  
20 - :class => 'button with-text icon-spread' %>  
21 - <% elsif profile.kind_of?(Community) && environment.portal_community %>  
22 - <%= link_to content_tag( 'span', _('Spread this') ),  
23 - profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }),  
24 - :class => 'button with-text icon-spread' %>  
25 - <% end %>  
26 - <% end %>  
27 - <% end %>  
28 - <% end %>  
29 - <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %>  
30 - <% if !@page.gallery? %>  
31 - <%= link_to _('Add translation'),  
32 - profile.admin_url.merge(:controller => 'cms', :action => 'new',  
33 - :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)),  
34 - :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }),  
35 - :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %>  
36 - <%= lightbox_remote_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %>  
37 - <% end %>  
38 - <% end %>  
39 - <% if @page.accept_uploads? %>  
40 - <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> 3 +
  4 + <% if @page.allow_edit?(user) %>
  5 + <%= link_to content_tag( 'span', label_for_edit_article(@page) ),
  6 + profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }),
  7 + :class => 'button with-text icon-edit' %>
  8 + <% end %>
  9 +
  10 + <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) %>
  11 + <%= link_to content_tag( 'span', _('Delete') ),
  12 + profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}),
  13 + :method => :post,
  14 + :class => 'button with-text icon-delete',
  15 + :confirm => delete_article_message(@page) %>
  16 + <% end %>
  17 +
  18 + <% if !@page.folder? && @page.allow_spread?(user) %>
  19 + <% if profile.kind_of?(Person) %>
  20 + <%= link_to content_tag( 'span', _('Spread this') ),
  21 + profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }),
  22 + :class => 'button with-text icon-spread' %>
  23 + <% elsif profile.kind_of?(Community) && environment.portal_community %>
  24 + <%= link_to content_tag( 'span', _('Spread this') ),
  25 + profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }),
  26 + :class => 'button with-text icon-spread' %>
41 <% end %> 27 <% end %>
  28 + <% end %>
  29 +
  30 + <% if !@page.gallery? && @page.allow_create?(user) %>
  31 + <%= link_to _('Add translation'),
  32 + profile.admin_url.merge(:controller => 'cms', :action => 'new',
  33 + :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)),
  34 + :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }),
  35 + :class => @page.translatable? && !@page.native_translation.language.blank? && 'button with-text icon-locale' %>
  36 + <%= lightbox_remote_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %>
  37 + <% end %>
  38 +
  39 + <% if @page.accept_uploads? && @page.allow_create?(user) %>
  40 + <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %>
  41 + <% end %>
42 42
43 - <% elsif profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> 43 + <% if !@page.allow_create?(user) && profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %>
44 <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :id => 'suggest-article-link', :class => 'button with-text icon-new' %> 44 <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :id => 'suggest-article-link', :class => 'button with-text icon-new' %>
45 <% end %> 45 <% end %>
46 46
app/views/profile_editor/index.rhtml
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 26
27 <%= control_panel_button(_('Edit Header and Footer'), 'header-and-footer', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin?(environment) %> 27 <%= control_panel_button(_('Edit Header and Footer'), 'header-and-footer', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin?(environment) %>
28 28
29 - <%= control_panel_button(_('Manage Content'), 'cms', :controller => 'cms') if !environment.enabled?('disable_cms') || profile.community? %> 29 + <%= control_panel_button(_('Manage Content'), 'cms', :controller => 'cms') %>
30 30
31 <% unless profile.enterprise? %> 31 <% unless profile.enterprise? %>
32 <%= case profile.blogs.count 32 <%= case profile.blogs.count
features/delete_profile.feature
@@ -98,13 +98,6 @@ Feature: delete profile @@ -98,13 +98,6 @@ Feature: delete profile
98 And I go to /myprofile/sample-enterprise/profile_editor/destroy_profile 98 And I go to /myprofile/sample-enterprise/profile_editor/destroy_profile
99 Then I should see "Access denied" 99 Then I should see "Access denied"
100 100
101 - Scenario: community regular member cannot see link to delete profile  
102 - Given "Joao Silva" is a member of "Sample Community"  
103 - And I am logged in as "joaosilva"  
104 - And I am on Sample Community's control panel  
105 - When I follow "Community Info and settings"  
106 - Then I should not see "Delete profile"  
107 -  
108 Scenario: environment admin deletes profile 101 Scenario: environment admin deletes profile
109 Given I am logged in as admin 102 Given I am logged in as admin
110 And I am on Joao Silva's control panel 103 And I am on Joao Silva's control panel
lib/noosfero/i18n.rb
@@ -12,7 +12,6 @@ repos = [] @@ -12,7 +12,6 @@ repos = []
12 if File.exists?(locale_dir) 12 if File.exists?(locale_dir)
13 repos << FastGettext::TranslationRepository.build('noosfero', :type => 'mo', :path => locale_dir) 13 repos << FastGettext::TranslationRepository.build('noosfero', :type => 'mo', :path => locale_dir)
14 repos << FastGettext::TranslationRepository.build('iso_3166', :type => 'mo', :path => locale_dir) 14 repos << FastGettext::TranslationRepository.build('iso_3166', :type => 'mo', :path => locale_dir)
15 - repos << FastGettext::TranslationRepository.build('rails', :type => 'mo', :path => locale_dir)  
16 end 15 end
17 16
18 FastGettext.add_text_domain 'noosferofull', :type => :chain, :chain => repos 17 FastGettext.add_text_domain 'noosferofull', :type => :chain, :chain => repos
lib/tasks/gettext.rake
@@ -26,7 +26,7 @@ task :symlinkmo do @@ -26,7 +26,7 @@ task :symlinkmo do
26 lang = File.basename(dir) 26 lang = File.basename(dir)
27 orig_lang = langmap[lang] || lang 27 orig_lang = langmap[lang] || lang
28 mkdir_p("#{Rails.root}/locale/#{lang}/LC_MESSAGES") 28 mkdir_p("#{Rails.root}/locale/#{lang}/LC_MESSAGES")
29 - ['iso_3166', 'rails'].each do |domain| 29 + ['iso_3166'].each do |domain|
30 origin = "/usr/share/locale/#{orig_lang}/LC_MESSAGES/#{domain}.mo" 30 origin = "/usr/share/locale/#{orig_lang}/LC_MESSAGES/#{domain}.mo"
31 target = "#{Rails.root}/locale/#{lang}/LC_MESSAGES/#{domain}.mo" 31 target = "#{Rails.root}/locale/#{lang}/LC_MESSAGES/#{domain}.mo"
32 if !File.symlink?(target) 32 if !File.symlink?(target)
script/quick-start-debian
@@ -22,7 +22,7 @@ run sudo apt-get -y install $runtime_dependencies @@ -22,7 +22,7 @@ run sudo apt-get -y install $runtime_dependencies
22 22
23 # needed for development 23 # needed for development
24 run sudo apt-get -y install libtidy-ruby libhpricot-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev 24 run sudo apt-get -y install libtidy-ruby libhpricot-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev
25 -run gem install bundler 25 +gem which bundler >/dev/null 2>&1 || run gem install bundler
26 run bundle install 26 run bundle install
27 27
28 # create the database with sample data 28 # create the database with sample data
@@ -34,7 +34,10 @@ run rake db:test:prepare @@ -34,7 +34,10 @@ run rake db:test:prepare
34 # compile translations 34 # compile translations
35 run rake noosfero:translations:compile 35 run rake noosfero:translations:compile
36 36
37 -# start server 37 +# create needed directory
  38 +mkdir -p tmp/pids
  39 +
  40 +# you can now start the server
38 say "I: Congratulations, you are ready to run Noosfero." 41 say "I: Congratulations, you are ready to run Noosfero."
39 -say "I: To execute Noosfero server, run \`/script/server-say "I: To execute Noosfero server, run \`/script/server and browse to http://localhost:3000" 42 +say "I: To execute Noosfero in development mode, run \`/script/development+say "I: To execute Noosfero in development mode, run \`/script/development and browse to http://localhost:3000"
40 say "I: To execute Noosfero tests, run \`rake\`." 43 say "I: To execute Noosfero tests, run \`rake\`."
test/factories.rb
@@ -71,7 +71,8 @@ module Noosfero::Factory @@ -71,7 +71,8 @@ module Noosfero::Factory
71 # testing that passes through the actual user creation process. 71 # testing that passes through the actual user creation process.
72 # 72 #
73 # Be aware that this is slow, though. 73 # Be aware that this is slow, though.
74 - def create_user_full(name, options = {}, person_options = {}) 74 + def create_user_full(name = nil, options = {}, person_options = {})
  75 + name ||= 'user' + factory_num_seq.to_s
75 data = { 76 data = {
76 :login => name, 77 :login => name,
77 :email => name + '@noosfero.org', 78 :email => name + '@noosfero.org',
@@ -90,7 +91,8 @@ module Noosfero::Factory @@ -90,7 +91,8 @@ module Noosfero::Factory
90 91
91 # This method knows way too much about the model. But since creating an 92 # This method knows way too much about the model. But since creating an
92 # actual user is really expensive, for tests we need a fast alternative. 93 # actual user is really expensive, for tests we need a fast alternative.
93 - def create_user(name, options = {}, person_options = {}) 94 + def create_user(name = nil, options = {}, person_options = {})
  95 + name ||= 'user' + factory_num_seq.to_s
94 environment_id = options.delete(:environment_id) || (options.delete(:environment) || Environment.default).id 96 environment_id = options.delete(:environment_id) || (options.delete(:environment) || Environment.default).id
95 97
96 password = options.delete(:password) 98 password = options.delete(:password)
test/fixtures/roles.yml
@@ -58,9 +58,7 @@ profile_member: @@ -58,9 +58,7 @@ profile_member:
58 name: 'Profile Member' 58 name: 'Profile Member'
59 system: true 59 system: true
60 permissions: 60 permissions:
61 - - edit_profile  
62 - - post_content  
63 - - manage_products 61 + - invite_members
64 profile_moderator: 62 profile_moderator:
65 id: 7 63 id: 7
66 environment_id: 1 64 environment_id: 1
test/functional/account_controller_test.rb
@@ -737,6 +737,16 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -737,6 +737,16 @@ class AccountControllerTest &lt; ActionController::TestCase
737 end 737 end
738 end 738 end
739 739
  740 + should 'login after signup when no e-mail confirmation is required' do
  741 + e = Environment.default
  742 + e.enable('skip_new_user_email_confirmation')
  743 + e.save!
  744 +
  745 + new_user
  746 + assert_response :redirect
  747 + assert_not_nil assigns(:current_user)
  748 + end
  749 +
740 protected 750 protected
741 def new_user(options = {}, extra_options ={}) 751 def new_user(options = {}, extra_options ={})
742 data = {:profile_data => person_data} 752 data = {:profile_data => person_data}
test/functional/cms_controller_test.rb
@@ -15,7 +15,6 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -15,7 +15,6 @@ class CmsControllerTest &lt; ActionController::TestCase
15 15
16 @profile = create_user_with_permission('testinguser', 'post_content') 16 @profile = create_user_with_permission('testinguser', 'post_content')
17 login_as :testinguser 17 login_as :testinguser
18 - @controller.stubs(:user).returns(@profile)  
19 end 18 end
20 19
21 attr_reader :profile 20 attr_reader :profile
@@ -601,12 +600,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -601,12 +600,14 @@ class CmsControllerTest &lt; ActionController::TestCase
601 600
602 should 'not make enterprise homepage available to person' do 601 should 'not make enterprise homepage available to person' do
603 @controller.stubs(:profile).returns(profile) 602 @controller.stubs(:profile).returns(profile)
604 - assert_not_includes @controller.available_article_types, EnterpriseHomepage 603 + @controller.stubs(:user).returns(profile)
  604 + assert_not_includes available_article_types, EnterpriseHomepage
605 end 605 end
606 606
607 should 'make enterprise homepage available to enterprises' do 607 should 'make enterprise homepage available to enterprises' do
608 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 608 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
609 - assert_includes @controller.available_article_types, EnterpriseHomepage 609 + @controller.stubs(:user).returns(profile)
  610 + assert_includes available_article_types, EnterpriseHomepage
610 end 611 end
611 612
612 should 'update categories' do 613 should 'update categories' do
@@ -838,18 +839,20 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -838,18 +839,20 @@ class CmsControllerTest &lt; ActionController::TestCase
838 839
839 should 'not offer folder to blog articles' do 840 should 'not offer folder to blog articles' do
840 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 841 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
  842 + @controller.stubs(:user).returns(profile)
841 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 843 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
842 @controller.stubs(:params).returns({ :parent_id => blog.id }) 844 @controller.stubs(:params).returns({ :parent_id => blog.id })
843 845
844 - assert_not_includes @controller.available_article_types, Folder 846 + assert_not_includes available_article_types, Folder
845 end 847 end
846 848
847 should 'not offer rssfeed to blog articles' do 849 should 'not offer rssfeed to blog articles' do
848 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 850 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
  851 + @controller.stubs(:user).returns(profile)
849 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 852 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
850 @controller.stubs(:params).returns({ :parent_id => blog.id }) 853 @controller.stubs(:params).returns({ :parent_id => blog.id })
851 854
852 - assert_not_includes @controller.available_article_types, RssFeed 855 + assert_not_includes available_article_types, RssFeed
853 end 856 end
854 857
855 should 'update blog posts_per_page setting' do 858 should 'update blog posts_per_page setting' do
@@ -1140,6 +1143,21 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1140,6 +1143,21 @@ class CmsControllerTest &lt; ActionController::TestCase
1140 assert_template 'edit' 1143 assert_template 'edit'
1141 end 1144 end
1142 1145
  1146 + should 'allow community members to edit articles that allow it' do
  1147 + community = fast_create(Community)
  1148 + admin = create_user('community-admin').person
  1149 + member = create_user.person
  1150 +
  1151 + community.add_admin(admin)
  1152 + community.add_member(member)
  1153 +
  1154 + article = community.articles.create!(:name => 'test_article', :allow_members_to_edit => true)
  1155 +
  1156 + login_as member.identifier
  1157 + get :edit, :profile => community.identifier, :id => article.id
  1158 + assert_response :success
  1159 + end
  1160 +
1143 should 'create thumbnails for images with delayed_job' do 1161 should 'create thumbnails for images with delayed_job' do
1144 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/rails.png', 'image/png'), fixture_file_upload('/files/test.txt', 'text/plain')] 1162 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/rails.png', 'image/png'), fixture_file_upload('/files/test.txt', 'text/plain')]
1145 file_1 = profile.articles.find_by_path('rails.png') 1163 file_1 = profile.articles.find_by_path('rails.png')
@@ -1203,18 +1221,20 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1203,18 +1221,20 @@ class CmsControllerTest &lt; ActionController::TestCase
1203 1221
1204 should 'not offer folder to forum articles' do 1222 should 'not offer folder to forum articles' do
1205 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 1223 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
  1224 + @controller.stubs(:user).returns(profile)
1206 forum = Forum.create!(:name => 'Forum for test', :profile => profile) 1225 forum = Forum.create!(:name => 'Forum for test', :profile => profile)
1207 @controller.stubs(:params).returns({ :parent_id => forum.id }) 1226 @controller.stubs(:params).returns({ :parent_id => forum.id })
1208 1227
1209 - assert_not_includes @controller.available_article_types, Folder 1228 + assert_not_includes available_article_types, Folder
1210 end 1229 end
1211 1230
1212 should 'not offer rssfeed to forum articles' do 1231 should 'not offer rssfeed to forum articles' do
1213 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 1232 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
  1233 + @controller.stubs(:user).returns(profile)
1214 forum = Forum.create!(:name => 'Forum for test', :profile => profile) 1234 forum = Forum.create!(:name => 'Forum for test', :profile => profile)
1215 @controller.stubs(:params).returns({ :parent_id => forum.id }) 1235 @controller.stubs(:params).returns({ :parent_id => forum.id })
1216 1236
1217 - assert_not_includes @controller.available_article_types, RssFeed 1237 + assert_not_includes available_article_types, RssFeed
1218 end 1238 end
1219 1239
1220 should 'update forum posts_per_page setting' do 1240 should 'update forum posts_per_page setting' do
@@ -1499,20 +1519,12 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1499,20 +1519,12 @@ class CmsControllerTest &lt; ActionController::TestCase
1499 assert_nil data[1]['error'] 1519 assert_nil data[1]['error']
1500 end 1520 end
1501 1521
1502 - protected  
1503 -  
1504 - # FIXME this is to avoid adding an extra dependency for a proper JSON parser.  
1505 - # For now we are assuming that the JSON is close enough to Ruby and just  
1506 - # making some adjustments.  
1507 - def parse_json_response  
1508 - eval(@response.body.gsub('":', '"=>').gsub('null', 'nil'))  
1509 - end  
1510 -  
1511 should 'make RawHTMLArticle available only to environment admins' do 1522 should 'make RawHTMLArticle available only to environment admins' do
1512 @controller.stubs(:profile).returns(profile) 1523 @controller.stubs(:profile).returns(profile)
1513 - assert_not_includes @controller.available_article_types, RawHTMLArticle 1524 + @controller.stubs(:user).returns(profile)
  1525 + assert_not_includes available_article_types, RawHTMLArticle
1514 profile.environment.add_admin(profile) 1526 profile.environment.add_admin(profile)
1515 - assert_includes @controller.available_article_types, RawHTMLArticle 1527 + assert_includes available_article_types, RawHTMLArticle
1516 end 1528 end
1517 1529
1518 should 'include new contents special types from plugins' do 1530 should 'include new contents special types from plugins' do
@@ -1526,8 +1538,25 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1526,8 +1538,25 @@ class CmsControllerTest &lt; ActionController::TestCase
1526 1538
1527 get :index, :profile => profile.identifier 1539 get :index, :profile => profile.identifier
1528 1540
1529 - assert_includes @controller.special_article_types, Integer  
1530 - assert_includes @controller.special_article_types, Float 1541 + assert_includes special_article_types, Integer
  1542 + assert_includes special_article_types, Float
  1543 + end
  1544 +
  1545 + protected
  1546 +
  1547 + # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
  1548 + # For now we are assuming that the JSON is close enough to Ruby and just
  1549 + # making some adjustments.
  1550 + def parse_json_response
  1551 + eval(@response.body.gsub('":', '"=>').gsub('null', 'nil'))
  1552 + end
  1553 +
  1554 + def available_article_types
  1555 + @controller.send(:available_article_types)
  1556 + end
  1557 +
  1558 + def special_article_types
  1559 + @controller.send(:special_article_types)
1531 end 1560 end
1532 1561
1533 end 1562 end
test/functional/profile_editor_controller_test.rb
@@ -601,15 +601,6 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -601,15 +601,6 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
601 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } 601 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' }
602 end 602 end
603 603
604 - should 'not display link to CMS if disabled' do  
605 - env = Environment.default  
606 - env.enable('disable_cms')  
607 - env.save!  
608 - get :index, :profile => profile.identifier  
609 -  
610 - assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' }  
611 - end  
612 -  
613 should 'offer to create blog in control panel' do 604 should 'offer to create blog in control panel' do
614 get :index, :profile => profile.identifier 605 get :index, :profile => profile.identifier
615 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" } 606 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" }
test/unit/article_test.rb
@@ -1638,4 +1638,37 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1638,4 +1638,37 @@ class ArticleTest &lt; ActiveSupport::TestCase
1638 assert_equal [c1,c2,c5], Article.text_articles 1638 assert_equal [c1,c2,c5], Article.text_articles
1639 end 1639 end
1640 1640
  1641 + should 'not allow all community members to edit by default' do
  1642 + community = fast_create(Community)
  1643 + admin = create_user('community-admin').person
  1644 + member = create_user.person
  1645 +
  1646 + community.add_admin(admin)
  1647 + community.add_member(member)
  1648 + a = Article.new(:profile => community)
  1649 +
  1650 + assert_equal false, a.allow_members_to_edit
  1651 + assert_equal false, a.allow_edit?(member)
  1652 + end
  1653 +
  1654 + should 'be able to allow all members of a community to edit' do
  1655 + community = fast_create(Community)
  1656 + admin = create_user('community-admin').person
  1657 + member = create_user.person
  1658 +
  1659 + community.add_admin(admin)
  1660 + community.add_member(member)
  1661 + a = Article.new(:profile => community)
  1662 +
  1663 + a.allow_members_to_edit = true
  1664 +
  1665 + assert_equal true, a.allow_edit?(member)
  1666 + end
  1667 +
  1668 + should 'not crash on allow_edit without a current user' do
  1669 + a = build(Article)
  1670 + a.allow_members_to_edit = true
  1671 + assert !a.allow_edit?(nil)
  1672 + end
  1673 +
1641 end 1674 end
test/unit/cms_helper_test.rb
@@ -8,7 +8,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -8,7 +8,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
8 8
9 should 'show default options for article' do 9 should 'show default options for article' do
10 CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new) 10 CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)
11 - result = options_for_article(RssFeed.new) 11 + result = options_for_article(RssFeed.new(:profile => Profile.new))
12 assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result 12 assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result
13 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result 13 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result
14 end 14 end
test/unit/user_test.rb
@@ -478,6 +478,14 @@ class UserTest &lt; ActiveSupport::TestCase @@ -478,6 +478,14 @@ class UserTest &lt; ActiveSupport::TestCase
478 end 478 end
479 end 479 end
480 480
  481 + should 'activate right after creation when confirmation is not required' do
  482 + e = Environment.default
  483 + e.enable('skip_new_user_email_confirmation')
  484 + e.save!
  485 +
  486 + assert new_user.activated?
  487 + end
  488 +
481 protected 489 protected
482 def new_user(options = {}) 490 def new_user(options = {})
483 user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) 491 user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))