Commit 1e60d6cfe55c86011e1981bf14d81ce67a16dbdd
Committed by
Antonio Terceiro
1 parent
5f250899
Exists in
master
and in
29 other branches
ActionItem1002: adding select to choose destination folder when approving articles.
Showing
10 changed files
with
94 additions
and
9 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -493,6 +493,10 @@ module ApplicationHelper | @@ -493,6 +493,10 @@ module ApplicationHelper | ||
493 | content_tag('div', result) | 493 | content_tag('div', result) |
494 | end | 494 | end |
495 | 495 | ||
496 | + def select_folder(object, method, collection, html_options = {}, js_options = {}) | ||
497 | + labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options)) | ||
498 | + end | ||
499 | + | ||
496 | def theme_option(opt = nil) | 500 | def theme_option(opt = nil) |
497 | conf = RAILS_ROOT.to_s() + | 501 | conf = RAILS_ROOT.to_s() + |
498 | '/public' + theme_path + | 502 | '/public' + theme_path + |
app/helpers/cms_helper.rb
@@ -15,10 +15,6 @@ module CmsHelper | @@ -15,10 +15,6 @@ module CmsHelper | ||
15 | end | 15 | end |
16 | end | 16 | end |
17 | 17 | ||
18 | - def select_folder(object, method, collection, html_options, js_options) | ||
19 | - labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options)) | ||
20 | - end | ||
21 | - | ||
22 | def pagination_links(collection, options={}) | 18 | def pagination_links(collection, options={}) |
23 | options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options) | 19 | options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options) |
24 | will_paginate(collection, options) | 20 | will_paginate(collection, options) |
app/models/approve_article.rb
@@ -35,8 +35,24 @@ class ApproveArticle < Task | @@ -35,8 +35,24 @@ class ApproveArticle < Task | ||
35 | data[:closing_statment] = value | 35 | data[:closing_statment] = value |
36 | end | 36 | end |
37 | 37 | ||
38 | + def article_parent_id= value | ||
39 | + data[:parent_id] = value | ||
40 | + end | ||
41 | + | ||
42 | + def article_parent_id | ||
43 | + data[:parent_id] | ||
44 | + end | ||
45 | + | ||
46 | + def article_parent | ||
47 | + Article.find_by_id article_parent_id | ||
48 | + end | ||
49 | + | ||
50 | + def article_parent= value | ||
51 | + article_parent_id = value.id | ||
52 | + end | ||
53 | + | ||
38 | def perform | 54 | def perform |
39 | - PublishedArticle.create(:name => name, :profile => target, :reference_article => article) | 55 | + PublishedArticle.create(:name => name, :profile => target, :reference_article => article, :parent => article_parent) |
40 | end | 56 | end |
41 | 57 | ||
42 | def target_notification_message | 58 | def target_notification_message |
app/models/profile.rb
@@ -592,4 +592,7 @@ class Profile < ActiveRecord::Base | @@ -592,4 +592,7 @@ class Profile < ActiveRecord::Base | ||
592 | !environment.enabled?('disable_contact_' + self.class.name.downcase) | 592 | !environment.enabled?('disable_contact_' + self.class.name.downcase) |
593 | end | 593 | end |
594 | 594 | ||
595 | + def folders | ||
596 | + self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']]) | ||
597 | + end | ||
595 | end | 598 | end |
app/views/tasks/_approve_article.rhtml
@@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
21 | 21 | ||
22 | <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %> | 22 | <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %> |
23 | 23 | ||
24 | + <%= labelled_form_field(_('Select the folder where the article must be published'), select_folder('task', 'article_parent_id', task.target.folders)) %> | ||
24 | <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %> | 25 | <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %> |
25 | 26 | ||
26 | </div> | 27 | </div> |
test/functional/cms_controller_test.rb
@@ -941,10 +941,10 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -941,10 +941,10 @@ class CmsControllerTest < Test::Unit::TestCase | ||
941 | assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } | 941 | assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } |
942 | end | 942 | end |
943 | 943 | ||
944 | - should 'display iframe for media listing when it is TinyMceArticle' do | ||
945 | - env = Environment.default | ||
946 | - env.enable('media_panel') | ||
947 | - env.save! | 944 | + should 'display iframe for media listing when it is TinyMceArticle and enabled on environment' do |
945 | + e = Environment.default | ||
946 | + e.enable('media_panel') | ||
947 | + e.save! | ||
948 | 948 | ||
949 | image_folder = Folder.create(:profile => profile, :name => 'Image folder') | 949 | image_folder = Folder.create(:profile => profile, :name => 'Image folder') |
950 | non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') | 950 | non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') |
test/functional/tasks_controller_test.rb
@@ -153,4 +153,28 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -153,4 +153,28 @@ class TasksControllerTest < Test::Unit::TestCase | ||
153 | assert_equal f, assigns(:ticket).target | 153 | assert_equal f, assigns(:ticket).target |
154 | end | 154 | end |
155 | 155 | ||
156 | + should 'create published article after finish approve article task' do | ||
157 | + PublishedArticle.destroy_all | ||
158 | + c = Community.create!(:name => 'test comm', :moderated_articles => false) | ||
159 | + @controller.stubs(:profile).returns(c) | ||
160 | + c.affiliate(profile, Profile::Roles.all_roles) | ||
161 | + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') | ||
162 | + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) | ||
163 | + | ||
164 | + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name'} | ||
165 | + assert_equal article, PublishedArticle.find(:first).reference_article | ||
166 | + end | ||
167 | + | ||
168 | + should 'create published article in folder after finish approve article task' do | ||
169 | + PublishedArticle.destroy_all | ||
170 | + c = Community.create!(:name => 'test comm', :moderated_articles => false) | ||
171 | + @controller.stubs(:profile).returns(c) | ||
172 | + folder = c.articles.create!(:name => 'test folder', :type => 'Folder') | ||
173 | + c.affiliate(profile, Profile::Roles.all_roles) | ||
174 | + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') | ||
175 | + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) | ||
176 | + | ||
177 | + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => folder.id} | ||
178 | + assert_equal folder, PublishedArticle.find(:first).parent | ||
179 | + end | ||
156 | end | 180 | end |
test/unit/approve_article_test.rb
@@ -32,4 +32,22 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -32,4 +32,22 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
35 | + should 'have parent if defined' do | ||
36 | + profile = create_user('test_user').person | ||
37 | + article = profile.articles.create!(:name => 'test article') | ||
38 | + folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') | ||
39 | + | ||
40 | + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id) | ||
41 | + | ||
42 | + assert_equal folder, a.article_parent | ||
43 | + end | ||
44 | + | ||
45 | + should 'not have parent if not defined' do | ||
46 | + profile = create_user('test_user').person | ||
47 | + article = profile.articles.create!(:name => 'test article') | ||
48 | + | ||
49 | + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) | ||
50 | + | ||
51 | + assert_nil a.article_parent | ||
52 | + end | ||
35 | end | 53 | end |
test/unit/profile_test.rb
@@ -1296,6 +1296,21 @@ class ProfileTest < Test::Unit::TestCase | @@ -1296,6 +1296,21 @@ class ProfileTest < Test::Unit::TestCase | ||
1296 | assert_includes profile.possible_domains, domain2 | 1296 | assert_includes profile.possible_domains, domain2 |
1297 | end | 1297 | end |
1298 | 1298 | ||
1299 | + should 'list folder articles' do | ||
1300 | + profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') | ||
1301 | + Article.destroy_all | ||
1302 | + p1 = Folder.create!(:name => 'parent1', :profile => profile) | ||
1303 | + p2 = Blog.create!(:name => 'parent2', :profile => profile) | ||
1304 | + | ||
1305 | + assert p1.folder? | ||
1306 | + assert p2.folder? | ||
1307 | + | ||
1308 | + child = profile.articles.create!(:name => 'child', :parent => p1) | ||
1309 | + profile.reload | ||
1310 | + assert_equivalent [p1, p2], profile.folders | ||
1311 | + assert !profile.folders.include?(child) | ||
1312 | + end | ||
1313 | + | ||
1299 | private | 1314 | private |
1300 | 1315 | ||
1301 | def assert_invalid_identifier(id) | 1316 | def assert_invalid_identifier(id) |
test/unit/published_article_test.rb
@@ -84,4 +84,12 @@ class PublishedArticleTest < ActiveSupport::TestCase | @@ -84,4 +84,12 @@ class PublishedArticleTest < ActiveSupport::TestCase | ||
84 | assert_equal @profile, PublishedArticle.new(:profile => @profile).author | 84 | assert_equal @profile, PublishedArticle.new(:profile => @profile).author |
85 | end | 85 | end |
86 | 86 | ||
87 | + should 'have parent if defined' do | ||
88 | + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') | ||
89 | + folder = Folder.create(:name => 'folder test', :profile => prof) | ||
90 | + p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder) | ||
91 | + | ||
92 | + assert p | ||
93 | + assert_equal folder, p.parent | ||
94 | + end | ||
87 | end | 95 | end |