Class: AbuseReport

Inherits:
ApplicationRecord show all
Includes:
CacheMarkdownField, Gitlab::FileTypeDetection, Gitlab::Utils::StrongMemoize, Sortable, WithUploads
Defined in:
app/models/abuse_report.rb

Constant Summary collapse

MAX_CHAR_LIMIT_URL =
512
MAX_FILE_SIZE =
1.megabyte
HUMANIZED_ATTRIBUTES =
{
  reported_from_url: "Reported from"
}.freeze
CONTROLLER_TO_REPORT_TYPE =
{
  'users' => :profile,
  'projects/issues' => :issue,
  'projects/merge_requests' => :merge_request
}.freeze

Constants included from WithUploads

WithUploads::FILE_UPLOADERS

Constants included from Gitlab::FileTypeDetection

Gitlab::FileTypeDetection::DANGEROUS_AUDIO_EXT, Gitlab::FileTypeDetection::DANGEROUS_IMAGE_EXT, Gitlab::FileTypeDetection::DANGEROUS_VIDEO_EXT, Gitlab::FileTypeDetection::PDF_EXT, Gitlab::FileTypeDetection::SAFE_AUDIO_EXT, Gitlab::FileTypeDetection::SAFE_IMAGE_EXT, Gitlab::FileTypeDetection::SAFE_IMAGE_FOR_SCALING_EXT, Gitlab::FileTypeDetection::SAFE_VIDEO_EXT

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithUploads

#retrieve_upload

Methods included from FastDestroyAll::Helpers

#perform_fast_destroy

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Gitlab::FileTypeDetection

#audio?, #dangerous_audio?, #dangerous_embeddable?, #dangerous_image?, #dangerous_video?, #embeddable?, extension_match?, #image?, #image_safe_for_scaling?, #pdf?, #video?

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #updated_cached_html_for

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.human_attribute_name(attr, options = {}) ⇒ Object



99
100
101
# File 'app/models/abuse_report.rb', line 99

def self.human_attribute_name(attr, options = {})
  HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end

Instance Method Details

#notifyObject



107
108
109
110
111
# File 'app/models/abuse_report.rb', line 107

def notify
  return unless persisted?

  AbuseReportMailer.notify(id).deliver_later
end

#past_closed_reports_for_userObject



145
146
147
# File 'app/models/abuse_report.rb', line 145

def past_closed_reports_for_user
  user.abuse_reports.closed.id_not_in(id)
end

#remove_user(deleted_by:) ⇒ Object



103
104
105
# File 'app/models/abuse_report.rb', line 103

def remove_user(deleted_by:)
  user.delete_async(deleted_by: deleted_by, params: { hard_delete: true })
end

#report_typeObject



127
128
129
130
131
132
# File 'app/models/abuse_report.rb', line 127

def report_type
  type = CONTROLLER_TO_REPORT_TYPE[route_hash[:controller]]
  type = :comment if type.in?([:issue, :merge_request]) && note_id_from_url.present?

  type
end

#reported_contentObject



134
135
136
137
138
139
140
141
142
143
# File 'app/models/abuse_report.rb', line 134

def reported_content
  case report_type
  when :issue
    project.issues.iid_in(route_hash[:id]).pick(:description_html)
  when :merge_request
    project.merge_requests.iid_in(route_hash[:id]).pick(:description_html)
  when :comment
    project.notes.id_in(note_id_from_url).pick(:note_html)
  end
end

#screenshot_pathObject



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/abuse_report.rb', line 113

def screenshot_path
  return unless screenshot
  return screenshot.url unless screenshot.upload

  asset_host = ActionController::Base.asset_host || Gitlab.config.gitlab.base_url
  local_path = Gitlab::Routing.url_helpers.abuse_report_upload_path(
    filename: screenshot.filename,
    id: screenshot.upload.model_id,
    model: 'abuse_report',
    mounted_as: 'screenshot')

  Gitlab::Utils.append_path(asset_host, local_path)
end

#similar_open_reports_for_userObject



149
150
151
152
153
# File 'app/models/abuse_report.rb', line 149

def similar_open_reports_for_user
  return AbuseReport.none unless open?

  user.abuse_reports.open.by_category(category).id_not_in(id).includes(:reporter)
end