noosfero | 7 new commits pushed to repository
Leandro Nunes
gitlab at gitlab.com
Tue Feb 3 11:31:42 BRST 2015
Leandro Nunes pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/1dfcb26deb5c1592aa2de1a253ff11d7b526e087">1dfcb26d</a> by Victor Costa
Added a option to create a link when approve an article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/9913add2d092346c97dc5b277b4922b3c132290a">9913add2</a> by Victor Costa
Add custom edit page for link article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/3dda03d2e329287cf3eb7bb3ff1b333c54b57965">3dda03d2</a> by Victor Costa
Added body and abstract to link article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/f710300ac97c79d60a1ca67cf9f348b90a509443">f710300a</a> by Victor Costa
Copy parent and highlighted attributes to link article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/03e2965e2112c154ee2e7f4c75db3af04a1c49f0">03e2965e</a> by Leandro Nunes dos Santos
Merge branches 'master' and 'AI3269_link-article' into AI3269_link-article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/a5b13b2f82b2dbea0437c5d418d309d9bd6502f9">a5b13b2f</a> by Leandro Nunes dos Santos
Merge branch 'master' into AI3269_link-article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/b94dbd71dc169448aede979b004c718fece0ac6c">b94dbd71</a> by Leandro Nunes
Merge branch 'AI3269_link-article' into 'master'
Link original article when spread it
The community administrator has the option to create a link to original article when approve publication tasks.
More details Ai3269
See merge request !449
- - - - -
Changes:
=====================================
app/models/approve_article.rb
=====================================
--- a/app/models/approve_article.rb
+++ b/app/models/approve_article.rb
@@ -22,6 +22,7 @@ class ApproveArticle < Task
end
settings_items :closing_statment, :article_parent_id, :highlighted
+ settings_items :create_link, :type => :boolean, :default => false
def article_parent
Article.find_by_id article_parent_id.to_i
@@ -48,7 +49,11 @@ class ApproveArticle < Task
end
def perform
- 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)
+ if create_link
+ LinkArticle.create!(:reference_article => article, :profile => target, :parent => article_parent, :highlighted => highlighted)
+ else
+ 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)
+ end
end
def title
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -110,6 +110,11 @@ class Article < ActiveRecord::Base
self.activity.destroy if self.activity
end
+ after_destroy :destroy_link_article
+ def destroy_link_article
+ Article.where(:reference_article_id => self.id, :type => LinkArticle).destroy_all
+ end
+
xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
scope :in_category, lambda { |category|
=====================================
app/models/link_article.rb
=====================================
--- /dev/null
+++ b/app/models/link_article.rb
@@ -0,0 +1,14 @@
+class LinkArticle < Article
+
+ attr_accessible :reference_article
+
+ def self.short_description
+ "Article link"
+ end
+
+ delegate :name, :to => :reference_article
+ delegate :body, :to => :reference_article
+ delegate :abstract, :to => :reference_article
+ delegate :url, :to => :reference_article
+
+end
=====================================
app/views/cms/_link_article.html.erb
=====================================
--- /dev/null
+++ b/app/views/cms/_link_article.html.erb
@@ -0,0 +1,6 @@
+<div>
+ <%= labelled_form_field(_('Title'), @article.name) %>
+ <%= labelled_form_field(_('Reference'), link_to(url_for @article.view_url)) %>
+
+ <%= render :partial => 'general_fields' %>
+</div>
=====================================
app/views/tasks/_approve_article_accept_details.html.erb
=====================================
--- a/app/views/tasks/_approve_article_accept_details.html.erb
+++ b/app/views/tasks/_approve_article_accept_details.html.erb
@@ -1,5 +1,7 @@
<%= render :file => 'shared/tiny_mce' %>
+<%= labelled_form_field(_('Create a link'), f.check_box(:create_link)) %>
+
<%= labelled_form_field(_('Name for publishing'), f.text_field(:name)) %>
<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %>
<%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %>
=====================================
test/unit/approve_article_test.rb
=====================================
--- a/test/unit/approve_article_test.rb
+++ b/test/unit/approve_article_test.rb
@@ -431,4 +431,13 @@ class ApproveArticleTest < ActiveSupport::TestCase
end
end
+ should 'create link to referenced article' do
+ article = fast_create(Article)
+ a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.create_link = true
+ a.finish
+
+ assert_equal article, LinkArticle.last.reference_article
+ end
+
end
=====================================
test/unit/link_article_test.rb
=====================================
--- /dev/null
+++ b/test/unit/link_article_test.rb
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class LinkArticleTest < ActiveSupport::TestCase
+
+ def setup
+ @profile = create_user('testing').person
+ end
+ attr_reader :profile
+
+ should 'url of article link redirects to referenced article' do
+ article = fast_create(Article, :profile_id => profile.id)
+ link = LinkArticle.new(:reference_article => article)
+ assert_equal article.url, link.url
+ end
+
+ should 'name of article link is the same as the name of referenced article' do
+ article = fast_create(Article, :profile_id => profile.id)
+ link = LinkArticle.new(:reference_article => article)
+ assert_equal article.name, link.name
+ end
+
+ should 'destroy link article when reference article is removed' do
+ target_profile = fast_create(Community)
+ article = fast_create(Article, :profile_id => profile.id)
+ link = LinkArticle.create!(:reference_article => article, :profile => target_profile)
+ article.destroy
+ assert_raise ActiveRecord::RecordNotFound do
+ link.reload
+ end
+ end
+
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150203/0e507153/attachment-0001.html>
More information about the Noosfero-dev
mailing list