From 5d710b1139b34f2ed6bd556f448fa7248354e758 Mon Sep 17 00:00:00 2001 From: Eugen Date: Sun, 16 Apr 2017 12:51:30 +0200 Subject: Make file attachment on MediaAttachment optional (#1865) Create MediaAttachment but without actual file download when domain is blocked with reject_media set to true Clean up old media files when creating a new domain block with reject_media set to true Return remote_url in media attachments API if local file is not present Undo domain block action in admin UI Ability to enable reject_media from admin UI --- app/models/domain_block.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models') diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 3548ccd69..89c81f766 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -3,6 +3,8 @@ class DomainBlock < ApplicationRecord enum severity: [:silence, :suspend] + attr_accessor :retroactive + validates :domain, presence: true, uniqueness: true def self.blocked?(domain) -- cgit From de72db99fac56fa06fccdab443a1c4e44e8fb985 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Sun, 16 Apr 2017 23:28:26 +0900 Subject: Add presence validation to Import (#1928) ``` *An* `ActiveRecord::StatementInvalid` *occurred while* `POST ` *was processed by* `imports#create` Exception ---------------- PG::NotNullViolation: ERROR: null value in column "type" violates not-null constraint ``` --- app/models/import.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/import.rb b/app/models/import.rb index 3013bc50e..85f6ca4bd 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -1,13 +1,15 @@ # frozen_string_literal: true class Import < ApplicationRecord + FILE_TYPES = ['text/plain', 'text/csv'].freeze + self.inheritance_column = false - enum type: [:following, :blocking, :muting] + belongs_to :account, required: true - belongs_to :account + enum type: [:following, :blocking, :muting] - FILE_TYPES = ['text/plain', 'text/csv'].freeze + validates :type, presence: true has_attached_file :data, url: '/system/:hash.:extension', hash_secret: ENV['PAPERCLIP_SECRET'] validates_attachment_content_type :data, content_type: FILE_TYPES -- cgit From fc34e0e19145f0f681f19e003060f3aa4ef122d4 Mon Sep 17 00:00:00 2001 From: tackeyy Date: Sun, 16 Apr 2017 23:28:52 +0900 Subject: Remove .keep in models (#1892) --- app/models/concerns/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/models/concerns/.keep (limited to 'app/models') diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 -- cgit From 73b0af5c938b49ef0a4a21921b41a3b1bcd4e05e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sun, 16 Apr 2017 10:38:02 -0400 Subject: Simplify the og:image and og:description code in stream_entries/show (#1934) --- app/models/status.rb | 4 ++++ app/views/stream_entries/_og_description.html.haml | 4 ++++ app/views/stream_entries/_og_image.html.haml | 6 ++++++ app/views/stream_entries/show.html.haml | 13 ++----------- 4 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 app/views/stream_entries/_og_description.html.haml create mode 100644 app/views/stream_entries/_og_image.html.haml (limited to 'app/models') diff --git a/app/models/status.rb b/app/models/status.rb index 16cd4383f..c0a5d9d1b 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -110,6 +110,10 @@ class Status < ApplicationRecord results end + def non_sensitive_with_media? + !sensitive? && media_attachments.any? + end + class << self def as_home_timeline(account) where(account: [account] + account.following) diff --git a/app/views/stream_entries/_og_description.html.haml b/app/views/stream_entries/_og_description.html.haml new file mode 100644 index 000000000..5762aca04 --- /dev/null +++ b/app/views/stream_entries/_og_description.html.haml @@ -0,0 +1,4 @@ +- if activity.is_a?(Status) && activity.spoiler_text? + %meta{ property: 'og:description', content: activity.spoiler_text }/ +- else + %meta{ property: 'og:description', content: activity.content }/ diff --git a/app/views/stream_entries/_og_image.html.haml b/app/views/stream_entries/_og_image.html.haml new file mode 100644 index 000000000..f725209d8 --- /dev/null +++ b/app/views/stream_entries/_og_image.html.haml @@ -0,0 +1,6 @@ +- if activity.is_a?(Status) && activity.non_sensitive_with_media? + %meta{ property: 'og:image', content: full_asset_url(activity.media_attachments.first.file.url(:small)) }/ +- else + %meta{ property: 'og:image', content: full_asset_url(account.avatar.url(:original)) }/ + %meta{ property: 'og:image:width', content: '120' }/ + %meta{ property: 'og:image:height', content: '120' }/ diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml index eb8387ccb..dea5e9d40 100644 --- a/app/views/stream_entries/show.html.haml +++ b/app/views/stream_entries/show.html.haml @@ -6,17 +6,8 @@ %meta{ property: 'og:type', content: 'article' }/ %meta{ property: 'og:title', content: "#{@account.username} on #{Rails.configuration.x.local_domain}" }/ - - if @stream_entry.activity.is_a?(Status) && !@stream_entry.activity.spoiler_text.blank? - %meta{ property: 'og:description', content: @stream_entry.activity.spoiler_text }/ - - else - %meta{ property: 'og:description', content: @stream_entry.activity.content }/ - - - if @stream_entry.activity.is_a?(Status) && !@stream_entry.activity.sensitive? && @stream_entry.activity.media_attachments.size > 0 - %meta{ property: 'og:image', content: full_asset_url(@stream_entry.activity.media_attachments.first.file.url(:small)) }/ - - else - %meta{ property: 'og:image', content: full_asset_url(@account.avatar.url(:original)) }/ - %meta{ property: 'og:image:width', content: '120' }/ - %meta{ property: 'og:image:height', content: '120' }/ + = render 'stream_entries/og_description', activity: @stream_entry.activity + = render 'stream_entries/og_image', activity: @stream_entry.activity, account: @account %meta{ property: 'twitter:card', content: 'summary' }/ -- cgit