Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
File manager working properly, missing share option
  • Loading branch information
Ivan Chavero committed Nov 16, 2011
1 parent 768287b commit 81316c7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
49 changes: 26 additions & 23 deletions app/controllers/user_files_controller.rb
Expand Up @@ -38,7 +38,7 @@ def index
@posts = @person.posts.where("type = 'UserFile' and path = '#{userpath}' ").order("unixperms") @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]) #@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]) # @files = @person.posts.where(:type => ["UserFile"]).order("unixperms").paginate(:page => params[:page])
render 'people/show' render 'people/show'


Expand All @@ -50,20 +50,20 @@ def index


def create def create
@currdir = params[:currdir] @currdir = params[:currdir]
RAILS_DEFAULT_LOGGER.debug "DEBUG entrando con CURRDIR: #{params[:currdir]}" Rails.logger.debug "DEBUG entrando con CURRDIR: #{params[:currdir]}"
begin begin
if params.include? 'unixperms' if params.include? 'unixperms'
RAILS_DEFAULT_LOGGER.debug "Wrong arguments unixperms #{params[:unixperms]}" Rails.logger.debug "Wrong arguments unixperms #{params[:unixperms]}"
end end
if create_object if create_object
respond_to do |format| 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.json{ render(:layout => false , :json => {"success" => true, "data" => @file}.to_json )}
format.html{ redirect_to person_user_files_path + "/showdir/#{@currdir}"} 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 end
else 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 respond_with @file, :location => person_user_files_path, :error => message
end end


Expand All @@ -87,8 +87,8 @@ def create
end end


def create_object def create_object
RAILS_DEFAULT_LOGGER.debug "DEBUG Entrando a create object #{params[:file]}" Rails.logger.debug "DEBUG Entrando a create object #{params[:file]}"
RAILS_DEFAULT_LOGGER.debug "DEBUG ASPECT IDS #{params[:aspect_ids]}" Rails.logger.debug "DEBUG ASPECT IDS #{params[:aspect_ids]}"
raise unless params[:aspect_ids] raise unless params[:aspect_ids]


if params[:aspect_ids] == ["all"] if params[:aspect_ids] == ["all"]
Expand All @@ -105,15 +105,15 @@ def create_object
params[:username] = current_user.username params[:username] = current_user.username
#we're creating a directory #we're creating a directory
if !(params.include? 'unixperms') 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[:user_file] = file_handler(params)
params[:filename] = params[:user_file].original_filename params[:filename] = params[:user_file].original_filename
params[:unixperms] = "-r-wr--r--" params[:unixperms] = "-r-wr--r--"
else else
RAILS_DEFAULT_LOGGER.debug "DEBUG ES DIRECTORIO #{params[:unixperms]}" Rails.logger.debug "DEBUG ES DIRECTORIO #{params[:unixperms]}"
params[:filename] = params[:user_file] params[:filename] = params[:user_file]
end 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 begin
@file = current_user.build_post(:user_file, params) @file = current_user.build_post(:user_file, params)
rescue Exception => e rescue Exception => e
Expand All @@ -135,10 +135,12 @@ def create_object


def destroy def destroy
file = current_user.posts.where(:id => params[:id]).first 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 begin
if file if file
Rails.logger.debug "DEBUG :: DESTROY ANTES DE RETRACT"
current_user.retract(file) current_user.retract(file)
Rails.logger.debug "DEBUG :: DESTROY DESPUES DE RETRACT"


respond_to do |format| respond_to do |format|
format.json{ render :nothing => true, :status => 204 } format.json{ render :nothing => true, :status => 204 }
Expand All @@ -161,7 +163,8 @@ def destroy
message = I18n.t 'user_files.delete_file_error' message = I18n.t 'user_files.delete_file_error'
end end
flash[:notice] = message 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 respond_with file, :location => person_user_files_path, :error => message
end end


Expand All @@ -170,15 +173,15 @@ def destroy


def show def show
require 'mime/types' 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 = current_user.posts.where(:id => params[:id]).first
if @file = Post.where(:id => params[:id]).first if @file = Post.where(:id => params[:id]).first
path = @file.object_url.split("/") path = @file.object_url.split("/")
filename = path[path.length-1] filename = path[path.length-1]
mime_type = MIME::Types.type_for(filename) mime_type = MIME::Types.type_for(filename)
content_type = mime_type.to_s unless mime_type.nil? content_type = mime_type.to_s unless mime_type.nil?
filepath = "#{Rails.root}" + "/public/uploads/files/" + "#{@file.path}/#{filename}" 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 send_file filepath, :type=>"application/zip", :x_sendfile=>true, :type => content_type
else else
redirect_to :back redirect_to :back
Expand Down Expand Up @@ -221,7 +224,7 @@ def create_dir
begin begin
create_object create_object
rescue Exception => e 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' message = I18n.t 'user_files.index.create_dir_error'
flash[:error] = message flash[:error] = message
respond_to do |format| respond_to do |format|
Expand All @@ -230,7 +233,7 @@ def create_dir
end end
return return
end end
RAILS_DEFAULT_LOGGER.debug "DEBUG: Entrando a newdir con: #{fullpath}" Rails.logger.debug "DEBUG: Entrando a newdir con: #{fullpath}"
respond_to do |format| 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.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} format.html {redirect_to people_path}
Expand Down Expand Up @@ -276,20 +279,20 @@ def get_dir
get_user_info() get_user_info()
@currdir = "/#{params[:name]}" @currdir = "/#{params[:name]}"
realdir = "#{Rails.root}/public/uploads/files/#{@user_path}/#{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 if !File.directory? realdir
flash[:error] = I18n.t '.no_such_directory' flash[:error] = I18n.t '.no_such_directory'
redirect_to person_user_files_path(current_user.person) redirect_to person_user_files_path(current_user.person)
return return
end end
@posts = @person.posts.where("type = 'UserFile' and path = '#{@user_path}/#{params[:name]}' ").order("unixperms").paginate(:page => params[:page]) @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' render 'people/show'
end end


def filemanager def filemanager
get_user_info() 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]}" @currdir = "#{params[:dir]}"
if params[:dir] == '/' if params[:dir] == '/'
params[:dir] = '' params[:dir] = ''
Expand All @@ -298,7 +301,7 @@ def filemanager
params[:dir].slice!(params[:dir].length - 1) params[:dir].slice!(params[:dir].length - 1)
params[:dir].slice!(0) params[:dir].slice!(0)
realdir = "#{Rails.root}/public/uploads/files/#{@user_path}/#{params[:dir]}" 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 ## if !File.directory? realdir
# flash[:error] = I18n.t '.no_such_directory' # flash[:error] = I18n.t '.no_such_directory'
# redirect_to person_user_files_path(current_user.person) # redirect_to person_user_files_path(current_user.person)
Expand All @@ -310,7 +313,7 @@ def filemanager
end end


@files = @person.posts.where("type = 'UserFile' and path = '#{db_path}' ").order("unixperms") @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 render :template => 'user_files/filemanager', :layout => false
end end


Expand Down Expand Up @@ -353,7 +356,7 @@ def previous_file
def file_handler(params) def file_handler(params)
######################## dealing with local files ############# ######################## dealing with local files #############
# get file name # 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 file_name = params[:file].original_filename
# get file content type # get file content type
att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s
Expand Down
1 change: 0 additions & 1 deletion app/models/signed_retraction.rb
Expand Up @@ -72,7 +72,6 @@ def target= new_target
end end


def perform receiving_user 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 if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first
onward_retraction = self.dup onward_retraction = self.dup
onward_retraction.sender = receiving_user.person onward_retraction.sender = receiving_user.person
Expand Down
9 changes: 2 additions & 7 deletions app/models/user.rb
Expand Up @@ -289,6 +289,8 @@ def mail_confirm_email
def retract(target, opts={}) def retract(target, opts={})
if target.respond_to?(:relayable?) && target.relayable? if target.respond_to?(:relayable?) && target.relayable?
retraction = RelayableRetraction.build(self, target) retraction = RelayableRetraction.build(self, target)
elsif target.is_a? UserFile
retraction = Retraction.for(target)
elsif target.is_a? Post elsif target.is_a? Post
retraction = SignedRetraction.build(self, target) retraction = SignedRetraction.build(self, target)
else else
Expand Down Expand Up @@ -372,10 +374,8 @@ def setup(opts)
self.language ||= I18n.locale.to_s self.language ||= I18n.locale.to_s
self.valid? self.valid?
errors = self.errors errors = self.errors
Rails.logger.debug("DEBUG::ERRORS SETUP #{errors}")
errors.delete :person errors.delete :person
return if errors.size > 0 return if errors.size > 0
Rails.logger.debug("DEBUG::SETUP creando person")
self.set_person(Person.new(opts[:person] || {} )) self.set_person(Person.new(opts[:person] || {} ))
self.generate_keys self.generate_keys
self self
Expand Down Expand Up @@ -493,9 +493,7 @@ def registering?
end end


def create_person def create_person
Rails.logger.debug("USER::DEBUG entra a create_person")
if self.person.nil? if self.person.nil?
Rails.logger.debug("USER::DEBUG creando person")
@registering = true @registering = true
#ldapinfo = Hash.new #ldapinfo = Hash.new
#test = Devise::LdapAdapter.get_dn(self.username) #test = Devise::LdapAdapter.get_dn(self.username)
Expand All @@ -510,16 +508,13 @@ def create_person
opts = {:username => username, :email => email, opts = {:username => username, :email => email,
:password => password, :password => password,
:password_confirmation => password} :password_confirmation => password}
Rails.logger.debug("DEBUG::ANTES DE SETUP")
self.setup(opts) self.setup(opts)
Rails.logger.debug("DEBUG::DESPUES DE SETUP PERSON? #{self.person}")
self.seed_aspects self.seed_aspects
end end
self self
end end


def ldap_auth? def ldap_auth?
Rails.logger.debug("DEBUG::LDAP_AUTH?")
return 1 return 1
end end


Expand Down
15 changes: 2 additions & 13 deletions app/models/user_file.rb
Expand Up @@ -23,13 +23,10 @@ class UserFile < Post


def delete_file def delete_file
filepath = "#{Rails.root}/public/uploads/files/#{self.path}/#{self.filename}" filepath = "#{Rails.root}/public/uploads/files/#{self.path}/#{self.filename}"
Rails.logger.debug "DEBUG :: EN DELETE #{filepath} :: #{self.unixperms}"
if self.unixperms =~ /^d/ if self.unixperms =~ /^d/
Rails.logger.debug "DEBUG :: DIRECTORIO #{filepath} :: #{self.unixperms}"
begin begin
Dir.rmdir(filepath) Dir.rmdir(filepath)
rescue Exception => e rescue Exception => e
Rails.logger.debug "DEBUG :: DIRECTORIO con contenido"
raise e raise e
end end
return return
Expand Down Expand Up @@ -58,33 +55,25 @@ def self.diaspora_initialize(params = {})
file = super(params) file = super(params)
file_param = params.delete(:file) file_param = params.delete(:file)
file_object = FileObject.new file_object = FileObject.new
Rails.logger.debug "EN MODEL FILE OBJECT: #{file_object}"
Rails.logger.debug "EN MODEL USERNAME: #{params[:username]}"
@username = params[:username] @username = params[:username]
Rails.logger.debug "EN MODEL USERNAME: #{ @username}"
file.random_string = ActiveSupport::SecureRandom.hex(10) file.random_string = ActiveSupport::SecureRandom.hex(10)
if params[:unixperms] !~ /^d/ 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.filename = file_param.original_filename
file.file_object.user_path = params[:user_path] file.file_object.user_path = params[:user_path]
file.file_object.unixperms = params[:unixperms] file.file_object.unixperms = params[:unixperms]
file.file_object.store! file_param file.file_object.store! file_param
file.update_remote_path file.update_remote_path
else else
newdir = "#{Rails.root}/public/uploads/files/#{params[:user_path]}/#{params[:filename]}" newdir = "#{Rails.root}/public/uploads/files/#{params[:user_path]}/#{params[:filename]}"
Rails.logger.debug "DEBUG :: ES DIRECTORIO #{newdir}"
begin begin
Rails.logger.debug "DEBUG CREANDO DIR"
Dir.mkdir(newdir, 0755) Dir.mkdir(newdir, 0755)
Rails.logger.debug "DEBUG DIR CREADO"
rescue Exception => e rescue Exception => e
if e.message =~ /No such file/ if e.message =~ /No such file/
Rails.logger.debug "DEBUG no existe user path llamando a mkdir_p"
FileUtils.mkdir_p(newdir) FileUtils.mkdir_p(newdir)
return return
end end
Rails.logger.debug "DEBUG ERROR CREANDO DIR ID: #{e}"
Rails.logger.debug "DEBUG ERROR CREANDO DIR: #{e.message}" Rails.logger.debug "DEBUG ERROR CREANDO DIR: #{e.message}"
raise e raise e
end end
Expand Down
2 changes: 1 addition & 1 deletion app/uploaders/file_object.rb
Expand Up @@ -16,7 +16,7 @@ def store_dir
end end


def extension_white_list 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 end


def filename def filename
Expand Down

0 comments on commit 81316c7

Please sign in to comment.