Commit d97942a3f2e7bfbd7ab907db93a60235c421efdb
Exists in
staging
and in
1 other branch
merge with master
Showing
19 changed files
with
202 additions
and
156 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +class DownloadReportedImagesJob < Struct.new(:abuse_report, :article) | |
| 2 | + def perform | |
| 3 | + images_paths = article.image? ? [File.join(article.profile.environment.top_url, article.public_filename(:display))] : article.body_images_paths | |
| 4 | + images_paths.each do |image_path| | |
| 5 | + image = get_image(image_path) | |
| 6 | + reported_image = ReportedImage.create!( :abuse_report => abuse_report, | |
| 7 | + :uploaded_data => image, | |
| 8 | + :filename => File.basename(image_path), | |
| 9 | + :size => image.size ) | |
| 10 | + abuse_report.content = parse_content(abuse_report, image_path, reported_image) | |
| 11 | + end | |
| 12 | + abuse_report.save! | |
| 13 | + end | |
| 14 | + | |
| 15 | + def get_image(image_path) | |
| 16 | + image = ActionController::UploadedTempfile.new('reported_image') | |
| 17 | + image.write(Net::HTTP.get(URI.parse(image_path))) | |
| 18 | + image.original_path = 'tmp/' + File.basename(image_path) | |
| 19 | + image.content_type = 'image/' + File.extname(image_path).gsub('.','') | |
| 20 | + image | |
| 21 | + end | |
| 22 | + | |
| 23 | + def parse_content(report, old_path, image) | |
| 24 | + old_path = old_path.gsub(report.reporter.environment.top_url, '') | |
| 25 | + report.content.gsub(/#{old_path}/, image.public_filename) | |
| 26 | + end | |
| 27 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +class GetEmailContactsJob < Struct.new(:import_from, :login, :password, :contact_list_id) | |
| 2 | + def perform | |
| 3 | + begin | |
| 4 | + Invitation.get_contacts(import_from, login, password, contact_list_id) | |
| 5 | + rescue Contacts::AuthenticationError => ex | |
| 6 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_auth_error | |
| 7 | + rescue Exception => ex | |
| 8 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_error | |
| 9 | + end | |
| 10 | + end | |
| 11 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id, :locale) | |
| 2 | + def perform | |
| 3 | + Noosfero.with_locale(locale) do | |
| 4 | + person = Person.find(person_id) | |
| 5 | + profile = Profile.find(profile_id) | |
| 6 | + Invitation.invite(person, contacts_to_invite, message, profile) | |
| 7 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).destroy | |
| 8 | + end | |
| 9 | + end | |
| 10 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +class LogMemoryConsumptionJob < Struct.new(:last_stat) | |
| 2 | + # Number of entries do display | |
| 3 | + N = 20 | |
| 4 | + | |
| 5 | + def perform | |
| 6 | + logpath = File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_memory_consumption.log") | |
| 7 | + logger = Logger.new(logpath) | |
| 8 | + stats = Hash.new(0) | |
| 9 | + ObjectSpace.each_object {|o| stats[o.class.to_s] += 1} | |
| 10 | + i = 1 | |
| 11 | + | |
| 12 | + logger << "[#{Time.now.strftime('%F %T %z')}]\n" | |
| 13 | + stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v| | |
| 14 | + logger << (sprintf "%-60s %10d", k, v) | |
| 15 | + logger << (sprintf " | delta %10d", (v - last_stat[k])) if last_stat && last_stat[k] | |
| 16 | + logger << "\n" | |
| 17 | + break if i > N | |
| 18 | + i += 1 | |
| 19 | + end | |
| 20 | + logger << "\n" | |
| 21 | + end | |
| 22 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | +class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | |
| 2 | + NOTIFY_ONLY_COMMUNITY = [ | |
| 3 | + 'add_member_in_community' | |
| 4 | + ] | |
| 5 | + | |
| 6 | + NOT_NOTIFY_COMMUNITY = [ | |
| 7 | + 'join_community' | |
| 8 | + ] | |
| 9 | + def perform | |
| 10 | + return unless ActionTracker::Record.exists?(tracked_action_id) | |
| 11 | + tracked_action = ActionTracker::Record.find(tracked_action_id) | |
| 12 | + return unless tracked_action.user.present? | |
| 13 | + target = tracked_action.target | |
| 14 | + if target.is_a?(Community) && ( NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) || ! target.public_profile ) | |
| 15 | + ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) | |
| 16 | + return | |
| 17 | + end | |
| 18 | + | |
| 19 | + # Notify the user | |
| 20 | + ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) | |
| 21 | + | |
| 22 | + # Notify all friends | |
| 23 | + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") | |
| 24 | + | |
| 25 | + if tracked_action.user.is_a? Organization | |
| 26 | + ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + | |
| 27 | + "select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " + | |
| 28 | + if tracked_action.user.is_a? Enterprise then "union select distinct person_id, #{tracked_action.id} from favorite_enterprise_people where enterprise_id = #{tracked_action.user.id}" else "" end | |
| 29 | + end | |
| 30 | + | |
| 31 | + if target.is_a?(Community) | |
| 32 | + ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | |
| 33 | + | |
| 34 | + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}") | |
| 35 | + end | |
| 36 | + | |
| 37 | + if target.is_a?(Article) && target.profile.is_a?(Community) | |
| 38 | + ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | |
| 39 | + | |
| 40 | + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.profile.id}") | |
| 41 | + end | |
| 42 | + | |
| 43 | + end | |
| 44 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +class ProfileSuggestionsJob < Struct.new(:person_id) | |
| 2 | + | |
| 3 | + def self.exists?(person_id) | |
| 4 | + !find(person_id).empty? | |
| 5 | + end | |
| 6 | + | |
| 7 | + def self.find(person_id) | |
| 8 | + Delayed::Job.by_handler("--- !ruby/struct:ProfileSuggestionsJob\nperson_id: #{person_id}\n") | |
| 9 | + end | |
| 10 | + | |
| 11 | + def perform | |
| 12 | + logger = Delayed::Worker.logger | |
| 13 | + begin | |
| 14 | + person = Person.find(person_id) | |
| 15 | + ProfileSuggestion.calculate_suggestions(person) | |
| 16 | + UserMailer.profiles_suggestions_email(person).deliver if person.email_suggestions | |
| 17 | + rescue Exception => exception | |
| 18 | + logger.error("Error with suggestions for person ID %d: %s" % [person_id, exception.to_s]) | |
| 19 | + end | |
| 20 | + end | |
| 21 | + | |
| 22 | +end | ... | ... |
lib/download_reported_images_job.rb
| ... | ... | @@ -1,27 +0,0 @@ |
| 1 | -class DownloadReportedImagesJob < Struct.new(:abuse_report, :article) | |
| 2 | - def perform | |
| 3 | - images_paths = article.image? ? [File.join(article.profile.environment.top_url, article.public_filename(:display))] : article.body_images_paths | |
| 4 | - images_paths.each do |image_path| | |
| 5 | - image = get_image(image_path) | |
| 6 | - reported_image = ReportedImage.create!( :abuse_report => abuse_report, | |
| 7 | - :uploaded_data => image, | |
| 8 | - :filename => File.basename(image_path), | |
| 9 | - :size => image.size ) | |
| 10 | - abuse_report.content = parse_content(abuse_report, image_path, reported_image) | |
| 11 | - end | |
| 12 | - abuse_report.save! | |
| 13 | - end | |
| 14 | - | |
| 15 | - def get_image(image_path) | |
| 16 | - image = ActionController::UploadedTempfile.new('reported_image') | |
| 17 | - image.write(Net::HTTP.get(URI.parse(image_path))) | |
| 18 | - image.original_path = 'tmp/' + File.basename(image_path) | |
| 19 | - image.content_type = 'image/' + File.extname(image_path).gsub('.','') | |
| 20 | - image | |
| 21 | - end | |
| 22 | - | |
| 23 | - def parse_content(report, old_path, image) | |
| 24 | - old_path = old_path.gsub(report.reporter.environment.top_url, '') | |
| 25 | - report.content.gsub(/#{old_path}/, image.public_filename) | |
| 26 | - end | |
| 27 | -end |
lib/get_email_contacts_job.rb
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -class GetEmailContactsJob < Struct.new(:import_from, :login, :password, :contact_list_id) | |
| 2 | - def perform | |
| 3 | - begin | |
| 4 | - Invitation.get_contacts(import_from, login, password, contact_list_id) | |
| 5 | - rescue Contacts::AuthenticationError => ex | |
| 6 | - ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_auth_error | |
| 7 | - rescue Exception => ex | |
| 8 | - ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_error | |
| 9 | - end | |
| 10 | - end | |
| 11 | -end |
lib/invitation_job.rb
| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | -class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id, :locale) | |
| 2 | - def perform | |
| 3 | - Noosfero.with_locale(locale) do | |
| 4 | - person = Person.find(person_id) | |
| 5 | - profile = Profile.find(profile_id) | |
| 6 | - Invitation.invite(person, contacts_to_invite, message, profile) | |
| 7 | - ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).destroy | |
| 8 | - end | |
| 9 | - end | |
| 10 | -end |
lib/log_memory_consumption_job.rb
| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | -class LogMemoryConsumptionJob < Struct.new(:last_stat) | |
| 2 | - # Number of entries do display | |
| 3 | - N = 20 | |
| 4 | - | |
| 5 | - def perform | |
| 6 | - logpath = File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_memory_consumption.log") | |
| 7 | - logger = Logger.new(logpath) | |
| 8 | - stats = Hash.new(0) | |
| 9 | - ObjectSpace.each_object {|o| stats[o.class.to_s] += 1} | |
| 10 | - i = 1 | |
| 11 | - | |
| 12 | - logger << "[#{Time.now.strftime('%F %T %z')}]\n" | |
| 13 | - stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v| | |
| 14 | - logger << (sprintf "%-60s %10d", k, v) | |
| 15 | - logger << (sprintf " | delta %10d", (v - last_stat[k])) if last_stat && last_stat[k] | |
| 16 | - logger << "\n" | |
| 17 | - break if i > N | |
| 18 | - i += 1 | |
| 19 | - end | |
| 20 | - logger << "\n" | |
| 21 | - end | |
| 22 | -end |
lib/mailing_job.rb
lib/notify_activity_to_profiles_job.rb
| ... | ... | @@ -1,44 +0,0 @@ |
| 1 | -class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | |
| 2 | - NOTIFY_ONLY_COMMUNITY = [ | |
| 3 | - 'add_member_in_community' | |
| 4 | - ] | |
| 5 | - | |
| 6 | - NOT_NOTIFY_COMMUNITY = [ | |
| 7 | - 'join_community' | |
| 8 | - ] | |
| 9 | - def perform | |
| 10 | - return unless ActionTracker::Record.exists?(tracked_action_id) | |
| 11 | - tracked_action = ActionTracker::Record.find(tracked_action_id) | |
| 12 | - return unless tracked_action.user.present? | |
| 13 | - target = tracked_action.target | |
| 14 | - if target.is_a?(Community) && ( NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) || ! target.public_profile ) | |
| 15 | - ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) | |
| 16 | - return | |
| 17 | - end | |
| 18 | - | |
| 19 | - # Notify the user | |
| 20 | - ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) | |
| 21 | - | |
| 22 | - # Notify all friends | |
| 23 | - ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") | |
| 24 | - | |
| 25 | - if tracked_action.user.is_a? Organization | |
| 26 | - ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + | |
| 27 | - "select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " + | |
| 28 | - if tracked_action.user.is_a? Enterprise then "union select distinct person_id, #{tracked_action.id} from favorite_enterprise_people where enterprise_id = #{tracked_action.user.id}" else "" end | |
| 29 | - end | |
| 30 | - | |
| 31 | - if target.is_a?(Community) | |
| 32 | - ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | |
| 33 | - | |
| 34 | - ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}") | |
| 35 | - end | |
| 36 | - | |
| 37 | - if target.is_a?(Article) && target.profile.is_a?(Community) | |
| 38 | - ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | |
| 39 | - | |
| 40 | - ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.profile.id}") | |
| 41 | - end | |
| 42 | - | |
| 43 | - end | |
| 44 | -end |
lib/profile_suggestions_job.rb
| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | -class ProfileSuggestionsJob < Struct.new(:person_id) | |
| 2 | - | |
| 3 | - def self.exists?(person_id) | |
| 4 | - !find(person_id).empty? | |
| 5 | - end | |
| 6 | - | |
| 7 | - def self.find(person_id) | |
| 8 | - Delayed::Job.by_handler("--- !ruby/struct:ProfileSuggestionsJob\nperson_id: #{person_id}\n") | |
| 9 | - end | |
| 10 | - | |
| 11 | - def perform | |
| 12 | - logger = Delayed::Worker.logger | |
| 13 | - begin | |
| 14 | - person = Person.find(person_id) | |
| 15 | - ProfileSuggestion.calculate_suggestions(person) | |
| 16 | - UserMailer.profiles_suggestions_email(person).deliver if person.email_suggestions | |
| 17 | - rescue Exception => exception | |
| 18 | - logger.error("Error with suggestions for person ID %d: %s" % [person_id, exception.to_s]) | |
| 19 | - end | |
| 20 | - end | |
| 21 | - | |
| 22 | -end |
lib/user_activation_job.rb
plugins/display_content/test/unit/display_content_block_test.rb
| ... | ... | @@ -775,16 +775,62 @@ class DisplayContentBlockViewTest < ActionView::TestCase |
| 775 | 775 | assert_nil render_block_content(block).index(pt_article.name) |
| 776 | 776 | end |
| 777 | 777 | |
| 778 | - should 'not escape html in block content' do | |
| 778 | + should 'not escape abstract html of articles' do | |
| 779 | 779 | profile = create_user('testuser').person |
| 780 | 780 | a1 = fast_create(TextileArticle, abstract: "<p class='test-article-abstract'>Test</p>", name: 'test article 1', profile_id: profile.id, published_at: DateTime.current) |
| 781 | + | |
| 782 | + block = DisplayContentBlock.new | |
| 783 | + block.sections = [{:value => 'abstract', :checked => true}] | |
| 784 | + block.nodes = [a1.id] | |
| 785 | + box = mock() | |
| 786 | + block.stubs(:box).returns(box) | |
| 787 | + box.stubs(:owner).returns(profile) | |
| 788 | + assert_tag_in_string render_block_content(block), tag: 'p', attributes: { class: 'test-article-abstract' } | |
| 789 | + end | |
| 781 | 790 | |
| 791 | + should 'not raise if abstract of article is nil' do | |
| 792 | + profile = create_user('testuser').person | |
| 793 | + a1 = fast_create(TextileArticle, name: 'test article 1', profile_id: profile.id, published_at: DateTime.current) | |
| 794 | + | |
| 782 | 795 | block = DisplayContentBlock.new |
| 783 | - block.sections = [{:value => 'abstract', :checked => true}] | |
| 796 | + block.sections = [{:value => 'abstract', :checked => true}] | |
| 784 | 797 | block.nodes = [a1.id] |
| 785 | 798 | box = mock() |
| 786 | 799 | block.stubs(:box).returns(box) |
| 787 | 800 | box.stubs(:owner).returns(profile) |
| 788 | - assert_tag_in_string instance_eval(&block.content), tag: 'p', attributes: { class: 'test-article-abstract' } | |
| 801 | + assert_nil a1.abstract | |
| 802 | + assert_nothing_raised do | |
| 803 | + render_block_content(block) | |
| 804 | + end | |
| 789 | 805 | end |
| 806 | + | |
| 807 | + should 'not escape body html of articles' do | |
| 808 | + profile = create_user('testuser').person | |
| 809 | + a1 = fast_create(TextileArticle, body: "<p class='test-article-body'>Test</p>", name: 'test article 1', profile_id: profile.id, published_at: DateTime.current) | |
| 810 | + | |
| 811 | + block = DisplayContentBlock.new | |
| 812 | + block.sections = [{:value => 'body', :checked => true}] | |
| 813 | + block.nodes = [a1.id] | |
| 814 | + box = mock() | |
| 815 | + block.stubs(:box).returns(box) | |
| 816 | + box.stubs(:owner).returns(profile) | |
| 817 | + assert_tag_in_string render_block_content(block), tag: 'p', attributes: { class: 'test-article-body' } | |
| 818 | + end | |
| 819 | + | |
| 820 | + should 'not raise if body of article is nil' do | |
| 821 | + profile = create_user('testuser').person | |
| 822 | + a1 = fast_create(TextileArticle, name: 'test article 1', profile_id: profile.id, published_at: DateTime.current) | |
| 823 | + | |
| 824 | + block = DisplayContentBlock.new | |
| 825 | + block.sections = [{:value => 'abstract', :checked => true}] | |
| 826 | + block.nodes = [a1.id] | |
| 827 | + box = mock() | |
| 828 | + block.stubs(:box).returns(box) | |
| 829 | + box.stubs(:owner).returns(profile) | |
| 830 | + assert_nil a1.body | |
| 831 | + assert_nothing_raised do | |
| 832 | + render_block_content(block) | |
| 833 | + end | |
| 834 | + end | |
| 835 | + | |
| 790 | 836 | end | ... | ... |
plugins/display_content/views/blocks/display_content/_document.slim
| 1 | 1 | li |
| 2 | 2 | - unless item.folder? || item.class == RssFeed |
| 3 | 3 | = render partial: 'blocks/display_content/section', collection: block.sections, locals: { block: block, item: item } |
| 4 | - = render partial: 'blocks/display_content/read_more', locals: { item: item, abstract_section: block.sections.bsearch { |section| section[:value] == 'abstract' }, block: block } | |
| 5 | 4 | \ No newline at end of file |
| 5 | + = render partial: 'blocks/display_content/read_more', locals: { item: item, abstract_section: block.sections.bsearch { |section| section[:value] == 'abstract' }, block: block } | ... | ... |
plugins/display_content/views/blocks/display_content/_section.slim
| ... | ... | @@ -8,10 +8,10 @@ |
| 8 | 8 | = link_to(h(item.title), item.url) |
| 9 | 9 | - when 'abstract' |
| 10 | 10 | div class='lead' |
| 11 | - = item.abstract | |
| 11 | + = (item.abstract || '').html_safe | |
| 12 | 12 | - when 'body' |
| 13 | 13 | div class='body' |
| 14 | - = item.body | |
| 14 | + = (item.body || '').html_safe | |
| 15 | 15 | - when 'image' |
| 16 | 16 | - unless item.image || item.image.public_filename |
| 17 | 17 | div class='image' | ... | ... |