From 41aac1ba3a247b2178699e529239a7f3b8eb6edc Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 8 Aug 2019 23:03:09 +0200 Subject: Add GIF and WebP support for custom emojis (#11519) Fix #11466 --- app/models/custom_emoji.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 514cf4845..643a7e46a 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -28,6 +28,8 @@ class CustomEmoji < ApplicationRecord :(#{SHORTCODE_RE_FRAGMENT}): (?=[^[:alnum:]:]|$)/x + IMAGE_MIME_TYPES = %w(image/png image/gif image/webp).freeze + belongs_to :category, class_name: 'CustomEmojiCategory', optional: true has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode @@ -35,7 +37,7 @@ class CustomEmoji < ApplicationRecord before_validation :downcase_domain - validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { less_than: LIMIT } + validates_attachment :image, content_type: { content_type: IMAGE_MIME_TYPES }, presence: true, size: { less_than: LIMIT } validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 } scope :local, -> { where(domain: nil) } -- cgit From 898dacf83eaaec8ba02d4e44dd9901521d79a898 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 8 Aug 2019 23:03:28 +0200 Subject: Fix weekly usage not being displayed correctly in hashtag admin UI (#11524) Fix percentages in usage breakdown having too many digits Change trending hashtags to only ask for review if a hashtag enters the top 3 position in the set, since it's the only items shown in the default web UI --- app/controllers/admin/tags_controller.rb | 2 +- app/models/trending_tags.rb | 3 ++- app/views/admin/tags/show.html.haml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index d62361eaa..39aca2a4b 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -71,7 +71,7 @@ module Admin now = Time.now.utc.beginning_of_day.to_date (Date.commercial(now.cwyear, now.cweek)..now).map do |date| - date.to_time.utc.beginning_of_day.to_i + date.to_time(:utc).beginning_of_day.to_i end end end diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index 594ae9520..3d60a7fea 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -6,6 +6,7 @@ class TrendingTags EXPIRE_TRENDS_AFTER = 1.day.seconds THRESHOLD = 5 LIMIT = 10 + REVIEW_THRESHOLD = 3 class << self include Redisable @@ -60,7 +61,7 @@ class TrendingTags old_rank = redis.zrevrank(key, tag.id) redis.zadd(key, score, tag.id) - request_review!(tag) if (old_rank.nil? || old_rank > LIMIT) && redis.zrevrank(key, tag.id) <= LIMIT && !tag.trendable? && tag.requires_review? && !tag.requested_review? + request_review!(tag) if (old_rank.nil? || old_rank > REVIEW_THRESHOLD) && redis.zrevrank(key, tag.id) <= REVIEW_THRESHOLD && !tag.trendable? && tag.requires_review? && !tag.requested_review? end redis.expire(key, EXPIRE_TRENDS_AFTER) diff --git a/app/views/admin/tags/show.html.haml b/app/views/admin/tags/show.html.haml index 6a1e03065..c3779d48c 100644 --- a/app/views/admin/tags/show.html.haml +++ b/app/views/admin/tags/show.html.haml @@ -41,5 +41,5 @@ - @usage_by_domain.each do |(domain, count)| %tr %th= domain || site_hostname - %td= "#{number_with_delimiter((count.to_f / @tag.history[0][:uses].to_f) * 100)}%" + %td= number_to_percentage((count / @tag.history[0][:uses].to_f) * 100) %td= number_with_delimiter count -- cgit From 7a1f8a58df7edeb4f1d03c9dd3c25d5370d858a6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 8 Aug 2019 23:04:19 +0200 Subject: Fix crash when saving invalid domain name (#11528) Fix #7629 --- app/models/account_domain_block.rb | 2 +- app/models/concerns/domain_normalizable.rb | 2 +- app/models/domain_allow.rb | 2 +- app/models/domain_block.rb | 2 +- app/models/email_domain_block.rb | 2 +- app/validators/domain_validator.rb | 17 +++++++++++++++++ config/locales/en.yml | 2 ++ 7 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 app/validators/domain_validator.rb (limited to 'app/models') diff --git a/app/models/account_domain_block.rb b/app/models/account_domain_block.rb index 7c0d60379..3aaffde9a 100644 --- a/app/models/account_domain_block.rb +++ b/app/models/account_domain_block.rb @@ -15,7 +15,7 @@ class AccountDomainBlock < ApplicationRecord include DomainNormalizable belongs_to :account - validates :domain, presence: true, uniqueness: { scope: :account_id } + validates :domain, presence: true, uniqueness: { scope: :account_id }, domain: true after_commit :remove_blocking_cache after_commit :remove_relationship_cache diff --git a/app/models/concerns/domain_normalizable.rb b/app/models/concerns/domain_normalizable.rb index fb84058fc..c00b3142f 100644 --- a/app/models/concerns/domain_normalizable.rb +++ b/app/models/concerns/domain_normalizable.rb @@ -4,7 +4,7 @@ module DomainNormalizable extend ActiveSupport::Concern included do - before_validation :normalize_domain + before_save :normalize_domain end private diff --git a/app/models/domain_allow.rb b/app/models/domain_allow.rb index 85018b636..5fe0e3a29 100644 --- a/app/models/domain_allow.rb +++ b/app/models/domain_allow.rb @@ -13,7 +13,7 @@ class DomainAllow < ApplicationRecord include DomainNormalizable - validates :domain, presence: true, uniqueness: true + validates :domain, presence: true, uniqueness: true, domain: true scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 3f5b9f23e..37b8d98c6 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -19,7 +19,7 @@ class DomainBlock < ApplicationRecord enum severity: [:silence, :suspend, :noop] - validates :domain, presence: true, uniqueness: true + validates :domain, presence: true, uniqueness: true, domain: true has_many :accounts, foreign_key: :domain, primary_key: :domain delegate :count, to: :accounts, prefix: true diff --git a/app/models/email_domain_block.rb b/app/models/email_domain_block.rb index 0fcd36477..bc70dea25 100644 --- a/app/models/email_domain_block.rb +++ b/app/models/email_domain_block.rb @@ -12,7 +12,7 @@ class EmailDomainBlock < ApplicationRecord include DomainNormalizable - validates :domain, presence: true, uniqueness: true + validates :domain, presence: true, uniqueness: true, domain: true def self.block?(email) _, domain = email.split('@', 2) diff --git a/app/validators/domain_validator.rb b/app/validators/domain_validator.rb new file mode 100644 index 000000000..ae07f1798 --- /dev/null +++ b/app/validators/domain_validator.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DomainValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return if value.blank? + + record.errors.add(attribute, I18n.t('domain_validator.invalid_domain')) unless compliant?(value) + end + + private + + def compliant?(value) + Addressable::URI.new.tap { |uri| uri.host = value } + rescue Addressable::URI::InvalidURIError + false + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7fd0536ae..786906e2d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -628,6 +628,8 @@ en: people: one: "%{count} person" other: "%{count} people" + domain_validator: + invalid_domain: is not a valid domain name errors: '403': You don't have permission to view this page. '404': The page you are looking for isn't here. -- cgit From aebefc7ce9cff913c4f04bb94ebda428e755ecad Mon Sep 17 00:00:00 2001 From: kedama Date: Sun, 11 Aug 2019 20:15:18 +0900 Subject: Fix some emojis in profile metadata labels are not emojified. (#11534) --- app/models/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index b205c8c9e..60c06aaf0 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -506,7 +506,7 @@ class Account < ApplicationRecord end def emojifiable_text - [note, display_name, fields.map(&:value)].join(' ') + [note, display_name, fields.map(&:name), fields.map(&:value)].join(' ') end def clean_feed_manager -- cgit