diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-07-17 22:05:25 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-07-17 22:05:25 +0200 |
commit | 7dbed4dab93d3eaf79b7e7e4a61f52782909d1ae (patch) | |
tree | 7a235fc9422d71f56993b4682b06439310f21f65 /app | |
parent | 1fb78602c56b7bf52dcf383fea7a4c45ce568655 (diff) | |
parent | 6277a6db2a70b798aed71ff7e722d23b975182cd (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/dashboard_controller.rb | 43 | ||||
-rw-r--r-- | app/javascript/mastodon/locales/pl.json | 2 | ||||
-rw-r--r-- | app/javascript/styles/application.scss | 1 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/about.scss | 2 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/dashboard.scss | 69 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/stream_entries.scss | 4 | ||||
-rw-r--r-- | app/lib/sanitize_config.rb | 2 | ||||
-rw-r--r-- | app/models/trending_tags.rb | 27 | ||||
-rw-r--r-- | app/services/favourite_service.rb | 1 | ||||
-rw-r--r-- | app/services/post_status_service.rb | 4 | ||||
-rw-r--r-- | app/services/reblog_service.rb | 1 | ||||
-rw-r--r-- | app/views/admin/dashboard/index.html.haml | 149 | ||||
-rw-r--r-- | app/workers/activitypub/update_distribution_worker.rb | 2 |
13 files changed, 302 insertions, 5 deletions
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 000000000..7be753c9b --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true +require 'sidekiq/api' + +module Admin + class DashboardController < BaseController + def index + @users_count = User.count + @registrations_week = Redis.current.get("activity:accounts:local:#{current_week}") || 0 + @logins_week = Redis.current.pfcount("activity:logins:#{current_week}") + @interactions_week = Redis.current.get("activity:interactions:#{current_week}") || 0 + @relay_enabled = Relay.enabled.exists? + @single_user_mode = Rails.configuration.x.single_user_mode + @registrations_enabled = Setting.open_registrations + @deletions_enabled = Setting.open_deletion + @invites_enabled = Setting.min_invite_role == 'user' + @search_enabled = Chewy.enabled? + @version = Mastodon::Version.to_s + @database_version = ActiveRecord::Base.connection.execute('SELECT VERSION()').first['version'].match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1] + @redis_version = redis_info['redis_version'] + @reports_count = Report.unresolved.count + @queue_backlog = Sidekiq::Stats.new.enqueued + @recent_users = User.confirmed.recent.includes(:account).limit(4) + @database_size = ActiveRecord::Base.connection.execute('SELECT pg_database_size(current_database())').first['pg_database_size'] + @redis_size = redis_info['used_memory'] + @ldap_enabled = ENV['LDAP_ENABLED'] == 'true' + @cas_enabled = ENV['CAS_ENABLED'] == 'true' + @saml_enabled = ENV['SAML_ENABLED'] == 'true' + @pam_enabled = ENV['PAM_ENABLED'] == 'true' + @hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true' + @trending_hashtags = TrendingTags.get(7) + end + + private + + def current_week + @current_week ||= Time.now.utc.to_date.cweek + end + + def redis_info + @redis_info ||= Redis.current.info + end + end +end diff --git a/app/javascript/mastodon/locales/pl.json b/app/javascript/mastodon/locales/pl.json index 355a11a03..aaab1d85c 100644 --- a/app/javascript/mastodon/locales/pl.json +++ b/app/javascript/mastodon/locales/pl.json @@ -170,7 +170,7 @@ "navigation_bar.domain_blocks": "Ukryte domeny", "navigation_bar.edit_profile": "Edytuj profil", "navigation_bar.favourites": "Ulubione", - "navigation_bar.filters": "Muted words", + "navigation_bar.filters": "Wyciszone słowa", "navigation_bar.follow_requests": "Prośby o śledzenie", "navigation_bar.info": "Szczegółowe informacje", "navigation_bar.keyboard_shortcuts": "Skróty klawiszowe", diff --git a/app/javascript/styles/application.scss b/app/javascript/styles/application.scss index f207c02a6..7b3b10dfe 100644 --- a/app/javascript/styles/application.scss +++ b/app/javascript/styles/application.scss @@ -21,5 +21,6 @@ @import 'mastodon/about'; @import 'mastodon/tables'; @import 'mastodon/admin'; +@import 'mastodon/dashboard'; @import 'mastodon/rtl'; @import 'mastodon/accessibility'; diff --git a/app/javascript/styles/mastodon/about.scss b/app/javascript/styles/mastodon/about.scss index 19e14fe95..fefb03407 100644 --- a/app/javascript/styles/mastodon/about.scss +++ b/app/javascript/styles/mastodon/about.scss @@ -923,7 +923,7 @@ $small-breakpoint: 960px; } @media screen and (max-width: $column-breakpoint) { - height: 90vh; + display: none; } } diff --git a/app/javascript/styles/mastodon/dashboard.scss b/app/javascript/styles/mastodon/dashboard.scss new file mode 100644 index 000000000..949ca733f --- /dev/null +++ b/app/javascript/styles/mastodon/dashboard.scss @@ -0,0 +1,69 @@ +.dashboard__counters { + display: flex; + flex-wrap: wrap; + margin: 0 -5px; + margin-bottom: 20px; + + & > div { + box-sizing: border-box; + flex: 0 0 33.333%; + padding: 0 5px; + margin-bottom: 10px; + + & > div, + & > a { + padding: 20px; + background: lighten($ui-base-color, 4%); + border-radius: 4px; + } + + & > a { + text-decoration: none; + color: inherit; + display: block; + + &:hover, + &:focus, + &:active { + background: lighten($ui-base-color, 8%); + } + } + } + + &__num { + text-align: center; + font-weight: 500; + font-size: 24px; + color: $primary-text-color; + font-family: 'mastodon-font-display', sans-serif; + margin-bottom: 20px; + } + + &__label { + font-size: 14px; + color: $darker-text-color; + text-align: center; + font-weight: 500; + } +} + +.dashboard__widgets { + display: flex; + flex-wrap: wrap; + margin: 0 -5px; + + & > div { + flex: 0 0 33.333%; + margin-bottom: 20px; + + & > div { + padding: 0 5px; + } + } + + a:not(.name-tag) { + color: $ui-secondary-color; + font-weight: 500; + text-decoration: none; + } +} diff --git a/app/javascript/styles/mastodon/stream_entries.scss b/app/javascript/styles/mastodon/stream_entries.scss index 9188c2206..f4d6e237f 100644 --- a/app/javascript/styles/mastodon/stream_entries.scss +++ b/app/javascript/styles/mastodon/stream_entries.scss @@ -2,6 +2,10 @@ clear: both; box-shadow: 0 0 15px rgba($base-shadow-color, 0.2); + div[data-component] { + width: 100%; + } + .entry { background: $simple-background-color; diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index c2b466924..1bba4a5a6 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -2,7 +2,7 @@ class Sanitize module Config - HTTP_PROTOCOLS ||= ['http', 'https', :relative].freeze + HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', :relative].freeze CLASS_WHITELIST_TRANSFORMER = lambda do |env| node = env[:node] diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index c3641d7fd..c559651c6 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class TrendingTags + KEY = 'trending_tags' EXPIRE_HISTORY_AFTER = 7.days.seconds + EXPIRE_TRENDS_AFTER = 1.day.seconds + THRESHOLD = 5 class << self def record_use!(tag, account, at_time = Time.now.utc) @@ -9,6 +12,14 @@ class TrendingTags increment_historical_use!(tag.id, at_time) increment_unique_use!(tag.id, account.id, at_time) + increment_vote!(tag.id, at_time) + end + + def get(limit) + key = "#{KEY}:#{Time.now.utc.beginning_of_day.to_i}" + tag_ids = redis.zrevrange(key, 0, limit - 1).map(&:to_i) + tags = Tag.where(id: tag_ids).to_a.map { |tag| [tag.id, tag] }.to_h + tag_ids.map { |tag_id| tags[tag_id] }.compact end private @@ -25,6 +36,22 @@ class TrendingTags redis.expire(key, EXPIRE_HISTORY_AFTER) end + def increment_vote!(tag_id, at_time) + key = "#{KEY}:#{at_time.beginning_of_day.to_i}" + expected = redis.pfcount("activity:tags:#{tag_id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts").to_f + expected = 1.0 if expected.zero? + observed = redis.pfcount("activity:tags:#{tag_id}:#{at_time.beginning_of_day.to_i}:accounts").to_f + + if expected > observed || observed < THRESHOLD + redis.zrem(key, tag_id.to_s) + else + score = ((observed - expected)**2) / expected + redis.zadd(key, score, tag_id.to_s) + end + + redis.expire(key, EXPIRE_TRENDS_AFTER) + end + def disallowed_hashtags return @disallowed_hashtags if defined?(@disallowed_hashtags) diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index 6e1ac3ba9..b565bcc32 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -37,6 +37,7 @@ class FavouriteService < BaseService end def bump_potential_friendship(account, status) + ActivityTracker.increment('activity:interactions') return if account.following?(status.account_id) PotentialFriendshipTracker.record(account.id, status.account_id, :favourite) end diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index a27f28ef6..52d49a69e 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -86,7 +86,9 @@ class PostStatusService < BaseService end def bump_potential_friendship(account, status) - return if !status.reply? || account.following?(status.in_reply_to_account_id) + return if !status.reply? || account.id == status.in_reply_to_account_id + ActivityTracker.increment('activity:interactions') + return if account.following?(status.in_reply_to_account_id) PotentialFriendshipTracker.record(account.id, status.in_reply_to_account_id, :reply) end end diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 955a2bdbc..03db27406 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -47,6 +47,7 @@ class ReblogService < BaseService end def bump_potential_friendship(account, reblog) + ActivityTracker.increment('activity:interactions') return if account.following?(reblog.reblog.account_id) PotentialFriendshipTracker.record(account.id, reblog.reblog.account_id, :reblog) end diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml new file mode 100644 index 000000000..1996eef4d --- /dev/null +++ b/app/views/admin/dashboard/index.html.haml @@ -0,0 +1,149 @@ +- content_for :page_title do + = t('admin.dashboard.title') + +.dashboard__counters + %div + = link_to admin_accounts_url(local: 1, recent: 1) do + .dashboard__counters__num= number_with_delimiter @users_count + .dashboard__counters__label= t 'admin.dashboard.total_users' + %div + %div + .dashboard__counters__num= number_with_delimiter @registrations_week + .dashboard__counters__label= t 'admin.dashboard.week_users_new' + %div + %div + .dashboard__counters__num= number_with_delimiter @logins_week + .dashboard__counters__label= t 'admin.dashboard.week_users_active' + %div + %div + .dashboard__counters__num= number_with_delimiter @interactions_week + .dashboard__counters__label= t 'admin.dashboard.week_interactions' + %div + = link_to admin_reports_url do + .dashboard__counters__num= number_with_delimiter @reports_count + .dashboard__counters__label= t 'admin.dashboard.open_reports' + %div + = link_to sidekiq_url do + .dashboard__counters__num= number_with_delimiter @queue_backlog + .dashboard__counters__label= t 'admin.dashboard.backlog' + +.dashboard__widgets + .dashboard__widgets__users + %div + %h4= t 'admin.dashboard.recent_users' + %ul + - @recent_users.each do |user| + %li= admin_account_link_to(user.account) + + .dashboard__widgets__features + %div + %h4= t 'admin.dashboard.features' + %ul + %li + = link_to t('admin.dashboard.feature_registrations'), edit_admin_settings_path + - if @registrations_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_invites'), edit_admin_settings_path + - if @invites_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_deletions'), edit_admin_settings_path + - if @deletions_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_relay'), admin_relays_path + - if @relay_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__versions + %div + %h4= t 'admin.dashboard.software' + %ul + %li + Mastodon + %span.pull-right= @version + %li + Ruby + %span.pull-right= "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}" + %li + PostgreSQL + %span.pull-right= @database_version + %li + Redis + %span.pull-right= @redis_version + + .dashboard__widgets__space + %div + %h4= t 'admin.dashboard.space' + %ul + %li + PostgreSQL + %span.pull-right= number_to_human_size @database_size + %li + Redis + %span.pull-right= number_to_human_size @redis_size + + .dashboard__widgets__config + %div + %h4= t 'admin.dashboard.config' + %ul + %li + = t('admin.dashboard.search') + - if @search_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t('admin.dashboard.single_user_mode') + - if @single_user_mode + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + LDAP + - if @ldap_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + CAS + - if @cas_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + SAML + - if @saml_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + PAM + - if @pam_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t 'admin.dashboard.hidden_service' + - if @hidden_service + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__trends + %div + %h4= t 'admin.dashboard.trends' + %ul + - @trending_hashtags.each do |tag| + %li + = link_to "##{tag.name}", web_url("timelines/tag/#{tag.name}") + %span.pull-right= number_with_delimiter(tag.history[0][:accounts].to_i) diff --git a/app/workers/activitypub/update_distribution_worker.rb b/app/workers/activitypub/update_distribution_worker.rb index 87efafb3e..bbda69305 100644 --- a/app/workers/activitypub/update_distribution_worker.rb +++ b/app/workers/activitypub/update_distribution_worker.rb @@ -34,6 +34,6 @@ class ActivityPub::UpdateDistributionWorker @account, serializer: ActivityPub::UpdateSerializer, adapter: ActivityPub::Adapter - ).to_json + ).as_json end end |