Remove repetion of shareable initialization code

This commit is contained in:
cmrd Senya 2016-05-31 17:56:04 +03:00
parent 2737280fa4
commit 204f58e6a7
No known key found for this signature in database
GPG key ID: 5FCC5BA680E67BFE
3 changed files with 8 additions and 8 deletions

View file

@ -82,11 +82,7 @@ class Photo < ActiveRecord::Base
end
def self.diaspora_initialize(params = {})
photo = self.new params.to_hash.slice(:text, :pending)
photo.author = params[:author]
photo.public = params[:public] if params[:public]
photo.pending = params[:pending] if params[:pending]
photo = shareable_initialize(params)
photo.random_string = SecureRandom.hex(10)
if photo.author.local?

View file

@ -133,9 +133,7 @@ class Post < ActiveRecord::Base
#############
def self.diaspora_initialize(params)
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_post|
new_post.author = params[:author]
end
shareable_initialize(params)
end
# @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo).

View file

@ -57,6 +57,12 @@ module Diaspora
user.person.send(table_name).where(pending: false)
end
def self.shareable_initialize(params)
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_shareable|
new_shareable.author = params[:author]
end
end
def self.visible_by_user(user)
ShareVisibility.arel_table[:user_id].eq(user.id)
end