Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
maxwell
a validé
@aspect = :profile
@post_type = :photos
@person = Person.find_by_id(params[:person_id])
maxwell
a validé
if @person
@profile = @person.profile
@contact = current_user.contact_for(@person)
@is_contact = @person != current_user.person && @contact
if @contact
@aspects_with_person = @contact.aspects
end
@posts = current_user.raw_visible_posts.all(:_type => 'Photo', :person_id => @person.id, :order => 'created_at DESC').paginate :page => params[:page], :order => 'created_at DESC'
maxwell
a validé
render 'people/show'
maxwell
a validé
flash[:error] = I18n.t 'people.show.does_not_exist'
redirect_to people_path
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect{|x| x.id}
end
params[:photo][:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
raise 'MongoMapper failed to catch a failed save' unless @photo.id
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) unless @photo.pending
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
Daniel Vincent Grippi
a validé
end
message = I18n.t 'photos.create.type_error'
rescue CarrierWave::IntegrityError
message = I18n.t 'photos.create.integrity_error'
rescue RuntimeError => e
message = I18n.t 'photos.create.runtime_error'
raise e
photo = current_user.my_posts.where(:_id => params[:id]).first
if photo
photo.destroy
flash[:notice] = I18n.t 'photos.destroy.notice'
if photo.status_message_id
respond_with :location => photo.status_message
else
respond_with :location => photos_path
end
else
respond_with :location => photos_path
@photo = current_user.find_visible_post_by_id params[:id]
unless @photo
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@ownership = current_user.owns? @photo
def edit
if @photo = current_user.my_posts.where(:_id => params[:id]).first
respond_with @photo
maxwell
a validé
redirect_to person_photos_path(current_user.person)
end
def update
photo = current_user.my_posts.where(:_id => params[:id]).first
if photo
if current_user.update_post( photo, params[:photo] )
danielvincent
a validé
flash.now[:notice] = I18n.t 'photos.update.notice'
respond_to do |format|
format.js{ render :json => photo, :status => 200 }
end
danielvincent
a validé
flash.now[:error] = I18n.t 'photos.update.error'
respond_to do |format|
format.html{ redirect_to [:edit, photo] }
format.js{ render :status => 403 }
end
maxwell
a validé
redirect_to person_photos_path(current_user.person)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
private
def file_handler(params)
######################## dealing with local files #############
# get file name
file_name = params[:qqfile]
# get file content type
att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s
# create tempora##l file
begin
file = Tempfile.new(file_name, {:encoding => 'BINARY'})
file.print request.raw_post.force_encoding('BINARY')
rescue RuntimeError => e
raise e unless e.message.include?('cannot generate tempfile')
file = Tempfile.new(file_name) # Ruby 1.8 compatibility
file.print request.raw_post
end
# put data into this file from raw post request
# create several required methods for this temporal file
Tempfile.send(:define_method, "content_type") {return att_content_type}
Tempfile.send(:define_method, "original_filename") {return file_name}
file
end