Commit 95dcee2d53e57ad1b933c27f9c1c340260bda1b1

Authored by Augusto_Serpro
2 parents 199fc3b7 be05a862

Merge branch 'stable' of gitlab.com:participa/noosfero into stable

Showing 30 changed files with 492 additions and 71 deletions   Show diff stats
app/controllers/public/invite_controller.rb
... ... @@ -62,20 +62,36 @@ class InviteController < PublicController
62 62 redirect_to :action => 'invite_friends'
63 63 end
64 64  
  65 + #Invite or add member without create a task
  66 + #if logged user is admin of environment
65 67 def invite_registered_friend
  68 +
  69 + if !params['q'].present? || !request.post?
  70 +
  71 + redirect_to :action => 'invite_friends'
  72 + session[:notice] = _('Please enter a valid profile.')
  73 +
  74 + return
  75 + end
  76 +
66 77 contacts_to_invite = params['q'].split(',')
67   - if !contacts_to_invite.empty? && request.post?
  78 +
  79 + if user.is_admin? && profile.community?
  80 +
  81 + Delayed::Job.enqueue AddMembersJob.new contacts_to_invite, profile.id, locale
  82 +
  83 + session[:notice] = _('This friends was added!')
  84 + else
68 85 Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale)
69 86 session[:notice] = _('Your invitations are being sent.')
70   - if profile.person?
71   - redirect_to :controller => 'profile', :action => 'friends'
72   - else
73   - redirect_to :controller => 'profile', :action => 'members'
74   - end
  87 + end
  88 +
  89 + if profile.person?
  90 + redirect_to :controller => 'profile', :action => 'friends'
75 91 else
76   - redirect_to :action => 'invite_friends'
77   - session[:notice] = _('Please enter a valid profile.')
  92 + redirect_to :controller => 'profile', :action => 'members'
78 93 end
  94 +
79 95 end
80 96  
81 97 def search
... ...
app/helpers/application_helper.rb
... ... @@ -589,14 +589,24 @@ module ApplicationHelper
589 589 trigger_class = 'enterprise-trigger'
590 590 end
591 591 end
592   - extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
  592 +
  593 + extra_info_tag = ''
  594 + img_class = 'profile-image'
  595 +
  596 + if extra_info.is_a? Hash
  597 + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
  598 + img_class +=' '+extra_info[:class]
  599 + else
  600 + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
  601 + end
  602 + #extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
593 603 links = links_for_balloon(profile)
594 604 content_tag('div', content_tag(tag,
595 605 (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
596 606 link_to(
597   - content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
  607 + content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
598 608 content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
599   - extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ),
  609 + extra_info_tag + profile_sex_icon( profile ) + profile_cat_icons( profile ),
600 610 profile.url,
601 611 :class => 'profile_link url',
602 612 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
... ...
app/models/profile.rb
... ... @@ -703,6 +703,32 @@ private :generate_url, :url_options
703 703 end
704 704 end
705 705  
  706 + # Adds many people to profile by id's or email's
  707 + def add_members(people_ids)
  708 +
  709 + unless people_ids.nil? && people_ids.empty?
  710 + people = []
  711 +
  712 + if people_ids.first =~ /\@/
  713 + people = User.where(email: people_ids)
  714 + else
  715 + people = Person.where(id: people_ids)
  716 + end
  717 +
  718 + people.each do |profile|
  719 + person = profile
  720 +
  721 + if profile.is_a? User
  722 + person = profile.person
  723 + end
  724 +
  725 + unless person.is_member_of?(self)
  726 + add_member person
  727 + end
  728 + end
  729 + end
  730 + end
  731 +
706 732 def remove_member(person)
707 733 self.disaffiliate(person, Profile::Roles.all_roles(environment.id))
708 734 end
... ...
app/views/content_viewer/_article_toolbar.html.erb
... ... @@ -50,6 +50,8 @@
50 50 <%#*Adds extra buttons to the toolbar%>
51 51 <%= @plugins.dispatch(:article_extra_toolbar_buttons, @page).collect { |content| instance_exec(&content) }.join("") %>
52 52  
  53 + <%= @plugins.dispatch(:article_toolbar_actions, @page).collect { |content| instance_exec(&content) }.join("")%>
  54 +
53 55 <%= report_abuse(profile, :link, @page) %>
54 56 </div>
55 57 <div id="article-header">
... ...
app/views/profile/members.html.erb
... ... @@ -4,6 +4,10 @@
4 4  
5 5 <% cache_timeout(profile.members_cache_key(params), 4.hours) do %>
6 6 <ul class='profile-list'>
  7 + <!--
  8 + @todo Highlight visual for invited members
  9 + of a community
  10 + -->
7 11 <% @members.each do |member| %>
8 12 <%= profile_image_link(member) %>
9 13 <% end %>
... ...
lib/add_members_job.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddMembersJob < Struct.new(:people_ids, :profile_id, :locale)
  2 +
  3 + def perform
  4 + Noosfero.with_locale(locale) do
  5 +
  6 + profile = Profile.find(profile_id)
  7 + profile.add_members people_ids
  8 +
  9 + end
  10 + end
  11 +end
... ...
lib/noosfero/plugin.rb
... ... @@ -448,6 +448,12 @@ class Noosfero::Plugin
448 448 []
449 449 end
450 450  
  451 + # -> Adds aditional actions to article
  452 + # returns = lambda block that creates html code
  453 + def article_toolbar_actions article
  454 + nil
  455 + end
  456 +
451 457 # -> Adds adicional content to article
452 458 # returns = lambda block that creates html code
453 459 def article_extra_contents(article)
... ...
plugins/comment_paragraph/controllers/myprofile/comment_paragraph_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +class CommentParagraphPluginMyprofileController < MyProfileController
  2 +
  3 + before_filter :check_permission
  4 +
  5 + def toggle_activation
  6 + @article.comment_paragraph_plugin_activate = !@article.comment_paragraph_plugin_activate
  7 + @article.save!
  8 + redirect_to @article.view_url
  9 + end
  10 +
  11 + protected
  12 +
  13 + def check_permission
  14 + @article = profile.articles.find(params[:id])
  15 + render_access_denied unless @article.comment_paragraph_plugin_enabled? && @article.allow_edit?(user)
  16 + end
  17 +
  18 +end
... ...
plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
... ... @@ -41,7 +41,14 @@ class CommentParagraphPlugin &lt; Noosfero::Plugin
41 41 end
42 42  
43 43 def self.activation_mode_default_setting
44   - 'auto'
  44 + 'manual'
  45 + end
  46 +
  47 + def article_toolbar_actions(article)
  48 + return unless article.comment_paragraph_plugin_enabled?
  49 + proc do
  50 + button :toggle_comment_paragraph, article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), :controller => 'comment_paragraph_plugin_myprofile', :action => 'toggle_activation', :id => article.id if article.allow_edit?(user)
  51 + end
45 52 end
46 53  
47 54 end
... ...
plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
... ... @@ -12,7 +12,7 @@ class CommentParagraphPlugin::AllowComment &lt; Noosfero::Plugin::Macro
12 12 count = article.paragraph_comments.without_spam.in_paragraph(paragraph_uuid).count
13 13  
14 14 proc {
15   - if controller.kind_of?(ContentViewerController)
  15 + if controller.kind_of?(ContentViewerController) && article.comment_paragraph_plugin_activated?
16 16 render :partial => 'comment_paragraph_plugin_profile/comment_paragraph',
17 17 :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }
18 18 else
... ...
plugins/comment_paragraph/lib/ext/article.rb
... ... @@ -12,21 +12,21 @@ class Article
12 12 environment.plugin_enabled?(CommentParagraphPlugin) && self.kind_of?(TextArticle)
13 13 end
14 14  
15   - protected
16   -
17   - def comment_paragraph_plugin_activate?
18   - comment_paragraph_plugin_enabled? && comment_paragraph_plugin_settings.activation_mode == 'auto'
  15 + def comment_paragraph_plugin_activated?
  16 + comment_paragraph_plugin_activate && comment_paragraph_plugin_enabled?
19 17 end
20 18  
21   - def comment_paragraph_plugin_parse_html
22   - comment_paragraph_plugin_activate = comment_paragraph_plugin_activate?
23   - return unless comment_paragraph_plugin_activate
  19 + protected
24 20  
25   - if body && body_changed?
  21 + def comment_paragraph_plugin_parse_html
  22 + comment_paragraph_plugin_set_initial_value unless persisted?
  23 + return unless comment_paragraph_plugin_activated?
  24 + if body && (body_changed? || setting_changed?(:comment_paragraph_plugin_activate))
26 25 parsed_paragraphs = []
27   - updated = body_change[1]
28   - doc = Hpricot(updated)
29   - doc.search("/*").each do |paragraph|
  26 + updated = body_changed? ? body_change[1] : body
  27 + doc = Nokogiri::HTML(updated).css('body')
  28 +
  29 + doc.children.each do |paragraph|
30 30 if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/
31 31 parsed_paragraphs << paragraph.to_html
32 32 else
... ... @@ -41,6 +41,11 @@ class Article
41 41 end
42 42 end
43 43  
  44 + def comment_paragraph_plugin_set_initial_value
  45 + self.comment_paragraph_plugin_activate = comment_paragraph_plugin_enabled? &&
  46 + comment_paragraph_plugin_settings.activation_mode == 'auto'
  47 + end
  48 +
44 49 def comment_paragraph_plugin_settings
45 50 @comment_paragraph_plugin_settings ||= Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin)
46 51 end
... ... @@ -48,8 +53,7 @@ class Article
48 53 def comment_paragraph_plugin_parse_paragraph(paragraph_content, paragraph_uuid)
49 54 "<div class='macro article_comments paragraph_comment' " +
50 55 "data-macro='comment_paragraph_plugin/allow_comment' " +
51   - "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}</div>\r\n" +
52   - "<p>&nbsp;</p>"
  56 + "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}</div>\r\n"
53 57 end
54 58  
55 59 end
... ...
plugins/comment_paragraph/po/comment_paragraph.pot 0 → 100644
... ... @@ -0,0 +1,62 @@
  1 +# SOME DESCRIPTIVE TITLE.
  2 +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
  3 +# This file is distributed under the same license as the PACKAGE package.
  4 +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  5 +#
  6 +#, fuzzy
  7 +msgid ""
  8 +msgstr ""
  9 +"Project-Id-Version: 1.0-rc3-2337-g7296e49\n"
  10 +"POT-Creation-Date: 2015-03-03 07:51-0300\n"
  11 +"PO-Revision-Date: 2015-03-03 07:41-0300\n"
  12 +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  13 +"Language-Team: LANGUAGE <LL@li.org>\n"
  14 +"Language: \n"
  15 +"MIME-Version: 1.0\n"
  16 +"Content-Type: text/plain; charset=UTF-8\n"
  17 +"Content-Transfer-Encoding: 8bit\n"
  18 +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
  19 +
  20 +#: plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb:8
  21 +msgid "Settings successfuly saved"
  22 +msgstr ""
  23 +
  24 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:8
  25 +msgid "A plugin that display comments divided by paragraphs."
  26 +msgstr ""
  27 +
  28 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:50
  29 +msgid "Deactivate Comments"
  30 +msgstr ""
  31 +
  32 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:50
  33 +msgid "Activate Comments"
  34 +msgstr ""
  35 +
  36 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:2
  37 +msgid "Comment Paragraph Plugin Settings"
  38 +msgstr ""
  39 +
  40 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:7
  41 +msgid "Activation Mode"
  42 +msgstr ""
  43 +
  44 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:10
  45 +msgid "Auto"
  46 +msgstr ""
  47 +
  48 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:11
  49 +msgid "(all text articles will be activated by default)"
  50 +msgstr ""
  51 +
  52 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:15
  53 +msgid "Manual"
  54 +msgstr ""
  55 +
  56 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:16
  57 +msgid "(click on \"Activate Comment Paragraph\" )"
  58 +msgstr ""
  59 +
  60 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:21
  61 +msgid "Save"
  62 +msgstr ""
... ...
plugins/comment_paragraph/po/pt/comment_paragraph.po 0 → 100644
... ... @@ -0,0 +1,62 @@
  1 +# SOME DESCRIPTIVE TITLE.
  2 +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
  3 +# This file is distributed under the same license as the PACKAGE package.
  4 +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  5 +#
  6 +#, fuzzy
  7 +msgid ""
  8 +msgstr ""
  9 +"Project-Id-Version: 1.0-rc3-2337-g7296e49\n"
  10 +"POT-Creation-Date: 2015-03-03 07:51-0300\n"
  11 +"PO-Revision-Date: 2015-03-03 07:41-0300\n"
  12 +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  13 +"Language-Team: LANGUAGE <LL@li.org>\n"
  14 +"Language: \n"
  15 +"MIME-Version: 1.0\n"
  16 +"Content-Type: text/plain; charset=UTF-8\n"
  17 +"Content-Transfer-Encoding: 8bit\n"
  18 +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
  19 +
  20 +#: plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb:8
  21 +msgid "Settings successfuly saved"
  22 +msgstr "Configurações salvas com sucesso"
  23 +
  24 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:8
  25 +msgid "A plugin that display comments divided by paragraphs."
  26 +msgstr "Um plugin que mostra os comentários por paragráfos"
  27 +
  28 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:50
  29 +msgid "Deactivate Comments"
  30 +msgstr "Desativar Comentários"
  31 +
  32 +#: plugins/comment_paragraph/lib/comment_paragraph_plugin.rb:50
  33 +msgid "Activate Comments"
  34 +msgstr "Ativar Comentários"
  35 +
  36 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:2
  37 +msgid "Comment Paragraph Plugin Settings"
  38 +msgstr "Configurações do Plugin de Comentário por Parágrafos"
  39 +
  40 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:7
  41 +msgid "Activation Mode"
  42 +msgstr "Modo de Ativação"
  43 +
  44 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:10
  45 +msgid "Auto"
  46 +msgstr "Automático"
  47 +
  48 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:11
  49 +msgid "(all text articles will be activated by default)"
  50 +msgstr "(todos os artigos de texto serão ativados por padrão)"
  51 +
  52 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:15
  53 +msgid "Manual"
  54 +msgstr "Manual"
  55 +
  56 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:16
  57 +msgid "(click on \"Activate Comment Paragraph\" )"
  58 +msgstr "(clicar em \"Ativar Comentário por Parágrafo\")"
  59 +
  60 +#: plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb:21
  61 +msgid "Save"
  62 +msgstr "Salvar"
... ...
plugins/comment_paragraph/public/images/internet-group-chat.png 0 → 100644

364 Bytes

plugins/comment_paragraph/public/style.css
  1 +#content #article-toolbar .icon-toggle_comment_paragraph {
  2 + top: -71px;
  3 + border: 0;
  4 + background-color: transparent;
  5 + color: gray;
  6 +}
  7 +#content #article-toolbar .icon-toggle_comment_paragraph:hover {
  8 + color: black;
  9 +}
  10 +
  11 +.icon-toggle_comment_paragraph{
  12 + background-image: url('/plugins/comment_paragraph/images/internet-group-chat.png');
  13 +}
  14 +
1 15 #comment-bubble.visible {
2 16 visibility: visible;
3 17 }
... ...
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_admin_controller_test.rb
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -require File.dirname(__FILE__) + '/../../controllers/comment_paragraph_plugin_admin_controller'
  1 +require_relative '../../../../test/test_helper'
  2 +require_relative '../../controllers/comment_paragraph_plugin_admin_controller'
3 3  
4 4 # Re-raise errors caught by the controller.
5 5 class CommentParagraphPluginAdminController; def rescue_action(e) raise e end; end
... ... @@ -22,10 +22,10 @@ class CommentParagraphPluginAdminControllerTest &lt; ActionController::TestCase
22 22 end
23 23  
24 24 should 'update comment paragraph plugin settings' do
25   - assert_not_equal 'manual', plugin_settings.get_setting(:activation_mode)
26   - post :index, :settings => { :activation_mode => 'manual' }
  25 + assert_not_equal 'auto', plugin_settings.get_setting(:activation_mode)
  26 + post :index, :settings => { :activation_mode => 'auto' }
27 27 environment.reload
28   - assert_equal 'manual', plugin_settings.get_setting(:activation_mode)
  28 + assert_equal 'auto', plugin_settings.get_setting(:activation_mode)
29 29 end
30 30  
31 31 should 'get article types previously selected' do
... ...
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_myprofile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +require_relative '../test_helper'
  2 +
  3 +class CommentParagraphPluginMyprofileControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + @environment = Environment.default
  7 + @environment.enable_plugin(CommentParagraphPlugin)
  8 + @profile = fast_create(Profile)
  9 + @user = create_user_with_permission('testuser', 'post_content', @profile)
  10 + login_as(@user.identifier)
  11 + @article = fast_create(TextArticle, :profile_id => profile.id, :author_id => @user.id)
  12 + end
  13 +
  14 + attr_reader :article, :profile, :user, :environment
  15 +
  16 + should 'toggle comment paragraph activation' do
  17 + assert !article.comment_paragraph_plugin_activate
  18 + get :toggle_activation, :id => article.id, :profile => profile.identifier
  19 + assert article.reload.comment_paragraph_plugin_activate
  20 + assert_redirected_to article.view_url
  21 + end
  22 +
  23 + should 'deny access to toggle activation for forbidden users' do
  24 + login_as(create_user('anotheruser').login)
  25 + get :toggle_activation, :id => article.id, :profile => profile.identifier
  26 + assert_response :forbidden
  27 + end
  28 +
  29 + should 'deny access to toggle activation if plugin is not enabled' do
  30 + environment.disable_plugin(CommentParagraphPlugin)
  31 + get :toggle_activation, :id => article.id, :profile => profile.identifier
  32 + assert_response :forbidden
  33 + end
  34 +
  35 +end
... ...
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
2   -require File.dirname(__FILE__) + '/../../controllers/profile/comment_paragraph_plugin_profile_controller'
  1 +require_relative '../test_helper'
  2 +require_relative '../../controllers/profile/comment_paragraph_plugin_profile_controller'
3 3  
4 4 # Re-raise errors caught by the controller.
5 5 class CommentParagraphPluginProfileController; def rescue_action(e) raise e end; end
... ...
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
2   -require File.dirname(__FILE__) + '/../../controllers/public/comment_paragraph_plugin_public_controller'
  1 +require_relative '../test_helper'
  2 +require_relative '../../controllers/public/comment_paragraph_plugin_public_controller'
3 3  
4 4  
5 5 # Re-raise errors caught by the controller.
... ... @@ -9,8 +9,7 @@ class CommentParagraphPluginPublicControllerTest &lt; ActionController::TestCase
9 9  
10 10 def setup
11 11 @profile = create_user('testuser').person
12   - @article = profile.articles.build(:name => 'test')
13   - @article.save!
  12 + @article = profile.articles.create!(:name => 'test')
14 13 end
15 14 attr_reader :article, :profile
16 15  
... ...
plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
  1 +require_relative '../test_helper'
2 2  
3 3 class ContentViewerController
4 4 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
... ... @@ -10,10 +10,12 @@ end
10 10 class ContentViewerControllerTest < ActionController::TestCase
11 11  
12 12 def setup
13   - @profile = fast_create(Community)
14   - @page = fast_create(Article, :profile_id => @profile.id, :body => "<div class=\"macro\" data-macro-paragraph_uuid=\"0\" data-macro='comment_paragraph_plugin/allow_comment' ></div>")
15 13 @environment = Environment.default
16 14 @environment.enable_plugin(CommentParagraphPlugin)
  15 + @profile = fast_create(Community)
  16 + @page = fast_create(TextArticle, :profile_id => @profile.id, :body => "<p>inner text</p>")
  17 + @page.comment_paragraph_plugin_activate = true
  18 + @page.save!
17 19 end
18 20  
19 21 attr_reader :page
... ...
plugins/comment_paragraph/test/test_helper.rb
1   -require File.dirname(__FILE__) + '/../../../test/test_helper'
  1 +require_relative '../../../test/test_helper'
... ...
plugins/comment_paragraph/test/unit/allow_comment_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
  1 +require_relative '../test_helper'
2 2  
3 3 class AllowCommentTest < ActiveSupport::TestCase
4 4  
5 5 def setup
6 6 @macro = CommentParagraphPlugin::AllowComment.new
  7 + @environment = Environment.default
  8 + @environment.enable_plugin(CommentParagraphPlugin)
  9 +
  10 + @profile = fast_create(Community)
  11 +
  12 + @article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner')
  13 + @article.comment_paragraph_plugin_activate = true
  14 + @article.save!
  15 +
  16 + @comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
  17 + @controller = mock
7 18 end
8 19  
9   - attr_reader :macro
  20 + attr_reader :macro, :profile, :article, :controller, :comment, :environment
10 21  
11 22 should 'have a configuration' do
12 23 assert CommentParagraphPlugin::AllowComment.configuration
13 24 end
14 25  
15 26 should 'parse contents to include comment paragraph view' do
16   - profile = fast_create(Community)
17   - article = fast_create(Article, :profile_id => profile.id)
18   - comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
19   - inner_html = 'inner'
20   - content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article)
21   - expects(:controller).returns(ContentViewerController.new)
22   -
23   - expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} })
  27 + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
  28 + controller.expects(:kind_of?).with(ContentViewerController).returns(true)
  29 +
  30 + expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => article.body, :count => 1, :profile_identifier => profile.identifier} })
24 31 instance_eval(&content)
25 32 end
26 33  
27 34 should 'not parse contents outside content viewer controller' do
28   - profile = fast_create(Community)
29   - article = fast_create(Article, :profile_id => profile.id)
30   - comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
31   - inner_html = 'inner'
32   - content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article)
33   - expects(:controller).returns(HomeController.new)
  35 + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner')
  36 + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
  37 + controller.expects(:kind_of?).with(ContentViewerController).returns(false)
  38 + assert_equal 'inner', instance_eval(&content)
  39 + end
34 40  
  41 + should 'not parse contents if comment_paragraph is not activated' do
  42 + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner')
  43 + article.expects(:comment_paragraph_plugin_activated?).returns(false)
  44 + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
  45 + controller.expects(:kind_of?).with(ContentViewerController).returns(true)
35 46 assert_equal 'inner', instance_eval(&content)
36 47 end
37 48  
... ...
plugins/comment_paragraph/test/unit/article_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
  1 +require_relative '../test_helper'
2 2 require 'benchmark'
3 3  
4 4 class ArticleTest < ActiveSupport::TestCase
5 5  
6 6 def setup
7   - profile = fast_create(Community)
8   - @article = fast_create(Article, :profile_id => profile.id)
  7 + @profile = fast_create(Community)
  8 + @article = fast_create(TextArticle, :profile_id => profile.id)
9 9 @environment = Environment.default
10 10 @environment.enable_plugin(CommentParagraphPlugin)
11 11 end
12 12  
13   - attr_reader :article, :environment
  13 + attr_reader :article, :environment, :profile
14 14  
15 15 should 'return paragraph comments from article' do
16 16 comment1 = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
... ... @@ -34,9 +34,67 @@ class ArticleTest &lt; ActiveSupport::TestCase
34 34  
35 35 should 'parse html if the plugin is not enabled' do
36 36 article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
37   - article.expects(:comment_paragraph_plugin_enabled?).returns(true)
  37 + article.comment_paragraph_plugin_activate = true
38 38 article.save!
39   - assert_match /data-macro='comment_paragraph_plugin\/allow_comment'/, article.body
  39 + assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
  40 + end
  41 +
  42 + should 'do not remove macro div when disable comment paragraph' do
  43 + article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
  44 + article.comment_paragraph_plugin_activate = true
  45 + article.save!
  46 + assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
  47 + article.comment_paragraph_plugin_activate = false
  48 + article.save!
  49 + assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
  50 + end
  51 +
  52 + should 'parse html when activate comment paragraph' do
  53 + article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
  54 + article.comment_paragraph_plugin_activate = false
  55 + article.save!
  56 + assert_equal "<p>paragraph 1</p><p>paragraph 2</p>", article.body
  57 + article.comment_paragraph_plugin_activate = true
  58 + article.save!
  59 + assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
  60 + end
  61 +
  62 + should 'be enabled if plugin is enabled and article is a kind of TextArticle' do
  63 + assert article.comment_paragraph_plugin_enabled?
  64 + end
  65 +
  66 + should 'not be enabled if plugin is not enabled' do
  67 + environment.disable_plugin(CommentParagraphPlugin)
  68 + assert !article.comment_paragraph_plugin_enabled?
  69 + end
  70 +
  71 + should 'not be enabled if article if not a kind of TextArticle' do
  72 + article = fast_create(Article, :profile_id => profile.id)
  73 + assert !article.comment_paragraph_plugin_enabled?
  74 + end
  75 +
  76 + should 'not be activated by default' do
  77 + article = fast_create(TextArticle, :profile_id => profile.id)
  78 + assert !article.comment_paragraph_plugin_activated?
  79 + end
  80 +
  81 + should 'be activated by default if it is enabled and activation mode is auto' do
  82 + settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin)
  83 + settings.activation_mode = 'auto'
  84 + settings.save!
  85 + article = TextArticle.create!(:profile => profile, :name => 'title')
  86 + assert article.comment_paragraph_plugin_activated?
  87 + end
  88 +
  89 + should 'be activated when forced' do
  90 + article.comment_paragraph_plugin_activate = true
  91 + assert article.comment_paragraph_plugin_activated?
  92 + end
  93 +
  94 + should 'not be activated if plugin is not enabled' do
  95 + article.comment_paragraph_plugin_activate = true
  96 + environment.disable_plugin(CommentParagraphPlugin)
  97 + assert !article.comment_paragraph_plugin_enabled?
40 98 end
41 99  
42 100 end
... ...
plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
  1 +require_relative '../test_helper'
2 2 include ActionView::Helpers::FormTagHelper
3 3  
4 4 class CommentParagraphPluginTest < ActiveSupport::TestCase
... ... @@ -6,9 +6,10 @@ class CommentParagraphPluginTest &lt; ActiveSupport::TestCase
6 6 def setup
7 7 @environment = Environment.default
8 8 @plugin = CommentParagraphPlugin.new
  9 + @user = create_user('testuser').person
9 10 end
10 11  
11   - attr_reader :environment, :plugin
  12 + attr_reader :environment, :plugin, :user
12 13  
13 14 should 'have a name' do
14 15 assert_not_equal Noosfero::Plugin.plugin_name, CommentParagraphPlugin::plugin_name
... ... @@ -35,4 +36,30 @@ class CommentParagraphPluginTest &lt; ActiveSupport::TestCase
35 36 assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect)
36 37 end
37 38  
  39 + should 'display button to toggle comment paragraph for users which can edit the article' do
  40 + article = fast_create(Article)
  41 + article.expects(:comment_paragraph_plugin_enabled?).returns(true)
  42 + article.expects(:allow_edit?).with(user).returns(true)
  43 +
  44 + content = plugin.article_header_extra_contents(article)
  45 + expects(:button).once
  46 + instance_eval(&content)
  47 + end
  48 +
  49 + should 'not display button to toggle comment paragraph for users which can not edit the article' do
  50 + article = fast_create(Article)
  51 + article.expects(:comment_paragraph_plugin_enabled?).returns(true)
  52 + article.expects(:allow_edit?).with(user).returns(false)
  53 +
  54 + content = plugin.article_header_extra_contents(article)
  55 + assert_equal nil, instance_eval(&content)
  56 + end
  57 +
  58 + should 'not display button to toggle comment paragraph if plugin is not enabled' do
  59 + article = fast_create(Article)
  60 + article.expects(:comment_paragraph_plugin_enabled?).returns(false)
  61 +
  62 + assert_equal nil, plugin.article_header_extra_contents(article)
  63 + end
  64 +
38 65 end
... ...
plugins/comment_paragraph/test/unit/comment_test.rb
1   -require File.dirname(__FILE__) + '/../test_helper'
  1 +require_relative '../test_helper'
2 2  
3 3 class CommentTest < ActiveSupport::TestCase
4 4  
... ...
plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb
... ... @@ -6,10 +6,14 @@
6 6 <div class="activation-mode">
7 7 <h4><%= _('Activation Mode') %></h4>
8 8 <div class="auto">
9   - <%= f.radio_button(:activation_mode, 'auto') %> <%= _('Auto') %>
  9 + <%= f.radio_button(:activation_mode, 'auto') %>
  10 + <span class="name"><strong><%= _('Auto') %></strong></span>
  11 + <span class="detail"><%= _('(all text articles will be activated by default)') %></span>
10 12 </div>
11   - <div>
12   - <%= f.radio_button(:activation_mode, 'manual') %> <%= _('Manual') %>
  13 + <div class="manual">
  14 + <%= f.radio_button(:activation_mode, 'manual') %>
  15 + <span class="name"><strong><%= _('Manual') %></strong></span>
  16 + <span class="detail"><%= _('(click on "Activate Comment Paragraph" )') %></span>
13 17 </div>
14 18 </div>
15 19  
... ...
plugins/community_track/lib/community_track_plugin/track.rb
... ... @@ -65,7 +65,7 @@ class CommunityTrackPlugin::Track &lt; Folder
65 65  
66 66 def category_name
67 67 category = categories.first
68   - category ? category.top_ancestor.name : ''
  68 + category ? (category.top_ancestor.nil? ? '' : category.top_ancestor.name) : ''
69 69 end
70 70  
71 71 def to_html(options = {})
... ...
plugins/container_block/views/blocks/container.html.erb
... ... @@ -10,7 +10,7 @@
10 10 <div class="clear"></div>
11 11  
12 12 <style>
13   - <% box_decorator.select_blocks(block.blocks, { :article => @page, :request_path => request.path, :locale => locale }).each do |child| %>
  13 + <% box_decorator.select_blocks(block, block.blocks, { :article => @page, :request_path => request.path, :locale => locale, params: request.params, controller: controller}).each do |child| %>
14 14 #block-<%=block.id%> #block-<%=child.id%> { width: <%= block.child_width(child.id) %>px; }
15 15 <% end %>
16 16 </style>
... ...
public/stylesheets/application.css
... ... @@ -2205,6 +2205,21 @@ a.button.disabled, input.disabled {
2205 2205 .profile-list .extra_info {
2206 2206 font-size: 9px;
2207 2207 }
  2208 +
  2209 +/* New members of community added
  2210 +* by admin of environment feature
  2211 +* #issue 227
  2212 +*/
  2213 +.profile-list .extra_info.new-profile {
  2214 + margin-top: 5px;
  2215 + color: #0A0;
  2216 + font-weight: bold;
  2217 +}
  2218 +
  2219 +span.new-profile img{
  2220 + border-top: solid 2px #0A0;
  2221 + margin-top: -2px;
  2222 +}
2208 2223 /* ==> blocks/recent-documents-block.css <<= */
2209 2224  
2210 2225 #content .recent-documents-block {
... ...
test/functional/invite_controller_test.rb
... ... @@ -284,6 +284,11 @@ class InviteControllerTest &lt; ActionController::TestCase
284 284 assert_empty json_response
285 285 end
286 286  
  287 + #@todo Copy this test and create a another version
  288 + #of this, for test add members in a community
  289 + #logged as admin of environment!
  290 + # #issue227
  291 + #
287 292 should 'invite registered users through profile id' do
288 293 friend1 = create_user('testuser1').person
289 294 friend2 = create_user('testuser2').person
... ... @@ -297,6 +302,29 @@ class InviteControllerTest &lt; ActionController::TestCase
297 302 end
298 303 end
299 304  
  305 + should 'add registered users imediatly instead invite if logged user is a environment admin' do
  306 +
  307 + #Add user like a environment admin
  308 + Environment.default.add_admin profile
  309 +
  310 + friend1 = create_user('testuser1').person
  311 + friend2 = create_user('testuser2').person
  312 +
  313 + assert_difference 'Delayed::Job.count', 1 do
  314 + assert_equal 0,community.members.count
  315 +
  316 + post :invite_registered_friend, :profile => @community.identifier, :q => [friend1.id,friend2.id]
  317 +
  318 + assert_response :redirect
  319 + assert_redirected_to :controller => 'profile', :action => 'members'
  320 + end
  321 +
  322 + Delayed::Worker.new.run(Delayed::Job.last)
  323 +
  324 + assert_equal 2,community.members.count
  325 +
  326 + end
  327 +
300 328 private
301 329  
302 330 def json_response
... ...