From da77f65c4684a8a9ee25c3e18f6f09824c765c2d Mon Sep 17 00:00:00 2001 From: nullkal Date: Wed, 13 Sep 2017 19:30:07 +0900 Subject: Add instance search feature (#4925) --- app/controllers/admin/instances_controller.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb index 3296e08db..22f02e5d0 100644 --- a/app/controllers/admin/instances_controller.rb +++ b/app/controllers/admin/instances_controller.rb @@ -14,8 +14,12 @@ module Admin private + def filtered_instances + InstanceFilter.new(filter_params).results + end + def paginated_instances - Account.remote.by_domain_accounts.page(params[:page]) + filtered_instances.page(params[:page]) end helper_method :paginated_instances @@ -27,5 +31,11 @@ module Admin def subscribeable_accounts Account.with_followers.remote.where(domain: params[:by_domain]) end + + def filter_params + params.permit( + :domain_name + ) + end end end -- cgit From 9239e4ce4d4e958e62552d4a01183d0295c020f5 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 14 Sep 2017 00:04:30 +0200 Subject: Uploads for admin site settings (#4913) * Improve OpenGraph tags for about pages * Add thumbnail admin setting * Fix error * Fix up --- app/controllers/admin/settings_controller.rb | 14 ++++++-- app/javascript/images/mastodon_small.jpg | Bin 25199 -> 0 bytes app/javascript/images/preview.jpg | Bin 0 -> 292252 bytes app/models/site_upload.rb | 44 +++++++++++++++++++++++ app/presenters/instance_presenter.rb | 4 +++ app/serializers/rest/instance_serializer.rb | 8 ++++- app/views/about/_og.html.haml | 10 ++++++ app/views/about/more.html.haml | 11 +----- app/views/about/show.html.haml | 11 +----- app/views/admin/settings/edit.html.haml | 5 +++ config/locales/en.yml | 3 ++ db/migrate/20170913000752_create_site_uploads.rb | 10 ++++++ db/schema.rb | 14 +++++++- spec/fabricators/site_upload_fabricator.rb | 3 ++ spec/models/site_upload_spec.rb | 5 +++ spec/views/about/show.html.haml_spec.rb | 9 ++--- 16 files changed, 123 insertions(+), 28 deletions(-) delete mode 100644 app/javascript/images/mastodon_small.jpg create mode 100644 app/javascript/images/preview.jpg create mode 100644 app/models/site_upload.rb create mode 100644 app/views/about/_og.html.haml create mode 100644 db/migrate/20170913000752_create_site_uploads.rb create mode 100644 spec/fabricators/site_upload_fabricator.rb create mode 100644 spec/models/site_upload_spec.rb (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index c5e6fe4e5..a2f86b8a9 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -14,6 +14,7 @@ module Admin open_deletion timeline_preview bootstrap_timeline_accounts + thumbnail ).freeze BOOLEAN_SETTINGS = %w( @@ -22,14 +23,23 @@ module Admin timeline_preview ).freeze + UPLOAD_SETTINGS = %w( + thumbnail + ).freeze + def edit @admin_settings = Form::AdminSettings.new end def update settings_params.each do |key, value| - setting = Setting.where(var: key).first_or_initialize(var: key) - setting.update(value: value_for_update(key, value)) + if UPLOAD_SETTINGS.include?(key) + upload = SiteUpload.where(var: key).first_or_initialize(var: key) + upload.update(file: value) + else + setting = Setting.where(var: key).first_or_initialize(var: key) + setting.update(value: value_for_update(key, value)) + end end flash[:notice] = I18n.t('generic.changes_saved_msg') diff --git a/app/javascript/images/mastodon_small.jpg b/app/javascript/images/mastodon_small.jpg deleted file mode 100644 index 9c88ce3f7..000000000 Binary files a/app/javascript/images/mastodon_small.jpg and /dev/null differ diff --git a/app/javascript/images/preview.jpg b/app/javascript/images/preview.jpg new file mode 100644 index 000000000..ec2856748 Binary files /dev/null and b/app/javascript/images/preview.jpg differ diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb new file mode 100644 index 000000000..8ffdc8313 --- /dev/null +++ b/app/models/site_upload.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true +# == Schema Information +# +# Table name: site_uploads +# +# id :integer not null, primary key +# var :string default(""), not null +# file_file_name :string +# file_content_type :string +# file_file_size :integer +# file_updated_at :datetime +# meta :json +# created_at :datetime not null +# updated_at :datetime not null +# + +class SiteUpload < ApplicationRecord + has_attached_file :file + + validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ + validates :var, presence: true, uniqueness: true + + before_save :set_meta + after_commit :clear_cache + + def cache_key + "site_uploads/#{var}" + end + + private + + def set_meta + tempfile = file.queued_for_write[:original] + + return if tempfile.nil? + + geometry = Paperclip::Geometry.from_file(tempfile) + self.meta = { width: geometry.width.to_i, height: geometry.height.to_i } + end + + def clear_cache + Rails.cache.delete(cache_key) + end +end diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index 8104b7531..c9e3c31a1 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -35,4 +35,8 @@ class InstancePresenter def source_url Mastodon::Version.source_url end + + def thumbnail + @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') } + end end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index a97137909..2898011fd 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true class REST::InstanceSerializer < ActiveModel::Serializer + include RoutingHelper + attributes :uri, :title, :description, :email, - :version, :urls, :stats + :version, :urls, :stats, :thumbnail def uri Rails.configuration.x.local_domain @@ -24,6 +26,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer Mastodon::Version.to_s end + def thumbnail + full_asset_url(instance_presenter.thumbnail.file.url) if instance_presenter.thumbnail + end + def stats { user_count: instance_presenter.user_count, diff --git a/app/views/about/_og.html.haml b/app/views/about/_og.html.haml new file mode 100644 index 000000000..dbd476915 --- /dev/null +++ b/app/views/about/_og.html.haml @@ -0,0 +1,10 @@ +- thumbnail = @instance_presenter.thumbnail += opengraph 'og:site_name', t('about.hosted_on', domain: site_hostname) += opengraph 'og:url', about_url += opengraph 'og:type', 'website' += opengraph 'og:title', @instance_presenter.site_title += opengraph 'og:description', strip_tags(@instance_presenter.site_description.presence || t('about.about_mastodon_html')) += opengraph 'og:image', full_asset_url(thumbnail&.file&.url || asset_pack_path('preview.jpg', protocol: :request)) += opengraph 'og:image:width', thumbnail ? thumbnail.meta['width'] : '1200' += opengraph 'og:image:height', thumbnail ? thumbnail.meta['height'] : '630' += opengraph 'twitter:card', 'summary_large_image' diff --git a/app/views/about/more.html.haml b/app/views/about/more.html.haml index 094188472..1a4e74643 100644 --- a/app/views/about/more.html.haml +++ b/app/views/about/more.html.haml @@ -3,16 +3,7 @@ - content_for :header_tags do = javascript_pack_tag 'public', integrity: true, crossorigin: 'anonymous' - - %meta{ property: 'og:site_name', content: site_title }/ - %meta{ property: 'og:url', content: about_url }/ - %meta{ property: 'og:type', content: 'website' }/ - %meta{ property: 'og:title', content: site_hostname }/ - %meta{ property: 'og:description', content: strip_tags(@instance_presenter.site_description.presence || t('about.about_mastodon_html')) }/ - %meta{ property: 'og:image', content: asset_pack_path('mastodon_small.jpg', protocol: :request) }/ - %meta{ property: 'og:image:width', content: '400' }/ - %meta{ property: 'og:image:height', content: '400' }/ - %meta{ property: 'twitter:card', content: 'summary' }/ + = render partial: 'og' .landing-page .header-wrapper.compact diff --git a/app/views/about/show.html.haml b/app/views/about/show.html.haml index 93270fe3d..0d311b895 100644 --- a/app/views/about/show.html.haml +++ b/app/views/about/show.html.haml @@ -4,16 +4,7 @@ - content_for :header_tags do %script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json) = javascript_pack_tag 'about', integrity: true, crossorigin: 'anonymous' - - %meta{ property: 'og:site_name', content: site_title }/ - %meta{ property: 'og:url', content: about_url }/ - %meta{ property: 'og:type', content: 'website' }/ - %meta{ property: 'og:title', content: site_hostname }/ - %meta{ property: 'og:description', content: strip_tags(@instance_presenter.site_description.presence || t('about.about_mastodon_html')) }/ - %meta{ property: 'og:image', content: asset_pack_path('mastodon_small.jpg', protocol: :request) }/ - %meta{ property: 'og:image:width', content: '400' }/ - %meta{ property: 'og:image:height', content: '400' }/ - %meta{ property: 'twitter:card', content: 'summary' }/ + = render partial: 'og' .landing-page .header-wrapper diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 50d019ec4..468166035 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -10,6 +10,11 @@ %hr/ + .fields-group + = f.input :thumbnail, as: :file, wrapper: :with_block_label, label: t('admin.settings.thumbnail.title'), hint: t('admin.settings.thumbnail.desc_html') + + %hr/ + .fields-group = f.input :timeline_preview, as: :boolean, wrapper: :with_label, label: t('admin.settings.timeline_preview.title'), hint: t('admin.settings.timeline_preview.desc_html') diff --git a/config/locales/en.yml b/config/locales/en.yml index 0cd57a64f..8b5f52b02 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -195,6 +195,9 @@ en: desc_html: You can write your own privacy policy, terms of service or other legalese. You can use HTML tags title: Custom terms of service site_title: Instance name + thumbnail: + desc_html: Used for previews via OpenGraph and API. 1200x630px recommended + title: Instance thumbnail timeline_preview: desc_html: Display public timeline on landing page title: Timeline preview diff --git a/db/migrate/20170913000752_create_site_uploads.rb b/db/migrate/20170913000752_create_site_uploads.rb new file mode 100644 index 000000000..2246e48cd --- /dev/null +++ b/db/migrate/20170913000752_create_site_uploads.rb @@ -0,0 +1,10 @@ +class CreateSiteUploads < ActiveRecord::Migration[5.1] + def change + create_table :site_uploads do |t| + t.string :var, default: '', null: false, index: { unique: true } + t.attachment :file + t.json :meta + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d8af0a1f8..f2ca2af69 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170905165803) do +ActiveRecord::Schema.define(version: 20170913000752) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -288,6 +288,18 @@ ActiveRecord::Schema.define(version: 20170905165803) do t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true end + create_table "site_uploads", force: :cascade do |t| + t.string "var", default: "", null: false + t.string "file_file_name" + t.string "file_content_type" + t.integer "file_file_size" + t.datetime "file_updated_at" + t.json "meta" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["var"], name: "index_site_uploads_on_var", unique: true + end + create_table "status_pins", force: :cascade do |t| t.bigint "account_id", null: false t.bigint "status_id", null: false diff --git a/spec/fabricators/site_upload_fabricator.rb b/spec/fabricators/site_upload_fabricator.rb new file mode 100644 index 000000000..8f4e43ac9 --- /dev/null +++ b/spec/fabricators/site_upload_fabricator.rb @@ -0,0 +1,3 @@ +Fabricator(:site_upload) do + +end diff --git a/spec/models/site_upload_spec.rb b/spec/models/site_upload_spec.rb new file mode 100644 index 000000000..8745d54b8 --- /dev/null +++ b/spec/models/site_upload_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SiteUpload, type: :model do + +end diff --git a/spec/views/about/show.html.haml_spec.rb b/spec/views/about/show.html.haml_spec.rb index aa151dd27..724643cbc 100644 --- a/spec/views/about/show.html.haml_spec.rb +++ b/spec/views/about/show.html.haml_spec.rb @@ -15,15 +15,16 @@ describe 'about/show.html.haml', without_verify_partial_doubles: true do version_number: '1.0', source_url: 'https://github.com/tootsuite/mastodon', open_registrations: false, + thumbnail: nil, closed_registrations_message: 'yes') assign(:instance_presenter, instance_presenter) render header_tags = view.content_for(:header_tags) - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) + expect(header_tags).to match(%r{}) + expect(header_tags).to match(%r{}) + expect(header_tags).to match(%r{}) + expect(header_tags).to match(%r{}) end end -- cgit From 09a94b575e90dc7f6e179a1ec717156e725f915a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 19 Sep 2017 03:52:38 +0200 Subject: Admin interface for listing, adding and removing custom emojis (#5002) * Admin interface for listing, adding and removing custom emojis * Only display local ones in the list --- app/controllers/admin/custom_emojis_controller.rb | 34 ++++++++++++++++++++++ app/services/block_domain_service.rb | 9 ++++++ .../admin/custom_emojis/_custom_emoji.html.haml | 7 +++++ app/views/admin/custom_emojis/index.html.haml | 14 +++++++++ app/views/admin/custom_emojis/new.html.haml | 12 ++++++++ config/locales/en.yml | 12 ++++++++ config/navigation.rb | 1 + config/routes.rb | 2 ++ 8 files changed, 91 insertions(+) create mode 100644 app/controllers/admin/custom_emojis_controller.rb create mode 100644 app/views/admin/custom_emojis/_custom_emoji.html.haml create mode 100644 app/views/admin/custom_emojis/index.html.haml create mode 100644 app/views/admin/custom_emojis/new.html.haml (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/custom_emojis_controller.rb b/app/controllers/admin/custom_emojis_controller.rb new file mode 100644 index 000000000..616a279b3 --- /dev/null +++ b/app/controllers/admin/custom_emojis_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Admin + class CustomEmojisController < BaseController + def index + @custom_emojis = CustomEmoji.where(uri: nil) + end + + def new + @custom_emoji = CustomEmoji.new + end + + def create + @custom_emoji = CustomEmoji.new(resource_params) + + if @custom_emoji.save + redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg') + else + render :new + end + end + + def destroy + CustomEmoji.find(params[:id]).destroy + redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg') + end + + private + + def resource_params + params.require(:custom_emoji).permit(:shortcode, :image) + end + end +end diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb index 1473bc841..eefdc0dbf 100644 --- a/app/services/block_domain_service.rb +++ b/app/services/block_domain_service.rb @@ -26,6 +26,7 @@ class BlockDomainService < BaseService def clear_media! clear_account_images clear_account_attachments + clear_emojos end def suspend_accounts! @@ -51,6 +52,10 @@ class BlockDomainService < BaseService end end + def clear_emojos + emojis_from_blocked_domains.destroy_all + end + def blocked_domain domain_block.domain end @@ -62,4 +67,8 @@ class BlockDomainService < BaseService def media_from_blocked_domain MediaAttachment.joins(:account).merge(blocked_domain_accounts).reorder(nil) end + + def emojis_from_blocked_domains + CustomEmoji.where(domain: blocked_domain) + end end diff --git a/app/views/admin/custom_emojis/_custom_emoji.html.haml b/app/views/admin/custom_emojis/_custom_emoji.html.haml new file mode 100644 index 000000000..ff1aa9925 --- /dev/null +++ b/app/views/admin/custom_emojis/_custom_emoji.html.haml @@ -0,0 +1,7 @@ +%tr + %td + = image_tag custom_emoji.image.url, class: 'emojione', alt: ":#{custom_emoji.shortcode}:" + %td + %samp= ":#{custom_emoji.shortcode}:" + %td + = table_link_to 'times', t('admin.custom_emojis.delete'), admin_custom_emoji_path(custom_emoji), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } diff --git a/app/views/admin/custom_emojis/index.html.haml b/app/views/admin/custom_emojis/index.html.haml new file mode 100644 index 000000000..d5f32e84b --- /dev/null +++ b/app/views/admin/custom_emojis/index.html.haml @@ -0,0 +1,14 @@ +- content_for :page_title do + = t('admin.custom_emojis.title') + +.table-wrapper + %table.table + %thead + %tr + %th= t('admin.custom_emojis.emoji') + %th= t('admin.custom_emojis.shortcode') + %th + %tbody + = render @custom_emojis + += link_to t('admin.custom_emojis.upload'), new_admin_custom_emoji_path, class: 'button' diff --git a/app/views/admin/custom_emojis/new.html.haml b/app/views/admin/custom_emojis/new.html.haml new file mode 100644 index 000000000..672afe435 --- /dev/null +++ b/app/views/admin/custom_emojis/new.html.haml @@ -0,0 +1,12 @@ +- content_for :page_title do + = t('.title') + += simple_form_for @custom_emoji, url: admin_custom_emojis_path do |f| + = render 'shared/error_messages', object: @custom_emoji + + .fields-group + = f.input :shortcode, placeholder: t('admin.custom_emojis.shortcode'), hint: t('admin.custom_emojis.shortcode_hint') + = f.input :image, input_html: { accept: 'image/png' }, hint: t('admin.custom_emojis.image_hint') + + .actions + = f.button :button, t('admin.custom_emojis.upload'), type: :submit diff --git a/config/locales/en.yml b/config/locales/en.yml index 0f6bac9e1..9013f0ac9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -108,6 +108,18 @@ en: unsubscribe: Unsubscribe username: Username web: Web + custom_emojis: + created_msg: Emoji successfully created! + delete: Delete + destroyed_msg: Emojo successfully destroyed! + emoji: Emoji + image_hint: PNG up to 50KB + new: + title: Add new custom emoji + shortcode: Shortcode + shortcode_hint: At least 2 characters, only alphanumeric characters and underscores + title: Custom emojis + upload: Upload domain_blocks: add_new: Add new created_msg: Domain block is now being processed diff --git a/config/navigation.rb b/config/navigation.rb index 4b454b3fc..0a6ab6d3d 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -28,6 +28,7 @@ SimpleNavigation::Configuration.run do |navigation| admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' } admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' } admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url + admin.item :custom_emojis, safe_join([fa_icon('smile-o fw'), t('admin.custom_emojis.title')]), admin_custom_emojis_url, highlights_on: %r{/admin/custom_emojis} end primary.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' } diff --git a/config/routes.rb b/config/routes.rb index bf5428869..d38f5308a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -136,6 +136,8 @@ Rails.application.routes.draw do resources :users, only: [] do resource :two_factor_authentication, only: [:destroy] end + + resources :custom_emojis, only: [:index, :new, :create, :destroy] end get '/admin', to: redirect('/admin/settings/edit', status: 302) -- cgit From 1664e52cbb5ec08db896127640bd0554cee1d384 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 19 Sep 2017 12:06:13 +0900 Subject: Fix custom emojis index (#5006) --- app/controllers/admin/custom_emojis_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/custom_emojis_controller.rb b/app/controllers/admin/custom_emojis_controller.rb index 616a279b3..572ad1ac2 100644 --- a/app/controllers/admin/custom_emojis_controller.rb +++ b/app/controllers/admin/custom_emojis_controller.rb @@ -3,7 +3,7 @@ module Admin class CustomEmojisController < BaseController def index - @custom_emojis = CustomEmoji.where(uri: nil) + @custom_emojis = CustomEmoji.where(domain: nil) end def new -- cgit