Commit b94dbd71dc169448aede979b004c718fece0ac6c
Exists in
master
and in
29 other branches
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
Showing
7 changed files
with
74 additions
and
1 deletions
Show diff stats
app/models/approve_article.rb
| ... | ... | @@ -22,6 +22,7 @@ class ApproveArticle < Task |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | settings_items :closing_statment, :article_parent_id, :highlighted |
| 25 | + settings_items :create_link, :type => :boolean, :default => false | |
| 25 | 26 | |
| 26 | 27 | def article_parent |
| 27 | 28 | Article.find_by_id article_parent_id.to_i |
| ... | ... | @@ -48,7 +49,11 @@ class ApproveArticle < Task |
| 48 | 49 | end |
| 49 | 50 | |
| 50 | 51 | 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.last_changed_by_id, :created_by_id => article.created_by_id) | |
| 52 | + if create_link | |
| 53 | + LinkArticle.create!(:reference_article => article, :profile => target, :parent => article_parent, :highlighted => highlighted) | |
| 54 | + else | |
| 55 | + 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) | |
| 56 | + end | |
| 52 | 57 | end |
| 53 | 58 | |
| 54 | 59 | def title | ... | ... |
app/models/article.rb
| ... | ... | @@ -110,6 +110,11 @@ class Article < ActiveRecord::Base |
| 110 | 110 | self.activity.destroy if self.activity |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | + after_destroy :destroy_link_article | |
| 114 | + def destroy_link_article | |
| 115 | + Article.where(:reference_article_id => self.id, :type => LinkArticle).destroy_all | |
| 116 | + end | |
| 117 | + | |
| 113 | 118 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' |
| 114 | 119 | |
| 115 | 120 | scope :in_category, lambda { |category| | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +class LinkArticle < Article | |
| 2 | + | |
| 3 | + attr_accessible :reference_article | |
| 4 | + | |
| 5 | + def self.short_description | |
| 6 | + "Article link" | |
| 7 | + end | |
| 8 | + | |
| 9 | + delegate :name, :to => :reference_article | |
| 10 | + delegate :body, :to => :reference_article | |
| 11 | + delegate :abstract, :to => :reference_article | |
| 12 | + delegate :url, :to => :reference_article | |
| 13 | + | |
| 14 | +end | ... | ... |
app/views/tasks/_approve_article_accept_details.html.erb
| 1 | 1 | <%= render :file => 'shared/tiny_mce' %> |
| 2 | 2 | |
| 3 | +<%= labelled_form_field(_('Create a link'), f.check_box(:create_link)) %> | |
| 4 | + | |
| 3 | 5 | <%= labelled_form_field(_('Name for publishing'), f.text_field(:name)) %> |
| 4 | 6 | <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %> |
| 5 | 7 | <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> | ... | ... |
test/unit/approve_article_test.rb
| ... | ... | @@ -431,4 +431,13 @@ class ApproveArticleTest < ActiveSupport::TestCase |
| 431 | 431 | end |
| 432 | 432 | end |
| 433 | 433 | |
| 434 | + should 'create link to referenced article' do | |
| 435 | + article = fast_create(Article) | |
| 436 | + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile) | |
| 437 | + a.create_link = true | |
| 438 | + a.finish | |
| 439 | + | |
| 440 | + assert_equal article, LinkArticle.last.reference_article | |
| 441 | + end | |
| 442 | + | |
| 434 | 443 | end | ... | ... |
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class LinkArticleTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @profile = create_user('testing').person | |
| 7 | + end | |
| 8 | + attr_reader :profile | |
| 9 | + | |
| 10 | + should 'url of article link redirects to referenced article' do | |
| 11 | + article = fast_create(Article, :profile_id => profile.id) | |
| 12 | + link = LinkArticle.new(:reference_article => article) | |
| 13 | + assert_equal article.url, link.url | |
| 14 | + end | |
| 15 | + | |
| 16 | + should 'name of article link is the same as the name of referenced article' do | |
| 17 | + article = fast_create(Article, :profile_id => profile.id) | |
| 18 | + link = LinkArticle.new(:reference_article => article) | |
| 19 | + assert_equal article.name, link.name | |
| 20 | + end | |
| 21 | + | |
| 22 | + should 'destroy link article when reference article is removed' do | |
| 23 | + target_profile = fast_create(Community) | |
| 24 | + article = fast_create(Article, :profile_id => profile.id) | |
| 25 | + link = LinkArticle.create!(:reference_article => article, :profile => target_profile) | |
| 26 | + article.destroy | |
| 27 | + assert_raise ActiveRecord::RecordNotFound do | |
| 28 | + link.reload | |
| 29 | + end | |
| 30 | + end | |
| 31 | + | |
| 32 | +end | ... | ... |