Skip to content

Commit

Permalink
File manager working properly, missing share option
Browse files Browse the repository at this point in the history
  • 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
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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

Expand All @@ -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"]
Expand 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
Expand All @@ -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 }
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -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}
Expand Down Expand Up @@ -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] = ''
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/models/signed_retraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
15 changes: 2 additions & 13 deletions app/models/user_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/uploaders/file_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81316c7

Please sign in to comment.