@@ -1,56 +1,56 | |||
|
1 |
# Red |
|
|
1 | # Redmine - project management software | |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Document < ActiveRecord::Base |
|
19 | 19 | include Redmine::SafeAttributes |
|
20 | 20 | belongs_to :project |
|
21 | 21 | belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" |
|
22 | 22 | acts_as_attachable :delete_permission => :manage_documents |
|
23 | 23 | |
|
24 | 24 | acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project |
|
25 | 25 | acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"}, |
|
26 | 26 | :author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil }, |
|
27 | 27 | :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}} |
|
28 | 28 | acts_as_activity_provider :find_options => {:include => :project} |
|
29 | 29 | |
|
30 | 30 | validates_presence_of :project, :title, :category |
|
31 | 31 | validates_length_of :title, :maximum => 60 |
|
32 | 32 | |
|
33 | 33 | scope :visible, lambda {|*args| { :include => :project, |
|
34 | 34 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } } |
|
35 | 35 | |
|
36 | 36 | safe_attributes 'category_id', 'title', 'description' |
|
37 | 37 | |
|
38 | 38 | def visible?(user=User.current) |
|
39 | 39 | !user.nil? && user.allowed_to?(:view_documents, project) |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def initialize(attributes=nil, *args) |
|
43 | 43 | super |
|
44 | 44 | if new_record? |
|
45 | 45 | self.category ||= DocumentCategory.default |
|
46 | 46 | end |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def updated_on |
|
50 | 50 | unless @updated_on |
|
51 | 51 | a = attachments.last |
|
52 | 52 | @updated_on = (a && a.created_on) || created_on |
|
53 | 53 | end |
|
54 | 54 | @updated_on |
|
55 | 55 | end |
|
56 | 56 | end |
@@ -1,118 +1,118 | |||
|
1 |
# Red |
|
|
1 | # Redmine - project management software | |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # FileSystem adapter |
|
5 | 5 | # File written by Paul Rivier, at Demotera. |
|
6 | 6 | # |
|
7 | 7 | # This program is free software; you can redistribute it and/or |
|
8 | 8 | # modify it under the terms of the GNU General Public License |
|
9 | 9 | # as published by the Free Software Foundation; either version 2 |
|
10 | 10 | # of the License, or (at your option) any later version. |
|
11 | 11 | # |
|
12 | 12 | # This program is distributed in the hope that it will be useful, |
|
13 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 | 15 | # GNU General Public License for more details. |
|
16 | 16 | # |
|
17 | 17 | # You should have received a copy of the GNU General Public License |
|
18 | 18 | # along with this program; if not, write to the Free Software |
|
19 | 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 20 | |
|
21 | 21 | require 'redmine/scm/adapters/abstract_adapter' |
|
22 | 22 | require 'find' |
|
23 | 23 | |
|
24 | 24 | module Redmine |
|
25 | 25 | module Scm |
|
26 | 26 | module Adapters |
|
27 | 27 | class FilesystemAdapter < AbstractAdapter |
|
28 | 28 | |
|
29 | 29 | class << self |
|
30 | 30 | def client_available |
|
31 | 31 | true |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def initialize(url, root_url=nil, login=nil, password=nil, |
|
36 | 36 | path_encoding=nil) |
|
37 | 37 | @url = with_trailling_slash(url) |
|
38 | 38 | @path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def path_encoding |
|
42 | 42 | @path_encoding |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def format_path_ends(path, leading=true, trailling=true) |
|
46 | 46 | path = leading ? with_leading_slash(path) : |
|
47 | 47 | without_leading_slash(path) |
|
48 | 48 | trailling ? with_trailling_slash(path) : |
|
49 | 49 | without_trailling_slash(path) |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def info |
|
53 | 53 | info = Info.new({:root_url => target(), |
|
54 | 54 | :lastrev => nil |
|
55 | 55 | }) |
|
56 | 56 | info |
|
57 | 57 | rescue CommandFailed |
|
58 | 58 | return nil |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def entries(path="", identifier=nil, options={}) |
|
62 | 62 | entries = Entries.new |
|
63 | 63 | trgt_utf8 = target(path) |
|
64 | 64 | trgt = scm_iconv(@path_encoding, 'UTF-8', trgt_utf8) |
|
65 | 65 | Dir.new(trgt).each do |e1| |
|
66 | 66 | e_utf8 = scm_iconv('UTF-8', @path_encoding, e1) |
|
67 | 67 | next if e_utf8.blank? |
|
68 | 68 | relative_path_utf8 = format_path_ends( |
|
69 | 69 | (format_path_ends(path,false,true) + e_utf8),false,false) |
|
70 | 70 | t1_utf8 = target(relative_path_utf8) |
|
71 | 71 | t1 = scm_iconv(@path_encoding, 'UTF-8', t1_utf8) |
|
72 | 72 | relative_path = scm_iconv(@path_encoding, 'UTF-8', relative_path_utf8) |
|
73 | 73 | e1 = scm_iconv(@path_encoding, 'UTF-8', e_utf8) |
|
74 | 74 | if File.exist?(t1) and # paranoid test |
|
75 | 75 | %w{file directory}.include?(File.ftype(t1)) and # avoid special types |
|
76 | 76 | not File.basename(e1).match(/^\.+$/) # avoid . and .. |
|
77 | 77 | p1 = File.readable?(t1) ? relative_path : "" |
|
78 | 78 | utf_8_path = scm_iconv('UTF-8', @path_encoding, p1) |
|
79 | 79 | entries << |
|
80 | 80 | Entry.new({ :name => scm_iconv('UTF-8', @path_encoding, File.basename(e1)), |
|
81 | 81 | # below : list unreadable files, but dont link them. |
|
82 | 82 | :path => utf_8_path, |
|
83 | 83 | :kind => (File.directory?(t1) ? 'dir' : 'file'), |
|
84 | 84 | :size => (File.directory?(t1) ? nil : [File.size(t1)].pack('l').unpack('L').first), |
|
85 | 85 | :lastrev => |
|
86 | 86 | Revision.new({:time => (File.mtime(t1)) }) |
|
87 | 87 | }) |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | entries.sort_by_name |
|
91 | 91 | rescue => err |
|
92 | 92 | logger.error "scm: filesystem: error: #{err.message}" |
|
93 | 93 | raise CommandFailed.new(err.message) |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def cat(path, identifier=nil) |
|
97 | 97 | p = scm_iconv(@path_encoding, 'UTF-8', target(path)) |
|
98 | 98 | File.new(p, "rb").read |
|
99 | 99 | rescue => err |
|
100 | 100 | logger.error "scm: filesystem: error: #{err.message}" |
|
101 | 101 | raise CommandFailed.new(err.message) |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | private |
|
105 | 105 | |
|
106 | 106 | # AbstractAdapter::target is implicitly made to quote paths. |
|
107 | 107 | # Here we do not shell-out, so we do not want quotes. |
|
108 | 108 | def target(path=nil) |
|
109 | 109 | # Prevent the use of .. |
|
110 | 110 | if path and !path.match(/(^|\/)\.\.(\/|$)/) |
|
111 | 111 | return "#{self.url}#{without_leading_slash(path)}" |
|
112 | 112 | end |
|
113 | 113 | return self.url |
|
114 | 114 | end |
|
115 | 115 | end |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | end |
General Comments 0
You need to be logged in to leave comments.
Login now