Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JantsoP authored Apr 5, 2017
2 parents 3ec221d + ccb6a65 commit 20b53e6
Show file tree
Hide file tree
Showing 57 changed files with 573 additions and 167 deletions.
2 changes: 2 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ OTP_SECRET=
# SINGLE_USER_MODE=true
# Prevent registrations with following e-mail domains
# EMAIL_DOMAIN_BLACKLIST=example1.com|example2.de|etc
# Only allow registrations with the following e-mail domains
# EMAIL_DOMAIN_WHITELIST=example1.com|example2.de|etc

# E-mail configuration
SMTP_SERVER=smtp.mailgun.org
Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ gem 'rqrcode'
gem 'twitter-text'
gem 'oj'
gem 'hiredis'
gem 'redis', '~>3.2'
gem 'redis', '~>3.2', require: ['redis', 'redis/connection/hiredis']
gem 'fast_blank'
gem 'htmlentities'
gem 'simple_form'
gem 'will_paginate'
gem 'rack-attack'
gem 'rack-cors', require: 'rack/cors'
gem 'sidekiq'
gem 'sidekiq-unique-jobs'
gem 'rails-settings-cached'
gem 'simple-navigation'
gem 'statsd-instrument'
Expand All @@ -66,9 +67,10 @@ group :development, :test do
end

group :test do
gem 'faker'
gem 'rspec-sidekiq'
gem 'simplecov', require: false
gem 'webmock'
gem 'rspec-sidekiq'
end

group :development do
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ GEM
erubis (2.7.0)
execjs (2.7.0)
fabrication (2.15.2)
faker (1.6.6)
i18n (~> 0.5)
fast_blank (1.0.0)
font-awesome-rails (4.6.3.1)
railties (>= 3.2, < 5.1)
Expand Down Expand Up @@ -387,6 +389,9 @@ GEM
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
sidekiq-unique-jobs (4.0.18)
sidekiq (>= 2.6)
thor
simple-navigation (4.0.3)
activesupport (>= 2.3.2)
simple_form (3.2.1)
Expand Down Expand Up @@ -467,6 +472,7 @@ DEPENDENCIES
doorkeeper
dotenv-rails
fabrication
faker
fast_blank
font-awesome-rails
fuubar
Expand Down Expand Up @@ -510,6 +516,7 @@ DEPENDENCIES
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
sidekiq
sidekiq-unique-jobs
simple-navigation
simple_form
simplecov
Expand Down
5 changes: 5 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Issue text goes here].

* * * *

- [ ] I searched or browsed the repo’s other issues to ensure this is not a duplicate.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const iconStyle = {
};

const ClearColumnButton = ({ onClick }) => (
<div className='column-icon' style={iconStyle} onClick={onClick}>
<div className='column-icon' tabindex='0' style={iconStyle} onClick={onClick}>
<i className='fa fa-trash' />
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion app/assets/stylesheets/about.scss
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
}
}

.simple_form {
.simple_form, .closed-registrations-message {
width: 300px;
flex: 0 0 auto;
background: rgba(darken($color1, 7%), 0.5);
Expand All @@ -340,3 +340,11 @@
}
}
}

.closed-registrations-message {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/accounts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
text-align: center;
position: relative;
z-index: 2;
text-shadow: 0 0 2px $color8;

small {
display: block;
Expand Down Expand Up @@ -128,6 +129,7 @@
text-transform: uppercase;
display: block;
margin-bottom: 5px;
text-shadow: 0 0 2px $color8;
}

.counter-number {
Expand Down Expand Up @@ -385,5 +387,6 @@
.account__header__content {
font-size: 14px;
color: $color1;
text-shadow: 0 0 2px $color8;
}
}
4 changes: 3 additions & 1 deletion app/controllers/about_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class AboutController < ApplicationController
before_action :set_body_classes

def index
@description = Setting.site_description
@description = Setting.site_description
@open_registrations = Setting.open_registrations
@closed_registrations_message = Setting.closed_registrations_message

@user = User.new
@user.build_account
Expand Down
14 changes: 12 additions & 2 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def index

def update
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
value = settings_params[:value]

if @setting.value != params[:setting][:value]
@setting.value = params[:setting][:value]
# Special cases
value = value == 'true' if @setting.var == 'open_registrations'

if @setting.value != value
@setting.value = value
@setting.save
end

Expand All @@ -22,4 +26,10 @@ def update
format.json { respond_with_bip(@setting) }
end
end

private

def settings_params
params.require(:setting).permit(:value)
end
end
10 changes: 5 additions & 5 deletions app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Auth::RegistrationsController < Devise::RegistrationsController
layout :determine_layout

before_action :check_single_user_mode
before_action :check_enabled_registrations, only: [:new, :create]
before_action :configure_sign_up_params, only: [:create]

protected
Expand All @@ -27,12 +27,12 @@ def after_inactive_sign_up_path_for(_resource)
new_user_session_path
end

def check_single_user_mode
redirect_to root_path if Rails.configuration.x.single_user_mode
def check_enabled_registrations
redirect_to root_path if Rails.configuration.x.single_user_mode || !Setting.open_registrations
end

private

def determine_layout
%w(edit update).include?(action_name) ? 'admin' : 'auth'
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/remote_follow_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RemoteFollowController < ApplicationController

def new
@remote_follow = RemoteFollow.new
@remote_follow.acct = session[:remote_follow] if session.key?(:remote_follow)
end

def create
Expand All @@ -22,6 +23,8 @@ def create
render(:new) && return
end

session[:remote_follow] = @remote_follow.acct

redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: "#{@account.username}@#{Rails.configuration.x.local_domain}").to_s
else
render :new
Expand Down
17 changes: 15 additions & 2 deletions app/lib/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@

class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if Rails.configuration.x.email_domains_blacklist.empty?

record.errors.add(attribute, I18n.t('users.invalid_email')) if blocked_email?(value)
end

private

def blocked_email?(value)
on_blacklist?(value) || not_on_whitelist?(value)
end

def on_blacklist?(value)
return false if Rails.configuration.x.email_domains_blacklist.blank?

domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)

value =~ regexp
end

def not_on_whitelist?(value)
return false if Rails.configuration.x.email_domains_whitelist.blank?

domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.')
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)

value !~ regexp
end
end
107 changes: 53 additions & 54 deletions app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
class FeedManager
include Singleton

MAX_ITEMS = 800
MAX_ITEMS = 400

def key(type, id)
"feed:#{type}:#{id}"
end

def filter?(timeline_type, status, receiver)
def filter?(timeline_type, status, receiver_id)
if timeline_type == :home
filter_from_home?(status, receiver)
filter_from_home?(status, receiver_id)
elsif timeline_type == :mentions
filter_from_mentions?(status, receiver)
filter_from_mentions?(status, receiver_id)
else
false
end
Expand Down Expand Up @@ -50,42 +50,39 @@ def trim(type, account_id)

def merge_into_timeline(from_account, into_account)
timeline_key = key(:home, into_account.id)
query = from_account.statuses.limit(FeedManager::MAX_ITEMS / 4)

from_account.statuses.limit(MAX_ITEMS).each do |status|
next if status.direct_visibility? || filter?(:home, status, into_account)
redis.zadd(timeline_key, status.id, status.id)
if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4
oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true)&.first&.last&.to_i || 0
query = query.where('id > ?', oldest_home_score)
end

redis.pipelined do
query.each do |status|
next if status.direct_visibility? || filter?(:home, status, into_account)
redis.zadd(timeline_key, status.id, status.id)
end
end

trim(:home, into_account.id)
end

def unmerge_from_timeline(from_account, into_account)
timeline_key = key(:home, into_account.id)

from_account.statuses.select('id').find_each do |status|
redis.zrem(timeline_key, status.id)
redis.zremrangebyscore(timeline_key, status.id, status.id)
oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true)&.first&.last&.to_i || 0

from_account.statuses.select('id').where('id > ?', oldest_home_score).find_in_batches do |statuses|
redis.pipelined do
statuses.each do |status|
redis.zrem(timeline_key, status.id)
redis.zremrangebyscore(timeline_key, status.id, status.id)
end
end
end
end

def inline_render(target_account, template, object)
rabl_scope = Class.new do
include RoutingHelper

def initialize(account)
@account = account
end

def current_user
@account.try(:user)
end

def current_account
@account
end
end

Rabl::Renderer.new(template, object, view_path: 'app/views', format: :json, scope: rabl_scope.new(target_account)).render
Rabl::Renderer.new(template, object, view_path: 'app/views', format: :json, scope: InlineRablScope.new(target_account)).render
end

private
Expand All @@ -94,38 +91,40 @@ def redis
Redis.current
end

def filter_from_home?(status, receiver)
return true if receiver.muting?(status.account)

should_filter = false

if status.reply? && status.in_reply_to_id.nil?
should_filter = true
elsif status.reply? && !status.in_reply_to_account_id.nil? # Filter out if it's a reply
should_filter = !receiver.following?(status.in_reply_to_account) # and I'm not following the person it's a reply to
should_filter &&= !(receiver.id == status.in_reply_to_account_id) # and it's not a reply to me
should_filter &&= !(status.account_id == status.in_reply_to_account_id) # and it's not a self-reply
elsif status.reblog? # Filter out a reblog
should_filter = receiver.blocking?(status.reblog.account) # if I'm blocking the reblogged person
should_filter ||= receiver.muting?(status.reblog.account) # or muting that person
should_filter ||= status.reblog.account.blocking?(receiver) # or if the author of the reblogged status is blocking me
end
def filter_from_home?(status, receiver_id)
return true if status.reply? && status.in_reply_to_id.nil?

should_filter ||= receiver.blocking?(status.mentions.map(&:account_id)) # or if it mentions someone I blocked
check_for_mutes = [status.account_id]
check_for_mutes.concat([status.reblog.account_id]) if status.reblog?

should_filter
end
return true if Mute.where(account_id: receiver_id, target_account_id: check_for_mutes).any?

def filter_from_mentions?(status, receiver)
should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself
should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked
should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account)) # or if it mentions someone I blocked
should_filter ||= (status.account.silenced? && !receiver.following?(status.account)) # of if the account is silenced and I'm not following them
check_for_blocks = status.mentions.map(&:account_id)
check_for_blocks.concat([status.reblog.account_id]) if status.reblog?

if status.reply? && !status.in_reply_to_account_id.nil? # or it's a reply
should_filter ||= receiver.blocking?(status.in_reply_to_account) # to a user I blocked
return true if Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any?

if status.reply? && !status.in_reply_to_account_id.nil? # Filter out if it's a reply
should_filter = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists? # and I'm not following the person it's a reply to
should_filter &&= !(receiver_id == status.in_reply_to_account_id) # and it's not a reply to me
should_filter &&= !(status.account_id == status.in_reply_to_account_id) # and it's not a self-reply
return should_filter
elsif status.reblog? # Filter out a reblog
return Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists? # or if the author of the reblogged status is blocking me
end

false
end

def filter_from_mentions?(status, receiver_id)
check_for_blocks = [status.account_id]
check_for_blocks.concat(status.mentions.pluck(:account_id))
check_for_blocks.concat([status.in_reply_to_account]) if status.reply? && !status.in_reply_to_account_id.nil?

should_filter = receiver_id == status.account_id # Filter if I'm mentioning myself
should_filter ||= Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any? # or it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked
should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them

should_filter
end
end
Loading

0 comments on commit 20b53e6

Please sign in to comment.