|
|
|
2 ISO8601_TIMESTAMP = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\z/
|
|
|
|
|
|
5 @selected_tags ||= Array(params[:tags]).flatten.map(&:to_i).compact.reject(&:zero?)
|
|
|
|
|
|
|
|
9 content_tag :span, raw('*'), class: 'mandatory'
|
|
|
|
|
- DuplicateMethodCall - calls 'options[:model_name]' 2 times » reek
- DuplicateMethodCall - calls 'options[:url]' 2 times » reek
|
12 def cms_delete_link(model, options = {})
|
|
13 options[:model_name] ||= model.name
|
|
14 options[:url] ||= resource_path(model)
|
|
15 link_to image_tag('admin/delete.png', :size => "16x16", :alt => "Delete"), options[:url], :data => {
|
|
16 :confirm => "WARNING: This action cannot be undone.\nAre you sure you want to delete #{h options[:model_name]}?",
|
|
|
|
|
|
|
|
|
|
21 def admin_petition_facets_for_select(facets, selected)
|
|
22 options = admin_petition_facets.map do |facet|
|
|
23 [I18n.t(facet, scope: :"petitions.facets.names.admin", quantity: facets[facet]), facet]
|
|
|
|
|
|
26 options_for_select(options, selected)
|
|
|
|
|
|
29 def admin_signature_states_for_select(selected)
|
|
30 options_for_select(I18n.t(:states, scope: :"admin.signature"), selected)
|
|
|
|
|
|
33 def admin_archived_petition_facets_for_select(facets, selected)
|
|
34 options = admin_archived_petition_facets.map do |facet|
|
|
35 [I18n.t(facet, scope: :"petitions.facets.names.admin_archived", quantity: facets[facet]), facet]
|
|
|
|
|
|
38 options_for_select(options, selected)
|
|
|
|
|
|
41 def admin_invalidation_facets_for_select(facets, selected)
|
|
42 options = admin_invalidation_facets.map do |facet|
|
|
43 [I18n.t(facet, scope: :"admin.invalidations.facets.labels", quantity: facets[facet]), facet]
|
|
|
|
|
|
46 options_for_select(options, selected)
|
|
|
|
|
|
49 def admin_parliaments_for_select(selected)
|
|
50 options_from_collection_for_select(archived_parliaments, :id, :name, selected)
|
|
|
|
|
- DuplicateMethodCall - calls 'petition.signature_count' 2 times » reek
|
53 def email_petitioners_with_count_submit_button(form, petition, options = {})
|
|
|
|
55 scope: :admin, count: petition.signature_count,
|
|
56 formatted_count: number_with_delimiter(petition.signature_count)
|
|
|
|
|
|
|
|
60 name: 'save_and_email', class: 'button',
|
|
61 data: { confirm: t(:email_confirm, i18n_options) }
|
|
|
|
|
|
64 form.submit(t(:email_button, i18n_options), html_options)
|
|
|
|
|
|
67 def fraudulent_domains?(since: 1.hour.ago, limit: 10)
|
|
68 !fraudulent_domains(since: since, limit: limit).empty?
|
|
|
|
|
|
71 def fraudulent_domains(since: 1.hour.ago, limit: 10)
|
|
72 @fraudulent_domains ||= build_fraudulent_domains(since, limit)
|
|
|
|
|
|
75 def fraudulent_ips?(since: 1.hour.ago, limit: 10)
|
|
76 !fraudulent_ips(since: since, limit: limit).empty?
|
|
|
|
|
|
79 def fraudulent_ips(since: 1.hour.ago, limit: 10)
|
|
80 @fraudulent_ips ||= build_fraudulent_ips(since, limit)
|
|
|
|
|
|
83 def trending_domains(since: 1.hour.ago, limit: 10)
|
|
84 @trending_domains ||= build_trending_domains(since, limit)
|
|
|
|
|
|
87 def trending_domains?(since: 1.hour.ago, limit: 10)
|
|
88 !trending_domains(since: since, limit: limit).empty?
|
|
|
|
|
|
91 def trending_ips(since: 1.hour.ago, limit: 10)
|
|
92 @trending_ips ||= build_trending_ips(since, limit)
|
|
|
|
|
|
95 def trending_ips?(since: 1.hour.ago, limit: 10)
|
|
96 !trending_ips(since: since, limit: limit).empty?
|
|
|
|
|
- DuplicateMethodCall - calls 'params[:window]' 2 times » reek
|
|
|
100 params[:window].present? && params[:window] =~ ISO8601_TIMESTAMP
|
|
|
|
|
|
|
|
|
|
105 starts_at = params[:window].in_time_zone
|
|
106 ends_at = starts_at.advance(hours: 1)
|
|
|
|
|
|
|
|
|
|
|
|
112 def signature_count_interval_menu
|
|
|
|
|
|
|
|
|
|
117 "10 seconds" => "10",
|
|
118 "30 seconds" => "30",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
|
126 def admin_petition_facets
|
|
127 I18n.t(:admin, scope: :"petitions.facets")
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
|
130 def admin_archived_petition_facets
|
|
131 I18n.t(:admin_archived, scope: :"petitions.facets")
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
|
134 def admin_invalidation_facets
|
|
135 I18n.t(:keys, scope: :"admin.invalidations.facets")
|
|
|
|
|
|
|
|
139 @rate_limit ||= RateLimit.first_or_create!
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
|
142 def build_fraudulent_domains(since, limit)
|
|
143 Signature.fraudulent_domains(since: since, limit: limit)
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
|
146 def build_fraudulent_ips(since, limit)
|
|
147 Signature.fraudulent_ips(since: since, limit: limit)
|
|
|
|
|
- FeatureEnvy - refers to 'domains' more than self (maybe move it to another class?) » reek
- NestedIterators - contains iterators nested 2 deep » reek
- TooManyStatements - has approx 7 statements » reek
- UncommunicativeVariableName - has the variable name 'd' » reek
|
150 def build_trending_domains(since, limit)
|
|
151 all_domains = Signature.trending_domains(since: since, limit: limit + 30)
|
|
152 allowed_domains = rate_limit.allowed_domains_list
|
|
|
|
154 all_domains.inject([]) do |domains, (domain, count)|
|
|
155 return domains if domains.size == limit
|
|
|
|
157 unless allowed_domains.any?{ |d| d === domain }
|
|
158 domains << [domain, count]
|
|
|
|
|
|
|
|
|
|
|
|
|
- FeatureEnvy - refers to 'ips' more than self (maybe move it to another class?) » reek
- NestedIterators - contains iterators nested 2 deep » reek
- TooManyStatements - has approx 7 statements » reek
- UncommunicativeVariableName - has the variable name 'i' » reek
|
165 def build_trending_ips(since, limit)
|
|
166 all_ips = Signature.trending_ips(since: since, limit: limit + 30)
|
|
167 allowed_ips = rate_limit.allowed_ips_list
|
|
|
|
169 all_ips.inject([]) do |ips, (ip, count)|
|
|
170 return ips if ips.size == limit
|
|
|
|
172 unless allowed_ips.any?{ |i| i.include?(ip) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|