How to use block method of Reportable Package

Best Minitest_ruby code snippet using Reportable.block

event.rb

Source:event.rb Github

copy

Full Screen

...20 serialize :reason, Array21 xss_terminate :except => [:reason]22 23 named_scope :reports, :conditions => ['type=?', 'Moderation::Report']24 named_scope :blocks, :conditions => ['type=?', 'Moderation::Block']25 named_scope :uniq_items, :group => 'reportable_type, reportable_id'2627 named_scope :for_users, :conditions => {:reportable_type => ['BasicUser', 'AdvancedUser', 'Project']}28 named_scope :for_content, :conditions => {:reportable_type => Content::VALID_SUBCLASS_NAMES}2930 named_scope :order, lambda { |order_str| {:order => order_str}}31 32 belongs_to :user33 alias_method :reporter, :user34 belongs_to :reportable, :polymorphic => true35 36 after_create :notify_admins3738 REPORT_CATEGORIES = [39 'Copyright violation',40 'Offensive or sexually explicit content',41 'Individual or group attacks'42 ]43 44 BLOCK_CATEGORIES = [45 'Copyright violation',46 'Sexually explicit content',47 'Individual or group attacks',48 'TOS agreement violation',49 ]5051 USER_CATEGORIES = [52 'Copyright violation',53 'Offensive or sexually explicit content',54 'Individual or group attacks',55 'Unauthorized use of login credentials',56 'Forging or impersonating any person or identity',57 'Unauthorized solicitation',58 'Unlawful activities',59 'TOS agreement violation',60 ]6162 # Wrapper around categories to translate them as necessary -- can't translate on strings directly, b/c only translated once when class is loaded63 def self.categories(type)64 case type65 when :report then REPORT_CATEGORIES.collect{|x| [x.t, x]}66 when :block then BLOCK_CATEGORIES.collect{|x| [x.t, x]}67 when :block_user then USER_CATEGORIES.collect{|x| [x.t, x]}68 else []69 end70 end7172 # Not invidual events, but the uniq items they happened to73 def self.items(type = nil)74 all_items = self.find(:all, :group => 'reportable_type, reportable_id').map(&:reportable)7576 to_be_returned = if type.nil? then all_items77 elsif type == :user then all_items.select{|x| x.is_a?(User)}78 elsif type == :content then all_items.select{|x| x.is_a?(Content)}79 else all_items80 end81 return to_be_returned82 end838485 # Return the user responsible for the thing being reported, regardless of what kind of thing it is86 def responsible_user87 if reportable.is_a?(User)88 reportable89 elsif reportable.is_a?(Content)90 reportable.user91 else92 nil93 end94 end95 96 def kind97 'Generic Event'.t98 end99 100 # Reason is now an array -- stringify it prettily101 def display_reason102 return nil if reason.to_s.blank?103 reason.to_sentence104 end105 106 def validate107 errors.add_to_base("Must have an attached 'reportable' item".t) unless reportable108 errors.add_to_base("Must either select or describe the reason for your report".t) if reason.blank? && message.blank?109 if self.instance_of?(Moderation::Report)110 errors.add_to_base("Invalid report reason selected".t) if reason && !reason.all?{|r| REPORT_CATEGORIES.include?(r)}111 end112 if self.instance_of?(Moderation::Block)113 if reportable.is_a?(User)114 errors.add_to_base("Invalid block reason selected".t) if reason && !reason.all?{|r| USER_CATEGORIES.include?(r)}115 else116 errors.add_to_base("Invalid block reason selected".t) if reason && !reason.all?{|r| BLOCK_CATEGORIES.include?(r)}117 end118 end119 end120 121 protected122 123 def notify_admins124 if reportable.is_a?(Content)125 content_url = "http://#{reportable.user.login}.#{APP_CONFIG.hostname}/content/show/#{reportable.id}"126 msg = "#{reportable.user.display_name}'s \"#{reportable.title || 'Untitled'}\", #{content_url} for #{display_reason || 'an unknown reason.'}"127 else128 user = reportable129 user_url = "http://#{user.login}.#{APP_CONFIG.hostname}"130 msg = "kroogi user #{user.title_long}, #{user_url} for #{display_reason || 'an unknown reason.'}"131 end132 msg += "\nMessage from #{reporter.login}: #{self.message}" if self.message133 if self.is_a?(Moderation::Report)134 msg = "#{reporter.login} has reported " + msg135 elsif self.is_a?(Moderation::Block)136 msg = "#{reporter.login} has blocked " + msg137 end138 AdminNotifier.async_deliver_kroogi_admin_alert(msg)139 end140 141end ...

Full Screen

Full Screen

report.rb

Source:report.rb Github

copy

Full Screen

...56 @report = Report.find(params[:id])57 @song = Song.find(@report.reportable_id)58 @report.open = true59 @report.save60 @song.blocked = false61 @song.save62 BlockedUpload.find_by_song_id(@song.song_id).destroy if BlockedUpload.exists?(song_id: @song.song_id)63 redirect_to :action => :show64 end65 member_action :block_song, method: :post do66 @report = Report.find(params[:report_id])67 @song = Song.find(@report.reportable_id)68# @artist = @song.artist69# @reported_user = @artist.user70 UserMailer.admin_message(params[:email], params[:subject], params[:body]).deliver71 @song.blocked = true72 @song.active = false73 @song.save74 @blocked = BlockedUpload.find_by_song_id(@song.song_id).nil? ? BlockedUpload.new(upload_source: @song.upload_source, song_id: @song.song_id) : BlockedUpload.find_by_song_id(@song.song_id)75 @blocked.save76 @report.open = false77 @report.resolution = 'blocked'78 @report.save79 redirect_to :action => :show80 end81 member_action :invalid_report, method: :post do82 @report = Report.find(params[:report_id])83 UserMailer.admin_message(params[:email], params[:subject], params[:body]).deliver84 @report.open = false85 @report.resolution = 'allowed'86 @report.save87 redirect_to :action => :show88 end89end...

Full Screen

Full Screen

report_index.rb

Source:report_index.rb Github

copy

Full Screen

...23 base.__elasticsearch__.extend ElasticsearchMethods24 base.extend ClassMethods25 end26 module ElasticsearchMethods27 def import(options = {}, &block)28 # Allow a query29 q = options[:query] || -> { self }30 super(options.merge(query: -> { includes(:user, :admin, :reportable).instance_exec(&q) }), &block)31 end32 end33 module ClassMethods34 def default_sort(*)35 [created_at: :desc]36 end37 def allowed_search_fields(*)38 [:id, :created_at, :reason, :state, :user, :user_id, :admin, :admin_id,39 :ip, :fingerprint, :reportable_type, :reportable_id, :image_id]40 end41 def default_field42 :reason43 end44 end...

Full Screen

Full Screen

block

Using AI Code Generation

copy

Full Screen

1report.output_report { |r| puts r.title }2report.output_report { |r| puts r.text }3Report.output_report { |r| puts r.title }4Report.output_report { |r| puts r.text }

Full Screen

Full Screen

block

Using AI Code Generation

copy

Full Screen

1 def output_report(format)2report.output_report(:html)3report.output_report(:plain)4report.output_report(:csv)5 def output_report(format)6report.output_report(:html)7report.output_report(:plain)8report.output_report(:csv)9 def output_report(format)

Full Screen

Full Screen

block

Using AI Code Generation

copy

Full Screen

1 puts("<html>")2 puts(" <head>")3 puts(" </head>")4 puts(" <body>")5 puts(" </body>")6 puts("</html>")7 puts("<html>")8 puts(" <head>")9 puts(" </head>")10 puts(" <body>")11 def output_line(line)12 puts(" </body>")13 puts("</html>")14 def output_report(format)15 puts("<html>")16 puts(" <head>")17 puts(" </head>")18 puts(" <body>")19 puts(line)

Full Screen

Full Screen

block

Using AI Code Generation

copy

Full Screen

1 def initialize(balance)2account = Account.new(100)3 def initialize(balance)4 def initialize(amount)5account = Account.new(100)6transaction = Transaction.new(25)7 def initialize(balance)8 def initialize(amount)9account = Account.new(100)10transaction = Transaction.new(25)

Full Screen

Full Screen

block

Using AI Code Generation

copy

Full Screen

1t.report { puts "hello" }2 def method_missing(name, *args)3 if name.to_s =~ /^report_(.*)/4t.report_hello { puts "hello" }5 def method_missing(name, *args)6 if name.to_s =~ /^report_(.*)/7 def method_missing(name, *args)8 if name.to_s =~ /^report_(.*)/9 def method_missing(name, *args)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Minitest_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful