Permalink
Browse files

File manager working properly, missing share option

  • Loading branch information...
1 parent 768287b commit 81316c780f7d72a40aa702216e83cf7738392c3c Ivan Chavero committed Nov 16, 2011
@@ -38,7 +38,7 @@ def index
@posts = @person.posts.where("type = 'UserFile' and path = '#{userpath}' ").order("unixperms")
#@posts = current_user.posts_from(@person).where(:type => 'UserFile').order("unixperms").paginate(:page => params[:page])
- RAILS_DEFAULT_LOGGER.debug "DEBUG:: Entrando a INDEX DE FILES: #{userpath}"
+ Rails.logger.debug "DEBUG:: Entrando a INDEX DE FILES: #{userpath}"
# @files = @person.posts.where(:type => ["UserFile"]).order("unixperms").paginate(:page => params[:page])
render 'people/show'
@@ -50,20 +50,20 @@ def index
def create
@currdir = params[:currdir]
- RAILS_DEFAULT_LOGGER.debug "DEBUG entrando con CURRDIR: #{params[:currdir]}"
+ Rails.logger.debug "DEBUG entrando con CURRDIR: #{params[:currdir]}"
begin
if params.include? 'unixperms'
- RAILS_DEFAULT_LOGGER.debug "Wrong arguments unixperms #{params[:unixperms]}"
+ Rails.logger.debug "Wrong arguments unixperms #{params[:unixperms]}"
end
if create_object
respond_to do |format|
- RAILS_DEFAULT_LOGGER.debug "DEBUG FILE SALVADA #{params[:text]} ";
+ Rails.logger.debug "DEBUG FILE SALVADA #{params[:text]} ";
format.json{ render(:layout => false , :json => {"success" => true, "data" => @file}.to_json )}
format.html{ redirect_to person_user_files_path + "/showdir/#{@currdir}"}
- RAILS_DEFAULT_LOGGER.debug "DEBUG DESPUES de JSON";
+ Rails.logger.debug "DEBUG DESPUES de JSON";
end
else
- RAILS_DEFAULT_LOGGER.debug "DEBUG FILE NO SALVADA #{message}";
+ Rails.logger.debug "DEBUG FILE NO SALVADA #{message}";
respond_with @file, :location => person_user_files_path, :error => message
end
@@ -87,8 +87,8 @@ def create
end
def create_object
- RAILS_DEFAULT_LOGGER.debug "DEBUG Entrando a create object #{params[:file]}"
- RAILS_DEFAULT_LOGGER.debug "DEBUG ASPECT IDS #{params[:aspect_ids]}"
+ Rails.logger.debug "DEBUG Entrando a create object #{params[:file]}"
+ Rails.logger.debug "DEBUG ASPECT IDS #{params[:aspect_ids]}"
raise unless params[:aspect_ids]
if params[:aspect_ids] == ["all"]
@@ -105,15 +105,15 @@ def create_object
params[:username] = current_user.username
#we're creating a directory
if !(params.include? 'unixperms')
- RAILS_DEFAULT_LOGGER.debug "DEBUG NO ES DIRECTORIO #{params[:unixperms]}"
+ Rails.logger.debug "DEBUG NO ES DIRECTORIO #{params[:unixperms]}"
params[:user_file] = file_handler(params)
params[:filename] = params[:user_file].original_filename
params[:unixperms] = "-r-wr--r--"
else
- RAILS_DEFAULT_LOGGER.debug "DEBUG ES DIRECTORIO #{params[:unixperms]}"
+ Rails.logger.debug "DEBUG ES DIRECTORIO #{params[:unixperms]}"
params[:filename] = params[:user_file]
end
- RAILS_DEFAULT_LOGGER.debug "CREATE FILE CON USERNAME #{params[:user_path]}/#{params[:filename]}"
+ Rails.logger.debug "CREATE FILE CON USERNAME #{params[:user_path]}/#{params[:filename]}"
begin
@file = current_user.build_post(:user_file, params)
rescue Exception => e
@@ -135,10 +135,12 @@ def create_object
def destroy
file = current_user.posts.where(:id => params[:id]).first
- RAILS_DEFAULT_LOGGER.debug "DEBUG :: DESTROY #{params[:id]}"
+ Rails.logger.debug "DEBUG :: DESTROY #{params[:id]}"
begin
if file
+ Rails.logger.debug "DEBUG :: DESTROY ANTES DE RETRACT"
current_user.retract(file)
+ Rails.logger.debug "DEBUG :: DESTROY DESPUES DE RETRACT"
respond_to do |format|
format.json{ render :nothing => true, :status => 204 }
@@ -161,7 +163,8 @@ def destroy
message = I18n.t 'user_files.delete_file_error'
end
flash[:notice] = message
- RAILS_DEFAULT_LOGGER.debug "DEBUG :: DESTROY user_files directorio con contenido"
+ Rails.logger.debug "DEBUG :: DESTROY user_files directorio con contenido #{e}"
+ Rails.logger.debug "DEBUG :: DESTROY user_files directorio con contenido INSPECT: #{e.inspect}"
respond_with file, :location => person_user_files_path, :error => message
end
@@ -170,15 +173,15 @@ def destroy
def show
require 'mime/types'
- RAILS_DEFAULT_LOGGER.debug "DEBUG :: SHOW #{current_user.id} #{params[:id]}"
+ Rails.logger.debug "DEBUG :: SHOW #{current_user.id} #{params[:id]}"
#if @file = current_user.posts.where(:id => params[:id]).first
if @file = Post.where(:id => params[:id]).first
path = @file.object_url.split("/")
filename = path[path.length-1]
mime_type = MIME::Types.type_for(filename)
content_type = mime_type.to_s unless mime_type.nil?
filepath = "#{Rails.root}" + "/public/uploads/files/" + "#{@file.path}/#{filename}"
- RAILS_DEFAULT_LOGGER.debug "DEBUG FILENAM #{Rails.root} #{filepath}, MIME: #{content_type}"
+ Rails.logger.debug "DEBUG FILENAM #{Rails.root} #{filepath}, MIME: #{content_type}"
send_file filepath, :type=>"application/zip", :x_sendfile=>true, :type => content_type
else
redirect_to :back
@@ -221,7 +224,7 @@ def create_dir
begin
create_object
rescue Exception => e
- RAILS_DEFAULT_LOGGER.debug "DEBUG: ERROR CREATEDIR CACHADO #{e.message}"
+ Rails.logger.debug "DEBUG: ERROR CREATEDIR CACHADO #{e.message}"
message = I18n.t 'user_files.index.create_dir_error'
flash[:error] = message
respond_to do |format|
@@ -230,7 +233,7 @@ def create_dir
end
return
end
- RAILS_DEFAULT_LOGGER.debug "DEBUG: Entrando a newdir con: #{fullpath}"
+ Rails.logger.debug "DEBUG: Entrando a newdir con: #{fullpath}"
respond_to do |format|
format.json{ render :json => {path: "/people/#{current_user.id}/user_files/showdir#{params[:currdir]}/#{params[:user_file]}", status: 200 }, :status => 200 }
format.html {redirect_to people_path}
@@ -276,20 +279,20 @@ def get_dir
get_user_info()
@currdir = "/#{params[:name]}"
realdir = "#{Rails.root}/public/uploads/files/#{@user_path}/#{params[:name]}"
- RAILS_DEFAULT_LOGGER.debug "DEBUG Entrando a DIRECTORIO: #{params[:name]} post_type: #{@post_type} REALDIR: #{realdir}"
+ Rails.logger.debug "DEBUG Entrando a DIRECTORIO: #{params[:name]} post_type: #{@post_type} REALDIR: #{realdir}"
if !File.directory? realdir
flash[:error] = I18n.t '.no_such_directory'
redirect_to person_user_files_path(current_user.person)
return
end
@posts = @person.posts.where("type = 'UserFile' and path = '#{@user_path}/#{params[:name]}' ").order("unixperms").paginate(:page => params[:page])
- RAILS_DEFAULT_LOGGER.debug "FILES #{@posts}";
+ Rails.logger.debug "FILES #{@posts}";
render 'people/show'
end
def filemanager
get_user_info()
- RAILS_DEFAULT_LOGGER.debug "DEBUG Entrando a FILEMANAGER: #{params[:dir]} post_type: #{@post_type}"
+ Rails.logger.debug "DEBUG Entrando a FILEMANAGER: #{params[:dir]} post_type: #{@post_type}"
@currdir = "#{params[:dir]}"
if params[:dir] == '/'
params[:dir] = ''
@@ -298,7 +301,7 @@ def filemanager
params[:dir].slice!(params[:dir].length - 1)
params[:dir].slice!(0)
realdir = "#{Rails.root}/public/uploads/files/#{@user_path}/#{params[:dir]}"
- RAILS_DEFAULT_LOGGER.debug "DEBUG Entrando a DIRECTORIO: #{params[:dir]} post_type: #{@post_type} REALDIR: #{realdir}"
+ Rails.logger.debug "DEBUG Entrando a DIRECTORIO: #{params[:dir]} post_type: #{@post_type} REALDIR: #{realdir}"
## if !File.directory? realdir
# flash[:error] = I18n.t '.no_such_directory'
# redirect_to person_user_files_path(current_user.person)
@@ -310,7 +313,7 @@ def filemanager
end
@files = @person.posts.where("type = 'UserFile' and path = '#{db_path}' ").order("unixperms")
- RAILS_DEFAULT_LOGGER.debug "DEBUG DIR: #{params[:dir]}";
+ Rails.logger.debug "DEBUG DIR: #{params[:dir]}";
render :template => 'user_files/filemanager', :layout => false
end
@@ -353,7 +356,7 @@ def previous_file
def file_handler(params)
######################## dealing with local files #############
# get file name
- RAILS_DEFAULT_LOGGER.debug "Entrando a INDEX DE FILES #{params[:file].original_filename}"
+ Rails.logger.debug "Entrando a INDEX DE FILES #{params[:file].original_filename}"
file_name = params[:file].original_filename
# get file content type
att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s
@@ -72,7 +72,6 @@ def target= new_target
end
def perform receiving_user
- Rails.logger.debug "Performing retraction for #{target_guid}"
if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first
onward_retraction = self.dup
onward_retraction.sender = receiving_user.person
View
@@ -289,6 +289,8 @@ def mail_confirm_email
def retract(target, opts={})
if target.respond_to?(:relayable?) && target.relayable?
retraction = RelayableRetraction.build(self, target)
+ elsif target.is_a? UserFile
+ retraction = Retraction.for(target)
elsif target.is_a? Post
retraction = SignedRetraction.build(self, target)
else
@@ -372,10 +374,8 @@ def setup(opts)
self.language ||= I18n.locale.to_s
self.valid?
errors = self.errors
- Rails.logger.debug("DEBUG::ERRORS SETUP #{errors}")
errors.delete :person
return if errors.size > 0
- Rails.logger.debug("DEBUG::SETUP creando person")
self.set_person(Person.new(opts[:person] || {} ))
self.generate_keys
self
@@ -493,9 +493,7 @@ def registering?
end
def create_person
- Rails.logger.debug("USER::DEBUG entra a create_person")
if self.person.nil?
- Rails.logger.debug("USER::DEBUG creando person")
@registering = true
#ldapinfo = Hash.new
#test = Devise::LdapAdapter.get_dn(self.username)
@@ -510,16 +508,13 @@ def create_person
opts = {:username => username, :email => email,
:password => password,
:password_confirmation => password}
- Rails.logger.debug("DEBUG::ANTES DE SETUP")
self.setup(opts)
- Rails.logger.debug("DEBUG::DESPUES DE SETUP PERSON? #{self.person}")
self.seed_aspects
end
self
end
def ldap_auth?
- Rails.logger.debug("DEBUG::LDAP_AUTH?")
return 1
end
View
@@ -23,13 +23,10 @@ class UserFile < Post
def delete_file
filepath = "#{Rails.root}/public/uploads/files/#{self.path}/#{self.filename}"
- Rails.logger.debug "DEBUG :: EN DELETE #{filepath} :: #{self.unixperms}"
if self.unixperms =~ /^d/
- Rails.logger.debug "DEBUG :: DIRECTORIO #{filepath} :: #{self.unixperms}"
begin
Dir.rmdir(filepath)
rescue Exception => e
- Rails.logger.debug "DEBUG :: DIRECTORIO con contenido"
raise e
end
return
@@ -58,33 +55,25 @@ def self.diaspora_initialize(params = {})
file = super(params)
file_param = params.delete(:file)
file_object = FileObject.new
- Rails.logger.debug "EN MODEL FILE OBJECT: #{file_object}"
- Rails.logger.debug "EN MODEL USERNAME: #{params[:username]}"
@username = params[:username]
- Rails.logger.debug "EN MODEL USERNAME: #{ @username}"
file.random_string = ActiveSupport::SecureRandom.hex(10)
if params[:unixperms] !~ /^d/
- Rails.logger.debug "DEBUG :: ES ARCHIVO "
- Rails.logger.debug "EN MODEL FILENAME OBJ: #{file_param}"
- Rails.logger.debug "EN MODEL FILENAME OBJ: #{file_param.original_filename}"
- Rails.logger.debug "EN MODEL FILENAME ATTR: #{file.filename}"
file.filename = file_param.original_filename
file.file_object.user_path = params[:user_path]
file.file_object.unixperms = params[:unixperms]
file.file_object.store! file_param
file.update_remote_path
else
newdir = "#{Rails.root}/public/uploads/files/#{params[:user_path]}/#{params[:filename]}"
- Rails.logger.debug "DEBUG :: ES DIRECTORIO #{newdir}"
begin
+ Rails.logger.debug "DEBUG CREANDO DIR"
Dir.mkdir(newdir, 0755)
+ Rails.logger.debug "DEBUG DIR CREADO"
rescue Exception => e
if e.message =~ /No such file/
- Rails.logger.debug "DEBUG no existe user path llamando a mkdir_p"
FileUtils.mkdir_p(newdir)
return
end
- Rails.logger.debug "DEBUG ERROR CREANDO DIR ID: #{e}"
Rails.logger.debug "DEBUG ERROR CREANDO DIR: #{e.message}"
raise e
end
@@ -16,7 +16,7 @@ def store_dir
end
def extension_white_list
- %w(jpg jpeg png gif doc xls ppt pdf exe mp3 mpeg mp4 avi ogg wmf csv flv jar zip gz bz2 rar arj)
+ %w(jpg jpeg png gif doc xls ppt pdf exe mp3 mpeg mp4 avi ogg wmf csv flv jar zip gz bz2 rar arj docx pptx xslx svg)
end
def filename

0 comments on commit 81316c7

Please sign in to comment.