Class: AbuseReport
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AbuseReport
- Includes:
- CacheMarkdownField, Gitlab::FileTypeDetection, Gitlab::Utils::StrongMemoize, Mentionable, Noteable, 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 Noteable
Constants included from WithUploads
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
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Noteable
Attributes included from CacheMarkdownField
#skip_markdown_cache_validation
Class Method Summary collapse
Instance Method Summary collapse
- #notify ⇒ Object
- #past_closed_reports_for_user ⇒ Object
-
#project ⇒ Object
createNote mutation calls noteable.project, which in case of abuse reports is nil.
- #remove_user(deleted_by:) ⇒ Object
- #report_type ⇒ Object
- #reported_content ⇒ Object
- #screenshot_path ⇒ Object
- #similar_open_reports_for_user ⇒ Object
- #uploads_sharding_key ⇒ Object
Methods included from Noteable
#after_note_created, #after_note_destroyed, #base_class_name, #broadcast_notes_changed, #capped_notes_count, #commenters, #creatable_note_email_address, #discussion_ids_relation, #discussion_notes, #discussion_root_note_ids, #discussions, #discussions_can_be_resolved_by?, #discussions_rendered_on_frontend?, #discussions_resolvable?, #discussions_resolved?, #discussions_to_be_resolved, #grouped_diff_discussions, #has_any_diff_note_positions?, #human_class_name, #lockable?, #noteable_target_type_name, #preloads_discussion_diff_highlighting?, #real_time_notes_enabled?, #resolvable_discussions, #supports_creating_notes_by_email?, #supports_discussions?, #supports_replying_to_individual_notes?, #supports_resolvable_notes?, #supports_suggestion?
Methods included from Mentionable
#all_references, #create_cross_references!, #create_new_cross_references!, #directly_addressed_users, #extractors, #gfm_reference, #local_reference, #matches_cross_reference_regex?, #mentioned_users, #referenced_group_users, #referenced_groups, #referenced_mentionables, #referenced_project_users, #referenced_projects, #referenced_users, #user_mention_class, #user_mention_identifier
Methods included from WithUploads
Methods included from FastDestroyAll::Helpers
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, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #store_mentions_after_commit?, #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, nullable_column?, 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 ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.human_attribute_name(attr, options = {}) ⇒ Object
114 115 116 |
# File 'app/models/abuse_report.rb', line 114 def self.human_attribute_name(attr, = {}) HUMANIZED_ATTRIBUTES[attr.to_sym] || super end |
Instance Method Details
#notify ⇒ Object
122 123 124 125 126 |
# File 'app/models/abuse_report.rb', line 122 def notify return unless persisted? AbuseReportMailer.notify(id).deliver_later end |
#past_closed_reports_for_user ⇒ Object
160 161 162 |
# File 'app/models/abuse_report.rb', line 160 def past_closed_reports_for_user user.abuse_reports.closed.id_not_in(id) end |
#project ⇒ Object
createNote mutation calls noteable.project, which in case of abuse reports is nil
172 173 174 |
# File 'app/models/abuse_report.rb', line 172 def project nil end |
#remove_user(deleted_by:) ⇒ Object
118 119 120 |
# File 'app/models/abuse_report.rb', line 118 def remove_user(deleted_by:) user.delete_async(deleted_by: deleted_by, params: { hard_delete: true }) end |
#report_type ⇒ Object
142 143 144 145 146 147 |
# File 'app/models/abuse_report.rb', line 142 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_content ⇒ Object
149 150 151 152 153 154 155 156 157 158 |
# File 'app/models/abuse_report.rb', line 149 def reported_content case report_type when :issue reported_project.issues.iid_in(route_hash[:id]).pick(:description_html) when :merge_request reported_project.merge_requests.iid_in(route_hash[:id]).pick(:description_html) when :comment reported_project.notes.id_in(note_id_from_url).pick(:note_html) end end |
#screenshot_path ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/models/abuse_report.rb', line 128 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_screenshot_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_user ⇒ Object
164 165 166 167 168 |
# File 'app/models/abuse_report.rb', line 164 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 |
#uploads_sharding_key ⇒ Object
176 177 178 |
# File 'app/models/abuse_report.rb', line 176 def uploads_sharding_key {} end |