gollum_rails 1.5.13 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDJiNDIyYWE3Y2MyODMxOTk0NmFkNGFjMzBiYzc0NWI5NDlmNzg2OQ==
4
+ OTc1MGI5YjRhZjVlNTNlNmYzYzM4MThkMTY3NGUyMThiMzdiY2FjNw==
5
5
  data.tar.gz: !binary |-
6
- YWM3YmM3M2VmNTk0YWQ2MTA5ZTRjNWU0ZjJkMjQ5NTYyOTg2ZmVlYg==
6
+ ODZkZDc5MTQwNDY5ODk1MjI2ZDk5MDFhYjQ0MjY1ZWEzZDRhZjMyNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGRmNmViZDg3M2JjYjBjMTMzMDM2MmMzYjFiNmM1NDYwNmJlNjMyNTA5ODNi
10
- ZDEzN2VlMWEyYzVlMGE0NTA3OTEyYmQ3NzNjYjIzNDlhNjgzNmU2NjZjNWM0
11
- OWQwY2QwMmMxNjFlN2VlNjIzZjg4NTA0Y2YyNTIwNTMxNTYyYWI=
9
+ ZDMxNDllZDRkMWQ5ZmIzOWNjYmI0MDNkMTJhY2MxODQ1ZDg3NzY2MDFjYTg1
10
+ MDViNDE3MTkyMzMzMTQyYmExNDRmMzVlMGY5MmEzN2YzNWZmNGI2MTVjM2Qx
11
+ NTM2ZTc5NzJlNGRiNmQ2OGRiYzdmZTQ0Y2U1NzVhMzRiOWJiNzE=
12
12
  data.tar.gz: !binary |-
13
- YzAyMTUxZDZmMGQxMmI3YjI4NzExZGE1MjBkMjliNjczZjQzYjk0YzIzMjA2
14
- OTYyMmQ3NTE5ODdlYTkwZjlkZGMwYzdjYjMwZGNlYzc0MjNhMjVmOTc2ZWIz
15
- NWFmZDU3NDZiMDdlODM2NmVjZjcwMjBiODExMmUyODNmNDE3NDU=
13
+ MmY0ZmJkZjk3NWM5MjNlZDNlYTM0YTBkYTMzMjk5MmUzMzJiMTM1MjJjMzBj
14
+ ODU2OTYzOTdiMmRkZDllZWE4MzYzZjA4MWNjNTBhNjUyNGNmNWMyOWI3Njc1
15
+ Nzc0ODk5ZDE2MTQyNjI2ODhhZDk0YzIyNzFjMDZmOTViMmJmOWI=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gollum_rails (1.5.13)
4
+ gollum_rails (1.6.0)
5
5
  activemodel (>= 3.2.11)
6
6
  activesupport (>= 3.2.11)
7
7
  gollum-lib (~> 3.0.0)
@@ -56,7 +56,7 @@ GEM
56
56
  formatador (0.2.5)
57
57
  github-markup (1.1.2)
58
58
  posix-spawn (~> 0.3.8)
59
- gitlab-grit (2.6.9)
59
+ gitlab-grit (2.6.10)
60
60
  charlock_holmes (~> 0.6)
61
61
  diff-lcs (~> 1.1)
62
62
  mime-types (~> 1.15)
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = 'gollum_rails'
5
5
  s.rubyforge_project = s.name
6
6
 
7
- s.version = '1.5.13'
7
+ s.version = '1.6.0'
8
8
 
9
9
  s.summary = 'Combines Gollum and Rails'
10
10
  s.description= 'include Gollum into Rails with ease'
@@ -59,9 +59,12 @@ Gem::Specification.new do |s|
59
59
  lib/gollum_rails/setup/options.rb
60
60
  lib/gollum_rails/store.rb
61
61
  lib/gollum_rails/upload.rb
62
+ lib/gollum_rails/upload/blacklisted_filetype_error.rb
62
63
  lib/gollum_rails/upload/class_definitions.rb
63
64
  lib/gollum_rails/upload/file_too_big_error.rb
64
65
  lib/gollum_rails/validation.rb
66
+ spec/GLD-LOTR-2T.jpg
67
+ spec/GLD-LOTR-2T.png
65
68
  spec/factories.rb
66
69
  spec/gollum_rails/page_core_spec.rb
67
70
  spec/gollum_rails/page_spec.rb
@@ -75,7 +78,6 @@ Gem::Specification.new do |s|
75
78
  spec/support/gollum_page_spec.rb
76
79
  spec/support/sample_upload.rb
77
80
  spec/support/special_commit.rb
78
- uploads/GLD-LOTR-2T.jpg
79
81
  ]
80
82
  # = MANIFEST =
81
83
 
@@ -45,7 +45,7 @@ module GollumRails
45
45
  autoload :Meta
46
46
 
47
47
  # GollumRails version
48
- VERSION = '1.5.13'
48
+ VERSION = '1.6.0'
49
49
 
50
50
  end
51
51
 
@@ -11,6 +11,7 @@ module GollumRails
11
11
 
12
12
  autoload :ClassDefinitions, 'gollum_rails/upload/class_definitions'
13
13
  autoload :FileTooBigError, 'gollum_rails/upload/file_too_big_error'
14
+ autoload :BlacklistedFiletypeError, 'gollum_rails/upload/blacklisted_filetype_error'
14
15
 
15
16
  include Attributes
16
17
  include Store
@@ -69,9 +70,7 @@ module GollumRails
69
70
  def destroy(commit=nil)
70
71
  return false if !persisted?
71
72
  committer = Gollum::Committer.new(self.class.wiki, commit||self.commit)
72
-
73
73
  committer.delete(self.gollum_file.path)
74
-
75
74
  committer.after_commit do |index, sha|
76
75
  path = self.gollum_file.path
77
76
  dir = ::File.dirname(path)
@@ -80,11 +79,9 @@ module GollumRails
80
79
  ext = ::File.extname(fullname)
81
80
  format = ext.split('.').last || "txt"
82
81
  filename = ::File.basename(fullname, ext)
83
-
84
82
  self.class.wiki.clear_cache
85
83
  index.update_working_dir(dir, filename, format)
86
84
  end
87
-
88
85
  sha = committer.commit
89
86
  _update_gollum_file(nil)
90
87
  sha
@@ -109,6 +106,16 @@ module GollumRails
109
106
  raise FileTooBigError,
110
107
  "File is too big. Max. size is #{self.class.max_size}" if tempfile.size > self.class.max_size
111
108
  end
109
+ ext = ::File.extname(tempfile.original_filename)
110
+ type = (ext.split('.').last || "txt").to_sym
111
+ if self.class.whitelist
112
+ raise BlacklistedFiletypeError,
113
+ "Filetype #{type} is blacklisted." unless self.class.whitelist.include?(type)
114
+ end
115
+ if self.class.blacklist
116
+ raise BlacklistedFiletypeError,
117
+ "Filetype #{type} is blacklisted." if self.class.blacklist.include?(type)
118
+ end
112
119
  end
113
120
 
114
121
  def _find_gollum_file(path)
@@ -0,0 +1,6 @@
1
+ module GollumRails
2
+ class Upload
3
+ class BlacklistedFiletypeError < StandardError
4
+ end
5
+ end
6
+ end
@@ -7,6 +7,16 @@ module GollumRails
7
7
  module ClassMethods
8
8
  attr_accessor :destination
9
9
  attr_accessor :overwrite
10
+ attr_accessor :blacklist
11
+ attr_accessor :whitelist
12
+ def blacklist_format(*formats)
13
+ self.blacklist ||= []
14
+ self.blacklist += Array(formats)
15
+ end
16
+ def whitelist_format(*formats)
17
+ self.whitelist ||= []
18
+ self.whitelist += Array(formats)
19
+ end
10
20
  def max_filesize(size)
11
21
  @max_size=size if size
12
22
  end
File without changes
Binary file
@@ -24,17 +24,31 @@ FactoryGirl.define do
24
24
  initialize_with { attributes }
25
25
  end
26
26
 
27
- factory :restrictions_upload, class: SampleClassDefinitions, traits: [:initialize] do
28
- file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
29
- destination 'uploads'
27
+ trait :default_upload do
30
28
  initialize_with { new(attributes) }
31
29
  commit { build(:commit_fakes) }
30
+ destination 'uploads'
31
+ end
32
+ factory :blacklist_upload, class: SampleUploadBlacklistPng, traits: [:initialize, :default_upload] do
33
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.png', __FILE__), "image/png")
32
34
  end
33
- factory :upload, class: GollumRails::Upload, traits: [:initialize] do
35
+ factory :multi_blacklist_upload, class: MultiUploadBlacklistPng, traits: [:initialize, :default_upload] do
36
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.png', __FILE__), "image/png")
37
+ end
38
+ factory :not_blacklist_upload, class: SampleUploadBlacklistPng, traits: [:initialize, :default_upload] do
39
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
40
+ end
41
+ factory :not_whitelist_upload, class: SampleUploadWhitelistPng, traits: [:initialize, :default_upload] do
42
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.png', __FILE__), "image/png")
43
+ end
44
+ factory :whitelist_upload, class: SampleUploadWhitelistPng, traits: [:initialize, :default_upload] do
45
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
46
+ end
47
+ factory :restrictions_upload, class: SampleClassDefinitions, traits: [:initialize, :default_upload] do
48
+ file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
49
+ end
50
+ factory :upload, class: GollumRails::Upload, traits: [:initialize, :default_upload] do
34
51
  file Rack::Test::UploadedFile.new(File.expand_path('../GLD-LOTR-2T.jpg', __FILE__), "image/jpeg")
35
- destination 'uploads'
36
- initialize_with { new(attributes) }
37
- commit { build(:commit_fakes) }
38
52
  end
39
53
  #factory :commit_fakes, class: DefaultCommit do
40
54
  #end
@@ -14,6 +14,12 @@ describe GollumRails::Upload::ClassDefinitions do
14
14
  it "overwrites existing files" do
15
15
  expect(SampleClassDefinitions.overwrite) == true
16
16
  end
17
+ it "blacklists formats" do
18
+ expect(SampleUploadBlacklistPng.blacklist).to include :png
19
+ end
20
+ it "whitelists formats" do
21
+ expect(SampleUploadWhitelistPng.whitelist).to include :png
22
+ end
17
23
  describe "validation" do
18
24
  let(:ins){build(:restrictions_upload)}
19
25
  let(:ins2){build(:upload)}
@@ -25,5 +31,54 @@ describe GollumRails::Upload::ClassDefinitions do
25
31
  end
26
32
  end
27
33
 
34
+ describe "allowed formats to upload" do
35
+ let(:ins2){build(:upload)}
36
+ let(:ins){build(:blacklist_upload)}
37
+ let(:not_blacklisted){build(:not_blacklist_upload)}
38
+ let(:multi){build(:multi_blacklist_upload)}
39
+ after(:each) do
40
+ ins2.save
41
+ ins2.destroy
42
+ end
43
+ it "accepts arrays" do
44
+ begin
45
+ expect{multi.save!}.to raise_error GollumRails::Upload::BlacklistedFiletypeError
46
+ ensure
47
+ multi.destroy
48
+ end
49
+ end
50
+ it "does not allow to upload blacklisted formats" do
51
+ begin
52
+ expect{ins.save!}.to raise_error GollumRails::Upload::BlacklistedFiletypeError
53
+ ensure
54
+ ins.destroy
55
+ end
56
+ end
57
+ it "does allow to upload non-blacklisted formats" do
58
+ begin
59
+ expect{not_blacklisted.save!}.not_to raise_error
60
+ ensure
61
+ not_blacklisted.destroy
62
+ end
63
+ end
64
+ end
65
+ describe "whitelist" do
66
+ let(:ins){build(:whitelist_upload)}
67
+ let(:whitelisted){build(:not_whitelist_upload)}
68
+ it "does not allow to upload non-whitelisted formats" do
69
+ begin
70
+ expect{ins.save!}.to raise_error GollumRails::Upload::BlacklistedFiletypeError
71
+ ensure
72
+ ins.destroy
73
+ end
74
+ end
75
+ it "does allow to upload whitelisted formats" do
76
+ begin
77
+ expect{whitelisted.save!}.not_to raise_error
78
+ ensure
79
+ whitelisted.destroy
80
+ end
81
+ end
82
+ end
28
83
 
29
84
  end
@@ -19,4 +19,8 @@ RSpec.configure do |config|
19
19
  config.before(:suite) do
20
20
  FactoryGirl.lint
21
21
  end
22
+ config.before(:all) do
23
+ folder = File.expand_path('../utils/wiki.git',__FILE__)
24
+ `test -d #{folder} || git init --bare #{folder}`
25
+ end
22
26
  end
@@ -3,3 +3,15 @@ class SampleClassDefinitions < GollumRails::Upload
3
3
  upload_directory 'uploads'
4
4
  overwrite_existing_files true
5
5
  end
6
+
7
+ class SampleUploadBlacklistPng < GollumRails::Upload
8
+ blacklist_format :png
9
+ end
10
+
11
+ class MultiUploadBlacklistPng < GollumRails::Upload
12
+ blacklist_format :png, :tar, :gz
13
+ end
14
+
15
+ class SampleUploadWhitelistPng < GollumRails::Upload
16
+ whitelist_format :png
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.13
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
@@ -198,9 +198,12 @@ files:
198
198
  - lib/gollum_rails/setup/options.rb
199
199
  - lib/gollum_rails/store.rb
200
200
  - lib/gollum_rails/upload.rb
201
+ - lib/gollum_rails/upload/blacklisted_filetype_error.rb
201
202
  - lib/gollum_rails/upload/class_definitions.rb
202
203
  - lib/gollum_rails/upload/file_too_big_error.rb
203
204
  - lib/gollum_rails/validation.rb
205
+ - spec/GLD-LOTR-2T.jpg
206
+ - spec/GLD-LOTR-2T.png
204
207
  - spec/factories.rb
205
208
  - spec/gollum_rails/page_core_spec.rb
206
209
  - spec/gollum_rails/page_spec.rb
@@ -214,7 +217,6 @@ files:
214
217
  - spec/support/gollum_page_spec.rb
215
218
  - spec/support/sample_upload.rb
216
219
  - spec/support/special_commit.rb
217
- - uploads/GLD-LOTR-2T.jpg
218
220
  homepage: https://github.com/nirnanaaa/gollum_rails
219
221
  licenses:
220
222
  - AGPL