Merge pull request #7514 from SuperTux88/rails5

Upgrade to rails 5.1
This commit is contained in:
Benjamin Neff 2017-08-12 15:42:36 +02:00
commit dc92633dab
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
266 changed files with 2005 additions and 2801 deletions

6
.gitignore vendored
View file

@ -27,6 +27,12 @@ public/404.html
public/422.html
public/500.html
# the db/schema.rb. Although this is contrary to rails best-practises, we
# cannot provide a schema.rb that works for both MySQL and PostgreSQL, so we
# have no choice. Our migrations are maintained, so it should always be
# possible to get back to a "clean" database schema anyway.
db/schema.rb
# Sprites
app/assets/images/branding-*.png
app/assets/images/branding/logos-*.png

View file

@ -28,6 +28,7 @@ If so, please delete it since it will prevent the federation from working proper
* Update the user data export archive format [#6726](https://github.com/diaspora/diaspora/pull/6726)
* Use id as fallback when sorting posts [#7523](https://github.com/diaspora/diaspora/pull/7523)
* Remove no-posts-info when adding posts to the stream [#7523](https://github.com/diaspora/diaspora/pull/7523)
* Upgrade to rails 5.1 [#7514](https://github.com/diaspora/diaspora/pull/7514)
## Bug fixes

12
Gemfile
View file

@ -1,6 +1,6 @@
source "https://rubygems.org"
gem "rails", "4.2.9"
gem "rails", "5.1.3"
# Legacy Rails features, remove me!
# responders (class level)
@ -90,7 +90,7 @@ gem "entypo-rails", "3.0.0"
gem "handlebars_assets", "0.23.2"
gem "jquery-rails", "4.3.1"
gem "js-routes", "1.3.3"
gem "js_image_paths", "0.1.0"
gem "js_image_paths", "0.1.1"
source "https://rails-assets.org" do
gem "rails-assets-jquery", "3.2.1" # Should be kept in sync with jquery-rails
@ -124,7 +124,7 @@ end
gem "http_accept_language", "2.1.1"
gem "i18n-inflector-rails", "1.0.7"
gem "rails-i18n", "4.0.9"
gem "rails-i18n", "5.0.4"
# Mail
@ -185,7 +185,7 @@ gem "typhoeus", "1.1.2"
gem "gon", "6.1.0"
gem "hamlit", "2.8.4"
gem "mobile-fu", "1.3.1"
gem "mobile_fu", "1.4.0"
gem "rails-timeago", "2.16.0"
gem "will_paginate", "3.1.6"
@ -280,7 +280,6 @@ group :test do
gem "fuubar", "2.2.0"
gem "json-schema-rspec", "0.0.4"
gem "rspec-json_expectations", "~> 2.1"
gem "test_after_commit", "1.1.0"
# Cucumber (integration tests)
@ -315,4 +314,7 @@ group :development, :test do
gem "jasmine-jquery-rails", "2.0.3"
gem "rails-assets-jasmine-ajax", "3.3.1", source: "https://rails-assets.org"
gem "sinon-rails", "1.15.0"
# For `assigns` in controller specs
gem "rails-controller-testing", "1.0.2"
end

View file

@ -2,44 +2,47 @@ GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
actionmailer (4.2.9)
actionpack (= 4.2.9)
actionview (= 4.2.9)
activejob (= 4.2.9)
actioncable (5.1.3)
actionpack (= 5.1.3)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.3)
actionpack (= 5.1.3)
actionview (= 5.1.3)
activejob (= 5.1.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.9)
actionview (= 4.2.9)
activesupport (= 4.2.9)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-dom-testing (~> 2.0)
actionpack (5.1.3)
actionview (= 5.1.3)
activesupport (= 5.1.3)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.9)
activesupport (= 4.2.9)
actionview (5.1.3)
activesupport (= 5.1.3)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_model_serializers (0.9.7)
activemodel (>= 3.2)
concurrent-ruby (~> 1.0)
activejob (4.2.9)
activesupport (= 4.2.9)
globalid (>= 0.3.0)
activemodel (4.2.9)
activesupport (= 4.2.9)
builder (~> 3.1)
activerecord (4.2.9)
activemodel (= 4.2.9)
activesupport (= 4.2.9)
arel (~> 6.0)
activejob (5.1.3)
activesupport (= 5.1.3)
globalid (>= 0.3.6)
activemodel (5.1.3)
activesupport (= 5.1.3)
activerecord (5.1.3)
activemodel (= 5.1.3)
activesupport (= 5.1.3)
arel (~> 8.0)
activerecord-import (0.19.1)
activerecord (>= 3.2)
activesupport (4.2.9)
activesupport (5.1.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
acts-as-taggable-on (5.0.0)
activerecord (>= 4.2.8)
@ -49,7 +52,7 @@ GEM
rack (>= 1.1.0)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (6.0.4)
arel (8.0.0)
asset_sync (2.2.0)
activemodel (>= 4.1.0)
fog-core
@ -183,7 +186,7 @@ GEM
entypo-rails (3.0.0)
railties (>= 4.1, < 6)
equalizer (0.0.11)
erubis (2.7.0)
erubi (1.6.1)
eslintrb (2.1.0)
execjs
multi_json (>= 1.3)
@ -324,8 +327,9 @@ GEM
js-routes (1.3.3)
railties (>= 3.2)
sprockets-rails
js_image_paths (0.1.0)
rails (~> 4.0)
js_image_paths (0.1.1)
rails (>= 4.0, < 6.0)
sprockets (>= 3.0.0)
json (2.1.0)
json-jwt (1.7.2)
activesupport
@ -371,7 +375,7 @@ GEM
mini_magick (4.8.0)
mini_portile2 (2.2.0)
minitest (5.10.3)
mobile-fu (1.3.1)
mobile_fu (1.4.0)
rack-mobile-detect
rails
multi_json (1.12.1)
@ -430,7 +434,7 @@ GEM
validate_url
webfinger (>= 1.0.1)
orm_adapter (0.5.0)
parallel (1.11.2)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
pg (0.21.0)
@ -467,7 +471,7 @@ GEM
byebug (~> 9.0)
pry (~> 0.10)
public_suffix (2.0.5)
rack (1.6.8)
rack (2.0.3)
rack-cors (1.0.1)
rack-google-analytics (1.2.0)
actionpack
@ -488,17 +492,18 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.9)
actionmailer (= 4.2.9)
actionpack (= 4.2.9)
actionview (= 4.2.9)
activejob (= 4.2.9)
activemodel (= 4.2.9)
activerecord (= 4.2.9)
activesupport (= 4.2.9)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.9)
sprockets-rails
rails (5.1.3)
actioncable (= 5.1.3)
actionmailer (= 5.1.3)
actionpack (= 5.1.3)
actionview (= 5.1.3)
activejob (= 5.1.3)
activemodel (= 5.1.3)
activerecord (= 5.1.3)
activesupport (= 5.1.3)
bundler (>= 1.3.0)
railties (= 5.1.3)
sprockets-rails (>= 2.0.0)
rails-assets-autosize (4.0.0)
rails-assets-backbone (1.3.3)
rails-assets-underscore (>= 1.8.3)
@ -545,23 +550,25 @@ GEM
rails-assets-markdown-it-sup (1.0.0)
rails-assets-perfect-scrollbar (0.6.16)
rails-assets-underscore (1.8.3)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.8)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails-i18n (4.0.9)
rails-i18n (5.0.4)
i18n (~> 0.7)
railties (~> 4.0)
railties (~> 5.0)
rails-timeago (2.16.0)
actionpack (>= 3.1)
activesupport (>= 3.1)
railties (4.2.9)
actionpack (= 4.2.9)
activesupport (= 4.2.9)
railties (5.1.3)
actionpack (= 5.1.3)
activesupport (= 5.1.3)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.2.2)
@ -682,8 +689,6 @@ GEM
tins (~> 1.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
test_after_commit (1.1.0)
activerecord (>= 3.2)
thor (0.19.1)
thread_safe (0.3.6)
tilt (2.0.8)
@ -803,7 +808,7 @@ DEPENDENCIES
jasmine-jquery-rails (= 2.0.3)
jquery-rails (= 4.3.1)
js-routes (= 1.3.3)
js_image_paths (= 0.1.0)
js_image_paths (= 0.1.1)
json (= 2.1.0)
json-schema (= 2.8.0)
json-schema-rspec (= 0.0.4)
@ -812,7 +817,7 @@ DEPENDENCIES
markerb (= 1.1.0)
mini_magick (= 4.8.0)
minitest
mobile-fu (= 1.3.1)
mobile_fu (= 1.4.0)
mysql2 (= 0.4.8)
nokogiri (= 1.8.0)
omniauth (= 1.6.1)
@ -836,7 +841,7 @@ DEPENDENCIES
rack-piwik (= 0.3.0)
rack-rewrite (= 1.5.1)
rack-ssl (= 1.4.1)
rails (= 4.2.9)
rails (= 5.1.3)
rails-assets-autosize (= 4.0.0)!
rails-assets-backbone (= 1.3.3)!
rails-assets-blueimp-gallery (= 2.25.2)!
@ -859,7 +864,8 @@ DEPENDENCIES
rails-assets-markdown-it-sub (= 1.0.0)!
rails-assets-markdown-it-sup (= 1.0.0)!
rails-assets-perfect-scrollbar (= 0.6.16)!
rails-i18n (= 4.0.9)
rails-controller-testing (= 1.0.2)
rails-i18n (= 5.0.4)
rails-timeago (= 2.16.0)
rb-fsevent (= 0.10.2)
rb-inotify (= 0.9.10)
@ -883,7 +889,6 @@ DEPENDENCIES
spring-commands-rspec (= 1.0.4)
sprockets-rails (= 3.2.0)
string-direction (= 1.2.0)
test_after_commit (= 1.1.0)
thor (= 0.19.1)
timecop (= 0.9.1)
turbo_dev_assets (= 0.0.2)

View file

@ -33,7 +33,6 @@ function createUploader(){
$("#fileInfo-publisher").text(fileName + " " + progress + "%");
},
onSubmit: function() {
$("#file-upload-publisher").addClass("loading");
$("#publisher_textarea_wrapper").addClass("with_attachments");
$("#photodropzone").append(
"<li class='publisher_photo loading' style='position:relative;'>" +

View file

@ -1,7 +1,7 @@
// Calling this file bootstrap would cause an infinite recursion during asset compilation.
@import "bootstrap-sprockets";
@import "bootstrap-variables"; //our overwrites of bootstrap variables
@import "bootstrap";
@import "_bootstrap";
// Plugins

View file

@ -1,8 +1,6 @@
module Admin
class AdminController < ApplicationController
before_filter :authenticate_user!
before_filter :redirect_unless_admin
before_action :authenticate_user!
before_action :redirect_unless_admin
end
end

View file

@ -205,7 +205,7 @@ module Api
if prompt && prompt.include?("none")
handle_prompt_none
elsif prompt && prompt.include?("login")
new_params = params.except("controller", "action").merge(prompt: prompt.remove("login"))
new_params = params.except("controller", "action").permit!.to_h.merge(prompt: prompt.remove("login"))
reauthenticate(new_params)
else
authenticate_user!

View file

@ -8,7 +8,8 @@ module Api
if req["client_assertion_type"] == "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
handle_jwt_bearer(req)
end
self.status, response.headers, self.response_body = Api::OpenidConnect::TokenEndpoint.new.call(request.env)
self.status, headers, self.response_body = Api::OpenidConnect::TokenEndpoint.new.call(request.env)
headers.each {|name, value| response.headers[name] = value }
nil
end

View file

@ -5,7 +5,7 @@
class ApplicationController < ActionController::Base
before_action :force_tablet_html
has_mobile_fu
protect_from_forgery except: :receive, with: :exception
protect_from_forgery except: :receive, with: :exception, prepend: true
rescue_from ActionController::InvalidAuthenticityToken do
if user_signed_in?

View file

@ -6,7 +6,7 @@
class AspectMembershipsController < ApplicationController
before_action :authenticate_user!
respond_to :html, :json
respond_to :json
def destroy
aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
@ -30,18 +30,9 @@ class AspectMembershipsController < ApplicationController
if success
render json: AspectMembershipPresenter.new(membership).base_hash
else
render text: membership.errors.full_messages, status: 403
render plain: membership.errors.full_messages, status: 403
end
end
format.all do
if success
flash.now[:notice] = I18n.t "aspect_memberships.destroy.success"
else
flash.now[:error] = I18n.t "aspect_memberships.destroy.failure"
end
redirect_to :back
end
end
end
@ -58,35 +49,25 @@ class AspectMembershipsController < ApplicationController
AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first)
.base_hash
end
format.all do
flash.now[:notice] = I18n.t("aspects.add_to_aspect.success")
redirect_to :back
end
end
else
respond_to do |format|
format.json do
render text: I18n.t("aspects.add_to_aspect.failure"), status: 409
end
format.all do
flash.now[:error] = I18n.t("aspects.add_to_aspect.failure")
render nothing: true, status: 409
render plain: I18n.t("aspects.add_to_aspect.failure"), status: 409
end
end
end
end
rescue_from ActiveRecord::StatementInvalid do
render text: I18n.t("aspect_memberships.destroy.invalid_statement"), status: 400
render plain: I18n.t("aspect_memberships.destroy.invalid_statement"), status: 400
end
rescue_from ActiveRecord::RecordNotFound do
render text: I18n.t("aspect_memberships.destroy.no_membership"), status: 404
render plain: I18n.t("aspect_memberships.destroy.no_membership"), status: 404
end
rescue_from Diaspora::NotMine do
render text: I18n.t("aspect_memberships.destroy.forbidden"), status: 403
render plain: I18n.t("aspect_memberships.destroy.forbidden"), status: 403
end
end

View file

@ -22,7 +22,7 @@ class AspectsController < ApplicationController
render json: result
else
render nothing: true, status: 422
head :unprocessable_entity
end
end
@ -71,7 +71,7 @@ class AspectsController < ApplicationController
params[:ordered_aspect_ids].each_with_index do |id, i|
current_user.aspects.find(id).update_attributes(order_id: i)
end
render nothing: true
head :no_content
end
def toggle_chat_privilege
@ -79,7 +79,7 @@ class AspectsController < ApplicationController
@aspect.chat_enabled = !@aspect.chat_enabled
@aspect.save
render :nothing => true
head :no_content
end
def toggle_contact_visibility
@ -91,7 +91,7 @@ class AspectsController < ApplicationController
@aspect.contacts_visible = true
end
@aspect.save
render :nothing => true
head :no_content
end
private

View file

@ -1,34 +1,23 @@
class BlocksController < ApplicationController
before_action :authenticate_user!
respond_to :html, :json
respond_to :json
def create
block = current_user.blocks.new(block_params)
if block.save
disconnect_if_contact(block.person)
notice = {:notice => t('blocks.create.success')}
else
notice = {:error => t('blocks.create.failure')}
end
disconnect_if_contact(block.person) if block.save
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
format.json { head :no_content }
end
end
def destroy
if current_user.blocks.find(params[:id]).delete
notice = {:notice => t('blocks.destroy.success')}
else
notice = {:error => t('blocks.destroy.failure')}
end
current_user.blocks.find(params[:id]).delete
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
format.json { head :no_content }
end
end

View file

@ -8,21 +8,21 @@ class CommentsController < ApplicationController
respond_to :html, :mobile, :json
rescue_from ActiveRecord::RecordNotFound do
render nothing: true, status: 404
head :not_found
end
def create
begin
comment = comment_service.create(params[:post_id], params[:text])
rescue ActiveRecord::RecordNotFound
render text: I18n.t("comments.create.error"), status: 404
render plain: I18n.t("comments.create.error"), status: 404
return
end
if comment
respond_create_success(comment)
else
render text: I18n.t("comments.create.error"), status: 422
render plain: I18n.t("comments.create.error"), status: 422
end
end
@ -57,24 +57,24 @@ class CommentsController < ApplicationController
def respond_create_success(comment)
respond_to do |format|
format.json { render json: CommentPresenter.new(comment), status: 201 }
format.html { render nothing: true, status: 201 }
format.html { head :created }
format.mobile { render partial: "comment", locals: {comment: comment} }
end
end
def respond_destroy_success
respond_to do |format|
format.mobile { redirect_to :back }
format.js { render nothing: true, status: 204 }
format.json { render nothing: true, status: 204 }
format.mobile { redirect_back fallback_location: stream_path }
format.js { head :no_content }
format.json { head :no_content }
end
end
def respond_destroy_error
respond_to do |format|
format.mobile { redirect_to :back }
format.js { render nothing: true, status: 403 }
format.json { render nothing: true, status: 403 }
format.mobile { redirect_back fallback_location: stream_path }
format.js { head :forbidden }
format.json { head :forbidden }
end
end
end

View file

@ -39,7 +39,7 @@ class ConversationsController < ApplicationController
end
unless person_ids.present?
render text: I18n.t("javascripts.conversation.create.no_recipient"), status: 422
render plain: I18n.t("javascripts.conversation.create.no_recipient"), status: 422
return
end
@ -53,7 +53,7 @@ class ConversationsController < ApplicationController
flash[:notice] = I18n.t("conversations.create.sent")
render json: {id: @conversation.id}
else
render text: I18n.t("conversations.create.fail"), status: 422
render plain: I18n.t("conversations.create.fail"), status: 422
end
end
@ -82,7 +82,7 @@ class ConversationsController < ApplicationController
@conversation.set_read(current_user)
render partial: "conversations/show", locals: {conversation: @conversation}
else
render nothing: true, status: 404
head :not_found
end
end

View file

@ -33,7 +33,7 @@ class HomeController < ApplicationController
def toggle_mobile
session[:mobile_view] = session[:mobile_view].nil? ? true : !session[:mobile_view]
redirect_to :back
redirect_back fallback_location: root_path
end
def force_mobile

View file

@ -42,7 +42,7 @@ class InvitationsController < ApplicationController
t("invitations.create.rejected", emails: invalid_emails.join(", "))
end
redirect_to :back
redirect_back fallback_location: stream_path
end
private
@ -55,7 +55,7 @@ class InvitationsController < ApplicationController
else
t("invitations.create.closed")
end
redirect_to :back
redirect_back fallback_location: stream_path
end
def valid_email?(email)
@ -71,6 +71,6 @@ class InvitationsController < ApplicationController
end
def inviter_params
params.require(:email_inviter).permit(:message, :locale, :emails)
params.require(:email_inviter).permit(:message, :locale, :emails).to_h
end
end

View file

@ -13,10 +13,10 @@ class LikesController < ApplicationController
def create
like = like_service.create(params[:post_id])
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
render text: I18n.t("likes.create.error"), status: 422
render plain: I18n.t("likes.create.error"), status: 422
else
respond_to do |format|
format.html { render nothing: true, status: 201 }
format.html { head :created }
format.mobile { redirect_to post_path(like.post_id) }
format.json { render json: like.as_api_response(:backbone), status: 201 }
end
@ -24,9 +24,9 @@ class LikesController < ApplicationController
def destroy
if like_service.destroy(params[:id])
render nothing: true, status: 204
head :no_content
else
render text: I18n.t("likes.destroy.error"), status: 404
render plain: I18n.t("likes.destroy.error"), status: 404
end
end

View file

@ -5,9 +5,9 @@ class ParticipationsController < ApplicationController
post = current_user.find_visible_shareable_by_id(Post, params[:post_id])
if post
current_user.participate! post
render nothing: true, status: :created
head :created
else
render nothing: true, status: :forbidden
head :forbidden
end
end
@ -15,9 +15,9 @@ class ParticipationsController < ApplicationController
participation = current_user.participations.find_by target_id: params[:post_id]
if participation
participation.destroy
render nothing: true, status: :ok
head :ok
else
render nothing: true, status: :unprocessable_entity
head :unprocessable_entity
end
end
end

View file

@ -19,8 +19,8 @@ class PeopleController < ApplicationController
rescue_from Diaspora::AccountClosed do
respond_to do |format|
format.any { redirect_to :back, :notice => t("people.show.closed_account") }
format.json { render :nothing => true, :status => 410 } # 410 GONE
format.any { redirect_back fallback_location: root_path, notice: t("people.show.closed_account") }
format.json { head :gone }
end
end
@ -115,15 +115,15 @@ class PeopleController < ApplicationController
def retrieve_remote
if params[:diaspora_handle]
Workers::FetchWebfinger.perform_async(params[:diaspora_handle])
render :nothing => true
head :ok
else
render :nothing => true, :status => 422
head :unprocessable_entity
end
end
def contacts
respond_to do |format|
format.json { render nothing: true, status: 406 }
format.json { head :not_acceptable }
format.any do
@person = Person.find_by_guid(params[:person_id])

View file

@ -66,10 +66,10 @@ class PhotosController < ApplicationController
:status => 201}
end
else
render :nothing => true, :status => 422
head :unprocessable_entity
end
else
render :nothing => true, :status => 422
head :unprocessable_entity
end
end
@ -80,7 +80,7 @@ class PhotosController < ApplicationController
current_user.retract(photo)
respond_to do |format|
format.json{ render :nothing => true, :status => 204 }
format.json { head :no_content }
format.html do
flash[:notice] = I18n.t 'photos.destroy.notice'
if StatusMessage.find_by_guid(photo.status_message_guid)
@ -125,27 +125,28 @@ class PhotosController < ApplicationController
end
def legacy_create
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect { |x| x.id }
elsif params[:photo][:aspect_ids].is_a?(Hash)
params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values
photo_params = params.require(:photo).permit(:pending, :set_profile_photo, aspect_ids: [])
if photo_params[:aspect_ids] == "all"
photo_params[:aspect_ids] = current_user.aspects.map(&:id)
elsif photo_params[:aspect_ids].is_a?(Hash)
photo_params[:aspect_ids] = params[:photo][:aspect_ids].values
end
params[:photo][:user_file] = file_handler(params)
photo_params[:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
@photo = current_user.build_post(:photo, photo_params)
if @photo.save
unless @photo.pending
unless @photo.public?
aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids])
aspects = current_user.aspects_from_ids(photo_params[:aspect_ids])
current_user.add_to_streams(@photo, aspects)
end
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids])
current_user.dispatch_post(@photo, to: photo_params[:aspect_ids])
end
if params[:photo][:set_profile_photo]
if photo_params[:set_profile_photo]
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}

View file

@ -1,20 +1,17 @@
class PollParticipationsController < ApplicationController
include ApplicationHelper
before_filter :authenticate_user!
before_action :authenticate_user!
def create
answer = PollAnswer.find(params[:poll_answer_id])
poll_participation = current_user.participate_in_poll!(target, answer) if target
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render json: poll_participation, :status => 201 }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render :nothing => true, :status => 403 }
format.json { head :forbidden }
end
end
@ -25,4 +22,4 @@ class PollParticipationsController < ApplicationController
current_user.find_visible_shareable_by_id(Post, params[:post_id]) || raise(ActiveRecord::RecordNotFound.new)
end
end
end
end

View file

@ -13,7 +13,7 @@ class PostsController < ApplicationController
end
rescue_from Diaspora::NotMine do
render text: I18n.t("posts.show.forbidden"), status: 403
render plain: I18n.t("posts.show.forbidden"), status: 403
end
def show
@ -36,7 +36,7 @@ class PostsController < ApplicationController
oembed = params.slice(:format, :maxheight, :minheight)
render json: OEmbedPresenter.new(post, oembed)
rescue
render nothing: true, status: 404
head :not_found
end
def interactions
@ -45,7 +45,7 @@ class PostsController < ApplicationController
post = post_service.find!(params[:id])
render json: PostInteractionPresenter.new(post, current_user)
}
format.any { render nothing: true, status: 406 }
format.any { head :not_acceptable }
end
end
@ -55,19 +55,19 @@ class PostsController < ApplicationController
if params[:id].present? && params[:q].present?
render json: post_service.mentionable_in_comment(params[:id], params[:q])
else
render nothing: true, status: 204
head :no_content
end
}
format.any { render nothing: true, status: 406 }
format.any { head :not_acceptable }
end
rescue ActiveRecord::RecordNotFound
render nothing: true, status: 404
head :not_found
end
def destroy
post_service.destroy(params[:id])
respond_to do |format|
format.json { render nothing: true, status: 204 }
format.json { head :no_content }
format.any { redirect_to stream_path }
end
end

View file

@ -48,7 +48,7 @@ class ProfilesController < ApplicationController
end
respond_to do |format|
format.js { render :nothing => true, :status => 200 }
format.js { head :ok }
format.any {
if current_user.getting_started?
redirect_to getting_started_path
@ -77,6 +77,6 @@ class ProfilesController < ApplicationController
def profile_params
params.require(:profile).permit(:first_name, :last_name, :gender, :bio,
:location, :searchable, :tag_string, :nsfw,
:public_details, date: %i(year month day)) || {}
:public_details, date: %i[year month day]).to_h || {}
end
end

View file

@ -31,7 +31,7 @@ class ReportController < ApplicationController
if report.save
render json: true, status: 200
else
render nothing: true, status: 409
head :conflict
end
end

View file

@ -5,7 +5,7 @@ class ResharesController < ApplicationController
def create
reshare = reshare_service.create(params[:root_guid])
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
render text: I18n.t("reshares.create.error"), status: 422
render plain: I18n.t("reshares.create.error"), status: 422
else
render json: ExtremePostPresenter.new(reshare, current_user), status: 201
end

View file

@ -1,24 +1,24 @@
class SearchController < ApplicationController
before_action :authenticate_user!
def search
if search_query.starts_with?('#')
if search_query.length > 1
respond_to do |format|
respond_to do |format|
format.json {redirect_to tags_path(:q => search_query.delete("#."))}
format.any {redirect_to tag_path(:name => search_query.delete("#."))}
end
else
flash[:error] = I18n.t('tags.show.none', :name => search_query)
redirect_to :back
redirect_back fallback_location: stream_path
end
else
redirect_to people_path(:q => search_query)
end
end
end
private
def search_query
@search_query ||= (params[:q] || params[:term] || '').strip
end

View file

@ -3,8 +3,8 @@
# the COPYRIGHT file.
class SessionsController < Devise::SessionsController
after_filter :reset_authentication_token, :only => [:create]
before_filter :reset_authentication_token, :only => [:destroy]
after_action :reset_authentication_token, only: [:create]
before_action :reset_authentication_token, only: [:destroy]
def reset_authentication_token
current_user.reset_authentication_token! unless current_user.nil?

View file

@ -47,14 +47,8 @@ class StatusMessagesController < ApplicationController
end
def create
normalized_params = params.merge(
services: normalize_services,
aspect_ids: normalize_aspect_ids,
public: normalize_public_flag
)
status_message = StatusMessageCreationService.new(current_user).create(normalized_params)
status_message = StatusMessageCreationService.new(current_user).create(normalize_params)
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render json: PostPresenter.new(status_message, current_user), status: 201 }
end
@ -71,9 +65,8 @@ class StatusMessagesController < ApplicationController
def handle_create_error(error)
logger.debug error
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render text: error.message, status: 403 }
format.json { render plain: error.message, status: 403 }
end
end
@ -89,8 +82,19 @@ class StatusMessagesController < ApplicationController
request.env["HTTP_REFERER"].include?("/people/" + current_user.guid)
end
def normalize_services
[*params[:services]].compact
def normalize_params
params.permit(
:location_address,
:location_coords,
:poll_question,
status_message: %i[text provider_display_name],
poll_answers: []
).to_h.merge(
services: [*params[:services]].compact,
aspect_ids: normalize_aspect_ids,
public: [*params[:aspect_ids]].first == "public",
photos: [*params[:photos]].compact
)
end
def normalize_aspect_ids
@ -102,10 +106,6 @@ class StatusMessagesController < ApplicationController
end
end
def normalize_public_flag
[*params[:aspect_ids]].first == "public"
end
def remove_getting_started
current_user.disable_getting_started
end

View file

@ -15,7 +15,7 @@ class TagFollowingsController < ApplicationController
name_normalized = ActsAsTaggableOn::Tag.normalize(params['name'])
if name_normalized.nil? || name_normalized.empty?
render :nothing => true, :status => 403
head :forbidden
else
@tag = ActsAsTaggableOn::Tag.find_or_create_by(name: name_normalized)
@tag_following = current_user.tag_followings.new(:tag_id => @tag.id)
@ -23,7 +23,7 @@ class TagFollowingsController < ApplicationController
if @tag_following.save
render :json => @tag.to_json, :status => 201
else
render :nothing => true, :status => 403
head :forbidden
end
end
end
@ -35,11 +35,11 @@ class TagFollowingsController < ApplicationController
if tag_following && tag_following.destroy
respond_to do |format|
format.any(:js, :json) { render :nothing => true, :status => 204 }
format.any(:js, :json) { head :no_content }
end
else
respond_to do |format|
format.any(:js, :json) {render :nothing => true, :status => 403}
format.any(:js, :json) { head :forbidden }
end
end
end

View file

@ -24,8 +24,8 @@ class TagsController < ApplicationController
end
else
respond_to do |format|
format.json{ render :nothing => true, :status => 422 }
format.html{ redirect_to tag_path('partytimeexcellent') }
format.json { head :unprocessable_entity }
format.html { redirect_to tag_path("partytimeexcellent") }
end
end
end

View file

@ -46,7 +46,7 @@ class UsersController < ApplicationController
flash[:error] = t("users.update.settings_not_updated")
end
redirect_to :back
redirect_back fallback_location: privacy_settings_path
end
def destroy
@ -60,7 +60,7 @@ class UsersController < ApplicationController
else
flash[:error] = t "users.destroy.no_password"
end
redirect_to :back
redirect_back fallback_location: edit_user_path
end
end

View file

@ -11,7 +11,7 @@ module MetaDataHelper
end
def default_image_url
asset_url "assets/branding/logos/asterisk.png"
asset_url("assets/branding/logos/asterisk.png", skip_pipeline: true)
end
def default_author_name

View file

@ -0,0 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>"
end

View file

@ -1,5 +1,5 @@
class DiasporaDeviseMailer < Devise::Mailer
default :from => AppConfig.mail.sender_address
default from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>"
def self.mailer_name
"devise/mailer"

View file

@ -1,6 +1,4 @@
class ExportMailer < ActionMailer::Base
default from: AppConfig.mail.sender_address
class ExportMailer < ApplicationMailer
def export_complete_for(user)
@user = user

View file

@ -1,6 +1,4 @@
class Maintenance < ActionMailer::Base
default :from => AppConfig.mail.sender_address
class Maintenance < ApplicationMailer
def account_removal_warning(user)
@user = user
@login_url = new_user_session_url

View file

@ -1,4 +1,4 @@
class Notifier < ActionMailer::Base
class Notifier < ApplicationMailer
helper :application
helper :notifier
helper :people

View file

@ -1,6 +1,4 @@
class ReportMailer < ActionMailer::Base
default from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>"
class ReportMailer < ApplicationMailer
def self.new_report(report_id)
report = Report.find_by_id(report_id)
Role.moderators.map {|role| super(report.item_type, report.item_id, report.text, role) }

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AccountDeletion < ActiveRecord::Base
class AccountDeletion < ApplicationRecord
include Diaspora::Federated::Base
scope :uncompleted, -> { where('completed_at is null') }

View file

@ -2,12 +2,11 @@
module Api
module OpenidConnect
class Authorization < ActiveRecord::Base
class Authorization < ApplicationRecord
belongs_to :user
belongs_to :o_auth_application
validates :user, presence: true, uniqueness: {scope: :o_auth_application}
validates :o_auth_application, presence: true
validates :user, uniqueness: {scope: :o_auth_application}
validate :validate_scope_names
serialize :scopes, JSON

View file

@ -23,13 +23,12 @@
module Api
module OpenidConnect
class OAuthAccessToken < ActiveRecord::Base
class OAuthAccessToken < ApplicationRecord
belongs_to :authorization
before_validation :setup, on: :create
validates :token, presence: true, uniqueness: true
validates :authorization, presence: true
scope :valid, ->(time) { where("expires_at >= ?", time) }

View file

@ -25,7 +25,7 @@ require "digest"
module Api
module OpenidConnect
class OAuthApplication < ActiveRecord::Base
class OAuthApplication < ApplicationRecord
has_many :authorizations, dependent: :destroy
has_many :user, through: :authorizations

View file

@ -23,13 +23,12 @@
module Api
module OpenidConnect
class PairwisePseudonymousIdentifier < ActiveRecord::Base
class PairwisePseudonymousIdentifier < ApplicationRecord
self.table_name = "ppid"
belongs_to :o_auth_application
belongs_to :o_auth_application, optional: true
belongs_to :user
validates :user, presence: true
validates :identifier, presence: true, uniqueness: {scope: :user}
validates :guid, presence: true, uniqueness: true

View file

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Aspect < ActiveRecord::Base
class Aspect < ApplicationRecord
belongs_to :user
has_many :aspect_memberships, :dependent => :destroy

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AspectMembership < ActiveRecord::Base
class AspectMembership < ApplicationRecord
belongs_to :aspect
belongs_to :contact

View file

@ -2,13 +2,11 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AspectVisibility < ActiveRecord::Base
class AspectVisibility < ApplicationRecord
belongs_to :aspect
validates :aspect, :presence => true
belongs_to :shareable, :polymorphic => true
validates :shareable, :presence => true
validates :aspect, uniqueness: {scope: %i(shareable_id shareable_type)}
end

View file

@ -1,11 +1,10 @@
class Block < ActiveRecord::Base
class Block < ApplicationRecord
belongs_to :person
belongs_to :user
delegate :name, to: :person, prefix: true
validates :user_id, :presence => true
validates :person_id, :presence => true, :uniqueness => { :scope => :user_id }
validates :person_id, uniqueness: {scope: :user_id}
validate :not_blocking_yourself

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Comment < ActiveRecord::Base
class Comment < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
@ -26,7 +26,6 @@ class Comment < ActiveRecord::Base
delegate :author_name, to: :parent, prefix: true
validates :text, :presence => true, :length => {:maximum => 65535}
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
has_many :reports, as: :item

View file

@ -1,7 +1,6 @@
class CommentSignature < ActiveRecord::Base
class CommentSignature < ApplicationRecord
include Diaspora::Signature
self.primary_key = :comment_id
belongs_to :comment
validates :comment, presence: true
end

View file

@ -2,14 +2,11 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Contact < ActiveRecord::Base
class Contact < ApplicationRecord
include Diaspora::Federated::Base
belongs_to :user
validates :user, presence: true
belongs_to :person
validates :person, presence: true
validates :person_id, uniqueness: {scope: :user_id}

View file

@ -1,4 +1,4 @@
class Conversation < ActiveRecord::Base
class Conversation < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
include Diaspora::Fields::Author

View file

@ -1,4 +1,4 @@
class ConversationVisibility < ActiveRecord::Base
class ConversationVisibility < ApplicationRecord
belongs_to :conversation
belongs_to :person
@ -6,7 +6,7 @@ class ConversationVisibility < ActiveRecord::Base
after_destroy :check_orphan_conversation
private
def check_orphan_conversation
conversation = Conversation.find_by_id(self.conversation.id)
if conversation

View file

@ -1,8 +1,6 @@
class InvitationCode < ActiveRecord::Base
class InvitationCode < ApplicationRecord
belongs_to :user
validates_presence_of :user
before_create :generate_token, :set_default_invite_count
delegate :name, to: :user, prefix: true

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Like < ActiveRecord::Base
class Like < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
include Diaspora::Fields::Author

View file

@ -1,7 +1,6 @@
class LikeSignature < ActiveRecord::Base
class LikeSignature < ApplicationRecord
include Diaspora::Signature
self.primary_key = :like_id
belongs_to :like
validates :like, presence: true
end

View file

@ -1,4 +1,4 @@
class Location < ActiveRecord::Base
class Location < ApplicationRecord
before_validation :split_coords, on: :create
validates_presence_of :lat, :lng

View file

@ -2,11 +2,9 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Mention < ActiveRecord::Base
class Mention < ApplicationRecord
belongs_to :mentions_container, polymorphic: true
belongs_to :person
validates :mentions_container, presence: true
validates :person, presence: true
scope :local, -> {
joins(:person).where.not(people: {owner_id: nil})

View file

@ -1,4 +1,4 @@
class Message < ActiveRecord::Base
class Message < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
include Diaspora::Fields::Author
@ -7,7 +7,6 @@ class Message < ActiveRecord::Base
delegate :name, to: :author, prefix: true
validates :conversation, presence: true
validates :text, presence: true
validate :participant_of_parent_conversation

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
class Notification < ActiveRecord::Base
class Notification < ApplicationRecord
belongs_to :recipient, class_name: "User"
has_many :notification_actors, dependent: :destroy
has_many :actors, class_name: "Person", through: :notification_actors, source: :person

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class NotificationActor < ActiveRecord::Base
class NotificationActor < ApplicationRecord
belongs_to :notification
belongs_to :person

View file

@ -1,4 +1,4 @@
class OEmbedCache < ActiveRecord::Base
class OEmbedCache < ApplicationRecord
serialize :data
validates :data, :presence => true

View file

@ -1,4 +1,4 @@
class OpenGraphCache < ActiveRecord::Base
class OpenGraphCache < ApplicationRecord
validates :title, :presence => true
validates :ob_type, :presence => true
validates :image, :presence => true

View file

@ -1,4 +1,4 @@
class Participation < ActiveRecord::Base
class Participation < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
include Diaspora::Fields::Author

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Person < ActiveRecord::Base
class Person < ApplicationRecord
include Diaspora::Fields::Guid
# NOTE API V1 to be extracted
@ -44,8 +44,8 @@ class Person < ActiveRecord::Base
has_many :roles
belongs_to :owner, :class_name => 'User'
belongs_to :pod
belongs_to :owner, class_name: "User", optional: true
belongs_to :pod, optional: true
has_many :notification_actors
has_many :notifications, :through => :notification_actors
@ -100,10 +100,12 @@ class Person < ActiveRecord::Base
# @return [Person::ActiveRecord_Relation]
scope :find_by_substring, ->(search_str) {
search_str.strip!
return none if search_str.blank? || search_str.size < 2
sql, tokens = search_query_string(search_str)
joins(:profile).where(sql, *tokens)
if search_str.blank? || search_str.size < 2
none
else
sql, tokens = search_query_string(search_str)
joins(:profile).where(sql, *tokens)
end
}
# Left joins likes and comments to a specific post where people are authors of these comments and likes

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Photo < ActiveRecord::Base
class Photo < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Commentable
include Diaspora::Shareable
@ -37,7 +37,7 @@ class Photo < ActiveRecord::Base
mount_uploader :processed_image, ProcessedImage
mount_uploader :unprocessed_image, UnprocessedImage
belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid
belongs_to :status_message, foreign_key: :status_message_guid, primary_key: :guid, optional: true
validates_associated :status_message
delegate :author_name, to: :status_message, prefix: true

View file

@ -1,4 +1,4 @@
class Pod < ActiveRecord::Base
class Pod < ApplicationRecord
enum status: %i(
unchecked
no_errors

View file

@ -1,4 +1,4 @@
class Poll < ActiveRecord::Base
class Poll < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid

View file

@ -1,4 +1,4 @@
class PollAnswer < ActiveRecord::Base
class PollAnswer < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid

View file

@ -1,4 +1,4 @@
class PollParticipation < ActiveRecord::Base
class PollParticipation < ApplicationRecord
include Diaspora::Federated::Base
include Diaspora::Fields::Guid
include Diaspora::Fields::Author
@ -12,7 +12,6 @@ class PollParticipation < ActiveRecord::Base
alias_attribute :parent, :poll
validates :poll_answer, presence: true
validate :not_already_participated
def poll_answer_guid=(new_poll_answer_guid)

View file

@ -1,7 +1,6 @@
class PollParticipationSignature < ActiveRecord::Base
class PollParticipationSignature < ApplicationRecord
include Diaspora::Signature
self.primary_key = :poll_participation_id
belongs_to :poll_participation
validates :poll_participation, presence: true
end

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Post < ActiveRecord::Base
class Post < ApplicationRecord
self.include_root_in_json = false
include ApplicationHelper
@ -24,8 +24,8 @@ class Post < ActiveRecord::Base
has_many :reshares, class_name: "Reshare", foreign_key: :root_guid, primary_key: :guid
has_many :resharers, class_name: "Person", through: :reshares, source: :author
belongs_to :o_embed_cache
belongs_to :open_graph_cache
belongs_to :o_embed_cache, optional: true
belongs_to :open_graph_cache, optional: true
validates_uniqueness_of :id

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Profile < ActiveRecord::Base
class Profile < ApplicationRecord
self.include_root_in_json = false
include Diaspora::Federated::Base
@ -106,10 +106,6 @@ class Profile < ActiveRecord::Base
end
end
def formatted_birthday
birthday.to_s(:long).gsub(/, 100[0|4]/, "") if birthday.present?
end
def bio_message
@bio_message ||= Diaspora::MessageRenderer.new(bio)
end

View file

@ -1,4 +1,4 @@
class Report < ActiveRecord::Base
class Report < ApplicationRecord
validates :user_id, presence: true
validates :item_id, presence: true
validates :item_type, presence: true, inclusion: {
@ -9,8 +9,8 @@ class Report < ActiveRecord::Base
validate :post_or_comment_does_exist, :on => :create
belongs_to :user
belongs_to :post
belongs_to :comment
belongs_to :post, optional: true
belongs_to :comment, optional: true
belongs_to :item, polymorphic: true
after_commit :send_report_notification, :on => :create

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file.
class Reshare < Post
belongs_to :root, :class_name => 'Post', :foreign_key => :root_guid, :primary_key => :guid
belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true
validate :root_must_be_public
validates_presence_of :root, :on => :create
validates_uniqueness_of :root_guid, :scope => :author_id

View file

@ -1,9 +1,8 @@
# NOTE add the person object you want to attach role to...
class Role < ActiveRecord::Base
class Role < ApplicationRecord
belongs_to :person
validates :person, presence: true
validates :name, uniqueness: {scope: :person_id}
validates :name, inclusion: {in: %w(admin moderator spotlight)}

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service < ActiveRecord::Base
class Service < ApplicationRecord
attr_accessor :provider, :info, :access_level
belongs_to :user

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class ShareVisibility < ActiveRecord::Base
class ShareVisibility < ApplicationRecord
belongs_to :user
belongs_to :shareable, polymorphic: :true
@ -22,7 +22,7 @@ class ShareVisibility < ActiveRecord::Base
# @param share [Shareable]
# @return [void]
def self.batch_import(user_ids, share)
return false unless ShareVisibility.new(shareable_id: share.id, shareable_type: share.class.base_class.to_s).valid?
return false if share.public?
user_ids -= ShareVisibility.for_shareable(share).where(user_id: user_ids).pluck(:user_id)
return false if user_ids.empty?

View file

@ -1,3 +1,3 @@
class SignatureOrder < ActiveRecord::Base
class SignatureOrder < ApplicationRecord
validates :order, presence: true, uniqueness: true
end

View file

@ -1,4 +1,4 @@
class TagFollowing < ActiveRecord::Base
class TagFollowing < ApplicationRecord
belongs_to :user
belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag"

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class User < ActiveRecord::Base
class User < ApplicationRecord
include AuthenticationToken
include Connecting
include Querying
@ -51,8 +51,8 @@ class User < ActiveRecord::Base
has_many :aspects, -> { order('order_id ASC') }
belongs_to :auto_follow_back_aspect, :class_name => 'Aspect'
belongs_to :invited_by, :class_name => 'User'
belongs_to :auto_follow_back_aspect, class_name: "Aspect", optional: true
belongs_to :invited_by, class_name: "User", optional: true
has_many :aspect_memberships, :through => :aspects
@ -473,14 +473,17 @@ class User < ActiveRecord::Base
def guard_unconfirmed_email
self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email
if unconfirmed_email_changed?
self.confirm_email_token = unconfirmed_email ? SecureRandom.hex(15) : nil
end
return unless will_save_change_to_unconfirmed_email?
self.confirm_email_token = unconfirmed_email ? SecureRandom.hex(15) : nil
end
# Whenever email is set, clear all unconfirmed emails which match
def remove_invalid_unconfirmed_emails
User.where(unconfirmed_email: email).update_all(unconfirmed_email: nil, confirm_email_token: nil) if email_changed?
return unless saved_change_to_email?
# rubocop:disable Rails/SkipsModelValidations
User.where(unconfirmed_email: email).update_all(unconfirmed_email: nil, confirm_email_token: nil)
# rubocop:enable Rails/SkipsModelValidations
end
# Generate public/private keys for User and associated Person

View file

@ -1,4 +1,4 @@
class UserPreference < ActiveRecord::Base
class UserPreference < ApplicationRecord
belongs_to :user
validate :must_be_valid_email_type

View file

@ -36,7 +36,8 @@ class StatusMessageCreationService
if params[:poll_question].present?
status_message.build_poll(question: params[:poll_question])
[*params[:poll_answers]].each do |poll_answer|
status_message.poll.poll_answers.build(answer: poll_answer)
answer = status_message.poll.poll_answers.build(answer: poll_answer)
answer.poll = status_message.poll
end
end
end

View file

@ -9,7 +9,7 @@ module Workers
def perform(user_id, object_class_name, object_id, opts)
user = User.find(user_id)
object = object_class_name.constantize.find(object_id)
opts = HashWithIndifferentAccess.new(opts)
opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run

View file

@ -10,7 +10,7 @@ module Workers
user = User.find(user_id)
subscribers = Person.where(id: recipient_ids)
object = retraction_class.constantize.new(retraction_data.deep_symbolize_keys, subscribers)
opts = HashWithIndifferentAccess.new(opts)
opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
end

View file

@ -8,7 +8,7 @@ module Workers
def perform(service_id, opts)
service = Service.find_by_id(service_id)
opts = HashWithIndifferentAccess.new(opts)
opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
service.delete_from_service(opts)
end
end

View file

@ -4,8 +4,6 @@ begin
rescue LoadError => e
raise unless e.message.include?('spring')
end
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

View file

@ -1,7 +1,10 @@
require_relative 'boot'
require 'rails/all'
Bundler.require(:default, *Bundler.settings.with, Rails.env)
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups(*Bundler.settings.with))
# Do not dump the limit of boolean fields on MySQL,
# since that generates a db/schema.rb that's incompatible
@ -24,6 +27,9 @@ require_relative 'asset_sync'
module Diaspora
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
@ -64,8 +70,9 @@ module Diaspora
# Speed up precompile by not loading the environment
config.assets.initialize_on_precompile = false
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w(
# Precompile additional assets.
# (application.js, application.css, and all non-JS/CSS in the app/assets are already added)
config.assets.precompile += %w[
contact-list.js
ie.js
jquery3.js
@ -82,10 +89,7 @@ module Diaspora
rtl.css
color_themes/*/desktop.css
color_themes/*/mobile.css
)
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
]
# See lib/tasks/assets.rake: non_digest_assets
config.assets.non_digest_assets = %w(branding/logos/asterisk.png)
@ -96,9 +100,6 @@ module Diaspora
g.test_framework :rspec
end
# Will be default with Rails 5
config.active_record.raise_in_transactional_callbacks = true
# Setup action mailer early
config.action_mailer.default_url_options = {
protocol: AppConfig.pod_uri.scheme,

View file

@ -1,9 +1,6 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
# Ensure Builder is loaded
require 'active_support/builder' unless defined?(Builder)
require "bundler/setup" # Set up gems listed in the Gemfile.
# Load configuration early
require_relative 'load_config'
require_relative "load_config"

View file

@ -1,5 +1,5 @@
# Load the rails application
# Load the Rails application.
require_relative 'application'
# Initialize the rails application
Diaspora::Application.initialize!
# Initialize the Rails application.
Rails.application.initialize!

View file

@ -1,5 +1,5 @@
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@ -9,30 +9,40 @@ Diaspora::Application.configure do
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Show full error reports.
config.consider_all_requests_local = true
# Don't care if the mailer can't send
# Enable/disable caching. By default caching is disabled.
if Rails.root.join("tmp", "caching-dev.txt").exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.seconds.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# No assets request logging
# Suppress logger output for asset requests.
config.assets.quiet = true
# Set the logging destination(s)
@ -41,6 +51,13 @@ Diaspora::Application.configure do
# Show the logging configuration on STDOUT
config.show_log_configuration = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# Speed up asset serving
config.middleware.insert 0, TurboDevAssets
end

View file

@ -1,35 +1,51 @@
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_files = false
# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Don't fallback to assets pipeline if a precompiled asset is missed
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs
# Generate digests for assets URLs.
config.assets.digest = true
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
if AppConfig.environment.assets.host.present?
config.action_controller.asset_host = AppConfig.environment.assets.host.get
end
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
@ -37,44 +53,44 @@ Diaspora::Application.configure do
# Log level
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :request_id ]
# Set the logging destination(s)
config.log_to = %w[file]
# Show the logging configuration on STDOUT
config.show_log_configuration = false
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
config.action_mailer.perform_caching = false
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable autoload for rake tasks
config.dependency_loading = true if $rails_rake_task
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# For nginx:
config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
# Use default logging formatter so that PID and timestamp are not suppressed.
# config.log_formatter = ::Logger::Formatter.new
if AppConfig.environment.assets.host.present?
config.action_controller.asset_host = AppConfig.environment.assets.host.get
end
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
# if ENV["RAILS_LOG_TO_STDOUT"].present?
# logger = ActiveSupport::Logger.new(STDOUT)
# logger.formatter = config.log_formatter
# config.logger = ActiveSupport::TaggedLogging.new(logger)
# end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

View file

@ -1,5 +1,5 @@
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
@ -12,11 +12,13 @@ Diaspora::Application.configure do
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_files = true
config.static_cache_control = "public, max-age=3600"
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.seconds.to_i}"
}
# No assets request logging
# Suppress logger output for asset requests.
config.assets.quiet = true
# Precompile poltergeist_disable_transition.css for tests
@ -30,24 +32,28 @@ Diaspora::Application.configure do
color_themes/original/mobile.css
]
# Show full error reports and disable caching
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = true
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Set the logging destination(s)
config.log_to = %w[file]
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View file

@ -0,0 +1,6 @@
# Be sure to restart your server when you modify this file.
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )

View file

@ -1,15 +1,26 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# Be sure to restart your server when you modify this file.
# bootstrap-markdown plugin relies on rails-assets-bootstrap gem but we use
# bootstrap-sass this line makes sure we exclude every asset comming
# from rails-assets-bootstrap to prevent conflicts with bootstrap-sass
Rails.configuration.assets.paths.reject! do |path|
path.include?("rails-assets-bootstrap") && !path.include?("rails-assets-bootstrap-markdown")
# See https://github.com/tenex/rails-assets/issues/314
Rails.application.config.after_initialize do
# add the gem names you wish to reject to the below array
excluded_gem_names = ["rails-assets-bootstrap"]
excluded_gem_full_names = Gem::Specification.select {|g| excluded_gem_names.include? g.name }.flat_map(&:full_name)
Rails.application.config.assets.paths.reject! do |path|
excluded_gem_full_names.any? {|gem_name| path.include? gem_name }
end
end
Diaspora::Application.configure do
config.serve_static_files = AppConfig.environment.assets.serve?
# config.static_cache_control = "public, max-age=3600" if AppConfig[:serve_static_assets].to_s == 'true'
end
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
# Rails.application.config.assets.paths << Rails.root.join("node_modules")
Rails.application.config.public_file_server.enabled = AppConfig.environment.assets.serve?

View file

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View file

@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :marshal

View file

@ -1,4 +1,11 @@
Rails.application.config.middleware.insert 0, Rack::Cors do
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"
resource "/api/openid_connect/user_info", methods: %i(get post)
@ -6,6 +13,5 @@ Rails.application.config.middleware.insert 0, Rack::Cors do
resource "/.well-known/host-meta"
resource "/.well-known/webfinger"
resource "/.well-known/openid-configuration"
resource "/webfinger"
end
end

View file

@ -1,4 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += %i(password message text bio)
Rails.application.config.filter_parameters += %i[password message text bio]

Some files were not shown because too many files have changed in this diff Show more