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 end
def self.diaspora_initialize(params = {}) def self.diaspora_initialize(params = {})
photo = self.new params.to_hash.slice(:text, :pending) photo = shareable_initialize(params)
photo.author = params[:author]
photo.public = params[:public] if params[:public]
photo.pending = params[:pending] if params[:pending]
photo.random_string = SecureRandom.hex(10) photo.random_string = SecureRandom.hex(10)
if photo.author.local? if photo.author.local?

View file

@ -133,9 +133,7 @@ class Post < ActiveRecord::Base
############# #############
def self.diaspora_initialize(params) def self.diaspora_initialize(params)
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_post| shareable_initialize(params)
new_post.author = params[:author]
end
end end
# @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo). # @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) user.person.send(table_name).where(pending: false)
end 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) def self.visible_by_user(user)
ShareVisibility.arel_table[:user_id].eq(user.id) ShareVisibility.arel_table[:user_id].eq(user.id)
end end