dms-tog_depot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/CHANGELOG.md +0 -0
  2. data/MIT-LICENSE +19 -0
  3. data/README.markdown +78 -0
  4. data/Rakefile +22 -0
  5. data/app/controllers/depot/filefolders_controller.rb +10 -0
  6. data/app/controllers/depot/files_controller.rb +35 -0
  7. data/app/controllers/member/depot/filefolders_controller.rb +84 -0
  8. data/app/controllers/member/depot/files_controller.rb +102 -0
  9. data/app/helpers/depot/files_helper.rb +18 -0
  10. data/app/models/depot/file.rb +41 -0
  11. data/app/models/depot/filefolder.rb +21 -0
  12. data/app/models/tog/depot/version.rb +17 -0
  13. data/app/models/user.rb +4 -0
  14. data/app/views/depot/filefolders/show.html.erb +97 -0
  15. data/app/views/depot/files/_tag_cloud_file.html.erb +6 -0
  16. data/app/views/depot/files/by_tag.html.erb +113 -0
  17. data/app/views/depot/files/index.html.erb +111 -0
  18. data/app/views/depot/files/show.html.erb +69 -0
  19. data/app/views/member/depot/filefolders/edit.html.erb +22 -0
  20. data/app/views/member/depot/filefolders/new.html.erb +19 -0
  21. data/app/views/member/depot/filefolders/show.html.erb +121 -0
  22. data/app/views/member/depot/files/by_tag.html.erb +130 -0
  23. data/app/views/member/depot/files/edit.html.erb +27 -0
  24. data/app/views/member/depot/files/index.html.erb +132 -0
  25. data/app/views/member/depot/files/new.html.erb +24 -0
  26. data/app/views/member/depot/files/show.html.erb +79 -0
  27. data/config/routes.rb +32 -0
  28. data/db/migrate/001_create_files.rb +21 -0
  29. data/db/migrate/002_create_files_folder.rb +16 -0
  30. data/init.rb +14 -0
  31. data/public/images/1px.gif +0 -0
  32. data/public/images/privacity/admin.gif +0 -0
  33. data/public/images/privacity/community.gif +0 -0
  34. data/public/images/privacity/member.gif +0 -0
  35. data/public/images/privacity/public_domain.gif +0 -0
  36. data/public/images/tog-depot_arrow_dn.gif +0 -0
  37. data/public/images/tog-depot_arrow_dn_deact.gif +0 -0
  38. data/public/images/tog-depot_arrow_up.gif +0 -0
  39. data/public/images/tog-depot_arrow_up_deact.gif +0 -0
  40. data/public/images/tog-depot_file_dl.gif +0 -0
  41. data/public/images/tog-depot_iconfile_16px.gif +0 -0
  42. data/public/images/tog-depot_iconfile_32px.gif +0 -0
  43. data/public/images/tog-depot_iconfile_48px.gif +0 -0
  44. data/public/images/tog-depot_iconfolder_16px.gif +0 -0
  45. data/public/images/tog-depot_iconfolder_32px.gif +0 -0
  46. data/public/images/tog-depot_iconfolder_48px.gif +0 -0
  47. data/public/stylesheets/depot.css +52 -0
  48. data/test/factories.rb +17 -0
  49. data/test/functional/depot/filefolders_controller_test.rb +30 -0
  50. data/test/functional/depot/files_controller_test.rb +43 -0
  51. data/test/functional/member/depot/filefolders_controller_test.rb +15 -0
  52. data/test/functional/member/depot/files_controller_test.rb +107 -0
  53. data/test/test_helper.rb +26 -0
  54. data/test/unit/file_test.rb +8 -0
  55. data/test/unit/filefolder_test.rb +8 -0
  56. data/tog_depot.gemspec +81 -0
  57. metadata +155 -0
data/CHANGELOG.md ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008 DMS - Desarrollo de Medios y Sistemas
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,78 @@
1
+ Depot
2
+ ===========
3
+
4
+ File management system for TOG:Community framework.
5
+
6
+ Included functionality
7
+ ----------------------
8
+
9
+ * File management
10
+ * Folder management
11
+ * Filesize and disk cuota configuration
12
+ * Tag system
13
+ * File and folder privacity
14
+ * Abuse report
15
+ * And more...
16
+
17
+ Resources
18
+ =========
19
+
20
+ Plugin requirements
21
+ -------------------
22
+
23
+ In case you haven't got any of them installed previously, you'll need the following plugins on your application:
24
+
25
+ * [acts\_as\_commentable](https://github.com/tog/tog/wikis/3rd-party-plugins-acts_as_commentable)
26
+ * [attachment\_fu](http://github.com/technoweenie/attachment_fu/tree/master)
27
+ * [acts\_as\_taggable\_on\_steroids](https://github.com/tog/tog/wikis/3rd-party-plugins-acts_as_taggable_on_steroids)
28
+ * [acts\_as\_rateable](http://github.com/tog/tog/wikis/3rd-party-plugins-acts_as_rateable)
29
+ * [seo\_urls](http://github.com/tog/tog/wikis/3rd-party-plugins-seo_urls)
30
+
31
+ Follow each link above for a short installation guide incase you have to install them.
32
+
33
+ Install
34
+ -------
35
+
36
+ * Install plugin form source:
37
+ <pre>
38
+ ruby script/plugin install git://github.com/dms/tog_depot.git
39
+ </pre>
40
+
41
+ * Add Depot's routes to your application's config/routes.rb
42
+ <pre>
43
+ map.routes_from_plugin 'tog_depot'
44
+ </pre>
45
+
46
+ * Add plugin static resources to public app:
47
+ <pre>
48
+ rake tog:plugins:copy_resources
49
+ </pre>
50
+
51
+ * Generate installation migration:
52
+ <pre>
53
+ ruby script/generate migration install_tog_depot
54
+ </pre>
55
+
56
+ * With the following content:
57
+ <pre>
58
+ class InstallTogDepot < ActiveRecord::Migration
59
+ def self.up
60
+ migrate_plugin "tog_depot", 2
61
+ end
62
+ def self.down
63
+ migrate_plugin "tog_depot", 0
64
+ end
65
+ end
66
+ </pre>
67
+
68
+ * And finally...
69
+ <pre>rake db:migrate</pre>
70
+
71
+
72
+ More
73
+ -------
74
+ Released under the MIT license
75
+
76
+ [http://dmsti.es](http://dmsti.es)
77
+
78
+ DMS 2008, Desarrollo de Medios y Sistemas.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the tog_depot plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for tog_depot plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Tog Depot'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README', 'MIT-LICENCE', 'CHANGELOG')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,10 @@
1
+ class Depot::FilefoldersController < ApplicationController
2
+
3
+ helper 'depot/files'
4
+
5
+ def show
6
+ @folder = Depot::Filefolder.find params[:id]
7
+ @my_files = Depot::File.paginate(:per_page => 10, :page => params[:page], :order => "created_at DESC", :conditions => ["filefolder_id=? and state=?", params[:id], 'public'])
8
+ end
9
+
10
+ end
@@ -0,0 +1,35 @@
1
+ class Depot::FilesController < ApplicationController
2
+
3
+ helper 'depot/files'
4
+
5
+ def index
6
+ if params[:order]
7
+ @order = params[:order]
8
+ else
9
+ @order = "created_at DESC"
10
+ end
11
+ @files = Depot::File.paginate(:per_page => 10, :page => params[:page], :order => @order, :conditions => ['state = ?', 'public'])
12
+ @folders = Depot::Filefolder.paginate(:page => params[:page], :conditions => ['state = ?', 'public'], :order => @order)
13
+ end
14
+
15
+ def show
16
+
17
+ @file = Depot::File.find params[:id]
18
+ @extension = @file.filename.to_s.scan(/\.\w+$/)
19
+ end
20
+
21
+ def by_tag
22
+ @tag = Tag.find_by_name(params[:tag_name])
23
+ @files = Depot::File.find_tagged_with(@tag, :conditions => ['state=?', "public"]).paginate(:per_page => 10, :page => params[:page]) unless @tag.nil?
24
+ @folders = Depot::Filefolder.find_tagged_with(@tag, :conditions => ['state=?', "public"]) unless @tag.nil?
25
+ end
26
+
27
+ def download
28
+ @file = Depot::File.find params[:id]
29
+ @num = @file.num_download+1
30
+ @file.update_attribute (:num_download, @num)
31
+ send_file("public/" + @file.public_filename)
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,84 @@
1
+ class Member::Depot::FilefoldersController < Member::BaseController
2
+
3
+ def show
4
+ @filefolder = current_user.filefolders.find(params[:id])
5
+ @my_files = current_user.files.paginate(:per_page => 10, :page => params[:page], :order => "created_at DESC", :conditions => ["filefolder_id=?",params[:id]])
6
+ end
7
+
8
+ def new
9
+ end
10
+
11
+ def create
12
+ @filefolder = current_user.filefolders.new(params[:folder])
13
+ @filefolder.user_id = current_user.id
14
+
15
+ @filefolder.state = 'public'
16
+
17
+ respond_to do |wants|
18
+ if @filefolder.save
19
+ wants.html do
20
+ flash[:ok] = "Folder <b>#{@filefolder.title}</b> created successfully"
21
+ redirect_to member_depot_files_path
22
+ end
23
+ else
24
+ wants.html do
25
+ redirect_to member_depot_files_path
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ def edit
33
+ @filefolder = current_user.filefolders.find(params[:id])
34
+ end
35
+
36
+ def update
37
+ @filefolder = current_user.filefolders.find(params[:id])
38
+ @old_state=@filefolder.state
39
+ @new_state = params[:state]
40
+
41
+ @filefolder.state = params[:state]
42
+
43
+ respond_to do |wants|
44
+ if @filefolder.update_attributes(params[:filefolder])
45
+ wants.html do
46
+ if @old_state!=@new_state
47
+ @files = current_user.files.find(:all, :conditions => ["filefolder_id=?",params[:id]])
48
+ @files.each {|c| c.update_attribute 'state', params[:state]}
49
+ flash[:ok] = "Folder <b>#{@filefolder.title}</b> and files into it succcessfully updated!"
50
+ else
51
+ flash[:ok] = "Folder <b>#{@filefolder.title}</b> succcessfully updated!"
52
+ end
53
+ redirect_to member_depot_files_path
54
+ end
55
+ else
56
+ wants.html do
57
+ flash.now[:error] = 'Failed to Update a filefolder.'
58
+ render :action => :edit
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ @folder = current_user.filefolders.find params[:id]
66
+ @my_files = current_user.files.paginate(:page => params[:page], :order => "created_at DESC", :conditions => ["filefolder_id=?",params[:id]])
67
+
68
+ if @my_files.empty?
69
+ @folder.destroy
70
+ respond_to do |wants|
71
+ wants.html do
72
+ flash[:ok]='Folder deleted.'
73
+ redirect_to member_depot_files_path
74
+ end
75
+ end
76
+ else
77
+ flash[:error] = 'This folder cannot be deleted, because there are still any files into it.'
78
+ redirect_to member_depot_filefolder_path
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
@@ -0,0 +1,102 @@
1
+ class Member::Depot::FilesController < Member::BaseController
2
+
3
+ def index
4
+ if params[:order]
5
+ @order = params[:order]
6
+ else
7
+ @order = "created_at DESC"
8
+ end
9
+ @my_files = current_user.files.paginate(:per_page => 10, :page => params[:page], :order => @order)
10
+ @my_folders = current_user.filefolders.paginate(:page => params[:page], :order => @order)
11
+ @tot_size = current_user.files.sum('size').to_i / 1024
12
+ @max_storage = Tog::Plugins.settings(:tog_depot, "file.max_size_storage")
13
+ end
14
+
15
+ def by_tag
16
+ @tag = Tag.find_by_name(params[:tag_name])
17
+ @my_files = current_user.files.find_tagged_with(@tag).paginate(:per_page => 10, :page => params[:page]) unless @tag.nil?
18
+ @my_folders = current_user.filefolders.find_tagged_with(@tag) unless @tag.nil?
19
+ end
20
+
21
+ def show
22
+ @file = current_user.files.find(params[:id])
23
+ @extension = @file.filename.to_s.scan(/\.\w+$/)
24
+ end
25
+
26
+ def new
27
+ @tot_size = current_user.files.sum('size').to_i / 1024
28
+ @max_storage = Tog::Plugins.settings(:tog_depot, "file.max_size_storage")
29
+ if (@max_storage.to_i - @tot_size.to_i)<0
30
+ flash[:error] = 'Your disk quota has been exceeded, please contact your administrator.'
31
+ redirect_to member_depot_files_path
32
+ end
33
+ @folders = current_user.filefolders.paginate(:page => params[:page], :order => "created_at DESC")
34
+ end
35
+
36
+ def create
37
+ @file = current_user.files.new(params[:file])
38
+ @file.user_id = current_user.id
39
+ @file.num_download=0
40
+
41
+ respond_to do |wants|
42
+ if @file.save
43
+ @file.send("#{params[:state].to_s}!")
44
+ wants.html do
45
+ flash[:ok] = 'New file Update.'
46
+ redirect_to member_depot_files_path
47
+ end
48
+ else
49
+ wants.html do
50
+ flash.now[:error] = 'Failed to Update a new file.'
51
+ render :action => :new
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def tags
58
+ end
59
+
60
+ def edit
61
+ @file = current_user.files.find(params[:id])
62
+ @folders = current_user.filefolders.paginate(:page => params[:page], :order => "created_at DESC")
63
+ end
64
+
65
+ def update
66
+ @file = current_user.files.find(params[:id])
67
+ respond_to do |wants|
68
+ if @file.update_attributes(params[:file])
69
+ @file.send("#{params[:state].to_s}!")
70
+ wants.html do
71
+ flash[:ok] = "File <b>#{@file.title}</b> succcessfully updated!"
72
+ redirect_to member_depot_files_path
73
+ end
74
+ else
75
+ wants.html do
76
+ flash.now[:error] = 'Failed to Update a new file.'
77
+ render :action => :edit
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ def download
84
+ @file = current_user.files.find params[:id]
85
+ @num = @file.num_download+1
86
+ @file.update_attribute (:num_download, @num)
87
+ send_file("public/" + @file.public_filename)
88
+ end
89
+
90
+ def destroy
91
+ @file = current_user.files.find params[:id]
92
+ @file.destroy
93
+ respond_to do |wants|
94
+ wants.html do
95
+ flash[:ok]='File deleted.'
96
+ redirect_to member_depot_files_path
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,18 @@
1
+ module Depot
2
+ module FilesHelper
3
+
4
+ def tag_cloud_files(classes)
5
+ tags1 = Depot::File.tag_counts(:conditions => ["files.state='public'"])
6
+ tags2 = Depot::Filefolder.tag_counts(:conditions => ["state='public'"])
7
+ tags= tags1 + tags2
8
+ return if tags.empty?
9
+ max_count = tags.sort_by(&:count).last.count.to_f
10
+ tags.each do |tag|
11
+ index = ((tag.count / max_count) * (classes.size - 1)).round
12
+ yield tag, classes[index]
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ class Depot::File < ActiveRecord::Base
2
+
3
+ # set_table_name :files
4
+
5
+ acts_as_commentable
6
+ acts_as_taggable
7
+ # acts_as_list :scope => :filefolder
8
+ seo_urls
9
+
10
+ belongs_to :user, :class_name => "User", :foreign_key => "user_id"
11
+ belongs_to :filefolder, :class_name => "Depot::Filefolder", :foreign_key => "filefolder_id"
12
+
13
+ has_attachment :storage => :file_system,
14
+ :max_size => Tog::Plugins.settings(:tog_depot, "file.max_size_file").to_i.kilobytes,
15
+ :path_prefix=>'public/system/files'
16
+ validates_as_attachment
17
+
18
+ attr_accessible :title, :description, :filefolder_id, :tag_list, :publiC
19
+
20
+ validates_presence_of :title
21
+
22
+ acts_as_state_machine :initial => :private
23
+
24
+ state :private
25
+ state :public
26
+
27
+ event :public do
28
+ transitions :from => [:private] , :to => :public
29
+ end
30
+
31
+ event :private do
32
+ transitions :from => [:public] , :to => :private
33
+ end
34
+
35
+
36
+ def owner
37
+ user
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,21 @@
1
+ class Depot::Filefolder < ActiveRecord::Base
2
+ acts_as_taggable
3
+ set_table_name :files_folder
4
+ belongs_to :user, :class_name => "User", :foreign_key => "user_id"
5
+ has_many :files
6
+ validates_presence_of :title
7
+
8
+ acts_as_state_machine :initial => :public, :column => 'state'
9
+
10
+ state :private
11
+ state :public
12
+
13
+ event :public do
14
+ transitions :from => [:private] , :to => :public
15
+ end
16
+
17
+ event :private do
18
+ transitions :from => [:public] , :to => :private
19
+ end
20
+
21
+ end