[Git][noosfero/noosfero][master] 6 commits: Fixed change of imgs/links url on profiles with domain

Antonio Terceiro gitlab at gitlab.com
Fri Aug 28 12:05:25 BRT 2015


Antonio Terceiro pushed to branch master at Noosfero / noosfero


Commits:
764f9947 by Daniela Feitosa at 2015-08-26T17:15:42Z
Fixed change of imgs/links url on profiles with domain

Links and images are saved with relative path but it wasn't considering
the profile domain. Because of this, the links were broken on article
visualization.
This commit also fix the url on edition of tinymce articles.

- - - - -
840e77eb by Daniela Feitosa at 2015-08-27T01:46:38Z
Added option to configure if preview in posts will be displayed

- - - - -
c9149e85 by Daniela Feitosa at 2015-08-27T02:41:53Z
Fixed js that fills in the slug field of blog

- - - - -
8f8895e7 by Antonio Terceiro at 2015-08-28T11:32:28Z
Merge branch 'blog_slug' of https://gitlab.com/danielafeitosa/noosfero

- - - - -
6f535a53 by Antonio Terceiro at 2015-08-28T11:32:37Z
Merge branch 'preview_configuration' of https://gitlab.com/danielafeitosa/noosfero

- - - - -
d3c41210 by Antonio Terceiro at 2015-08-28T11:32:54Z
Merge branch 'textarticle_links' of https://gitlab.com/danielafeitosa/noosfero

- - - - -


11 changed files:

- app/helpers/application_helper.rb
- app/helpers/blog_helper.rb
- app/models/article.rb
- app/models/profile.rb
- app/models/text_article.rb
- app/views/content_viewer/_article_title.html.erb
- public/javascripts/application.js
- test/unit/application_helper_test.rb
- test/unit/article_test.rb
- test/unit/profile_test.rb
- test/unit/text_article_test.rb


Changes:

=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -903,7 +903,7 @@ module ApplicationHelper
   end
 
   def base_url
-    environment.top_url(request.scheme)
+    profile ? profile.top_url(request.scheme) : environment.top_url(request.scheme)
   end
   alias :top_url :base_url
 


=====================================
app/helpers/blog_helper.rb
=====================================
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -6,7 +6,13 @@ module BlogHelper
     @article = article
     hidden_field_tag('article[published]', 1) +
     hidden_field_tag('article[accept_comments]', 0) +
-    visibility_options(article,tokenized_children)
+    visibility_options(article,tokenized_children) +
+    content_tag('h4', _('Visualization of posts')) +
+    content_tag(
+      'div',
+      check_box(:article, :display_preview) +
+      content_tag('label', _('I want to display the preview of posts before the text'), :for => 'article_display_preview')
+    )
   end
 
   def cms_label_for_new_children


=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -9,7 +9,7 @@ class Article < ActiveRecord::Base
                   :highlighted, :notify_comments, :display_hits, :slug,
                   :external_feed_builder, :display_versions, :external_link,
                   :image_builder, :show_to_followers,
-                  :author
+                  :author, :display_preview
 
   acts_as_having_image
 
@@ -643,6 +643,12 @@ class Article < ActiveRecord::Base
     false
   end
 
+  settings_items :display_preview, :type => :boolean, :default => false
+
+  def display_preview?
+    false
+  end
+
   def image?
     false
   end


=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -572,6 +572,14 @@ class Profile < ActiveRecord::Base
     options.merge(Noosfero.url_options)
   end
 
+  def top_url(scheme = 'http')
+    url = scheme + '://'
+    url << url_options[:host]
+    url << ':' << url_options[:port].to_s if url_options.key?(:port)
+    url << Noosfero.root('')
+    url
+  end
+
 private :generate_url, :url_options
 
   def default_hostname


=====================================
app/models/text_article.rb
=====================================
--- a/app/models/text_article.rb
+++ b/app/models/text_article.rb
@@ -33,12 +33,16 @@ class TextArticle < Article
   end
 
   def change_element_path(el, attribute)
-    fullpath = /(https?):\/\/(#{environment.default_hostname})(:\d+)?(\/.*)/.match(el[attribute])
+    fullpath = /(https?):\/\/(#{profile.default_hostname})(:\d+)?(\/.*)/.match(el[attribute])
     if fullpath
       domain = fullpath[2]
       path = fullpath[4]
-      el[attribute] = path if domain == environment.default_hostname
+      el[attribute] = path if domain == profile.default_hostname
     end
   end
 
+  def display_preview?
+    parent && parent.kind_of?(Blog) && parent.display_preview
+  end
+
 end


=====================================
app/views/content_viewer/_article_title.html.erb
=====================================
--- a/app/views/content_viewer/_article_title.html.erb
+++ b/app/views/content_viewer/_article_title.html.erb
@@ -7,7 +7,7 @@
     <% end %>
   </h1>
   <%= render :partial => "publishing_info" %>
-  <% unless @page.abstract.blank? %>
+  <% if @page.display_preview? %>
     <div class="preview">
       <%= @page.lead %>
     </div>


=====================================
public/javascripts/application.js
=====================================
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -107,11 +107,11 @@ function convToValidEmail( str ) {
 }
 
 function updateUrlField(name_field, id) {
-   url_field = $(id);
-   old_url_value = url_field.value;
+   url_field = jQuery('#'+id);
+   old_url_value = url_field.val();
    new_url_value = convToValidIdentifier(name_field.value, "-");
 
-   url_field.value = new_url_value;
+   url_field.val(new_url_value);
 
    if (!/^\s*$/.test(old_url_value)
        && old_url_value != new_url_value


=====================================
test/unit/application_helper_test.rb
=====================================
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -1022,6 +1022,27 @@ class ApplicationHelperTest < ActionView::TestCase
     assert_equal "Clone Article", label_for_clone_article(TinyMceArticle.new)
   end
 
+  should "return top url of environment" do
+    env = Environment.default
+    request = mock()
+    request.expects(:scheme).returns('http')
+    stubs(:request).returns(request)
+    stubs(:environment).returns(env)
+    stubs(:profile).returns(nil)
+    assert_equal env.top_url('http'), top_url
+  end
+
+  should "return top url considering profile" do
+    env = Environment.default
+    c = fast_create(Community)
+    request = mock()
+    request.stubs(:scheme).returns('http')
+    stubs(:request).returns(request)
+    stubs(:environment).returns(env)
+    stubs(:profile).returns(c)
+    assert_equal c.top_url, top_url
+  end
+
   protected
   include NoosferoTestHelper
 


=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -2214,4 +2214,9 @@ class ArticleTest < ActiveSupport::TestCase
     assert !a.display_media_panel?
   end
 
+  should 'have display_preview' do
+    a = Article.new(:display_preview => false)
+    assert !a.display_preview?
+  end
+
 end


=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -256,6 +256,20 @@ class ProfileTest < ActiveSupport::TestCase
     assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url)
   end
 
+  should 'provide environment top URL when profile has not a domain' do
+    env = Environment.default
+    profile = fast_create(Profile, :environment_id => env.id)
+    assert_equal env.top_url, profile.top_url
+  end
+
+  should 'provide top URL to profile with domain' do
+    env = Environment.default
+    profile = fast_create(Profile, :environment_id => env.id)
+    domain = fast_create(Domain, :name => 'example.net')
+    profile.domains << domain
+    assert_equal 'http://example.net', profile.top_url
+  end
+
   should 'help developers by adding a suitable port to url' do
     profile = build(Profile)
 


=====================================
test/unit/text_article_test.rb
=====================================
--- a/test/unit/text_article_test.rb
+++ b/test/unit/text_article_test.rb
@@ -85,6 +85,17 @@ class TextArticleTest < ActiveSupport::TestCase
     assert_equal "<img src=\"/test.png\">", article.body
   end
 
+  should 'change image path to relative for profile with own domain' do
+    person = create_user('testuser').person
+    person.domains << build(Domain)
+
+    article = TextArticle.new(:profile => person, :name => 'test')
+    env = Environment.default
+    article.body = "<img src=\"http://#{person.default_hostname}:3000/link-profile.png\">"
+    article.save!
+    assert_equal "<img src=\"/link-profile.png\">", article.body
+  end
+
   should 'not be translatable if there is no language available on environment' do
     environment = fast_create(Environment)
     environment.languages = nil
@@ -109,4 +120,12 @@ class TextArticleTest < ActiveSupport::TestCase
     assert text.translatable?
   end
 
+  should 'display preview when configured on parent that is a blog' do
+    person = fast_create(Person)
+    post = fast_create(TextArticle, :profile_id => person.id)
+    blog = Blog.new(:display_preview => true)
+    post.parent = blog
+    assert post.display_preview?
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/50c87964c9630b4acd43a24a8339375fdd0b993b...d3c41210fe0444b7bc8ad0f3257d081f432216f9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150828/994a0e27/attachment.html>


More information about the Noosfero-dev mailing list