Commit f2fd0dc184403962a3e73253d321e9d914d1deec
Exists in
master
and in
23 other branches
Merge branch 'stable'
Showing
23 changed files
with
151 additions
and
15 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
| ... | ... | @@ -8,7 +8,7 @@ class ProfileMembersController < MyProfileController |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | def update_roles |
| 11 | - @roles = params[:roles] ? environment.roles.find(params[:roles]) : [] | |
| 11 | + @roles = params[:roles] ? environment.roles.find(params[:roles].select{|r|!r.to_i.zero?}) : [] | |
| 12 | 12 | @roles = @roles.select{|r| r.has_kind?('Profile') } |
| 13 | 13 | @person = profile.members.find { |m| m.id == params[:person].to_i } |
| 14 | 14 | if @person && @person.define_roles(@roles, profile) | ... | ... |
app/helpers/catalog_helper.rb
| ... | ... | @@ -23,7 +23,7 @@ private |
| 23 | 23 | |
| 24 | 24 | def product_category_name(profile, product_category) |
| 25 | 25 | if profile.enabled? |
| 26 | - link_to_category(product_category) | |
| 26 | + link_to_product_category(product_category) | |
| 27 | 27 | else |
| 28 | 28 | product_category ? product_category.full_name(' → ') : _('Uncategorized product') |
| 29 | 29 | end | ... | ... |
app/helpers/display_helper.rb
| ... | ... | @@ -14,6 +14,14 @@ module DisplayHelper |
| 14 | 14 | link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }) |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | + def link_to_product_category(category) | |
| 18 | + if category | |
| 19 | + link_to(category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id, :host => category.environment.default_hostname) | |
| 20 | + else | |
| 21 | + _('Uncategorized product') | |
| 22 | + end | |
| 23 | + end | |
| 24 | + | |
| 17 | 25 | def txt2html(txt) |
| 18 | 26 | txt. |
| 19 | 27 | gsub( /\n\s*\n/, ' <p/> ' ). | ... | ... |
app/models/add_member.rb
| ... | ... | @@ -12,7 +12,7 @@ class AddMember < Task |
| 12 | 12 | |
| 13 | 13 | def perform |
| 14 | 14 | self.roles ||= [Profile::Roles.member(organization.environment.id).id] |
| 15 | - target.affiliate(requestor, self.roles.map{|i| Role.find(i)}) | |
| 15 | + target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) | |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | def description | ... | ... |
app/models/approve_article.rb
app/models/article.rb
| ... | ... | @@ -54,7 +54,7 @@ class Article < ActiveRecord::Base |
| 54 | 54 | def category_ids=(ids) |
| 55 | 55 | ArticleCategorization.remove_all_for(self) |
| 56 | 56 | ids.uniq.each do |item| |
| 57 | - add_category(Category.find(item)) | |
| 57 | + add_category(Category.find(item)) unless item.to_i.zero? | |
| 58 | 58 | end |
| 59 | 59 | end |
| 60 | 60 | ... | ... |
app/models/profile.rb
| ... | ... | @@ -176,7 +176,7 @@ class Profile < ActiveRecord::Base |
| 176 | 176 | def category_ids=(ids) |
| 177 | 177 | ProfileCategorization.remove_all_for(self) |
| 178 | 178 | ids.uniq.each do |item| |
| 179 | - add_category(Category.find(item)) | |
| 179 | + add_category(Category.find(item)) unless item.to_i.zero? | |
| 180 | 180 | end |
| 181 | 181 | end |
| 182 | 182 | |
| ... | ... | @@ -638,4 +638,9 @@ class Profile < ActiveRecord::Base |
| 638 | 638 | ProfileSweeper.new().after_update(profile) |
| 639 | 639 | end |
| 640 | 640 | |
| 641 | + # FIXME: horrible workaround to circular dependancy in environment.rb | |
| 642 | + after_create do |profile| | |
| 643 | + ProfileSweeper.new().after_create(profile) | |
| 644 | + end | |
| 645 | + | |
| 641 | 646 | end | ... | ... |
app/models/published_article.rb
app/sweepers/profile_sweeper.rb
| ... | ... | @@ -7,6 +7,10 @@ class ProfileSweeper # < ActiveRecord::Observer |
| 7 | 7 | expire_caches(profile) |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | + def after_create(profile) | |
| 11 | + expire_statistics_block_cache(profile) | |
| 12 | + end | |
| 13 | + | |
| 10 | 14 | protected |
| 11 | 15 | |
| 12 | 16 | def expire_caches(profile) |
| ... | ... | @@ -19,4 +23,9 @@ protected |
| 19 | 23 | expire_timeout_fragment(block.cache_keys) |
| 20 | 24 | end |
| 21 | 25 | end |
| 26 | + | |
| 27 | + def expire_statistics_block_cache(profile) | |
| 28 | + blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } | |
| 29 | + blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} | |
| 30 | + end | |
| 22 | 31 | end | ... | ... |
app/views/catalog/show.rhtml
app/views/manage_products/index.rhtml
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | <% @consumptions.each do |consumption| %> |
| 46 | 46 | <tr> |
| 47 | 47 | <td> |
| 48 | - <strong><%= link_to_category(consumption.product_category) %></strong> | |
| 48 | + <strong><%= link_to_product_category(consumption.product_category) %></strong> | |
| 49 | 49 | <br/> |
| 50 | 50 | <em><%= consumption.aditional_specifications %></em> |
| 51 | 51 | </td> | ... | ... |
app/views/manage_products/show.rhtml
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | <p> <%= image_tag @product.image.public_filename if @product.image %> </p> |
| 4 | 4 | <p> <strong><%= _('Price:') %></strong> <%= @product.price %> </p> |
| 5 | 5 | <p> <strong><%= _('Description:') %></strong> <%= txt2html @product.description if @product.description %> </p> |
| 6 | -<p> <strong><%= _('Category:') %></strong> <%= link_to_category(@product.product_category) %> </p> | |
| 6 | +<p> <strong><%= _('Category:') %></strong> <%= link_to_product_category(@product.product_category) %> </p> | |
| 7 | 7 | |
| 8 | 8 | <%= button :back, _('back'), :action => 'index' %> |
| 9 | 9 | | ... | ... |
app/views/search/_product.rhtml
| ... | ... | @@ -16,6 +16,6 @@ product_item_pos += 1 |
| 16 | 16 | <% if product.enterprise %> |
| 17 | 17 | <li> <%= _('Suplier: %s') % link_to_homepage(product.enterprise.name, product.enterprise.identifier) %> </li> |
| 18 | 18 | <% end %> |
| 19 | - <li> <%= _('Category:') + ' ' + (product.product_category ? link_to(product.product_category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => product.product_category.id) : _('Uncategorized product')) %> </li> | |
| 19 | + <li> <%=_('Category:') + ' ' + link_to_product_category(product.product_category) %> </li> | |
| 20 | 20 | </ul> |
| 21 | 21 | </li> | ... | ... |
lib/noosfero.rb
test/functional/catalog_controller_test.rb
| ... | ... | @@ -12,6 +12,7 @@ class CatalogControllerTest < Test::Unit::TestCase |
| 12 | 12 | |
| 13 | 13 | @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent') |
| 14 | 14 | end |
| 15 | + attr_accessor :enterprise | |
| 15 | 16 | |
| 16 | 17 | def test_local_files_reference |
| 17 | 18 | ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') |
| ... | ... | @@ -113,4 +114,20 @@ class CatalogControllerTest < Test::Unit::TestCase |
| 113 | 114 | end |
| 114 | 115 | end |
| 115 | 116 | |
| 117 | + should 'link to assets products wiht product category in the link to product category on index' do | |
| 118 | + pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment) | |
| 119 | + prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc) | |
| 120 | + | |
| 121 | + get :index, :profile => enterprise.identifier | |
| 122 | + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} | |
| 123 | + end | |
| 124 | + | |
| 125 | + should 'link to assets products wiht product category in the link to product category on show' do | |
| 126 | + pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment) | |
| 127 | + prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc) | |
| 128 | + | |
| 129 | + get :show, :id => prod.id, :profile => enterprise.identifier | |
| 130 | + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} | |
| 131 | + end | |
| 132 | + | |
| 116 | 133 | end | ... | ... |
test/functional/manage_products_controller_test.rb
| ... | ... | @@ -274,5 +274,23 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
| 274 | 274 | |
| 275 | 275 | assert_equivalent [pc1, pc2], assigns(:categories) |
| 276 | 276 | end |
| 277 | + | |
| 278 | + should 'links to products asset for consumption link' do | |
| 279 | + pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment) | |
| 280 | + @enterprise.consumptions.create!(:product_category => pc) | |
| 281 | + | |
| 282 | + get :index, :profile => @enterprise.identifier | |
| 283 | + | |
| 284 | + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} | |
| 285 | + end | |
| 286 | + | |
| 287 | + should 'links to products asset for product category link when showing' do | |
| 288 | + pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment) | |
| 289 | + p = @enterprise.products.create!(:name => 'test product', :product_category => pc) | |
| 290 | + | |
| 291 | + get :show, :profile => @enterprise.identifier, :id => p.id | |
| 292 | + | |
| 293 | + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} | |
| 294 | + end | |
| 277 | 295 | |
| 278 | 296 | end | ... | ... |
test/functional/profile_members_controller_test.rb
| ... | ... | @@ -253,4 +253,16 @@ class ProfileMembersControllerTest < Test::Unit::TestCase |
| 253 | 253 | assert_includes assigns(:users_found), daniela |
| 254 | 254 | end |
| 255 | 255 | |
| 256 | + should 'ignore roles with id zero' do | |
| 257 | + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') | |
| 258 | + p = create_user_with_permission('test_user', 'manage_memberships', ent) | |
| 259 | + login_as :test_user | |
| 260 | + r = ent.environment.roles.create!(:name => 'test_role', :permissions => ['some_perm']) | |
| 261 | + get :update_roles, :profile => ent.identifier, :person => p.id, :roles => ["0", r.id, nil] | |
| 262 | + | |
| 263 | + p_roles = p.find_roles(ent).map(&:role).uniq | |
| 264 | + | |
| 265 | + assert p_roles, [r] | |
| 266 | + end | |
| 267 | + | |
| 256 | 268 | end | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -203,4 +203,24 @@ class TasksControllerTest < Test::Unit::TestCase |
| 203 | 203 | assert_not_nil PublishedArticle.find(:first) |
| 204 | 204 | end |
| 205 | 205 | |
| 206 | + should 'handle blank names for published articles' do | |
| 207 | + c = Community.create!(:name => 'test comm') | |
| 208 | + @controller.stubs(:profile).returns(c) | |
| 209 | + c.affiliate(profile, Profile::Roles.all_roles(c.environment)) | |
| 210 | + person = create_user('test_user').person | |
| 211 | + p_blog = Blog.create!(:profile => person) | |
| 212 | + c_blog1 = Blog.create!(:profile => c) | |
| 213 | + c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save! | |
| 214 | + | |
| 215 | + article = person.articles.create!(:name => 'test article', :parent => p_blog) | |
| 216 | + a = ApproveArticle.create!(:article => article, :target => c, :requestor => person) | |
| 217 | + assert_includes c.tasks, a | |
| 218 | + | |
| 219 | + assert_difference PublishedArticle, :count do | |
| 220 | + post :close, {"commit"=>"Ok!", "id"=> a.id.to_s, "task"=>{"name"=>"", "closing_statment"=>"", "highlighted"=>"0", "article_parent_id"=>c_blog2.id.to_s}, "decision"=>"finish"} | |
| 221 | + end | |
| 222 | + assert p_article = PublishedArticle.find_by_reference_article_id(article.id) | |
| 223 | + assert_includes c_blog2.children(true), p_article | |
| 224 | + end | |
| 225 | + | |
| 206 | 226 | end | ... | ... |
test/unit/add_member_test.rb
| ... | ... | @@ -95,4 +95,17 @@ class AddMemberTest < ActiveSupport::TestCase |
| 95 | 95 | end |
| 96 | 96 | end |
| 97 | 97 | |
| 98 | + should 'ignore roles with id zero' do | |
| 99 | + p = create_user('testuser1').person | |
| 100 | + c = Community.create!(:name => 'community_test') | |
| 101 | + | |
| 102 | + role = Profile::Roles.member(c.environment.id) | |
| 103 | + TaskMailer.stubs(:deliver_target_notification) | |
| 104 | + task = AddMember.create!(:roles => ["0", role.id, nil], :person => p, :organization => c) | |
| 105 | + task.finish | |
| 106 | + | |
| 107 | + current_roles = p.find_roles(c).map(&:role) | |
| 108 | + assert_includes current_roles, role | |
| 109 | + end | |
| 110 | + | |
| 98 | 111 | end | ... | ... |
test/unit/approve_article_test.rb
| ... | ... | @@ -63,4 +63,22 @@ class ApproveArticleTest < ActiveSupport::TestCase |
| 63 | 63 | assert_match /text was removed/, a.description |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | + should 'preserve article_parent' do | |
| 67 | + profile = create_user('test_user').person | |
| 68 | + article = profile.articles.create!(:name => 'test article') | |
| 69 | + a = ApproveArticle.new(:article_parent => article) | |
| 70 | + | |
| 71 | + assert_equal article, a.article_parent | |
| 72 | + end | |
| 73 | + | |
| 74 | + should 'handle blank names' do | |
| 75 | + profile = create_user('test_user').person | |
| 76 | + article = profile.articles.create!(:name => 'test article') | |
| 77 | + community = Community.create!(:name => 'test comm') | |
| 78 | + a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) | |
| 79 | + | |
| 80 | + assert_difference PublishedArticle, :count do | |
| 81 | + a.finish | |
| 82 | + end | |
| 83 | + end | |
| 66 | 84 | end | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -741,4 +741,12 @@ class ArticleTest < Test::Unit::TestCase |
| 741 | 741 | assert_not_includes as, a1 |
| 742 | 742 | end |
| 743 | 743 | |
| 744 | + should 'ignore category with zero as id' do | |
| 745 | + a = profile.articles.create!(:name => 'a test article') | |
| 746 | + c = Category.create!(:name => 'test category', :environment => profile.environment) | |
| 747 | + a.category_ids = ['0', c.id, nil] | |
| 748 | + assert a.save | |
| 749 | + assert_equal [c], a.categories | |
| 750 | + end | |
| 751 | + | |
| 744 | 752 | end | ... | ... |
test/unit/category_test.rb
| ... | ... | @@ -288,9 +288,9 @@ class CategoryTest < Test::Unit::TestCase |
| 288 | 288 | c = @env.categories.build(:name => 'my category'); c.save! |
| 289 | 289 | person = create_user('testuser').person |
| 290 | 290 | |
| 291 | - a1 = person.articles.build(:name => 'art1', :category_ids => [c]); a1.save! | |
| 292 | - a2 = person.articles.build(:name => 'art2', :category_ids => [c]); a2.save! | |
| 293 | - a3 = person.articles.build(:name => 'art3', :category_ids => [c]); a3.save! | |
| 291 | + a1 = person.articles.build(:name => 'art1', :category_ids => [c.id]); a1.save! | |
| 292 | + a2 = person.articles.build(:name => 'art2', :category_ids => [c.id]); a2.save! | |
| 293 | + a3 = person.articles.build(:name => 'art3', :category_ids => [c.id]); a3.save! | |
| 294 | 294 | |
| 295 | 295 | c1 = a1.comments.build(:title => 'test', :body => 'asdsa', :author => person); c1.save! |
| 296 | 296 | c2 = a2.comments.build(:title => 'test', :body => 'asdsa', :author => person); c2.save! | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -1385,6 +1385,14 @@ class ProfileTest < Test::Unit::TestCase |
| 1385 | 1385 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'join'}, profile.join_url) |
| 1386 | 1386 | end |
| 1387 | 1387 | |
| 1388 | + should 'ignore categgory with id zero' do | |
| 1389 | + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
| 1390 | + c = Category.create!(:name => 'test cat', :environment => profile.environment) | |
| 1391 | + profile.category_ids = ['0', c.id, nil] | |
| 1392 | + | |
| 1393 | + assert_equal [c], profile.categories | |
| 1394 | + end | |
| 1395 | + | |
| 1388 | 1396 | private |
| 1389 | 1397 | |
| 1390 | 1398 | def assert_invalid_identifier(id) | ... | ... |