repository-manager 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbf60a439b0b337f819cdc38e21b42351783a93f
4
- data.tar.gz: e366f2254bbb226188a71f07f0457139aac5641a
3
+ metadata.gz: cf4767c19280879648bb81c83442854d471c7b8d
4
+ data.tar.gz: aa71d60c28c24053af0e19153b270f73554fc3f8
5
5
  SHA512:
6
- metadata.gz: 46e363948f796a7f6830bf0a13d38e54a525a0484d3f3036597d14f55ac9f2dbc1923b28677364707d9e43298a857eb13da88fb6809b5661218f825c178b3190
7
- data.tar.gz: 81cf606e9e4a4624fd484da3838396fb166a0af557db84575bb805747e2e33ecc84ae8f59b4b4e58d40ff767bf5eef49cc11277746aa825ead2a5f382a8bbbe5
6
+ metadata.gz: 665c150b8f12c7130c7027de8a590438e502465ea3b900872349a8cf89f66113062abecf8c0fc84043a82f6a0eeec5c8caaf7825d1b61818d29d435c73105ebb
7
+ data.tar.gz: fe0025b6ab497be34fca378e0bc62ad7b653b6b5ebc05781c2b441566048128e91f143a624c6e1d6efd0c208612d306bb44d89486bdf3580446ccc5e1985e2d9
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharing).
2
2
 
3
- # Repository Manager [![Gem Version](https://badge.fury.io/rb/repository-manager.png)](http://badge.fury.io/rb/repository-manager)
3
+ # Repository Manager [![Gem Version](https://badge.fury.io/rb/repository-manager.svg)](http://badge.fury.io/rb/repository-manager)
4
4
 
5
5
  This gem add functionalities to manage files and folders (repositories). Each instance (users, groups, etc..) has it own repository (with files and folders). It can manage them (create, edit, remove, copy, move, etc) and share them with other objects.
6
6
 
@@ -58,6 +58,9 @@ RepositoryManager.setup do |config|
58
58
 
59
59
  # Define if we enable or not the versioning on the repo_item
60
60
  config.has_paper_trail = false
61
+
62
+ # Define if a repo item with the same name will be automaticaly overwrited when a new item is created, moved or copied
63
+ config.auto_overwrite_item = false
61
64
  end
62
65
  ```
63
66
 
@@ -72,11 +75,13 @@ end
72
75
  ```
73
76
 
74
77
  NOTE : If you want to add paper_trail to the repo_item model. You first have to install PaperTrail in you project.
75
- More informations on the [documentation of the PaperTrail gem](https://github.com/airblade/paper_trail)
76
-
78
+ More informations on the [documentation of the PaperTrail gem](https://github.com/airblade/paper_trail).
77
79
 
78
80
  See the chapter [Permissions](#permissions) for more details about the permissions.
79
81
 
82
+ See the chapter [Overwrite](#overwrite) for more details about the overwrite.
83
+
84
+
80
85
  ## Preparing your models
81
86
 
82
87
  You can choose witch model can have repository.
@@ -157,14 +162,14 @@ user1.create_file(repo_file, source_folder: the_new_folder)
157
162
  # | |-- 'The new folder'
158
163
  # | | |-- 'file.txt'
159
164
 
160
- # user1 want to create a file on the root of his repository
161
- file2 = user1.create_file(params[:file2])
165
+ # user1 want to create a file with a specific name on the root of his repository
166
+ file2 = user1.create_file(params[:file2], filename: 'specific_name.jpg')
162
167
 
163
168
  # user1 own repository :
164
169
  # |-- 'Root folder'
165
170
  # | |-- 'The new folder'
166
171
  # | | |-- 'file.txt'
167
- # |-- 'file2.jpg'
172
+ # |-- 'specific_name.jpg'
168
173
 
169
174
  # user1 want to create a folder on the root of his repository
170
175
  test_folder = user1.create_folder('Test folder')
@@ -173,7 +178,7 @@ test_folder = user1.create_folder('Test folder')
173
178
  # |-- 'Root folder'
174
179
  # | |-- 'The new folder'
175
180
  # | | |-- 'file.txt'
176
- # |-- 'file2.jpg'
181
+ # |-- 'specific_name.jpg'
177
182
  # |-- 'Test folder'
178
183
 
179
184
  # user1 want to move 'The new folder' in 'Test folder'
@@ -181,7 +186,7 @@ user1.move_repo_item(the_new_folder, source_folder: test_folder)
181
186
 
182
187
  # user1 own repository :
183
188
  # |-- 'Root folder'
184
- # |-- 'file2.jpg'
189
+ # |-- 'specific_name.jpg'
185
190
  # |-- 'Test folder'
186
191
  # | |-- 'The new folder'
187
192
  # | | |-- 'file.txt'
@@ -191,7 +196,7 @@ user1.rename_repo_item(the_new_folder, 'The renamed folder')
191
196
 
192
197
  # user1 own repository :
193
198
  # |-- 'Root folder'
194
- # |-- 'file2.jpg'
199
+ # |-- 'specific_name.jpg'
195
200
  # |-- 'Test folder'
196
201
  # | |-- 'The renamed folder'
197
202
  # | | |-- 'file.txt'
@@ -201,7 +206,7 @@ user1.copy_repo_item(source_folder, source_folder: test_folder)
201
206
 
202
207
  # user1 own repository :
203
208
  # |-- 'Root folder'
204
- # |-- 'file2.jpg'
209
+ # |-- 'specific_name.jpg'
205
210
  # |-- 'Test folder'
206
211
  # | |-- 'Root folder'
207
212
  # | |-- 'The renamed folder'
@@ -213,7 +218,7 @@ user1.delete_repo_item(test_folder)
213
218
 
214
219
  # user1 own repository :
215
220
  # |-- 'Root folder'
216
- # |-- 'file2.jpg'
221
+ # |-- 'specific_name.jpg'
217
222
 
218
223
  user1.delete_repo_item(file2)
219
224
 
@@ -222,6 +227,8 @@ user1.delete_repo_item(file2)
222
227
 
223
228
  ```
224
229
 
230
+ #### Owner and Sender
231
+
225
232
  If a user (sender of the item) send a file or folder into a group (owner of this item), you can specify the owner and the sender like this :
226
233
 
227
234
  ```ruby
@@ -243,6 +250,23 @@ file.sender # Returns user1
243
250
 
244
251
  WARNING : There is no verification if the user1 has the permission to create a file or folder into this group. You have to check this in your controller ! The fact that user1 is the sender of this folder gives him NO PERMISSION on it !
245
252
 
253
+ #### Overwrite
254
+
255
+ You can overwrite a file or a folder. You juste have to pass the `overwrite: true` option in method : `create_file`, `create_folder`, `copy_repo_item`, `move_repo_item`. See those examples below :
256
+
257
+ ```ruby
258
+ # @user want to create a new file in a `specific_folder`, and overwrite the existing one if it exist
259
+ @user.create_file(the_new_file, source_folder: specific_folder, overwrite: true)
260
+
261
+ # @user want to create a new folder, and overwrite the existing one if it exist
262
+ @user.create_folder("Folder Name", overwrite: true)
263
+
264
+ # This options can be passed to the `copy_repo_item` and the `move_repo_item` methods.
265
+
266
+ ```
267
+
268
+ NOTE : If you overwrite a folder, the old folder will be destroyed ! If you overwrite a file, the existing file will be updated with the new file (better for versionning).
269
+
246
270
  ### How can I share a repo_item (file/folder)
247
271
 
248
272
  Now, user1 want to share his folder 'The new folder' with a Group object `group1` and another User object `user2`. You can use the `has_repository` method `share_repo_item(repo_item, member, options = nil)`.
@@ -76,6 +76,90 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem
76
76
  end
77
77
  end
78
78
 
79
+ # Unzip the compressed file and create the repo_items
80
+ # options
81
+ # :source_folder = the folder in witch you unzip this archive
82
+ # :owner = the owner of the item
83
+ # :sender = the sender of the item (if you don't specify sender.. The sender is still the same)
84
+ # :overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
85
+ def unzip!(options = {})
86
+ !!options[:overwrite] == options[:overwrite] ? overwrite = options[:overwrite] : overwrite = RepositoryManager.auto_overwrite_item
87
+ options[:owner] ? owner = options[:owner] : owner = self.owner
88
+ options[:sender] ? sender = options[:sender] : sender = self.sender
89
+
90
+ Zip::File.open(self.file.path) do |zip_file|
91
+ # This hash make the link between the path and the item (if it exist)
92
+ #link_path_item = {}
93
+
94
+ # Handle entries one by one
95
+ zip_file.each do |entry|
96
+ array_name = entry.name.split('/')
97
+ name = array_name[-1]
98
+ path_array = array_name.first(array_name.size - 1)
99
+ #name.parameterize.underscore
100
+
101
+ #it is a folder
102
+ if entry.ftype == :directory
103
+
104
+ new_item = RepositoryManager::RepoFolder.new(name: name)
105
+ new_item.owner = owner
106
+ new_item.sender = sender
107
+ if path_array.empty?
108
+ new_item.move!(source_folder: options[:source_folder], owner: owner, overwrite: overwrite)
109
+ else
110
+ # He specified a source_folder
111
+ if options[:source_folder]
112
+ source_folder = options[:source_folder].get_or_create_by_path_array(path_array, owner: options[:owner], sender: options[:sender])
113
+ else # No source folder specified
114
+ # We have to check if we are in a folder
115
+ if parent = self.parent
116
+ # we unzip on this folder
117
+ source_folder = parent.get_or_create_by_path_array(path_array, owner: options[:owner], sender: options[:sender])
118
+ else
119
+ # We are in root
120
+ source_folder = owner.get_or_create_by_path_array(path_array, sender: options[:sender])
121
+ end
122
+ end
123
+ new_item.move!(source_folder: source_folder, owner: owner, overwrite: overwrite)
124
+ end
125
+ else # it is a :file
126
+ new_item = RepositoryManager::RepoFile.new
127
+ new_item.name = name
128
+ new_item.sender = sender
129
+ new_item.owner = owner
130
+
131
+ tmp_file_path = "#{Rails.root}/tmp/unzip/#{name}"
132
+ # Delete the path
133
+ FileUtils.rm_rf(tmp_file_path)
134
+ entry.extract(tmp_file_path)
135
+ new_item.file = File.open(tmp_file_path)
136
+
137
+
138
+ if path_array.empty?
139
+ new_item.move!(source_folder: options[:source_folder], owner: owner, overwrite: overwrite)
140
+ else
141
+ # He specified a source_folder
142
+ if options[:source_folder]
143
+ source_folder = options[:source_folder].get_or_create_by_path_array(path_array, owner: options[:owner], sender: options[:sender])
144
+ else # No source folder specified
145
+ # We have to check if we are in a folder
146
+ if parent = self.parent
147
+ # we unzip on this folder
148
+ source_folder = parent.get_or_create_by_path_array(path_array, owner: options[:owner], sender: options[:sender])
149
+ else
150
+ # We are in root
151
+ source_folder = owner.get_or_create_by_path_array(path_array, sender: options[:sender])
152
+ end
153
+ end
154
+ new_item.move!(source_folder: source_folder, owner: owner, overwrite: overwrite)
155
+ end
156
+ end
157
+ end
158
+
159
+ end
160
+ self
161
+ end
162
+
79
163
  private
80
164
 
81
165
  def update_asset_attributes
@@ -4,6 +4,28 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem
4
4
 
5
5
  validates :name, presence: true
6
6
 
7
+ # Get or create the folder with this name
8
+ # options
9
+ # :owner = you can path an owner (you have to if you have no :source_folder)
10
+ # :sender = the sender of the item
11
+ def get_or_create_by_path_array(path_array, options = {})
12
+ children = self
13
+ unless path_array.empty?
14
+ name = path_array[0]
15
+ children = self.get_children_by_name(name)
16
+ unless children
17
+ children = RepositoryManager::RepoFolder.new(name: name)
18
+ children.owner = options[:owner]
19
+ children.sender = options[:sender]
20
+ children.save!
21
+ end
22
+ # remove the first element
23
+ path_array.shift
24
+ children = children.get_or_create_by_path_array(path_array, options)
25
+ end
26
+ children
27
+ end
28
+
7
29
  # Add a repo_item in the folder.
8
30
  # options
9
31
  # :destroy_if_fail = false // the repo_item if it can't move it.
@@ -12,29 +34,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem
12
34
  # second param destroy the repo_item if it can't move it.
13
35
  def add!(repo_item, options = {})
14
36
  !!options[:overwrite] == options[:overwrite] ? overwrite = options[:overwrite] : overwrite = RepositoryManager.auto_overwrite_item
15
-
16
- # We check if this name already exist
17
- repo_item_with_same_name = get_children_by_name(repo_item.name)
18
- if repo_item_with_same_name && !overwrite
19
- # we delete the repo if asked
20
- repo_item.destroy if options[:destroy_if_fail]
21
- raise RepositoryManager::ItemExistException.new("add failed. The repo_item '#{repo_item.name}' already exist in the folder '#{name}'")
22
- elsif repo_item_with_same_name && overwrite
23
- # We destroy it
24
- if repo_item_with_same_name.is_file?
25
- #p "add: updates the file #{repo_item.name}"
26
- repo_item_with_same_name.file = repo_item.file
27
- repo_item_with_same_name.sender = repo_item.sender
28
- repo_item_with_same_name.owner = repo_item.owner
29
- repo_item = repo_item_with_same_name
30
- else
31
- repo_item_with_same_name.destroy!
32
- end
33
- else
34
- repo_item.parent = self
35
- repo_item.save! unless options[:do_not_save]
36
- end
37
- repo_item
37
+ repo_item.move!(source_folder: self, do_not_save: options[:do_not_save], destroy_if_fail: options[:destroy_if_fail], overwrite: overwrite)
38
38
  end
39
39
 
40
40
  def add(repo_item)
@@ -33,16 +33,20 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
33
33
 
34
34
  # Move itself into the target or root
35
35
  # options
36
+ # :destroy_if_fail = false // the repo_item if it can't move it.
37
+ # :do_not_save = false // Save the repo_item after changing his param
36
38
  # :source_folder = the folder in witch you copy this item
37
39
  # :owner = the owner of the item
38
40
  # :overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
39
41
  # If :source_folder = nil, move to the root (of same owner)
40
42
  def move!(options = {})
43
+ returned_item = self
41
44
  !!options[:overwrite] == options[:overwrite] ? overwrite = options[:overwrite] : overwrite = RepositoryManager.auto_overwrite_item
42
45
 
43
46
  # If we are in source_folder, we check if it's a folder
44
47
  if options[:source_folder]
45
48
  unless options[:source_folder].is_folder?
49
+ self.destroy if options[:destroy_if_fail]
46
50
  raise RepositoryManager::RepositoryManagerException.new("move failed. target '#{options[:source_folder].name}' can't be a file")
47
51
  end
48
52
 
@@ -50,10 +54,21 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
50
54
  # If the name exist and we don't want to overwrite, we raise an error
51
55
  if children_with_same_name and !overwrite
52
56
  self.errors.add(:move, I18n.t('repository_manager.errors.repo_item.item_exist'))
57
+ # we delete the repo if asked
58
+ self.destroy if options[:destroy_if_fail]
53
59
  raise RepositoryManager::ItemExistException.new("move failed. The repo_item '#{name}' already exist ine the folder '#{options[:source_folder].name}'")
54
60
  elsif children_with_same_name and overwrite
55
- # If a children with the same name exist and we want to overwrite, we have to destroy it
56
- children_with_same_name.destroy!
61
+ # If a children with the same name exist and we want to overwrite,
62
+ # We destroy or update it
63
+ if children_with_same_name.is_file?
64
+ children_with_same_name.file = self.file
65
+ children_with_same_name.sender = self.sender
66
+ #children_with_same_name.owner = self.owner
67
+ returned_item = children_with_same_name
68
+ self.destroy
69
+ else
70
+ children_with_same_name.destroy!
71
+ end
57
72
  end
58
73
  # We are in root, we check if name exist in root
59
74
  # We stay in the same owner
@@ -64,24 +79,36 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
64
79
  # If it exist and we don t want to overwrite, we raise an error
65
80
  if children_with_same_name and !overwrite
66
81
  self.errors.add(:move, I18n.t('repository_manager.errors.repo_item.item_exist'))
82
+ # we delete the repo if asked
83
+ self.destroy if options[:destroy_if_fail]
67
84
  raise RepositoryManager::ItemExistException.new("move failed. The repo_item '#{name}' already exist ine the root")
68
85
  # else we destroy it
69
86
  elsif children_with_same_name and overwrite
70
- children_with_same_name.destroy!
87
+ # If a children with the same name exist and we want to overwrite,
88
+ # We destroy or update it
89
+ if children_with_same_name.is_file?
90
+ children_with_same_name.file = self.file
91
+ children_with_same_name.sender = self.sender
92
+ #children_with_same_name.owner = self.owner
93
+ returned_item = children_with_same_name
94
+ self.destroy
95
+ else
96
+ children_with_same_name.destroy!
97
+ end
71
98
  end
72
99
  end
73
100
 
74
101
  # here, all is ok
75
102
  # We change the owner if another one is specify
76
103
  if options[:owner]
77
- self.owner = options[:owner]
104
+ returned_item.owner = options[:owner]
78
105
  elsif options[:source_folder]
79
- self.owner = options[:source_folder].owner
106
+ returned_item.owner = options[:source_folder].owner
80
107
  end
81
108
  # we update the tree with the new parent
82
- self.parent = options[:source_folder]
83
- self.save!
84
- self
109
+ returned_item.parent = options[:source_folder]
110
+ returned_item.save! unless options[:do_not_save]
111
+ returned_item
85
112
  end
86
113
 
87
114
  def move(options = {})
@@ -245,7 +245,6 @@ module RepositoryManager
245
245
  end
246
246
  repo_item_with_same_name.sender = options[:sender]
247
247
  #p "source: updates the file #{repo_item_with_same_name.name}"
248
-
249
248
  repo_file = repo_item_with_same_name
250
249
  end
251
250
  else
@@ -300,31 +299,6 @@ module RepositoryManager
300
299
  return false
301
300
  end
302
301
 
303
- # Download a repo_item if the object can_read it
304
- # If it is a file, he download the file
305
- # If it is a folder, we check witch repo_item is in it, and witch he can_read
306
- # We zip all the content that the object has access.
307
- # options
308
- # :path => 'path/to/zip'
309
- def download_repo_item!(repo_item, options = {})
310
- if can_download?(repo_item)
311
- path = options[:path] if options[:path]
312
-
313
- repo_item.download!({object: self, path: path})
314
- else
315
- repo_item.errors.add(:download, I18n.t('repository_manager.errors.repo_item.download.no_permission'))
316
- raise RepositoryManager::PermissionException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'")
317
- end
318
- end
319
-
320
- def download_repo_item(repo_item, options = {})
321
- begin
322
- download_repo_item!(repo_item, options)
323
- rescue RepositoryManager::PermissionException
324
- false
325
- end
326
- end
327
-
328
302
  # Rename the repo_item with the new_name
329
303
  def rename_repo_item!(repo_item, new_name)
330
304
  unless can_update?(repo_item)
@@ -416,13 +390,13 @@ module RepositoryManager
416
390
  end
417
391
 
418
392
  # The new owner
419
- if target
420
- owner = target.owner
421
- else
393
+ #if target
394
+ # owner = target.owner
395
+ #else
422
396
  owner = self
423
- end
397
+ #end
424
398
 
425
- # If it has the permission, we move the repo_item in the source_folder
399
+ # If it has the permission, we copy the repo_item in the source_folder
426
400
  repo_item.copy!(source_folder: target, owner: owner, sender: options[:sender], overwrite: overwrite)
427
401
  end
428
402
 
@@ -437,11 +411,67 @@ module RepositoryManager
437
411
  end
438
412
  end
439
413
 
414
+ # Download a repo_item if the object can_read it
415
+ # If it is a file, he download the file
416
+ # If it is a folder, we check witch repo_item is in it, and witch he can_read
417
+ # We zip all the content that the object has access.
418
+ # options
419
+ # :path => 'path/to/zip'
420
+ def download_repo_item!(repo_item, options = {})
421
+ if can_download?(repo_item)
422
+ path = options[:path] if options[:path]
423
+
424
+ repo_item.download!({object: self, path: path})
425
+ else
426
+ repo_item.errors.add(:download, I18n.t('repository_manager.errors.repo_item.download.no_permission'))
427
+ raise RepositoryManager::PermissionException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'")
428
+ end
429
+ end
430
+
431
+ def download_repo_item(repo_item, options = {})
432
+ begin
433
+ download_repo_item!(repo_item, options)
434
+ rescue RepositoryManager::PermissionException
435
+ false
436
+ end
437
+ end
438
+
440
439
  # Delete the download folder of the user
441
440
  def delete_download_path
442
441
  FileUtils.rm_rf(self.get_default_download_path())
443
442
  end
444
443
 
444
+ # Unzip the compressed file and create the repo_items
445
+ # options
446
+ # :source_folder = the folder in witch you unzip this archive
447
+ # :sender = the sender of the item (if you don't specify sender.. The sender is still the same)
448
+ # :overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
449
+ def unzip_repo_item!(repo_item, options = {})
450
+ target = options[:source_folder]
451
+
452
+ unless can_read?(repo_item)
453
+ repo_item.errors.add(:unzip, I18n.t('repository_manager.errors.repo_item.unzip.no_permission'))
454
+ raise RepositoryManager::PermissionException.new("unzip repo_file failed. You don't have the permission to read the repo_file '#{repo_item.name}'")
455
+ end
456
+
457
+ if target && !can_create?(target)
458
+ repo_item.errors.add(:unzip, I18n.t('repository_manager.errors.repo_item.unzip.no_permission'))
459
+ raise RepositoryManager::PermissionException.new("unzip repo_file failed. You don't have the permission to create in the source_folder '#{target.name}'")
460
+ end
461
+ repo_item.unzip!(source_folder: target, sender: options[:sender], overwrite: options[:overwrite])
462
+ end
463
+
464
+ def unzip_repo_item(repo_item, options = {})
465
+ begin
466
+ unzip_repo_item!(repo_item, options)
467
+ rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException
468
+ false
469
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
470
+ repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.unzip.not_unzipped'))
471
+ false
472
+ end
473
+ end
474
+
445
475
  # Return the permissions of the sharing (can_add, can_remove)
446
476
  def get_sharing_permissions(sharing)
447
477
  sharing.get_permissions(self)
@@ -559,6 +589,24 @@ module RepositoryManager
559
589
  RepoItem.where('name = ?', name).where(owner: self).where(ancestry: nil).first
560
590
  end
561
591
 
592
+ # Get or create the folder with this name
593
+ # options
594
+ # :sender = the sender of the item
595
+ def get_or_create_by_path_array(path_array, options = {})
596
+ name = path_array[0]
597
+ children = self.get_item_in_root_by_name(name)
598
+ unless children
599
+ children = RepositoryManager::RepoFolder.new(name: name)
600
+ children.owner = self
601
+ children.sender = options[:sender]
602
+ children.save!
603
+ end
604
+ # remove the first element
605
+ path_array.shift
606
+ children = children.get_or_create_by_path_array(path_array, sender: options[:sender], owner: self)
607
+ children
608
+ end
609
+
562
610
  private
563
611
 
564
612
  # Return if you can do or not this action in the sharing
@@ -23,6 +23,9 @@ en:
23
23
  copy:
24
24
  no_permission: You don't have the permission to copy this item
25
25
  not_copied: This item was not copied
26
+ unzip:
27
+ no_permission: You don't have the permission to unzip this item
28
+ not_unzipped: This item was not unzipped
26
29
  repo_folder:
27
30
  item_exist: This folder already exist
28
31
  create:
@@ -10,6 +10,7 @@ fr:
10
10
  created: Le fichier a été créé avec succès !
11
11
  errors:
12
12
  repo_item:
13
+ item_exist: Cet élément existe déjà dans la destination cible
13
14
  download:
14
15
  no_permission: Vous n'avez pas la permission de télécharger cet élément
15
16
  rename:
@@ -19,7 +20,12 @@ fr:
19
20
  move:
20
21
  no_permission: Vous n'avez pas la permission de déplacer cet élément
21
22
  not_moved: Cet élément n'a pas été déplacé
22
- item_exist: Cet élément existe déjà dans la destination cible
23
+ copy:
24
+ no_permission: Vous n'avez pas la permission de copier cet élément
25
+ not_copied: Cet élément n'a pas été copié
26
+ unzip:
27
+ no_permission: Vous n'avez pas la permission de décompresser cet archive
28
+ not_unzipped: Cette archive n'a pas été décompressée
23
29
  repo_folder:
24
30
  item_exist: Ce dossier existe déjà
25
31
  create:
@@ -1,3 +1,3 @@
1
1
  module RepositoryManager
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.9'
3
3
  end
File without changes
@@ -1,12 +1,17 @@
1
1
  FactoryGirl.define do
2
2
  factory :rm_repo_file, :class => RepositoryManager::RepoFile do
3
3
  file { fixture_file }
4
- #sequence :password do |n|
5
- # 'secret'
6
- #end
4
+ end
5
+
6
+ factory :rm_unzip, :class => RepositoryManager::RepoFile do
7
+ file { fixture_unzip }
7
8
  end
8
9
  end
9
10
 
10
11
  def fixture_file
11
12
  File.open("#{Rails.root}/../fixture/textfile.txt")
12
13
  end
14
+
15
+ def fixture_unzip
16
+ File.open("#{Rails.root}/../fixture/unzip.zip")
17
+ end
Binary file
@@ -340,8 +340,8 @@ describe 'RepoItem' do
340
340
 
341
341
  it "can move an item with the same name and overwrite it" do
342
342
  file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
343
- expect(@user1.move_repo_item!(file, overwrite: true)).to eq(file)
344
- overwrited = RepositoryManager::RepoItem.where(id: @user1_file.id).first
343
+ expect(@user1.move_repo_item!(file, overwrite: true)).to eq(@user1_file)
344
+ overwrited = RepositoryManager::RepoItem.where(id: file.id).first
345
345
  expect(overwrited).to eq(nil)
346
346
  end
347
347
 
@@ -375,7 +375,7 @@ describe 'RepoItem' do
375
375
 
376
376
  it 'can create a file in folder with same name and update the old one' do
377
377
  @user1.move_repo_item(@user1_file, source_folder: @user1_folder)
378
- file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder, overwrite: true)
378
+ file = @user1.create_file!(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder, overwrite: true)
379
379
  overwrited = RepositoryManager::RepoItem.where(id: @user1_file.id).first
380
380
  expect(overwrited).to eq(file)
381
381
  #expect(folder.name).to eq("Folder")
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Unzip' do
4
+
5
+ before do
6
+ @user1 = FactoryGirl.create(:user)
7
+ @zip_file = FactoryGirl.build(:rm_unzip)
8
+ @zip_file.owner = @user1
9
+ @zip_file.save
10
+ end
11
+
12
+ it 'can unzip an archive in root without options' do
13
+ @zip_file.unzip!
14
+ expect(@user1.root_repo_items.count).to eq(3)
15
+ root_folder = @user1.get_item_in_root_by_name('root_folder')
16
+ expect(root_folder.children.count).to eq(4)
17
+
18
+ folder_in_root = root_folder.get_children_by_name('Folder In Root')
19
+ expect(folder_in_root.children.count).to eq(3)
20
+
21
+ children_folder = folder_in_root.get_children_by_name('Children Folder')
22
+ expect(children_folder.children.count).to eq(2)
23
+
24
+ empty_folder = children_folder.get_children_by_name('Empty folder')
25
+ expect(empty_folder.children.count).to eq(0)
26
+ end
27
+
28
+ it 'can unzip an archive in a folder and overwrite' do
29
+ root = @user1.create_folder!('The root of the root')
30
+
31
+ @zip_file.unzip!(source_folder: root)
32
+
33
+ expect(@user1.root_repo_items.count).to eq(2)
34
+ nil_folder = @user1.get_item_in_root_by_name('root_folder')
35
+ expect(nil_folder).to eq(nil)
36
+
37
+ root_of_the_root = @user1.get_item_in_root_by_name('The root of the root')
38
+ expect(root_of_the_root).to eq(root)
39
+
40
+ root_folder = root_of_the_root.get_children_by_name('root_folder')
41
+ expect(root_folder.children.count).to eq(4)
42
+
43
+ folder_in_root = root_folder.get_children_by_name('Folder In Root')
44
+ expect(folder_in_root.children.count).to eq(3)
45
+
46
+ children_folder = folder_in_root.get_children_by_name('Children Folder')
47
+ expect(children_folder.children.count).to eq(2)
48
+
49
+ empty_folder = children_folder.get_children_by_name('Empty folder')
50
+ expect(empty_folder.children.count).to eq(0)
51
+
52
+ @zip_file.unzip!(source_folder: root, overwrite: true) # it raise no error, it works
53
+
54
+ end
55
+
56
+ it 'User with permission can unzip and other can\'t' do
57
+ @user2 = FactoryGirl.create(:user)
58
+
59
+ expect(@user1.unzip_repo_item!(@zip_file)).to eq(@zip_file)
60
+ expect(@user2.unzip_repo_item(@zip_file)).to eq(false)
61
+ end
62
+
63
+ # TODO test change owner and sender
64
+
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repository-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Baumann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -157,6 +157,7 @@ files:
157
157
  - lib/repository_manager/locales/repository_manager.en.yml
158
158
  - lib/repository_manager/locales/repository_manager.fr.yml
159
159
  - lib/repository_manager/version.rb
160
+ - rappord.md
160
161
  - repository-manager.gemspec
161
162
  - spec/dummy/Gemfile
162
163
  - spec/dummy/README.rdoc
@@ -203,6 +204,7 @@ files:
203
204
  - spec/factories/repo_folder.rb
204
205
  - spec/factories/user.rb
205
206
  - spec/fixture/textfile.txt
207
+ - spec/fixture/unzip.zip
206
208
  - spec/has_repository_spec.rb
207
209
  - spec/models/associations_spec.rb
208
210
  - spec/models/repository_spec.rb
@@ -210,6 +212,7 @@ files:
210
212
  - spec/repository_manager_spec.rb
211
213
  - spec/spec_helper.rb
212
214
  - spec/support/spec_test_helper.rb
215
+ - spec/unzip_spec.rb
213
216
  homepage: https://github.com/Texicitys/repository-manager
214
217
  licenses:
215
218
  - MIT
@@ -281,6 +284,7 @@ test_files:
281
284
  - spec/factories/repo_folder.rb
282
285
  - spec/factories/user.rb
283
286
  - spec/fixture/textfile.txt
287
+ - spec/fixture/unzip.zip
284
288
  - spec/has_repository_spec.rb
285
289
  - spec/models/associations_spec.rb
286
290
  - spec/models/repository_spec.rb
@@ -288,3 +292,4 @@ test_files:
288
292
  - spec/repository_manager_spec.rb
289
293
  - spec/spec_helper.rb
290
294
  - spec/support/spec_test_helper.rb
295
+ - spec/unzip_spec.rb