repository-manager 0.0.8 → 0.0.9

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- repository-manager (0.0.7)
4
+ repository-manager (0.0.8)
5
5
  ancestry
6
6
  carrierwave
7
7
  rails (> 3.0.0)
data/README.md CHANGED
@@ -107,7 +107,7 @@ A `repo_item` is an item in a repository, it can be:
107
107
 
108
108
  A folder can contains files and folders. Like in a real tree files and folders.
109
109
 
110
- ### How can I create/delete a repo_item (file or folder)
110
+ ### How can I create/delete/move a repo_item (file or folder)
111
111
 
112
112
  You just have to call the `has_repository` methods `create_file`, `create_folder`, or `delete_repo_item`.
113
113
 
@@ -136,7 +136,7 @@ user1.create_file(File.open('somewhere'), the_new_folder)
136
136
  # user1 own repository :
137
137
  # |-- 'Root folder'
138
138
  # | |-- 'The new folder'
139
- # | | |-- 'file'
139
+ # | | |-- 'file.txt'
140
140
 
141
141
  # user1 want to create a file on the root of his repository
142
142
  file2 = user1.create_file(params[:file2])
@@ -144,16 +144,36 @@ file2 = user1.create_file(params[:file2])
144
144
  # user1 own repository :
145
145
  # |-- 'Root folder'
146
146
  # | |-- 'The new folder'
147
- # | | |-- 'file'
148
- # |-- 'file2'
147
+ # | | |-- 'file.txt'
148
+ # |-- 'file2.jpg'
149
+
150
+ # user1 want to create a folder on the root of his repository
151
+ test_folder = user1.create_folder('Test folder')
152
+
153
+ # user1 own repository :
154
+ # |-- 'Root folder'
155
+ # | |-- 'The new folder'
156
+ # | | |-- 'file.txt'
157
+ # |-- 'file2.jpg'
158
+ # |-- 'Test folder'
159
+
160
+ # user1 want to move 'The new folder' in 'Test folder'
161
+ user1.move(the_new_folder, test_folder)
162
+
163
+ # user1 own repository :
164
+ # |-- 'Root folder'
165
+ # |-- 'file2.jpg'
166
+ # |-- 'Test folder'
167
+ # | |-- 'The new folder'
168
+ # | | |-- 'file.txt'
149
169
 
150
170
  # Delete a repo_item
151
171
  # Note : user1 needs the ':can_delete => true' permission in the folder : the_new_folder (else the method returns `false`).
152
- user1.delete_repo_item(the_new_folder)
172
+ user1.delete_repo_item(test_folder)
153
173
 
154
174
  # user1 own repository :
155
175
  # |-- 'Root folder'
156
- # |-- 'file2'
176
+ # |-- 'file2.jpg'
157
177
 
158
178
  user1.delete_repo_item(file2)
159
179
 
@@ -202,6 +222,16 @@ user1.repo_items.all # => You get the repo_items that user1 has created
202
222
  user2.shared_repo_items.all
203
223
  ```
204
224
 
225
+ If you only want to have the folders or the files, you can do it like that:
226
+
227
+ ```ruby
228
+ # return only the own folders of user1
229
+ user1.repo_items.folders.all # => You get the repo_folders that user1 has created
230
+
231
+ # user2 want to get his shared repo_files
232
+ user2.shared_repo_items.files.all
233
+ ```
234
+
205
235
  Recall: a repo_item can be:
206
236
  - A file
207
237
  - A folder
@@ -276,11 +306,11 @@ sharing.remove_members({user2, group1})
276
306
  #### Repository authorisations
277
307
 
278
308
  The owner of a `repo_item` (file or folder) has all the authorisations on it. When he share this `repo_item`, he can choose what authorisation he gives to the share. The authorisations are :
279
- - can_read?(repo_item) : The member can read (=download) this file/folder.
280
- - can_create?(repo_item) : Can create in the repo_item (Note: if repo_item is nil (= root), always true).
281
- - can_update?(repo_item) : Can update a repo_item.
282
- - can_delete?(repo_item) : Can delete a repo_item.
283
- - can_share?(repo_item) : Can share a repo_item.
309
+ - `can_read?(repo_item)` : The member can read (=download) this file/folder.
310
+ - `can_create?(repo_item)` : Can create in the repo_item (Note: if repo_item is nil (= root), always true).
311
+ - `can_update?(repo_item)` : Can update a repo_item.
312
+ - `can_delete?(repo_item)` : Can delete a repo_item.
313
+ - `can_share?(repo_item)` : Can share a repo_item.
284
314
 
285
315
  To check if a user has one of this authorisation, you just have to write : `user1.can_read?(repo_item)`, `user1.can_share?(repo_item)`, etc (it returns `true` or `false`).
286
316
 
@@ -303,18 +333,45 @@ You can get all the authorisations with this method: `user1.get_authorisations(r
303
333
  #### Sharing permissions
304
334
 
305
335
  You can manage the permissions of a member in a sharing. The owner of the sharing has all the permissions. The permissions are:
306
- - can_add_to?(sharing) : The member can add a new instance in this sharing.
307
- - can_remove_from?(sharing) : Can remove an instance from this sharing.
336
+ - `can_add_to?(sharing)` : The member can add a new instance in this sharing.
337
+ - `can_remove_from?(sharing)` : Can remove an instance from this sharing.
308
338
 
309
339
  To check if the object can add or remove an instance in the sharing, just write : `group1.can_add_to?(sharing)` or `group1.can_remove_from?(sharing)` (it returns `true` or `false`).
310
340
 
311
341
  Like the repo_item authorisations, you can get the sharing authorisations with : `group1.get_sharing_authorisations(sharing)`.
312
342
 
343
+ ### Download a repository
344
+
345
+ RepositoryManager make the download of a repo_item easy. If the user want to download a file, the `user.download(repo_item)` method returns you the path of the file (if the user `can_read` it).
346
+ If it want to download a folder, it automaticaly genere a zip file with all the contant that the user can_read. The method returns the path of this zip file.
347
+
348
+ ```ruby
349
+ # user1 want to download the_folder
350
+ path_to_zip = user1.download(the_folder)
351
+
352
+ # Then you can do what you want with this path, you can use the send_file method from rails in your controller
353
+ send_file path_to_zip
354
+
355
+ # Don't forget to delete the zip file after the user has downloaded it (when his session end for instance)
356
+ # I created a method how delete all the download file path
357
+ user1.delete_download_path()
358
+ ```
359
+
360
+ You can directly download the folder (without permission control):
361
+
362
+ ```ruby
363
+ # Directly download all the folder
364
+ path = the_folder.download
365
+
366
+ # You can delete the zip file with
367
+ the_folder.delete_zip
368
+ ```
369
+
313
370
  ## TODO
314
371
 
315
- - Can dowload a file or a folder (auto zip the folder)
372
+ - Qu'on ne puisse pas créer un deuxième sous partage pour le même user (évite beaucoup de soucis)
373
+ - Write the methods : move, copy, share_link, rename.
316
374
  - Snapshot the file if possible
317
- - Flexible configuration of authorised extensions
318
375
  - Versioning
319
376
  - ...
320
377
 
@@ -11,7 +11,7 @@ class RepoFile < RepoItem
11
11
  end
12
12
 
13
13
  # Downloading this file
14
- def download(object = nil)
14
+ def download(options = {})
15
15
  path = file.path
16
16
  #render status: :bad_request and return unless File.exist?(path)
17
17
  #send_file(path)
@@ -6,39 +6,93 @@ class RepoFolder < RepoItem
6
6
  validates :name, presence: true
7
7
 
8
8
  # Add a repo_item in the folder.
9
- def add(repo_item)
9
+ def add!(repo_item)
10
10
  # We check if this name already exist
11
+ #if repo_item.children.exists?(:name => repo_item.name)
11
12
  if RepoItem.where(name: repo_item.name).where(id: child_ids).first
12
- #raise "add failed. The repo_item '#{repo_item.name}' already exist in the folder '#{name}'"
13
+ raise RepositoryManager::RepositoryManagerException.new("add failed. The repo_item '#{repo_item.name}' already exist in the folder '#{name}'")
13
14
  false
14
15
  else
15
16
  repo_item.update_attribute :parent, self
16
17
  end
17
18
  end
18
19
 
19
- # Download this folder (zip it first)
20
- # If object = nil, it download all the folder
21
- # if object is set, it download only the folder that the object can_read.
22
- def download(object = nil)
20
+ def add(repo_item)
21
+ begin
22
+ add!(repo_item)
23
+ rescue RepositoryManager::RepositoryManagerException
24
+ false
25
+ end
26
+ end
27
+
28
+ # Download this folder (zip it first)
29
+ # Return the path to the folder.zip
30
+ # options can have :
31
+ # :object => Object : is the object that request the download
32
+ # If object = nil, it download all the folder
33
+ # if object is set, it download only the folder that the object `can_read`.
34
+ # :path => 'path/to/zip/' is the path where the zip is generated
35
+ def download!(options = {})
23
36
  # Get all the children
24
37
  children = RepoItem.find(child_ids)
25
38
 
26
39
  # If something is in the array to add, we zip it
27
40
  if children.length > 0
28
- # We create the zip here
29
- Zip::File.open("#{name}.zip", Zip::File::CREATE) { |zf|
41
+
42
+ # Default values
43
+ options[:object]? object = options[:object]: object = nil
44
+
45
+ RepositoryManager.default_zip_path == true ? path = get_default_download_path(object): path = RepositoryManager.default_zip_path
46
+ path = options[:path] if options[:path]
47
+
48
+ full_path = "#{path}#{name}.zip"
49
+
50
+ # Create the directory if not exist
51
+ dir = File.dirname(full_path)
52
+ unless File.directory?(dir)
53
+ FileUtils.mkdir_p(dir)
54
+ end
55
+ # Delete the zip if it already exist
56
+ File.delete(full_path) if File.exist?(full_path)
57
+
58
+ Zip::File.open(full_path, Zip::File::CREATE) { |zf|
30
59
  add_repo_item_to_zip(children, zf, object)
31
60
  }
61
+ return full_path
32
62
  else
33
63
  # Nothing to download here
34
- #raise "download failed. Folder #{name} is empty"
64
+ raise RepositoryManager::RepositoryManagerException.new("download failed. Folder #{name} is empty")
65
+ end
66
+ end
67
+
68
+ def download(options = {})
69
+ begin
70
+ download!(options)
71
+ rescue RepositoryManager::RepositoryManagerException
35
72
  false
36
73
  end
74
+ end
75
+
76
+
77
+ # Delete the zip file
78
+ def delete_zip(options = {})
79
+ options[:object]? object = options[:object]: object = nil
80
+ RepositoryManager.default_zip_path == true ? path = get_default_download_path(object): path = RepositoryManager.default_zip_path
81
+ path = options[:path] if options[:path]
37
82
 
83
+ # Delete the path
84
+ FileUtils.rm_rf(path)
38
85
  end
39
86
 
40
87
  private
41
88
 
89
+ # Returns the default path of the zip file
90
+ # object is the object that want to download this file
91
+ def get_default_download_path(object = nil)
92
+ object ? add_to_path = object.get_default_download_path(''): add_to_path = ''
93
+ "download/#{add_to_path}#{self.class.to_s.underscore}/#{self.id}/"
94
+ end
95
+
42
96
  def add_repo_item_to_zip(children, zf, object = nil, prefix = nil)
43
97
  children.each do |child|
44
98
  # If this is a file, we just add this file to the zip
@@ -4,7 +4,7 @@ class RepoItem < ActiveRecord::Base
4
4
 
5
5
  has_ancestry
6
6
 
7
- # Associate with the User Classe
7
+ # Associate with the User Class
8
8
  belongs_to :owner, :polymorphic => true
9
9
  has_many :sharings, :dependent => :destroy
10
10
  #has_many :members, through: :sharings
@@ -30,13 +30,22 @@ class RepoItem < ActiveRecord::Base
30
30
  #new_file
31
31
  end
32
32
 
33
- # Move the repo_item into the target_folder
34
- # TODO à faire
35
- def move(target_folder)
33
+ # Move itself into the target_folder
34
+ def move!(target_folder)
36
35
  if target_folder.type == 'RepoFolder'
37
36
  self.update_attribute :parent, target_folder
37
+ else
38
+ raise RepositoryManager::RepositoryManagerException.new("move failed. target '#{name}' can't be a file")
38
39
  end
39
40
  end
40
41
 
42
+ def move(target_folder)
43
+ begin
44
+ move!(target_folder)
45
+ rescue RepositoryManager::RepositoryManagerException
46
+ false
47
+ end
48
+
49
+ end
41
50
 
42
- end
51
+ end
@@ -26,7 +26,7 @@ class Sharing < ActiveRecord::Base
26
26
  end
27
27
 
28
28
  # Add members to the sharing
29
- def add_members(members, sharing_permissions = nil)
29
+ def add_members(members, sharing_permissions = RepositoryManager.default_sharing_permissions)
30
30
  if members.kind_of?(Array)
31
31
  # Add each member to this sharing
32
32
  members.each do |i|
@@ -5,4 +5,8 @@ RepositoryManager.setup do |config|
5
5
 
6
6
  # Default sharing permissions that an object has when he is added in a sharing.
7
7
  config.default_sharing_permissions = { can_add: false, can_remove: false }
8
+
9
+ # Default path for generating the zip file when a user want to download a folder
10
+ # Default is : "download/#{member.class.to_s.underscore}/#{member.id}/#{self.class.to_s.underscore}/#{self.id}/"
11
+ #config.default_zip_path = true
8
12
  end
@@ -8,6 +8,9 @@ module RepositoryManager
8
8
  mattr_accessor :default_sharing_permissions
9
9
  @@default_sharing_permissions = { can_add: false, can_remove: false }
10
10
 
11
+ mattr_accessor :default_zip_path
12
+ @@default_zip_path = true
13
+
11
14
  class << self
12
15
  def setup
13
16
  yield self
@@ -20,4 +23,5 @@ module RepositoryManager
20
23
 
21
24
  end
22
25
 
23
- require 'repository_manager/engine'
26
+ require 'repository_manager/engine'
27
+ require 'repository_manager/exceptions'
@@ -0,0 +1,7 @@
1
+ module RepositoryManager
2
+ class RepositoryManagerException < RuntimeError
3
+ end
4
+
5
+ class AuthorisationException < RepositoryManagerException
6
+ end
7
+ end
@@ -35,7 +35,7 @@ module RepositoryManager
35
35
  # options[:sharing_permissions] contains :
36
36
  # <tt>:can_add</tt> - Specify if the member can add objects to the sharing
37
37
  # <tt>:can_remove</tt> - Specify if the member can remove object to the sharing
38
- def share(repo_item, members, options = nil)
38
+ def share!(repo_item, members, options = {})
39
39
  authorisations = get_authorisations(repo_item)
40
40
 
41
41
  # Here we look if the instance has the authorisation for making a sharing
@@ -46,10 +46,8 @@ module RepositoryManager
46
46
  sharing_permissions = RepositoryManager.default_sharing_permissions
47
47
 
48
48
  # If there is options, we have to take it
49
- if options
50
- repo_item_permissions = options[:repo_item_permissions] if options[:repo_item_permissions]
51
- sharing_permissions = options[:sharing_permissions] if options[:sharing_permissions]
52
- end
49
+ repo_item_permissions = options[:repo_item_permissions] if options[:repo_item_permissions]
50
+ sharing_permissions = options[:sharing_permissions] if options[:sharing_permissions]
53
51
 
54
52
  repo_item_permissions = make_repo_item_permissions(repo_item_permissions, authorisations)
55
53
 
@@ -63,7 +61,14 @@ module RepositoryManager
63
61
  sharing
64
62
  else
65
63
  # No permission => No sharing
66
- #raise "sharing failed. You don't have the permission to share the repo_item '#{repo_item.name}'"
64
+ raise RepositoryManager::AuthorisationException.new("sharing failed. You don't have the permission to share the repo_item '#{repo_item.name}'")
65
+ end
66
+ end
67
+
68
+ def share(repo_item, members, options = {})
69
+ begin
70
+ share!(repo_item, members, options)
71
+ rescue RepositoryManager::AuthorisationException
67
72
  false
68
73
  end
69
74
  end
@@ -71,7 +76,7 @@ module RepositoryManager
71
76
  # Create a folder with the name (name) in the directory (source_folder)
72
77
  # Returns the object of the folder created if it is ok
73
78
  # Returns false if the folder is not created (no authorisation)
74
- def create_folder(name = 'New folder', source_folder = nil)
79
+ def create_folder!(name = 'New folder', source_folder = nil)
75
80
  # If he want to create a folder in a directory, we have to check if he have the authorisation
76
81
  if can_create?(source_folder)
77
82
 
@@ -85,22 +90,35 @@ module RepositoryManager
85
90
  else
86
91
  # The add didn't works, we delete the folder
87
92
  folder.destroy
88
- #raise "create_folder failed. The folder '#{name}' already exist in folder '#{source_folder.name}'"
89
- false
93
+ raise RepositoryManager::RepositoryManagerException.new("create_folder failed. The folder '#{name}' already exist in folder '#{source_folder.name}'")
90
94
  end
91
95
  else
92
- #raise "create_folder failed. You don't have the permission to create a folder in '#{source_folder.name}'"
93
- return false
96
+ raise RepositoryManager::AuthorisationException.new("create_folder failed. You don't have the permission to create a folder in '#{source_folder.name}'")
97
+ end
98
+ end
99
+
100
+ def create_folder(name = 'New folder', source_folder = nil)
101
+ begin
102
+ create_folder!(name, source_folder)
103
+ rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException
104
+ false
94
105
  end
95
106
  end
96
107
 
97
108
  # Delete the repo_item
98
- def delete_repo_item(repo_item)
109
+ def delete_repo_item!(repo_item)
99
110
  if can_delete?(repo_item)
100
111
  repo_item.destroy
101
112
  else
102
- #raise "delete_repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'"
103
- return false
113
+ raise RepositoryManager::AuthorisationException.new("delete_repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
114
+ end
115
+ end
116
+
117
+ def delete_repo_item(repo_item)
118
+ begin
119
+ delete_repo_item!(repo_item)
120
+ rescue RepositoryManager::AuthorisationException
121
+ false
104
122
  end
105
123
  end
106
124
 
@@ -108,7 +126,7 @@ module RepositoryManager
108
126
  # Param file can be a File, or a instance of RepoFile
109
127
  # Return the object of the file created if it is ok
110
128
  # Return false if the file is not created (no authorisation)
111
- def create_file(file, source_folder = nil)
129
+ def create_file!(file, source_folder = nil)
112
130
  # If he want to create a file in a directory, we have to check if he have the authorisation
113
131
  if can_create?(source_folder)
114
132
  if file.class.name == 'File'
@@ -128,12 +146,19 @@ module RepositoryManager
128
146
  else
129
147
  # The add didn't works, we delete the file
130
148
  file.destroy
131
- #raise "create_file failed. The file '#{name}' already exist in folder '#{source_folder.name}'"
132
- return false
149
+ raise RepositoryManager::RepositoryManagerException.new("create_file failed. The file '#{name}' already exist in folder '#{source_folder.name}'")
133
150
  end
134
151
  else
135
152
  #raise "create_file failed. You don't have the permission to create a file in the folder '#{source_folder.name}'"
136
- return false
153
+ raise RepositoryManager::AuthorisationException.new("create_file failed. The file '#{name}' already exist in folder '#{source_folder.name}'")
154
+ end
155
+ end
156
+
157
+ def create_file(file, source_folder = nil)
158
+ begin
159
+ create_file!(file, source_folder)
160
+ rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException
161
+ false
137
162
  end
138
163
  end
139
164
 
@@ -150,16 +175,11 @@ module RepositoryManager
150
175
  if repo_item.owner == self
151
176
  # You can do what ever you want :)
152
177
  return true
153
- # Find if a sharing of this rep exist for the self instance
154
- elsif s = self.sharings.where(repo_item_id: repo_item.id).first
155
- # Ok, give an array with the permission of the actual sharing
156
- # (we can't share with more permission then we have)
157
- return {can_share: s.can_share, can_read: s.can_read, can_create: s.can_create, can_update: s.can_update, can_delete: s.can_delete}
178
+ # Find if a sharing of this rep exist for the self instance or it ancestors
158
179
  else
159
- # We look at the ancestor if there is a sharing
160
- ancestor_ids = repo_item.ancestor_ids
180
+ path_ids = repo_item.path_ids
161
181
  # Check the nearest sharing if it exist
162
- if s = self.sharings.where(repo_item_id: ancestor_ids).last
182
+ if s = self.sharings.where(repo_item_id: path_ids).last
163
183
  return {can_share: s.can_share, can_read: s.can_read, can_create: s.can_create, can_update: s.can_update, can_delete: s.can_delete}
164
184
  end
165
185
  end
@@ -171,15 +191,51 @@ module RepositoryManager
171
191
  # If it is a file, he download the file
172
192
  # If it is a folder, we check witch repo_item is in it, and witch he can_read
173
193
  # We zip all the content that the object has access.
174
- def download(repo_item)
194
+ # options
195
+ # :path => 'path/to/zip'
196
+ def download!(repo_item, options = {})
175
197
  if can_download?(repo_item)
176
- repo_item.download(self)
198
+ path = options[:path] if options[:path]
199
+
200
+ repo_item.download({object: self, path: path})
177
201
  else
178
- #raise "download failed. You don't have the permission to download the repo_item '#{repo_item.name}'"
202
+ raise RepositoryManager::AuthorisationException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'")
203
+ end
204
+ end
205
+
206
+ def download(repo_item, options = {})
207
+ begin
208
+ download!(repo_item, options)
209
+ rescue RepositoryManager::AuthorisationException
179
210
  false
180
211
  end
181
212
  end
182
213
 
214
+ # Move the repo_item in the target_folder
215
+ def move_repo_item!(repo_item, target_folder)
216
+ unless can_delete?(repo_item)
217
+ raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
218
+ end
219
+ unless can_create?(target_folder)
220
+ raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to create in the target_folder '#{target_folder.name}'")
221
+ end
222
+ # If it has the permission, we move the repo_item in the target_folder
223
+ repo_item.move(target_folder)
224
+ end
225
+
226
+ def move_repo_item(repo_item, target_folder)
227
+ begin
228
+ move_repo_item!(repo_item, target_folder)
229
+ rescue RepositoryManager::AuthorisationException
230
+ false
231
+ end
232
+ end
233
+
234
+ # Delete the download folder of the user
235
+ def delete_download_path
236
+ FileUtils.rm_rf(self.get_default_download_path())
237
+ end
238
+
183
239
  #Return the authorisations of the sharing (can_add, can_remove)
184
240
  def get_sharing_authorisations(sharing)
185
241
  sharing.get_authorisations(self)
@@ -217,6 +273,11 @@ module RepositoryManager
217
273
  can_do?('delete', repo_item, authorisations)
218
274
  end
219
275
 
276
+ # Return true it has a sharing in the repo_item
277
+ def has_sharing?(repo_item)
278
+
279
+ end
280
+
220
281
  # Return true if you can add a member in this sharing, false else
221
282
  def can_add_to?(sharing)
222
283
  can_do_to?('add', sharing)
@@ -229,28 +290,47 @@ module RepositoryManager
229
290
 
230
291
  # You can here add new members in the sharing
231
292
  # Param member could be an object or an array of object
232
- def add_members_to(sharing, members, options = nil)
293
+ def add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions)
233
294
  authorisations = get_sharing_authorisations(sharing)
234
295
  if can_add_to?(sharing)
235
296
  sharing_permissions = make_sharing_permissions(options, authorisations)
236
297
  sharing.add_members(members, sharing_permissions)
237
298
  else
238
- #raise "add members failed. You don't have the permission to add a member in this sharing"
239
- return false
299
+ raise RepositoryManager::AuthorisationException.new("add members failed. You don't have the permission to add a member in this sharing")
240
300
  end
241
301
  end
242
302
 
243
- # You can here add new members in the sharing
303
+ def add_members_to(sharing, members, options = RepositoryManager.default_sharing_permissions)
304
+ begin
305
+ add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions)
306
+ rescue RepositoryManager::AuthorisationException
307
+ false
308
+ end
309
+ end
310
+
311
+ # You can here add new members in the sharing
244
312
  # Param member could be an object or an array of object
245
- def remove_members_from(sharing, members)
313
+ def remove_members_from!(sharing, members)
246
314
  if can_remove_from?(sharing)
247
315
  sharing.remove_members(members)
248
316
  else
249
- #raise "remove members failed. You don't have the permission to remove a member on this sharing"
250
- return false
317
+ raise RepositoryManager::AuthorisationException.new("remove members failed. You don't have the permission to remove a member on this sharing")
251
318
  end
252
319
  end
253
320
 
321
+ def remove_members_from(sharing, members)
322
+ begin
323
+ remove_members_from!(sharing, members)
324
+ rescue RepositoryManager::AuthorisationException
325
+ false
326
+ end
327
+ end
328
+
329
+ # Get the download path of the member
330
+ def get_default_download_path(prefix = 'download/')
331
+ "#{prefix}#{self.class.to_s.underscore}/#{self.id}/"
332
+ end
333
+
254
334
  private
255
335
 
256
336
  # Return if you can do or not this action in the sharing
@@ -269,7 +349,7 @@ module RepositoryManager
269
349
  # Return if you can do or not this action (what)
270
350
  def can_do?(what, repo_item, authorisations = nil)
271
351
  #If we pass no authorisations we have to get it
272
- if authorisations === nil
352
+ if authorisations == nil
273
353
  authorisations = get_authorisations(repo_item)
274
354
  end
275
355
 
@@ -1,3 +1,3 @@
1
1
  module RepositoryManager
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
Binary file
@@ -223,12 +223,14 @@ describe 'HasRepository' do
223
223
  #folder = @user1.repo_items.last
224
224
  expect(folder.name).to eq('test folder')
225
225
  expect(folder.type).to eq('RepoFolder')
226
+ expect(@user1.repo_items.folders.count).to eq(1)
226
227
  end
227
228
 
228
229
  it "can create a file" do
229
230
  file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
230
231
  expect(file.name).to eq('textfile.txt')
231
232
  expect(@user1.repo_items.count).to eq(1)
233
+ expect(@user1.repo_items.files.count).to eq(1)
232
234
  end
233
235
 
234
236
  end
@@ -111,11 +111,28 @@ describe 'RepoItem' do
111
111
  user1_file3.save
112
112
  @user1.create_file(user1_file3, @user1_folder)
113
113
 
114
+ @user1.download(@user1_folder)
115
+ @user1.download(@user1_folder)
116
+ @user1_folder.download
114
117
 
115
- pp @user1.download(@user1_folder)
118
+ @user1_folder.delete_zip
119
+ @user1.delete_download_path()
116
120
  end
117
121
 
118
122
  it 'can\'t add a repo_item with the same name in a folder' do
123
+ root_folder = @user1.create_folder('Root folder')
124
+ root_folder.add(@user1_folder)
125
+
126
+ root_test_folder = @user1.create_folder('root test folder')
127
+ test_folder = @user1.create_folder('Test folder', root_test_folder)
128
+ @user1.create_folder('Nested test folder', test_folder)
129
+
130
+ @user1.move_repo_item(test_folder, @user1_folder)
131
+
132
+ expect(test_folder.parent_id).to eq(@user1_folder.id)
133
+ end
134
+
135
+ it 'can move a folder into another folder' do
119
136
  folder = @user1.create_folder('Folder1', @user1_folder)
120
137
  expect(@user1.repo_items.count).to eq(3)
121
138
  folder2 = @user1.create_folder('Folder1', @user1_folder)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repository-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-15 00:00:00.000000000 Z
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -155,6 +155,7 @@ files:
155
155
  - lib/generators/repository_manager/templates/initializer.rb
156
156
  - lib/repository-manager.rb
157
157
  - lib/repository_manager/engine.rb
158
+ - lib/repository_manager/exceptions.rb
158
159
  - lib/repository_manager/has_repository.rb
159
160
  - lib/repository_manager/version.rb
160
161
  - lib/tasks/repository_manager_tasks.rake