Skip to content

Commit

Permalink
Merge pull request mastodon#1265 from ThibG/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes
  • Loading branch information
ClearlyClaire committed Jan 24, 2020
2 parents a8c109b + bdc1581 commit 0be67df
Show file tree
Hide file tree
Showing 272 changed files with 3,841 additions and 799 deletions.
10 changes: 10 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,13 @@ STREAMING_CLUSTER_NUM=1
# http_proxy=http://gateway.local:8118
# Access control for hidden service.
# ALLOW_ACCESS_TO_HIDDEN_SERVICE=true

# Authorized fetch mode (optional)
# Require remote servers to authentify when fetching toots, see
# https://docs.joinmastodon.org/admin/config/#authorized_fetch
# AUTHORIZED_FETCH=true

# Whitelist mode (optional)
# Only allow federation with whitelisted domains, see
# https://docs.joinmastodon.org/admin/config/#whitelist_mode
# WHITELIST_MODE=true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8
12
69 changes: 69 additions & 0 deletions app/controllers/admin/announcements_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

class Admin::AnnouncementsController < Admin::BaseController
before_action :set_announcements, only: :index
before_action :set_announcement, except: [:index, :new, :create]

def index
authorize :announcement, :index?
end

def new
authorize :announcement, :create?

@announcement = Announcement.new
end

def create
authorize :announcement, :create?

@announcement = Announcement.new(resource_params)

if @announcement.save
log_action :create, @announcement
redirect_to admin_announcements_path
else
render :new
end
end

def edit
authorize :announcement, :update?
end

def update
authorize :announcement, :update?

if @announcement.update(resource_params)
log_action :update, @announcement
redirect_to admin_announcements_path
else
render :edit
end
end

def destroy
authorize :announcement, :destroy?
@announcement.destroy!
log_action :destroy, @announcement
redirect_to admin_announcements_path
end

private

def set_announcements
@announcements = AnnouncementFilter.new(filter_params).results.page(params[:page])
end

def set_announcement
@announcement = Announcement.find(params[:id])
end

def filter_params
params.slice(*AnnouncementFilter::KEYS).permit(*AnnouncementFilter::KEYS)
end

def resource_params
params.require(:announcement).permit(:text, :scheduled_at, :starts_at, :ends_at, :all_day)
end
end
18 changes: 0 additions & 18 deletions app/controllers/admin/followers_controller.rb

This file was deleted.

25 changes: 25 additions & 0 deletions app/controllers/admin/relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Admin
class RelationshipsController < BaseController
before_action :set_account

PER_PAGE = 40

def index
authorize :account, :index?

@accounts = RelationshipFilter.new(@account, filter_params).results.page(params[:page]).per(PER_PAGE)
end

private

def set_account
@account = Account.find(params[:account_id])
end

def filter_params
params.slice(*RelationshipFilter::KEYS).permit(*RelationshipFilter::KEYS)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def current_user
end

def require_authenticated_user!
render json: { error: 'This API requires an authenticated user' }, status: 401 unless current_user
render json: { error: 'This method requires an authenticated user' }, status: 401 unless current_user
end

def require_user!
Expand Down
14 changes: 11 additions & 3 deletions app/controllers/api/oembed_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# frozen_string_literal: true

class Api::OEmbedController < Api::BaseController
respond_to :json

skip_before_action :require_authenticated_user!

before_action :set_status
before_action :require_public_status!

def show
@status = status_finder.status
render json: @status, serializer: OEmbedSerializer, width: maxwidth_or_default, height: maxheight_or_default
end

private

def set_status
@status = status_finder.status
end

def require_public_status!
not_found if @status.hidden?
end

def status_finder
StatusFinder.new(params[:url])
end
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/api/v1/announcements/reactions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

class Api::V1::Announcements::ReactionsController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
before_action :require_user!

before_action :set_announcement
before_action :set_reaction, except: :update

def update
@announcement.announcement_reactions.create!(account: current_account, name: params[:id])
render_empty
end

def destroy
@reaction.destroy!
render_empty
end

private

def set_reaction
@reaction = @announcement.announcement_reactions.where(account: current_account).find_by!(name: params[:id])
end

def set_announcement
@announcement = Announcement.published.find(params[:announcement_id])
end
end
33 changes: 33 additions & 0 deletions app/controllers/api/v1/announcements_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

class Api::V1::AnnouncementsController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: :dismiss
before_action :require_user!
before_action :set_announcements, only: :index
before_action :set_announcement, except: :index

def index
render json: @announcements, each_serializer: REST::AnnouncementSerializer
end

def dismiss
AnnouncementMute.create!(account: current_account, announcement: @announcement)
render_empty
end

private

def set_announcements
@announcements = begin
scope = Announcement.published

scope.merge!(Announcement.without_muted(current_account)) unless truthy_param?(:with_dismissed)

scope.chronological
end
end

def set_announcement
@announcement = Announcement.published.find(params[:id])
end
end
6 changes: 6 additions & 0 deletions app/controllers/auth/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class Auth::PasswordsController < Devise::PasswordsController

layout 'auth'

def update
super do |resource|
resource.session_activations.destroy_all if resource.errors.empty?
end
end

private

def check_validity_of_reset_password_token
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ def destroy
not_found
end

def update
super do |resource|
resource.clear_other_sessions(current_session.session_id) if resource.saved_change_to_encrypted_password?
end
end

protected

def update_resource(resource, params)
params[:password] = nil if Devise.pam_authentication && resource.encrypted_password.blank?

super
end

Expand Down
46 changes: 3 additions & 43 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,13 @@ def update
rescue ActionController::ParameterMissing
# Do nothing
ensure
redirect_to relationships_path(current_params)
redirect_to relationships_path(filter_params)
end

private

def set_accounts
@accounts = relationships_scope.page(params[:page]).per(40)
end

def relationships_scope
scope = begin
if following_relationship?
current_account.following.eager_load(:account_stat).reorder(nil)
else
current_account.followers.eager_load(:account_stat).reorder(nil)
end
end

scope.merge!(Follow.recent) if params[:order].blank? || params[:order] == 'recent'
scope.merge!(Account.by_recent_status) if params[:order] == 'active'
scope.merge!(mutual_relationship_scope) if mutual_relationship?
scope.merge!(moved_account_scope) if params[:status] == 'moved'
scope.merge!(primary_account_scope) if params[:status] == 'primary'
scope.merge!(by_domain_scope) if params[:by_domain].present?
scope.merge!(dormant_account_scope) if params[:activity] == 'dormant'

scope
end

def mutual_relationship_scope
Account.where(id: current_account.following)
end

def moved_account_scope
Account.where.not(moved_to_account_id: nil)
end

def primary_account_scope
Account.where(moved_to_account_id: nil)
end

def dormant_account_scope
AccountStat.where(last_status_at: nil).or(AccountStat.where(AccountStat.arel_table[:last_status_at].lt(1.month.ago)))
end

def by_domain_scope
Account.where(domain: params[:by_domain])
@accounts = RelationshipFilter.new(current_account, filter_params).results.page(params[:page]).per(40)
end

def form_account_batch_params
Expand All @@ -85,7 +45,7 @@ def followed_by_relationship?
params[:relationship] == 'followed_by'
end

def current_params
def filter_params
params.slice(:page, *RelationshipFilter::KEYS).permit(:page, *RelationshipFilter::KEYS)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def activity

def embed
use_pack 'embed'
raise ActiveRecord::RecordNotFound if @status.hidden?
return not_found if @status.hidden?

expires_in 180, public: true
response.headers['X-Frame-Options'] = 'ALLOWALL'
Expand All @@ -71,7 +71,7 @@ def set_status
@status = @account.statuses.find(params[:id])
authorize @status, :show?
rescue Mastodon::NotPermittedError
raise ActiveRecord::RecordNotFound
not_found
end

def set_instance_presenter
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/admin/action_logs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def relevant_log_changes(log)
log.recorded_changes.slice('severity', 'reject_media')
elsif log.target_type == 'Status' && log.action == :update
log.recorded_changes.slice('sensitive')
elsif log.target_type == 'Announcement' && log.action == :update
log.recorded_changes.slice('text', 'starts_at', 'ends_at', 'all_day')
end
end

Expand Down Expand Up @@ -52,6 +54,8 @@ def icon_for_log(log)
'pencil'
when 'AccountWarning'
'warning'
when 'Announcement'
'bullhorn'
end
end

Expand Down Expand Up @@ -94,6 +98,8 @@ def linkable_log_target(record)
link_to record.account.acct, ActivityPub::TagManager.instance.url_for(record)
when 'AccountWarning'
link_to record.target_account.acct, admin_account_path(record.target_account_id)
when 'Announcement'
link_to "##{record.id}", edit_admin_announcement_path(record.id)
end
end

Expand All @@ -111,6 +117,8 @@ def log_target_from_history(type, attributes)
else
I18n.t('admin.action_logs.deleted_status')
end
when 'Announcement'
"##{attributes['id']}"
end
end
end
11 changes: 11 additions & 0 deletions app/helpers/admin/announcements_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Admin::AnnouncementsHelper
def time_range(announcement)
if announcement.all_day?
safe_join([l(announcement.starts_at.to_date), ' - ', l(announcement.ends_at.to_date)])
else
safe_join([l(announcement.starts_at), ' - ', l(announcement.ends_at)])
end
end
end
Loading

0 comments on commit 0be67df

Please sign in to comment.