"
+ end
+
+ # shows a pretty printed list of directories and sub-dirs
+ def folder_tree
+ du_opt = (`uname` == "Darwin\n") ? "d0" : "-summarize"
+ @trash_size = `du -#{du_opt} -h #{TRASH_PATH}`.match(/(.*?)\t/)[1]
+ @ferret_size = `du -#{du_opt} -h #{FERRET_PATH}`.match(/(.*?)\t/)[1]
+ du_opt2 = (`uname` == "Darwin\n") ? "d2" : "-max-depth=2"
+ @folder_tree = `cd #{UPLOAD_PATH}; du -#{du_opt2} | sort -n`
+ end
+
+ def show_log
+ @pages, @usages = paginate_collection(:per_page => 30, :page => params[:page]) do
+ if params[:id]
+ @name = (params[:file] ? Myfile.find(params[:id]).filename : Folder.find(params[:id]).name )
+ (params[:file] ? Myfile : Folder).find(params[:id]).usages
+ else
+ Usage.find(:all,:order => "download_date_time desc")
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 1fb36cd..41546b5 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -1,12 +1,46 @@
# Application-wide functionality used by controllers.
class ApplicationController < ActionController::Base
+ include ExceptionNotifiable
before_filter :authorize # user should be logged in
+ # Paginates an existing AR result set, returning the Paginator and collection slice.
+ #
+ # Based upon:
+ # http://www.bigbold.com/snippets/posts/show/389
+ #
+ # Options:
+ # +:collection+: the collection to paginate
+ # +:per_page+: records per page
+ # +:page+: page
+ #
+ # Example:
+ # complex_query_result = Customer.find_by_sql('something complex')
+ # @pages, @customers = paginate_collection(:collection => complex_query_result)
+ #
+ # Alternatively, you can specify a block, the result of which will be used as the collection:
+ # @pages, @customers = paginate_collection { Customer.find_by_sql('something complex') }
+ def paginate_collection(options = {}, &block)
+ if block_given?
+ options[:collection] = block.call
+ elsif !options.include?(:collection)
+ raise ArgumentError, 'You must pass a collection in the options or using a block'
+ end
+
+ default_options = {:per_page => 10, :page => 1}
+ options = default_options.merge options
+
+ pages = Paginator.new self, options[:collection].size, options[:per_page], options[:page]
+ first = pages.current.offset
+ last = [first + options[:per_page], options[:collection].size].min
+ slice = options[:collection][first...last]
+ return [pages, slice]
+ end
+
# Returns the id of the current folder, which is used by the
# CRUD authorize methods to check the logged in user's permissions.
def folder_id
case params[:controller] + '/' + params[:action]
- when 'folder/index', 'folder/list', 'folder/new', 'folder/create', 'folder/update_permissions', 'folder/feed', 'file/upload', 'file/validate_filename'
+ when 'folder/index', 'folder/list', 'folder/new', 'folder/create', 'folder/update_permissions', 'folder/feed', 'file/upload', 'file/validate_filename','folder/multimove', 'folder/multichange'
current_folder_id = 1 unless current_folder_id = params[:id]
when 'file/do_the_upload'
# This prevents a URL like 0.0.0.0/file/do_the_upload/12,
@@ -35,6 +69,7 @@ class ApplicationController < ActionController::Base
# AuthenticationController.login or AuthenticationController.create_admin (if no users exist yet).
def authorize
@logged_in_user = User.find(session[:user_id])
+ User.logged_in_user = @logged_in_user
rescue
reset_session
@logged_in_user = nil
@@ -86,4 +121,5 @@ class ApplicationController < ActionController::Base
redirect_to :controller => 'folder', :action => 'list', :id => folder_id and return false
end
end
+
end
\ No newline at end of file
diff --git a/app/controllers/authentication_controller.rb b/app/controllers/authentication_controller.rb
index db2984c..dcd4493 100644
--- a/app/controllers/authentication_controller.rb
+++ b/app/controllers/authentication_controller.rb
@@ -18,7 +18,8 @@ class AuthenticationController < ApplicationController
# Create the session and redirect
unless logged_in_user.blank?
session[:user_id] = logged_in_user.id
- jumpto = session[:jumpto] || { :action => 'list', :controller => 'folder' }
+ User.logged_in_user = logged_in_user
+ jumpto = { :action => 'list', :controller => 'frontpage' }
session[:jumpto] = nil
redirect_to(jumpto)
else
@@ -49,6 +50,7 @@ class AuthenticationController < ApplicationController
Folder.create_root_folder
GroupPermission.create_initial_permissions
session[:user_id] = @user.id # Login
+ User.logged_in_user = @user
redirect_to(:action => 'list', :controller => 'folder')
end
diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb
index ed8e38a..74f9356 100644
--- a/app/controllers/file_controller.rb
+++ b/app/controllers/file_controller.rb
@@ -8,11 +8,12 @@
# [#update] updates the name of a file
# [#destroy] delete files
# [#preview] preview file; possibly with highlighted search words
+
class FileController < ApplicationController
skip_before_filter :authorize, :only => :progress
before_filter :does_folder_exist, :only => [:upload, :do_the_upload] # if the folder DOES exist, @folder is set to it
- before_filter :does_file_exist, :except => [:upload, :progress, :do_the_upload, :validate_filename] # if the file DOES exist, @myfile is set to it
+ before_filter :does_file_exist, :except => [:upload, :progress, :do_the_upload, :validate_filename,] # if the file DOES exist, @myfile is set to it
before_filter :authorize_creating, :only => :upload
before_filter :authorize_reading, :only => [:download, :preview]
before_filter :authorize_updating, :only => [:rename, :update]
@@ -25,14 +26,7 @@ class FileController < ApplicationController
# (adapted from http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles)
def download
# Log the 'usage' and return the file.
- usage = Usage.new
- usage.download_date_time = Time.now
- usage.user = @logged_in_user
- usage.myfile = @myfile
-
- if usage.save
- send_file @myfile.path, :filename => @myfile.filename
- end
+ send_file @myfile.path, :filename => @myfile.filename
end
# Shows upload progress.
@@ -47,6 +41,7 @@ class FileController < ApplicationController
# Shows the form where a user can select a new file to upload.
def upload
@myfile = Myfile.new
+
if USE_UPLOAD_PROGRESS
render
else
@@ -57,28 +52,188 @@ class FileController < ApplicationController
# Upload the file and create a record in the database.
# The file will be stored in the 'current' folder.
def do_the_upload
- @myfile = Myfile.new(params[:myfile])
- @myfile.folder_id = folder_id
- @myfile.date_modified = Time.now
- @myfile.user = @logged_in_user
+ err = ''
+ if( @myfile = process_each_file(params[:myfile], Time.now, params[:myfile_newname]) )
+ if @myfile.filename =~ FILE_TYPES_BLOCKED
+ flash[:folder_error] = "This file type is blocked and cannot be uploaded. Contact IT if you believe this is wrong."
+ @myfile.log_usage("error","user tried to upload file with blocked filetype")
+ @myfile.destroy
+ redirect_to :controller => 'file', :action => 'upload', :id => folder_id and return false
+ end
- # change the filename if it already exists
- if USE_UPLOAD_PROGRESS and not Myfile.find_by_filename_and_folder_id(@myfile.filename, folder_id).blank?
- @myfile.filename = @myfile.filename + ' (' + Time.now.strftime('%Y%m%d%H%M%S') + ')'
- end
+ @to_be_deleted = @myfile
+ is_zip = true if params[:zip][:yes] == '1' || params[:zip_folders][:yes] == '1'
+ zip_folders = true if params[:zip_folders][:yes] == '1'
- if @myfile.save
- if USE_UPLOAD_PROGRESS
- return_url = url_for(:controller => 'folder', :action => 'list', :id => folder_id)
- render :text => %()
- else
- redirect_to :controller => 'folder', :action => 'list', :id => folder_id
+ @folder = Folder.find(@myfile.folder_id)
+
+ # general for all zip files - check if files exist/blocked filetypes
+ if is_zip
+ # check that no files of the wrong filetype and that file doesn't exist
+ zf = Zip::ZipFile.open(@myfile.path)
+ zf.each_with_index do |entry, index|
+ next if entry.ftype != :file || entry.name =~ /^\.|\/\./ || entry.name == "__MACOSX"
+
+ name = File.basename(Myfile.base_part_of(entry.name))
+ if Myfile.find_by_filename_and_folder_id(name, @folder.id) || Folder.find_by_name_and_parent_id(name, @folder.parent_id)
+ err = "The file #{name} has the same name as a file or folder in the current folder, and the zip file could not be extracted."
+ end
+
+ # if zip_folders, only check root files for conflicts
+ next if entry.name.match(/\//) && zip_folders
+ if entry.name =~ FILE_TYPES_BLOCKED
+ err = "The file #{name} is not an allowed file type, and the zip file could not be uploaded. Please contact IT if you believe this is wrong."
+ @myfile.log_usage("error","user tried to upload file with blocked filetype #{entry.name}")
+ end
+
+ unless err.empty?
+ @to_be_deleted.destroy
+ flash[:folder_error] = err
+ redirect_to :controller => 'file', :action => 'upload', :id => folder_id and return false
+ end
+ end
+
+ unless zip_folders # we already know is_zip
+ # all's clear, let's do this! :)
+ zf.each_with_index do |entry, index|
+ # don't add dirs as files, most people don't want dot files added
+ # (Mac finder zip adds them)
+ next if entry.ftype != :file || entry.name =~ /^\.|\/\./ || entry.name == "__MACOSX"
+ date_time_created = Time.now
+ filesize = (entry.size / 1000).to_i
+ filesize = 1 if filesize == 0
+ # remove directory paths from the filename if they exist
+ name = File.basename(entry.name)
+
+ # extract one entry to a file in uploads/
+ File.open("#{TEMP_PATH}/#{date_time_created.to_f}.tmp",
+ 'wb') { |f| f.write(zf.file.open(entry.name).read) }
+ p "process #{name} #{date_time_created.to_f}"
+ process_each_file(name, date_time_created, name, filesize)
+
+ end
+
+ else # zip folders
+ # let's get the directories and make them first
+ dirs, files = [], []
+ zf.each_with_index do |entry, i|
+ p "entry name #{entry.name} ftype #{entry.ftype}"
+ dirs << entry.name if entry.ftype == :directory
+ files << entry if entry.ftype == :file
+ end
+
+ # # apparently not all dirs are listed as dir entries, so I have to do this. argh.
+ # TODO: I took this out because it caused problems with normal zip files, but
+ # there might still be some weird zip files which won't work
+ # files.each do |f|
+ # dir, name = File.split(f.name)
+ # unless dirs.include?(dir)
+ # fulld = ''
+ # dir.split("/").each do |d|
+ # fulld += (fulld.empty? ? '' : "/") + d
+ # dirs << fulld + "/" unless dirs.include?(fulld)
+ # end
+ # end
+ # end
+
+ level, parent, dirs_created = 1, [], {}
+ parent[level], old = @folder, @folder
+
+ p dirs
+ # create new directories necessary
+ dirs.sort.each do |dir|
+ newlevel = dir.scan("/").length
+ parent[newlevel] = old if newlevel > level
+ level = newlevel
+
+ dirname = dir.split("/").pop
+
+ old = make_new_folder(dirname, parent[level])
+ dirs_created[dir] = old
+ end
+
+ # extract files and put them in the new directories
+ files.each do |file|
+ dirname, filename = File.split(file.name)
+ next if filename =~ /^\.|\/\./ || filename == "__MACOSX"
+ date_time_created = Time.now
+ filesize = (file.size / 1000).to_i
+ filesize = 1 if filesize == 0
+
+ # remove directory paths from the filename if they exist
+ name = File.basename(filename)
+
+ # extract one entry to a file in TEMP_PATH
+ File.open("#{TEMP_PATH}/#{date_time_created.to_f}.tmp", 'wb') do |f|
+ f.write(zf.file.open(file.name).read)
+ end
+ p dirs_created
+ p dirname
+ dir = ( (dirname =~ /^\.$|^$/) ? @folder : dirs_created[dirname + "/"] )
+ process_each_file( name, date_time_created, name, filesize, dir.id )
+
+ end
+ end
+ zf.close
+ @to_be_deleted.destroy
end
+
+ redirect_to :controller => 'folder', :action => 'list', :id => folder_id
+ else # @myfile could not be saved
+ # todo: check activerecord errors for other types of errors?
+ flash[:folder_error] = "You cannot upload a file with the same name as a folder or a file that already exists."
+ redirect_to :controller => 'file', :action => 'upload', :id => folder_id and return false
+ end
+ end
+
+ def make_new_folder(folder, parent)
+ newfolder = Folder.new
+ newfolder.name = folder
+ newfolder.parent = parent
+ newfolder.date_modified = Time.now
+ newfolder.user = @logged_in_user
+ newfolder.save
+ copy_permissions_to_new_folder(parent, newfolder)
+ return newfolder
+ end
+
+ def process_each_file(file, date_modified, name, size=0, folder=folder_id)
+ @date_time_created=date_modified
+ if file.kind_of?(String)
+ @myfile = Myfile.new
else
- render :template =>'file/upload_without_progress' unless USE_UPLOAD_PROGRESS
+ @myfile = Myfile.new(file)
+ end
+ @myfile.filename = name
+ @myfile.user = @logged_in_user
+ @myfile.date_modified=date_modified if @myfile.date_modified.nil?
+ @myfile.filename=Myfile.base_part_of(file) if file.kind_of?(String) # zip files
+ @myfile.folder_id = folder
+ @myfile.user = @logged_in_user
+ @myfile.filesize=size if @myfile.filesize.nil?
+ # change the filename if it already exists
+ @myfile.save
+ p @myfile
+ return (@myfile.save ? @myfile : false)
+ end
+
+ # Copy the GroupPermissions of the parent folder to the given folder
+ def copy_permissions_to_new_folder(oldfolder, folder)
+ # get the 'parent' GroupPermissions
+ for parent_group_permissions in GroupPermission.find_all_by_folder_id(oldfolder.id)
+ # create the new GroupPermissions
+ group_permissions = GroupPermission.new
+ group_permissions.folder = folder
+ group_permissions.group = parent_group_permissions.group
+ group_permissions.can_create = parent_group_permissions.can_create
+ group_permissions.can_read = parent_group_permissions.can_read
+ group_permissions.can_update = parent_group_permissions.can_update
+ group_permissions.can_delete = parent_group_permissions.can_delete
+ group_permissions.save
end
end
+
# Validates a selected file in a file field via an Ajax call
def validate_filename
filename = CGI::unescape(request.raw_post).chomp('=')
@@ -98,7 +253,7 @@ class FileController < ApplicationController
# Update the name of the file with the new data.
def update
if request.post?
- if @myfile.update_attributes(:filename => Myfile.base_part_of(params[:myfile][:filename]), :date_modified => Time.now)
+ if @myfile.rename(Myfile.base_part_of(params[:myfile][:filename]))
redirect_to :controller => 'folder', :action => 'list', :id => folder_id
else
render_action 'rename'
@@ -109,6 +264,7 @@ class FileController < ApplicationController
# Preview file; possibly with highlighted search words.
def preview
if @myfile.indexed
+ @myfile.log_usage("previewed")
if params[:search].blank? # normal case
@text = @myfile.text
else # if we come from the search results page
@@ -126,12 +282,13 @@ class FileController < ApplicationController
# These methods are private:
# [#does_file_exist] Check if a file exists before executing an action
private
- # Check if a file exists before executing an action.
- # If it doesn't exist: redirect to 'list' and show an error message
- def does_file_exist
- @myfile = Myfile.find(params[:id])
- rescue
- flash.now[:folder_error] = 'Someone else deleted the file you are using. Your action was cancelled and you have been taken back to the root folder.'
- redirect_to :controller => 'folder', :action => 'list' and return false
- end
+ # Check if a file exists before executing an action.
+ # If it doesn't exist: redirect to 'list' and show an error message
+ def does_file_exist
+ @myfile = Myfile.find(params[:id])
+ rescue
+ flash.now[:folder_error] = 'Someone else deleted the file you are using. Your action was cancelled and you have been taken back to the root folder.'
+ redirect_to :controller => 'folder', :action => 'list' and return false
+ end
+
end
\ No newline at end of file
diff --git a/app/controllers/folder_controller.rb b/app/controllers/folder_controller.rb
index 4f2cd50..2379cc5 100644
--- a/app/controllers/folder_controller.rb
+++ b/app/controllers/folder_controller.rb
@@ -9,11 +9,12 @@
# [#update] updates the attributes of a folder
# [#destroy] delete a folder
# [#update_permissions] save the new rights given by the user
+
class FolderController < ApplicationController
skip_before_filter :authorize, :only => :feed
before_filter :does_folder_exist, :except => [:list, :feed, :feed_warning]
- before_filter :authorize_creating, :only => [:new, :create]
+ before_filter :authorize_creating, :only => [:new, :create, :multimove]
before_filter :authorize_reading, :only => :list
before_filter :authorize_updating, :only => [:rename, :update, :update_rights]
before_filter :authorize_deleting, :only => :destroy
@@ -21,6 +22,98 @@ class FolderController < ApplicationController
# Sessions are not needed for feeds
session :off, :only => 'feed'
layout 'folder', :except => 'feed'
+
+ # do something to selected files in folder list
+ def multichange
+ @folder = Folder.find(folder_id)
+ unless @logged_in_user.can_delete(folder_id)
+ flash[:folder_error] = "You don't have delete permissions for this folder."
+ redirect_to :action => 'list', :id => folder_id and return false
+ end
+
+ checked_files, checked_folders = [], []
+ params['checked_file'].each {|k,v| checked_files << Myfile.find(k.to_i) if v == 'yes' } if params['checked_file']
+ params['checked_folder'].each {|k,v| checked_folders << Folder.find(k.to_i) if v == 'yes' } if params['checked_folder']
+ unless (checked_files.size + checked_folders.size) > 0
+ flash[:folder_error] = "You didn't select any files or folders."
+ redirect_to :action => 'list', :id => folder_id and return false
+ end
+
+ case params['checked']['action']
+ when 'delete'
+ checked_files.each {|x| x.destroy }
+ checked_folders.each {|x| x.delete }
+
+ when 'add to clipboard'
+ flash[:folder_info] = "The files and/or folders you marked have been put on the clipboard. They will not disappear from this folder, until you choose moving them to a new folder."
+ temp = @logged_in_user.clipboards
+ already_files, already_folders = temp.collect(&:myfile), temp.collect(&:folder)
+ checked_files.each do |x|
+ unless already_files.index(x)
+ Clipboard.new(:user => @logged_in_user, :myfile => x).save
+ end
+ end
+
+ checked_folders.each do |x|
+ unless already_folders.index(x)
+ Clipboard.new(:user => @logged_in_user, :folder => x).save
+ end
+ end
+
+ when 'download all'
+ tmpfile = TEMP_PATH + "/zip" + Time.now.to_f.to_s + ".tmp"
+ folders, files = "", ""
+ checked_folders.collect(&:name).each {|x| folders << "\"#{x}\" " }
+ checked_files.collect(&:filename).each {|x| files << "\"#{x}\" " }
+
+ # tricky because we don't want absolute paths in the zip file, but the temp
+ # dir is a relative path
+ slashes = @folder.path_on_disk.scan('/').size
+ slashes += 1 unless @folder.id == 1
+ tmppath = '../' * slashes
+ cmd = "cd \"#{@folder.path_on_disk}\"; zip -r #{tmppath}#{tmpfile} #{folders} #{files}"
+ `#{cmd}`
+ puts cmd
+ p files
+ @folder.log_usage("zipped", cmd)
+ p @folder.path_on_disk
+
+ if File.exists?(tmpfile)
+ send_file tmpfile, :filename => "DownloadAllFiles.zip"
+ return false
+ else
+ flash[:folder_error] = "Could not zip selected files."
+ @folder.log_usage("error","could not zip " + checked_folders.join(":") + " " + checked_files.join(":") )
+ end
+
+ end
+ redirect_to :action => 'list', :id => folder_id
+ end
+
+ # move files and folders in clipboard to the current folder
+ def multimove
+ @logged_in_user.clipboards.each do |x|
+ if x.folder
+ File.mv(x.folder.path_on_disk, @folder.path_on_disk)
+ x.folder.log_usage("moved", "from #{x.folder.name} to #{@folder.name}")
+ x.folder.parent = @folder
+ x.folder.save
+ else
+ File.mv(File.join(x.myfile.folder.path_on_disk, x.myfile.filename), @folder.path_on_disk)
+ x.myfile.log_usage("moved", "from #{x.myfile.folder.name} to #{@folder.name}")
+ x.myfile.folder = @folder
+ x.myfile.save
+ end
+ x.destroy
+ end
+ redirect_to :action => 'list', :id => folder_id
+ end
+
+ # deletes all clipboard entries for a given user
+ def cancel_moving
+ @logged_in_user.clipboards.collect(&:destroy)
+ redirect_to :action => 'list', :id => params[:folder_id]
+ end
# The default action, redirects to list.
def index
@@ -32,7 +125,7 @@ class FolderController < ApplicationController
def list
# Get the folder
@folder = Folder.find_by_id(folder_id)
-
+
# Set if the user is allowed to update or delete in this folder;
# these instance variables are used in the view.
@can_update = @logged_in_user.can_update(@folder.id)
@@ -60,7 +153,7 @@ class FolderController < ApplicationController
url = url_for(:controller => 'folder', :action => 'list', :id => nil)
# it's nice to have the possibility to go up one level
- @folder_up = '..' if @folder.parent
+ @folder_up = @folder.parent.id.to_s if @folder.parent
end
# Authorizes, sets the appropriate variables and headers.
@@ -107,15 +200,14 @@ class FolderController < ApplicationController
# Create a new folder with the posted variables from the 'new' view.
def create
if request.post?
+ params[:folder][:name] = Myfile.base_part_of(params[:folder][:name])
@folder = Folder.new(params[:folder])
- @folder.parent_id = folder_id
+ @folder.parent = Folder.find(folder_id)
@folder.date_modified = Time.now
@folder.user = @logged_in_user
-
if @folder.save
# copy groups rights on parent folder to new folder
copy_permissions_to_new_folder(@folder)
-
# back to the list
redirect_to :action => 'list', :id => params[:id]
else
@@ -132,7 +224,7 @@ class FolderController < ApplicationController
# Update the folder attributes with the posted variables from the 'rename' view.
def update
if request.post?
- if @folder.update_attributes(:name => params[:folder][:name], :date_modified => Time.now)
+ if @folder.rename(params[:folder][:name])
redirect_to :action => 'list', :id => folder_id
else
render_action 'rename'
@@ -142,18 +234,48 @@ class FolderController < ApplicationController
# Delete a folder.
def destroy
- @folder.destroy
+ @folder.delete
redirect_to :action => 'list', :id => folder_id
end
# Saved the new permissions given by the user
def update_permissions
- if request.post? and @logged_in_user.is_admin?
- # update the create, read, update, delete right for this folder:
- update_group_permissions(folder_id, params[:create_check_box], 'create', params[:update_recursively][:checked] == 'yes' ? true : false)
- update_group_permissions(folder_id, params[:read_check_box], 'read', params[:update_recursively][:checked] == 'yes' ? true : false)
- update_group_permissions(folder_id, params[:update_check_box], 'update', params[:update_recursively][:checked] == 'yes' ? true : false)
- update_group_permissions(folder_id, params[:delete_check_box], 'delete', params[:update_recursively][:checked] == 'yes' ? true : false)
+ if request.post?
+ @folder = Folder.find(folder_id)
+ if @logged_in_user.can_update_perms?
+ # update the create, read, update, delete right for this folder:
+ update_group_permissions(folder_id, params[:create_check_box], 'create', params[:update_recursively][:checked] == 'yes' ? true : false)
+ update_group_permissions(folder_id, params[:read_check_box], 'read', params[:update_recursively][:checked] == 'yes' ? true : false)
+ update_group_permissions(folder_id, params[:update_check_box], 'update', params[:update_recursively][:checked] == 'yes' ? true : false)
+ update_group_permissions(folder_id, params[:delete_check_box], 'delete', params[:update_recursively][:checked] == 'yes' ? true : false)
+
+ # changing name of folder owner
+ newuser = User.find_by_name(params[:owner])
+ if newuser
+ to_change = [@folder]
+ to_change += @folder.all_children if params[:owner_recursive][:checked] == 'yes'
+ to_change.each do |f|
+ puts f
+ p "Changing #{f.name}"
+
+ f.user = newuser
+ f.save
+ end
+ else
+ flash[:folder_error] = "User #{params[:owner]} could not be found. No change in ownership committed."
+ end
+
+ end
+
+ # updating folder info and upload info
+ if @logged_in_user.can_update_folderinfo?(@folder)
+ @folder.quota = params[:folder][:quota]
+ @folder.note = params[:folder][:note]
+ @folder.note_upload = params[:folder][:note_upload]
+ @folder.note_inheritable = ( params[:folder][:note_inheritable] == '1' ? true : false )
+ @folder.note_upload_inheritable = ( params[:folder][:note_upload_inheritable] == '1' ? true : false )
+ @folder.save
+ end
end
# Return to the folder
@@ -196,11 +318,8 @@ class FolderController < ApplicationController
# The recursive part...
if recursively
# Update the child folders
- folder = Folder.find_by_id(folder_id_param)
- if folder
- folder.children.each do |child_folder|
- update_group_permissions(child_folder.id, group_check_box_list, field, true)
- end
+ Folder.find_by_id(folder_id_param).all_children.each do |f|
+ update_group_permissions(f, group_check_box_list, field, true)
end
end
end
@@ -238,7 +357,7 @@ class FolderController < ApplicationController
# if current user cannot delete in current folder
def authorize_deleting
folder = Folder.find_by_id(folder_id)
- unless @logged_in_user.can_delete(folder.id)
+ unless @logged_in_user.can_delete(folder_id)
flash.now[:folder_error] = "You don't have delete permissions for this folder."
redirect_to :controller => 'folder', :action => 'list', :id => folder_id and return false
else
@@ -262,4 +381,5 @@ class FolderController < ApplicationController
end
end
end
-end
\ No newline at end of file
+
+end
diff --git a/app/controllers/frontpage_controller.rb b/app/controllers/frontpage_controller.rb
new file mode 100644
index 0000000..d676028
--- /dev/null
+++ b/app/controllers/frontpage_controller.rb
@@ -0,0 +1,88 @@
+class FrontpageController < ApplicationController
+ session :off, :only => 'feed'
+ layout 'frontpage', :except => 'filelist'
+ before_filter :is_user_authorized, :except => [:list, :filelist]
+
+ uses_tiny_mce(:options => {:theme => 'advanced',
+ :theme_advanced_buttons1 => %w{bold italic underline strikethrough separator justifyleft justifycenter justifyright separator bullist numlist forecolor backcolor separator link unlink image undo redo},
+ :external_link_list_url => "/frontpage/filelist",
+ :convert_newlines_to_brs => true,
+ :theme_advanced_buttons2 => [],
+ :theme_advanced_buttons3 => []})
+
+ def is_user_authorized
+ unless @logged_in_user.groups.include?(Group.find_by_name('frontpage'))
+ flash.now[:news_error] = 'You are not authorized to edit the news.'
+ redirect_to(:controller => 'frontpage', :action => 'list', :id => nil) and return false
+ end
+ end
+
+ def index
+ list
+ render :action => 'list'
+ end
+
+ def delete
+ News.find(params[:id]).destroy
+ redirect_to(:controller => 'frontpage', :action => 'list', :id => nil)
+ end
+
+ def filelist
+ headers['Content-Type'] = 'text/javascript'
+ @text = 'var tinyMCELinkList = new Array('
+ Group.find_by_name('frontpage').users.each do |user|
+ user.clipboards.each do |x|
+ if x.folder
+ txt = x.folder.path_on_disk[UPLOAD_PATH.size..-1]
+ lnk = "/folder/list/#{x.folder.id}"
+ else
+ txt = x.myfile.folder.path_on_disk[UPLOAD_PATH.size..-1]+ "/" + x.myfile.filename
+ lnk = "/file/download/#{x.myfile.id}"
+ end
+ @text << "[\"#{txt.shorten(60)}\", \"#{lnk}\"],"
+ end
+ end
+ @text = @text.chop << ");"
+ end
+
+ def list
+ @news_pages, @news = paginate :news, :per_page => 10, :order => 'date DESC'
+ end
+
+ def show
+ @news = News.find(params[:id])
+ end
+
+ def new
+ @news = News.new
+ end
+
+ def create
+ @news = News.new(params[:news])
+ if @news.save
+ flash[:notice] = 'News was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @news = News.find(params[:id])
+ end
+
+ def update
+ @news = News.find(params[:id])
+ if @news.update_attributes(params[:news])
+ flash[:notice] = 'News was successfully updated.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ News.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
diff --git a/app/controllers/usage_controller.rb b/app/controllers/usage_controller.rb
new file mode 100644
index 0000000..01bd0bc
--- /dev/null
+++ b/app/controllers/usage_controller.rb
@@ -0,0 +1,13 @@
+class UsageController < ApplicationController
+ def show
+ @pages, @usages = paginate_collection(:per_page => 30, :page => params[:page]) do
+ if params[:id]
+ @name = (params[:file] ? Myfile.find(params[:id]).filename : Folder.find(params[:id]).name )
+ (params[:file] ? Myfile : Folder).find(params[:id]).usages
+ else
+ Usage.find(:all,:order => "download_date_time desc")
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index f992560..c717e89 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -10,7 +10,7 @@ class UserController < ApplicationController
before_filter :authorize_admin, :except => [:edit, :update]
before_filter :does_user_exist, :only => [:edit, :update, :destroy]
before_filter :do_not_destroy_admin_user, :only => :destroy
-
+
# The default action, redirects to list.
def index
list
@@ -21,6 +21,67 @@ class UserController < ApplicationController
def list
@users = User.find(:all, :order => 'name')
end
+
+ def mass_create
+ end
+
+ def mass_create_do
+ g_err, usercount = '', 0
+
+ params[:users][:textfield].each do |line|
+ err = ''
+ name, email, *groupnames = line.chomp.split(",")
+ if name[0, 1] == "@"
+ name = name[1..-1]
+ err << "User #{name} does not exist. " unless (user = User.find_by_name(name.strip))
+ p "#{user} going well"
+ p groupnames
+ groupnames.each do |g|
+ op, group = g.split(//, 2)
+ err << "Group #{group} does not exist. " unless (grp = Group.find_by_name(group.strip))
+ p "#{group} going well with #{op}"
+ case op
+ when "+"
+ user.groups.push(grp)
+ when "-"
+ tmp = user.groups.dup
+ user.groups.clear
+ tmp.delete_if {|x| x.id == grp.id }.each {|x| user.groups.push(x)}
+ else
+ err << "Invalid operator #{op}, must be + or -. "
+ end if err.empty?
+ user.save
+ usercount += 1
+ end if err.empty?
+ else
+ err << "User #{name} already exists. " if User.find_by_name(name)
+ err << "Email #{email} already exists. " if User.find_by_email(email)
+ err << "Email #{email} is invalid. " unless email.strip.match(VALID_EMAIL)
+
+ groups = []
+ groupnames.each do |g|
+ err << "Group #{g} does not exist. " if (groups << Group.find_by_name(g.strip)) == [nil]
+ end
+
+ if err.empty?
+ password = User.random_password(8)
+ user = User.new(
+ :name => name.strip,
+ :email => email.strip,
+ :password => password
+ )
+ groups.compact.each {|g| user.groups.push(g) }
+ user.save
+ usercount += 1
+ PasswordMailer.deliver_new_user(user.name, user.email, password)
+ end
+ end
+ g_err << err
+ end
+
+ flash[g_err.empty? ? :user_confirmation : :user_error] = g_err + "#{usercount} users added/changed."
+ redirect_to :action => 'list'
+ end
# Show a form to enter data for a new user.
def new
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f517516..3c1f7dd 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -5,9 +5,10 @@ module ApplicationHelper
return msg.sub('Name', 'Username') if msg
end
+
# Returns the path to the given folder.
# Link to self determines wether every part of the path links to itself.
- def path(folder, link_to_self)
+ def path(folder, link_to_self, html = true)
# the base url for a path is always the same:
url = url_for(:controller => 'folder', :action => 'list', :id => nil)
@@ -24,7 +25,9 @@ module ApplicationHelper
end
# Finally, make it a link...
- path = '' + h(path) + ''
+ if html
+ path = '' + h(path) + ''
+ end
else
path = h(folder.name)
diff --git a/app/helpers/frontpage_helper.rb b/app/helpers/frontpage_helper.rb
new file mode 100644
index 0000000..f86545a
--- /dev/null
+++ b/app/helpers/frontpage_helper.rb
@@ -0,0 +1,2 @@
+module FrontpageHelper
+end
diff --git a/app/models/clipboard.rb b/app/models/clipboard.rb
index b85ca9d..34453f1 100644
--- a/app/models/clipboard.rb
+++ b/app/models/clipboard.rb
@@ -1,17 +1,11 @@
-# Files and folders can be stored temporary on the clipboard.
-# Objects are not persisted to the database as the nature of a clipboard object
-# is that it's temporary.
-class Clipboard
- attr_reader :folders
- attr_reader :files
+class Clipboard < ActiveRecord::Base
+ belongs_to :myfile
+ belongs_to :user
+ belongs_to :folder
# Initialize clipboard object.
# We're starting with an empty clipboard:
# the @folders and @files arrays are empty too.
- def initialize
- @folders = []
- @files = []
- end
# Put given folder on clipboard
# unless it's already there
@@ -24,14 +18,4 @@ class Clipboard
def add_file(file)
@files << file unless @files.find{ |f| f.id == file.id }
end
-
- # Remove given folder from clipboard
- def remove_folder(folder)
- @folders.delete(folder)
- end
-
- # Remove given file from clipboard
- def remove_file(file)
- @files.delete(file)
- end
end
\ No newline at end of file
diff --git a/app/models/folder.rb b/app/models/folder.rb
index 19b5078..2cee915 100644
--- a/app/models/folder.rb
+++ b/app/models/folder.rb
@@ -3,23 +3,95 @@
# Via groups it is determined which actions the logged-in User can perform.
class Folder < ActiveRecord::Base
acts_as_ferret :store_class_name => true, :fields => { :name => { :store => :no } }
- acts_as_tree :order => 'name'
+ acts_as_tree :order => :name
belongs_to :user
has_many :myfiles, :dependent => :destroy
has_many :group_permissions, :dependent => :destroy
+ has_many :clipboards, :dependent => :destroy
+ has_many :usages
validates_uniqueness_of :name, :scope => 'parent_id'
validates_presence_of :name
+ cattr_accessor :clipboard
attr_accessible :name
+ def after_create
+ # create the physical folder on disk
+ Dir.mkdir(self.path_on_disk) unless File.exists?(self.path_on_disk)
+ end
+
+ # have to call destroy through this, otherwise the moving doesn't work properly
+ def delete
+ trash_name = "#{TRASH_PATH}/#{name}.#{Time.now.to_f.to_s}"
+ File.mv(path_on_disk, trash_name)
+ p "Moving from #{path_on_disk} to #{trash_name}"
+ destroy
+ end
+
+ # gets called after delete, so folder has already been moved
+ def before_destroy
+ trash_name = "#{TRASH_PATH}/#{@name}.#{Time.now.to_f.to_s}"
+ log_usage("deleted","moved from01 #{self.path_on_disk} moved to #{trash_name}")
+ end
+
+ def path_on_disk
+ folder = self
+ path = folder.name
+ unless folder.parent_id == 0
+ until folder.parent_id == 1
+ folder = folder.parent
+ path = folder.name + "/" + path
+ end
+ else
+ path = ""
+ end
+ return (UPLOAD_PATH + "/" + path)
+ end
+
+ def rename(name)
+ old_name = self.name
+ parent_path = self.parent.path_on_disk
+ if self.update_attributes(:name => Myfile.base_part_of(name), :date_modified => Time.now) && File.rename( parent_path + "/" + old_name, self.path_on_disk)
+ log_usage("renamed","from #{old_name} to #{self.name}")
+ else
+ return false
+ end
+ end
+
+ def note_inherited
+ return self.note unless self.note.nil? || self.note.empty?
+ current, result = self, ''
+ until !result.empty? || current == nil
+ if !current.note.nil? && !current.note.empty? && current.note_inheritable
+ result = current.note
+ else
+ current = current.parent
+ end
+ end
+ return (result.empty? ? nil : result)
+ end
+
+ def note_upload_inherited
+ return self.note_upload unless self.note_upload.nil? || self.note_upload.empty?
+ current, result = self, ''
+ until !result.empty? || current == nil
+ if !current.note_upload.nil? && !current.note_upload.empty? && current.note_upload_inheritable
+ result = current.note_upload
+ else
+ current = current.parent
+ end
+ end
+ return (result.empty? ? nil : result)
+ end
+
# List subfolders
# for the given user in the given order.
def list_subfolders(logged_in_user, order)
folders = []
if logged_in_user.can_read(self.id)
- self.children.find(:all, :order => order).each do |sub_folder|
+ self.children.each do |sub_folder|
folders << sub_folder if logged_in_user.can_read(sub_folder.id)
end
end
@@ -48,11 +120,13 @@ class Folder < ActiveRecord::Base
# Create the Root folder
def self.create_root_folder
- if User.admin_exists? #and Folder.root_folder_exists?
+ if User.admin_exists? #and Folder.root_folder_exists?
folder = self.new
folder.name = 'Root folder'
folder.date_modified = Time.now
folder.is_root = true
+ folder.lft, folder.rgt = 1, 2 # must be initialized, otherwise quota check on upload
+ # won't work until another folder has been added
# This folder is created by the admin
if user = User.find_by_is_the_administrator(true)
@@ -62,4 +136,36 @@ class Folder < ActiveRecord::Base
folder.save # this hopefully returns true
end
end
+
+ def log_usage(action, comment = nil)
+ usage = Usage.new(
+ :download_date_time => Time.now,
+ :user => User.logged_in_user,
+ :folder => self,
+ :filename => self.name,
+ :action => action,
+ :comment => comment
+ ).save
+ end
+
+ def all_with_children
+ folders = [self]
+ self.children.each do |child_folder|
+ folders += child_folder.all_with_children if child_folder.children
+ end
+ return folders
+ end
+
+ def all_children
+ self.all_with_children - [self]
+ end
+
+
+ private
+ def validate
+ if Myfile.find_by_filename_and_folder_id(self.name, self.parent_id)
+ errors.add_to_base "You cannot create a folder with the same name as a file."
+ end
+ end
+
end
\ No newline at end of file
diff --git a/app/models/group.rb b/app/models/group.rb
index 928c55e..318e649 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -32,16 +32,31 @@ class Group < ActiveRecord::Base
# Create admins group and add admin user to it.
def self.create_admins_group
if User.admin_exists? # and Group.admins_group_exists?
- group = Group.new
- group.name = 'admins'
- group.is_the_administrators_group = true
+ admins, folderadmins, frontpage = Group.new, Group.new, Group.new
+
+ admins.name = 'admins'
+ frontpage.name = 'frontpage'
+ folderadmins.name = 'folderadmins'
+ admins.is_the_administrators_group = true
# Add the adminstrator to this group:
if user = User.find_by_is_the_administrator(true)
- user.groups.push(group)
+ user.groups.push(admins)
+ user.groups.push(frontpage)
+ user.groups.push(folderadmins)
end
- group.save # save, so true is returned
+ admins.save # save, so true is returned
+ frontpage.save
+ folderadmins.save
end
+ end
+
+ def self.frontpage
+ self.find_by_name('frontpage')
+ end
+
+ def self.folderadmins
+ self.find_by_name('folderadmins')
end
end
\ No newline at end of file
diff --git a/app/models/group_permission.rb b/app/models/group_permission.rb
index 1017f03..775bb77 100644
--- a/app/models/group_permission.rb
+++ b/app/models/group_permission.rb
@@ -14,14 +14,16 @@ class GroupPermission < ActiveRecord::Base
# Create the permissions
unless root_folder.blank? or admins_group.blank?
- group_permission = GroupPermission.new
- group_permission.folder = root_folder
- group_permission.group = admins_group
- group_permission.can_create = true
- group_permission.can_read = true
- group_permission.can_update = true
- group_permission.can_delete = true
- group_permission.save
+ %w(admins frontpage folderadmins).each do |grpname|
+ group = GroupPermission.new
+ group.folder = root_folder
+ group.group = Group.find_by_name(grpname)
+ group.can_create = true
+ group.can_read = true
+ group.can_update = true
+ group.can_delete = true
+ group.save
+ end
end
end
end
\ No newline at end of file
diff --git a/app/models/myfile.rb b/app/models/myfile.rb
index fead7c9..d20b3de 100644
--- a/app/models/myfile.rb
+++ b/app/models/myfile.rb
@@ -9,7 +9,8 @@ class Myfile < ActiveRecord::Base
belongs_to :folder
belongs_to :user
- has_many :usages, :dependent => :destroy
+ has_many :usages
+ has_many :clipboards, :dependent => :destroy
validates_uniqueness_of :filename, :scope => 'folder_id'
@@ -18,8 +19,11 @@ class Myfile < ActiveRecord::Base
if self.filename.blank?
errors.add(:filename, " can't blank.")
end
+ if Folder.find_by_name_and_parent_id(self.filename, self.folder_id)
+ errors.add_to_base("You cannot upload a file with the same name as a folder.")
+ end
end
-
+
# Accessor that receives the data from the form in the view.
# The file will be saved in a folder called 'uploads'.
# (See: AWDWR pp. 362.)
@@ -28,10 +32,7 @@ class Myfile < ActiveRecord::Base
# Get the filename
filename = Myfile.base_part_of(myfile_field.original_filename)
- # Set date_time_created,
- # this will be the files temporary name.
- # (this instance variable is also used in temp_path)
- @date_time_created = Time.now.to_f
+ self.date_modified = Time.now
# Save the file on the file system
File.open(self.temp_path, 'wb') do |f|
@@ -40,10 +41,59 @@ class Myfile < ActiveRecord::Base
end
end
- # Variable to hold the plain text content of the uploaded file
- text_in_file = nil
+ # Save it all to the database
+ self.filename = filename
+ filesize = (myfile_field.length / 1024).to_i
+ if filesize == 0
+ self.filesize = 1 # a file of 0 KB doesn't make sense
+ else
+ self.filesize = filesize
+ end
+
+ end
+ end
+
- # Try to get the text from the uploaded file
+ def index
+ # Try to get the text from the uploaded file
+ # Variable to hold the plain text content of the uploaded file
+ text_in_file = nil
+ filename = self.filename
+
+ # Try the helpers first
+ INDEX_HELPERS.each do |index_helper| # defined in environment.rb
+ if filename =~ index_helper[:ext] # a matching helper!
+
+ if index_helper[:file_output] # a file that writes to an output file
+ `#{ sprintf(index_helper[:helper], self.temp_path, self.temp_path + '_copy') }`
+ if File.exists?(self.temp_path + '_copy') # avoid error messages if external prog
+ # borks
+ text_in_file = File.open(self.temp_path + '_copy') { |f| f.read }
+ File.delete(self.temp_path + '_copy')
+ else
+ text_in_file = ""
+ end
+ else # we get the contents from stido directly
+ text_in_file = `#{ sprintf(index_helper[:helper], self.temp_path) }`
+ end
+
+ # Check if we need to remove first part (e.g. unrtf)
+ unless index_helper[:remove_before].blank?
+ if index_helper[:remove_before].match(text_in_file)
+ text_in_file = Regexp::last_match.post_match
+ end
+ end
+
+ # Check if we need to remove last part
+ unless index_helper[:remove_after].blank?
+ if index_helper[:remove_after].match(text_in_file)
+ text_in_file = Regexp::last_match.pre_match
+ end
+ end
+ end
+ end
+
+ unless text_in_file # no hits yet - try the built in
case filename
when /.txt$/
text_in_file = File.open(self.temp_path) { |f| f.read }
@@ -56,53 +106,16 @@ class Myfile < ActiveRecord::Base
text_in_file = zipfile.file.open('content.xml') { |f| f.read.gsub(/<.*?>/, ' ') }
end
end
-
- # If it didn't get caught yet, try the helpers
- if text_in_file.blank?
- INDEX_HELPERS.each do |index_helper| # defined in environment.rb
- if filename =~ index_helper[:ext] # a matching helper!
-
- if index_helper[:file_output] # a file that writes to an output file
- `#{ sprintf(index_helper[:helper], self.temp_path, self.temp_path + '_copy') }`
- text_in_file = File.open(self.temp_path + '_copy') { |f| f.read }
- File.delete(self.temp_path + '_copy')
- else # we get the contents from stido directly
- text_in_file = `#{ sprintf(index_helper[:helper], self.temp_path) }`
- end
-
- # Check if we need to remove first part (e.g. unrtf)
- unless index_helper[:remove_before].blank?
- if index_helper[:remove_before].match(text_in_file)
- text_in_file = Regexp::last_match.post_match
- end
- end
-
- # Check if we need to remove last part
- unless index_helper[:remove_after].blank?
- if index_helper[:remove_after].match(text_in_file)
- text_in_file = Regexp::last_match.pre_match
- end
- end
- end
- end
- end
-
- unless text_in_file.blank?
- self.text = text_in_file.strip # assign text_in_file to self.text to get it indexed
- self.indexed = true
- end
-
- # Save it all to the database
- self.filename = filename
- filesize = (myfile_field.length / 1000).to_i
- if filesize == 0
- self.filesize = 1 # a file of 0 KB doesn't make sense
- else
- self.filesize = filesize
- end
+ end
+
+ if text_in_file && !text_in_file.strip.empty?
+ self.text = text_in_file.strip # assign text_in_file to self.text to get it indexed
+ self.indexed = true
+ self.save
end
end
+
attr_writer :text # Setter for text
# Getter for text.
@@ -111,21 +124,36 @@ class Myfile < ActiveRecord::Base
@text = Myfile.ferret_index[self.document_number][:text] if @text.blank?
end
- after_create :rename_newfile
+ after_create :index, :rename_newfile
# The file in the uploads folder has the same name as the id of the file.
# This must be done after_create, because the id won't be available any earlier.
def rename_newfile
File.rename self.temp_path, self.path
+ log_usage("uploaded")
end
before_destroy :delete_file_on_disk
# When removing a myfile record from the database,
# the actual file on disk has to be removed too.
- # That is exactly what this method does.
- def delete_file_on_disk
- File.delete self.path
+ # However, instead of deleting, we move it to the trash directory. Safer.
+ def delete_file_on_disk
+ if File.exists? self.path
+ new_name = "#{TRASH_PATH}/#{basename}.#{Time.now.to_f.to_s}"
+ log_usage("deleted","moved from #{self.path} to #{new_name}")
+ File.mv(self.path, new_name)
+ end
end
-
+
+ def rename(filename)
+ old_filename = self.filename
+ if self.update_attributes(:filename => filename, :date_modified => Time.now) && File.rename( self.folder.path_on_disk + "/" + old_filename, self.path )
+
+ log_usage("renamed","from #{old_filename} to #{self.filename}")
+ else
+ return false
+ end
+ end
+
# Strip of the path and replace all the non alphanumeric,
# underscores and periods in the filename with an underscore.
def self.base_part_of(file_name)
@@ -134,17 +162,53 @@ class Myfile < ActiveRecord::Base
# get only the filename, not the whole path
name = file_name.gsub(/^.*(\\|\/)/, '')
- # finally, replace all non alphanumeric, underscore or periods with underscore
- name.gsub(/[^\w\.\-]/, '_')
+ # finally, replace all non alphanumeric, underscore or periods with space, and
+ # reduce all spaces to maximum one, with no trailing or leading
+ name.gsub(/[^\w\.\-]/, ' ').gsub(/([^\s])(\s+?)([^\s])/,'\1 \3').gsub(/([^\s])(\s+?)([^\s])/,'\1 \3').strip
+ end
+
+ def basename
+ return Myfile.base_part_of(self.filename)
end
# Returns the location of the file before it's saved
def temp_path
- "#{UPLOAD_PATH}/#{@date_time_created}"
+ "#{TEMP_PATH}/#{self.date_modified.to_f}.tmp"
end
# The path of the file
def path
- "#{UPLOAD_PATH}/#{self.id}"
+ File.join(self.folder.path_on_disk, basename)
+ end
+
+ def icon_file
+ FILE_ICONS.each do |f_icon|
+ if self.filename =~ f_icon[:ext]
+ return f_icon[:icon]
+ end
+ end
+ return 'file.png'
+ end
+
+ def short_fname(length = 50)
+ return self.filename.shorten(length)
+ end
+
+ def log_usage(action, comment = nil)
+ usage = Usage.new(
+ :download_date_time => Time.now,
+ :user => User.logged_in_user,
+ :myfile => self,
+ :filename => self.filename,
+ :action => action,
+ :comment => comment
+ ).save
end
+
+
+ private
+ def read_file(file)
+ File.open(file) { |f| return f.read }
+ end
+
end
\ No newline at end of file
diff --git a/app/models/news.rb b/app/models/news.rb
new file mode 100644
index 0000000..75904da
--- /dev/null
+++ b/app/models/news.rb
@@ -0,0 +1,2 @@
+class News < ActiveRecord::Base
+end
diff --git a/app/models/password_mailer.rb b/app/models/password_mailer.rb
index e4d1491..fed1f01 100644
--- a/app/models/password_mailer.rb
+++ b/app/models/password_mailer.rb
@@ -3,20 +3,20 @@
class PasswordMailer < ActionMailer::Base
# E-mail login data to a new user.
def new_user(name, email, password)
- @subject = 'Your Boxroom password'
+ @subject = 'Your CARE Intranet File Library password'
@body['name'] = name
@body['password'] = password
@recipients = email
- @from = 'Boxroom '
+ @from = 'CARE Intranet '
end
# E-mail login data to an exiting user
# who requested a new password.
def forgotten(name, email, password)
- @subject = 'Your Boxroom password'
+ @subject = 'Your CARE Intranet File Library password'
@body['name'] = name
@body['password'] = password
@recipients = email
- @from = 'Boxroom '
+ @from = 'CARE Intranet '
end
end
\ No newline at end of file
diff --git a/app/models/usage.rb b/app/models/usage.rb
index f0831d5..7609b0f 100644
--- a/app/models/usage.rb
+++ b/app/models/usage.rb
@@ -3,4 +3,13 @@
class Usage < ActiveRecord::Base
belongs_to :user
belongs_to :myfile
+ belongs_to :folder
+
+ def self.log_usage(options)
+ usage = Usage.new(:download_date_time => Time.now)
+ %w(file folder comment user action).each do |x|
+ eval("usage.#{x} = options[:#{x}]") if options[x]
+ end
+ return usage.save
+ end
end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 53f8a3d..3781c32 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -7,6 +7,7 @@ require 'digest/sha1'
# Therefore passwords are hashed before they are stored.
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
+ has_many :clipboards, :dependent => :destroy
has_many :usages, :dependent => :destroy
has_many :myfiles, :dependent => :nullify
has_many :folders, :dependent => :nullify
@@ -14,14 +15,14 @@ class User < ActiveRecord::Base
# The password_required field, which determines if
# the presence of a password has to be checked
attr_accessor :password_required
-
+ cattr_accessor :logged_in_user
# We never allow the hashed password to be set from a form
attr_accessible :name, :email, :password, :password_confirmation, :password_required
validates_confirmation_of :password
validates_uniqueness_of :name, :email
validates_presence_of :name, :email
- validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/
+ validates_format_of :email, :with => VALID_EMAIL
# Validates if the data for this user is valid.
def validate
@@ -29,13 +30,30 @@ class User < ActiveRecord::Base
if self.password_required and self.password.blank?
errors.add(:password, " can't be blank")
end
+ end
+
+ def can_update_perms?
+ (is_admin? || groups.include?(Group.folderadmins)) ? true : false
+ end
+
+ def can_update_folderinfo?(folder)
+ ((folder.user == self) || can_update_perms?) ? true : false
end
+
# Password getter
def password
return @password
end
+ def no_or_nil(temp)
+ temp == 0 ? nil : temp
+ end
+
+ def no_files_clipboard; no_or_nil(self.clipboards.collect(&:myfile).compact.size); end
+ def no_folders_clipboard; no_or_nil(self.clipboards.collect(&:folder).compact.size); end
+ def empty_clipboard; self.clipboards.collect(&:destroy); end
+
# Password setter
def password=(new_password)
@password = new_password
diff --git a/app/views/admin_tool/folder_tree.rhtml b/app/views/admin_tool/folder_tree.rhtml
new file mode 100644
index 0000000..beecce9
--- /dev/null
+++ b/app/views/admin_tool/folder_tree.rhtml
@@ -0,0 +1,17 @@
+
Overview of directories and diskspace
+Size of trash folder: <%=@trash_size%>, and of Ferret index: <%=@ferret_size%>.
+
+
+
Size (in kB)
Folder
+
+ <%
+ @folder_tree.each do |x|
+ unless x =~ /\.svn/
+ size, line= x.split(/\t/) %>
+
<%=size%>
<%=line.gsub(/^\.\//,"").gsub(/^\.$/,"Total")%>
+
+<%
+end
+end
+ %>
+
diff --git a/app/views/admin_tool/server_status.rhtml b/app/views/admin_tool/server_status.rhtml
new file mode 100644
index 0000000..a4410fa
--- /dev/null
+++ b/app/views/admin_tool/server_status.rhtml
@@ -0,0 +1,5 @@
+
Server status
+
+<%= @status %>
+
+<%= link_to 'Back', :action => 'list', :id => controller.folder_id %>
\ No newline at end of file
diff --git a/app/views/admin_tool/show_log.rhtml b/app/views/admin_tool/show_log.rhtml
new file mode 100644
index 0000000..d114ea3
--- /dev/null
+++ b/app/views/admin_tool/show_log.rhtml
@@ -0,0 +1,35 @@
+
+ <%if @name.nil?%>
+ Latest system events
+ <%else%>
+ Latest events for <%=@name%>
+ <%end%>
+
+
Time
+
User
+
Action
+
File/Folder
+
+
+ <% for usage in @usages %>
+ <% cyc = cycle('even', 'odd') %>
+
+ <%= check_box :zip, :yes, :onchange => "if (document.upload_form.zip_yes.checked) {document.upload_form.zip_folders_yes.checked = false; Element.hide('newfilename');} if (document.upload_form.zip_yes.checked == false && document.upload_form.zip_folders_yes.checked == false) {Element.show('newfilename')}" %>
+Extract zip file and put all files into current directory
+(help)
+
+ <%= check_box(:zip_folders, :yes, :onchange => "if (document.upload_form.zip_folders_yes.checked) {document.upload_form.zip_yes.checked = false; ; Element.hide('newfilename');} if (document.upload_form.zip_yes.checked == false && document.upload_form.zip_folders_yes.checked == false) {Element.show('newfilename')}") %>
+Extract zip files and create new directories
+(help)
+
+
+
If you choose to put all files into the current directory, they will all be extracted into the directory you are in now. However, if you choose the second option, it will replicate the directory structure of the zip file in boxroom. So, if the zip file has files with paths like MIS/Accounting/Report.doc, the new folders MIS and Accounting will be created in the current folder. Make sure the paths are correct before you upload the zip file with this option.
+
<%= submit_tag 'Upload' %>
<% end %>
-<%= link_to 'Back', :controller => 'folder', :action => 'list', :id => controller.folder_id %>
\ No newline at end of file
+
+<%= link_to 'Back', :controller => 'folder', :action => 'list', :id => controller.folder_id %>
diff --git a/app/views/folder/list.rhtml b/app/views/folder/list.rhtml
index 2b36e9c..5b39496 100644
--- a/app/views/folder/list.rhtml
+++ b/app/views/folder/list.rhtml
@@ -1,8 +1,8 @@
-
+ <%= check_box('update_recursively', 'checked', {}, 'yes', 'no') %> Apply changes in permissions to subfolders
+ Owner of folder:
+ />
+<%= check_box('owner_recursive', 'checked', {}, 'yes', 'no') %> Apply changes in ownership to subfolders
+ <% end %>
+ <%= check_box('folder','note_inheritable', {}, 1, 0) %> Make sub-folders inherit this note
+ <%= text_area 'folder', 'note', :cols => 60, :rows => 3 %>
+ <%= check_box('folder','note_upload_inheritable', {}, 1, 0) %> Make sub-folders inherit these instructions
+ <%= text_area 'folder', 'note_upload', :cols => 60, :rows => 3 %>
+
+
+
+ <%= submit_tag 'Save' %>
<% end %>
<% end %>
\ No newline at end of file
diff --git a/app/views/frontpage/_form.rhtml b/app/views/frontpage/_form.rhtml
new file mode 100644
index 0000000..b7441ff
--- /dev/null
+++ b/app/views/frontpage/_form.rhtml
@@ -0,0 +1,12 @@
+<%= error_messages_for 'news' %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/password_mailer/forgotten.rhtml b/app/views/password_mailer/forgotten.rhtml
index b1485a8..859dd7b 100644
--- a/app/views/password_mailer/forgotten.rhtml
+++ b/app/views/password_mailer/forgotten.rhtml
@@ -1,6 +1,6 @@
-A new Boxroom password has been generated for you.
-Use the following to log in to Boxroom:
+A new CARE Indonesia File Library password has been generated for you.
+Use the following to log in to the File Library:
- URL: http://localhost:3000
+ URL: http://intranet.careindonesia.or.id
Username: <%= @name %>
Password: <%= @password %>
\ No newline at end of file
diff --git a/app/views/password_mailer/new_user.rhtml b/app/views/password_mailer/new_user.rhtml
index cbb67d4..0274c28 100644
--- a/app/views/password_mailer/new_user.rhtml
+++ b/app/views/password_mailer/new_user.rhtml
@@ -1,5 +1,5 @@
-A new Boxroom account has been created for you:
+A new CARE Indonesia File Library account has been created for you:
- URL: http://localhost:3000
+ URL: http://intranet.careindonesia.or.id
Username: <%= @name %>
Password: <%= @password %>
\ No newline at end of file
diff --git a/app/views/shared/_content.rhtml b/app/views/shared/_content.rhtml
new file mode 100644
index 0000000..9903865
--- /dev/null
+++ b/app/views/shared/_content.rhtml
@@ -0,0 +1,10 @@
+
+
+
+
+ <%= yield %>
+
+
+
+
+
diff --git a/app/views/shared/_create_file_folder.rhtml b/app/views/shared/_create_file_folder.rhtml
index 05377b7..df97e30 100644
--- a/app/views/shared/_create_file_folder.rhtml
+++ b/app/views/shared/_create_file_folder.rhtml
@@ -1,4 +1,7 @@
<% unless controller.folder_id.blank? or not @logged_in_user.can_create(controller.folder_id) %>
<%= link_to 'Create folder', { :controller => 'folder', :action => 'new', :id => controller.folder_id } %>
<%= link_to 'Upload file', { :controller => 'file', :action => 'upload', :id => controller.folder_id } %>
-<% end %>
\ No newline at end of file
+
+---
+
+<% end %>
diff --git a/app/views/shared/_go_to_menu.rhtml b/app/views/shared/_go_to_menu.rhtml
dissimilarity index 100%
index ed02f0d..ccf61d3 100644
--- a/app/views/shared/_go_to_menu.rhtml
+++ b/app/views/shared/_go_to_menu.rhtml
@@ -1,17 +1,11 @@
-<% if params[:controller] == 'folder' or params[:controller] == 'file' %>
-<%= link_to 'Folders', { :controller => 'folder', :action => 'list', :id => nil }, { :class => 'activeLink' } %>
-<% else %>
-<%= link_to 'Folders', { :controller => 'folder', :action => 'list', :id => nil } %>
-<% end %>
-<% if @logged_in_user.is_admin? %>
- <% if params[:controller] == 'user' %>
- <%= link_to 'Users', { :controller => 'user', :action => 'list' }, { :class => 'activeLink' } %>
- <% else %>
- <%= link_to 'Users', { :controller => 'user', :action => 'list' } %>
- <% end %>
- <% if params[:controller] == 'group' %>
- <%= link_to 'Groups', { :controller => 'group', :action => 'list' }, { :class => 'activeLink' } %>
- <% else %>
- <%= link_to 'Groups', { :controller => 'group', :action => 'list' } %>
- <% end %>
-<% end %>
\ No newline at end of file
+<% cls = (params[:controller] == 'frontpage' ? 'activeLink' : '') %>
+<%= link_to 'Home', { :controller => 'frontpage', :action => 'list', :id => nil }, { :class => cls } %>
+
+<%
+if @logged_in_user.is_admin?
+ [['user', 'list'], ['group', 'list'], ['admin_tool', 'server_status']].each do |contr, act|
+ cls = (params[:controller] == contr ? 'activeLink' : '') %>
+ <%= link_to contr.pluralize.upcase, { :controller => contr, :action => act }, { :class => cls } %>
+<% end; end %>
+
+<%= render_partial 'shared/intranet' %>
\ No newline at end of file
diff --git a/app/views/shared/_intranet.rhtml b/app/views/shared/_intranet.rhtml
new file mode 100644
index 0000000..d54a64c
--- /dev/null
+++ b/app/views/shared/_intranet.rhtml
@@ -0,0 +1,7 @@
+<% unless @logged_in_user.is_admin? %>
+ | CARE's website
+Webmail
+SCALA
+Asset management
+HRIS
+<% end %>
\ No newline at end of file
diff --git a/app/views/shared/_root_folder.rhtml b/app/views/shared/_root_folder.rhtml
new file mode 100755
index 0000000..d8281cd
--- /dev/null
+++ b/app/views/shared/_root_folder.rhtml
@@ -0,0 +1,3 @@
+<% Folder.find_all_by_parent_id(1).each do |folder| %>
+ <%= link_to h(folder.name), :controller => 'folder', :action => 'list', :id => folder %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/shared/_top_header.rhtml b/app/views/shared/_top_header.rhtml
new file mode 100644
index 0000000..7ab2860
--- /dev/null
+++ b/app/views/shared/_top_header.rhtml
@@ -0,0 +1,15 @@
+