repository-manager 0.0.13 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTlmNWQyMTJkYjFkOTI4MDE0OTY3Mjc0MmFhNTE1MDIxZGY1ZDkwOQ==
5
- data.tar.gz: !binary |-
6
- YjNhNzhmNWJjMzM4ZTVhYjdmMjcwMWUzMDk0NTMxNDE2N2ExNjI2MA==
2
+ SHA1:
3
+ metadata.gz: e37f122c9ac68a5696514ba45aa58590d70f8d2d
4
+ data.tar.gz: ff2275d01570d20ea9ddcca099890a7a41d2bee0
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MmVhNDkxYTc2YTI4NmFiNmY5YzkxMjk5OTQyODE4OTNkODlmMDRiODQ1ODE3
10
- OTIzYTIwNDllMWRlZjE2YWZjZDY4MDNhNmQyNzUyMjM2NDA5ZjZkYjMyNTQ5
11
- MjhhOGZhMDcyZmY0ODdhNjExNjc5NDBhZmVhMDFkZmIwNWZkNjY=
12
- data.tar.gz: !binary |-
13
- NWE1MzE0MmU0OTU1Yjc4OTMyYmE0ODdiMjdlMzI5MTU0ODRhNGQxMjliNTBh
14
- Mzg0YTkyYTVmYjYzYTg5ZjkwNDE5MTg5MDk5ZmFkNzc2MjM2YzNkNGY1Mzky
15
- ZTNlNTEyMjQ0MDQ3OTIxN2RjYTY0MzNlNjVkMDljMmM1MTU4MTM=
6
+ metadata.gz: cf1c68509fb5f38b59e6493b51b903e0a556dc8e27bc079f62080801f7c10eebbdf4e7268ed8ece90ddd4182480578d50c04140ecb62a4300cf8ac4af2c11432
7
+ data.tar.gz: 736abdc384ce33cb4484c249d5952753a6a7d1c2ca0477b2a3e774c2813bb9f3109d2eb862f40943ca72e0cf995d9860b3dde551da6177c1b2137b50ece164b4
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color
1
+ --color
data/README.md CHANGED
@@ -1,419 +1,424 @@
1
- WORK IN PROGRESS, but it already works !
2
-
3
- Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharing).
4
-
5
- # RepositoryManager
6
-
7
- This gem add fonctionalities to manage repositories. Each instance (users, groups, etc..) can have it own repository (with files and folders). It can manage them (edit, remove, add, etc) and share them with other objects.
8
-
9
- This project is based on the need for a repository manager system for [Collaide](https://github.com/facenord-sud/collaide). A system for easily create/delete files and folders in a repository. For sharing these "repo items" easily with other object with a flexible and complete authorisations management.
10
-
11
- Instead of creating my core repository manager system heavily
12
- dependent on our development, I'm trying to implement a generic and potent repository gem.
13
-
14
- After looking for a good gem to use I noticed the lack of repository gems
15
- and flexibility in them. RepositoryManager tries to be the more flexible possible.
16
-
17
- This gem is my informatics project for the Master in [University of Lausanne (CH)](http://www.unil.ch/index.html).
18
-
19
- ## Installation
20
-
21
-
22
- Add to your Gemfile:
23
-
24
- ```ruby
25
- gem 'repository-manager'
26
- ```
27
-
28
- Then run:
29
-
30
- ```sh
31
- $ bundle update
32
- ```
33
-
34
- Run install script:
35
-
36
- ```sh
37
- $ rails g repository_manager:install
38
- ```
39
-
40
- And don't forget to migrate your database:
41
-
42
- ```sh
43
- $ rake db:migrate
44
- ```
45
-
46
- ## Settings
47
-
48
- You can edit the RepositoryManager settings in the initializer (/config/initializer/repository_manager.rb).
49
-
50
- ```ruby
51
- RepositoryManager.setup do |config|
52
-
53
- # Default permissions that an object has on the repo_item after a sharing.
54
- config.default_repo_item_permissions = { can_read: true, can_create: false, can_update: false, can_delete: false, can_sharing: false }
55
-
56
- # Default permissions that an object has when he is added in a sharing.
57
- config.default_sharing_permissions = { can_add: false, can_remove: false }
58
-
59
- # Default path for generating the zip file when a user want to download a folder
60
- # Default is : "download/#{member.class.to_s.underscore}/#{member.id}/#{self.class.to_s.underscore}/#{self.id}/"
61
- #config.default_zip_path = true
62
- end
63
- ```
64
-
65
- For instance, if you want that a default sharing is totaly free (for edit, delete, etc), just put all default parameters to `true` :
66
- ```ruby
67
- RepositoryManager.setup do |config|
68
- config.default_repo_item_permissions = { can_read: true, can_create: true, can_update: true, can_delete: true, can_share: true }
69
- config.default_sharing_permissions = { can_add: true, can_remove: true }
70
- end
71
- ```
72
-
73
-
74
- See the chapter [Authorisations](#authorisations) for more details about the permissions.
75
-
76
- ## Preparing your models
77
-
78
- You can choose wich model can have repository.
79
-
80
- In your model:
81
-
82
- ```ruby
83
- class User < ActiveRecord::Base
84
- has_repository
85
- end
86
- ```
87
-
88
- You are not limited to the User model. You can use RepositoryManager in any other model and use it in serveral different models. If you have Groups and Houses in your application and you want to exchange `repo_items` as if they were the same, just add `has_repository` to each one and you will be able to sharing `repo_files`/`repo_folders` groups-groups, groups-users, users-groups and users-users. Of course, you can extend it for as many classes as you need.
89
-
90
- Example:
91
-
92
- ```ruby
93
- class User < ActiveRecord::Base
94
- has_repository
95
- end
96
- ```
97
-
98
- ```ruby
99
- class Group < ActiveRecord::Base
100
- has_repository
101
- end
102
- ```
103
-
104
- ## How to use RepositoryManager
105
-
106
- ### Introduction
107
-
108
- A `repo_item` is an item in a repository, it can be:
109
- - A file (`repo_file`, class name : `RepoFile`)
110
- - A folder (`repo_folder`, class name : `RepoFolder`).
111
-
112
- A folder can contains files and folders. Like in a real tree files and folders.
113
-
114
- A few methods are written in those two ways :
115
- - method(arg, options)
116
- - method!(arg, options) (note the "!")
117
-
118
- The two methods do the same, but the one with the "!" returns an Exeption error if it is a problem (AuthorisationException for instance) and the method without "!" return false if it has a problem.
119
-
120
- ### How can I create/delete/move a repo_item (file or folder)
121
-
122
- You just have to call the `has_repository` methods `create_file`, `create_folder`, or `delete_repo_item`.
123
-
124
- ```ruby
125
- # user1 wants to create a folder in his repository
126
-
127
- # Create a root folder on the user1 repository (you can have how many roots as you want)
128
- source_folder = user1.create_folder('Root folder')
129
-
130
- # user1 own repository :
131
- # -- 'Root folder'
132
-
133
- # source_folder is the directory in wich user1 wants to create the folder 'The new folder'
134
- the_new_folder = user1.create_folder('The new folder', source_folder)
135
-
136
- # user1 own repository :
137
- # |-- 'Root folder'
138
- # | |-- 'The new folder'
139
-
140
- # Now we want to add a file into the_new_folder
141
- # Note : user1 needs the ':can_create => true' permission in the folder : the_new_folder (else the method returns `false`).
142
- user1.create_file(params[:file], the_new_folder)
143
- # OR
144
- user1.create_file(File.open('somewhere'), the_new_folder)
145
-
146
- # user1 own repository :
147
- # |-- 'Root folder'
148
- # | |-- 'The new folder'
149
- # | | |-- 'file.txt'
150
-
151
- # user1 want to create a file on the root of his repository
152
- file2 = user1.create_file(params[:file2])
153
-
154
- # user1 own repository :
155
- # |-- 'Root folder'
156
- # | |-- 'The new folder'
157
- # | | |-- 'file.txt'
158
- # |-- 'file2.jpg'
159
-
160
- # user1 want to create a folder on the root of his repository
161
- test_folder = user1.create_folder('Test folder')
162
-
163
- # user1 own repository :
164
- # |-- 'Root folder'
165
- # | |-- 'The new folder'
166
- # | | |-- 'file.txt'
167
- # |-- 'file2.jpg'
168
- # |-- 'Test folder'
169
-
170
- # user1 want to move 'The new folder' in 'Test folder'
171
- user1.move(the_new_folder, test_folder)
172
-
173
- # user1 own repository :
174
- # |-- 'Root folder'
175
- # |-- 'file2.jpg'
176
- # |-- 'Test folder'
177
- # | |-- 'The new folder'
178
- # | | |-- 'file.txt'
179
-
180
- # Delete a repo_item
181
- # Note : user1 needs the ':can_delete => true' permission in the folder : the_new_folder (else the method returns `false`).
182
- user1.delete_repo_item(test_folder)
183
-
184
- # user1 own repository :
185
- # |-- 'Root folder'
186
- # |-- 'file2.jpg'
187
-
188
- user1.delete_repo_item(file2)
189
-
190
- # user1 own repository :
191
- # |-- 'Root folder'
192
-
193
- ```
194
-
195
- ### How can I share a repo_item (file/folder)
196
-
197
- Now, user1 want to share his folder 'The new folder' with a Group object `group1` et another User object `user2`. You can use the `has_repository` method `share(repo_item, member, options = nil)`.
198
-
199
-
200
- ```ruby
201
- # user1 wants to share the_new_folder with group1 and user2
202
-
203
- members = []
204
- # You can add other instances (who `has_repository`) in this array to share with more than one instance
205
- member << group1
206
- members << user2
207
-
208
- sharing = user1.share(the_new_folder, members)
209
-
210
- # If you want to customize your sharing options, you can do it like this:
211
- options = {sharing_permissions: {can_add: true, can_remove: true}, repo_item_permissions: {can_read: true, can_create: true, can_update: true, can_delete: true, can_share: true}}
212
-
213
- sharing = user1.share(the_new_folder, members, options)
214
- ```
215
-
216
- `repo_item_permissions` specifies what kind of permissions you give on the repo_item in a specific sharing.
217
-
218
- `sharing_permissions` specifies if the member selectionned can add or remove other members in this sharing.
219
-
220
- See the chapter [Authorisations](#authorisations) for more details.
221
-
222
- ### Repository Manager and the nested sharing
223
-
224
- Repository Manager actualy don't accept nested sharing.
225
-
226
- ```ruby
227
-
228
- parent = @user1.create_folder('Parent')
229
- nested = @user1.create_folder('Nested', parent)
230
- children = @user1.create_folder('Children', nested)
231
-
232
- # @user1 own repository :
233
- # |-- 'Parent'
234
- # | |-- 'Nested'
235
- # | | |-- 'Children'
236
-
237
- @user1.share(nested, @user2)
238
-
239
- nested.has_nested_sharing? # Returns false (because `nested` is shared but there is no nested sharing)
240
- parent.has_nested_sharing? # Returns true (because there is a sharing on one of his descendants)
241
- children.has_nested_sharing? # Returns true (because there is a sharing on one of his ancestors)
242
-
243
- # Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
244
- @user1.share(parent, @user2) # Returns false
245
- @user1.share!(parent, @user2) # Raise a NestedSharingException (note the "!")
246
- @user1.share!(children, @user2) # Raise a NestedSharingException (note the "!")
247
- ```
248
-
249
- ### How can I see my repo_items
250
-
251
- You can have two kind of repo_items:
252
- - Your own repo_items
253
- - The repo_items shared with you.
254
-
255
- ```ruby
256
- # user1 want to get his own repository
257
- user1.repo_items.all # => You get the repo_items that user1 has created
258
-
259
- # user2 want to get his shared repo_items
260
- user2.shared_repo_items.all
261
- ```
262
-
263
- If you only want to have the folders or the files, you can do it like that:
264
-
265
- ```ruby
266
- # return only the own folders of user1
267
- user1.repo_items.folders.all # => You get the repo_folders that user1 has created
268
-
269
- # user2 want to get his shared repo_files
270
- user2.shared_repo_items.files.all
271
- ```
272
-
273
- Recall: a repo_item can be:
274
- - A file
275
- - A folder
276
-
277
- ```ruby
278
- # We want to know if the object repo_item is a file or a folder:
279
- if repo_item.type == 'RepoFolder'
280
- repo_item.name #=> Returns the name of the folder (for instance : 'New folder').
281
- elsif repo_item.type == 'RepoFile'
282
- repo_item.name #=> Returns the name of the file (for instance : 'file.png').
283
- # Here is the file
284
- repo_item.file.url # => '/url/to/file.png'
285
- repo_item.file.current_path # => 'path/to/file.png'
286
- end
287
- ```
288
-
289
- For file informations, more infos on [the documentation of the carrierwave gem](https://github.com/carrierwaveuploader/carrierwave).
290
-
291
-
292
- ### How can I manage a sharing
293
-
294
-
295
- If it has the authorisation, an object can add members to a sharing.
296
-
297
- ```ruby
298
- # user1 want to add members to his sharing
299
- # NOTE: The action is done only if user1 has the ':can_add' permission.
300
- user1.can_add_to?(sharing) # => true
301
-
302
- # Add members
303
- members = []
304
- members << user3
305
- members << group2
306
- ...
307
-
308
- user1.add_members_to(sharing, members)
309
-
310
- # You can change the default sharing permissions options :
311
- options = {can_add: true, can_remove: false}
312
- user1.add_members_to(sharing, members, options)
313
-
314
-
315
- # Here user3 and group2 can add members in this sharing, but they can't remove a member.
316
- group2.can_add_to?(sharing) # => true
317
- group2.can_remove_from?(sharing) # => false
318
-
319
- # If user2 add a member in the sharing, he can choose if the permission ':can_add' is true or false, but he can't put ':can_remove' to true (because he don't have this permission himself).
320
- ```
321
-
322
- If an object has the authorisation, it can remove members from a sharing, else the method return `false`.
323
-
324
- ```ruby
325
- # user1 want to remove group2 from the sharing `sharing`
326
- user1.remove_members_from(sharing, group2) # The second parameter can be an object or an array of object
327
- ```
328
-
329
- You can directly work with the `sharing`. Be carefull, there is NO authorisation control !
330
-
331
- ```ruby
332
- # Add a member to the sharing `sharing`
333
- sharing.add_members(member)
334
- # Or with options :
335
- sharing.add_members(member, {can_add: true, can_remove: false})
336
-
337
-
338
- # Remove members from the sharing
339
- sharing.remove_members({user2, group1})
340
- ```
341
-
342
- ### Authorisations
343
-
344
- #### Repository authorisations
345
-
346
- 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 :
347
- - `can_read?(repo_item)` : The member can read (=download) this file/folder.
348
- - `can_create?(repo_item)` : Can create in the repo_item (Note: if repo_item is nil (= root), always true).
349
- - `can_update?(repo_item)` : Can update a repo_item.
350
- - `can_delete?(repo_item)` : Can delete a repo_item.
351
- - `can_share?(repo_item)` : Can share a repo_item.
352
-
353
- 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`).
354
-
355
- NOTICE : An object who can share a repo_item, can't set new permissions that it doesn't have.
356
- For instance: `user3` has a sharing of `repo_item1` with `:can_delete => false` and `:can_share => true`. He can share `repo_item1` with `user4`, but he can't put `:can_delete => true` in this new share.
357
-
358
- You can get all the authorisations with this method: `user1.get_authorisations(repo_item)`
359
-
360
- ```ruby
361
- # Gets the repo authorisations
362
- # Return false if the entity has not the authorisation to share this rep
363
- # Return true if the entity can share this rep with all the authorisations
364
- # Return an Array if the entity can share but with restriction
365
- # Return true if the repo_item is nil (he as all authorisations on his own rep)
366
- def get_authorisations(repo_item = nil)
367
- [...]
368
- end
369
- ```
370
-
371
- #### Sharing permissions
372
-
373
- You can manage the permissions of a member in a sharing. The owner of the sharing has all the permissions. The permissions are:
374
- - `can_add_to?(sharing)` : The member can add a new instance in this sharing.
375
- - `can_remove_from?(sharing)` : Can remove an instance from this sharing.
376
-
377
- 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`).
378
-
379
- Like the repo_item authorisations, you can get the sharing authorisations with : `group1.get_sharing_authorisations(sharing)`.
380
-
381
- ### Download a repository
382
-
383
- 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).
384
- 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.
385
-
386
- ```ruby
387
- # user1 want to download the_folder
388
- path_to_zip = user1.download(the_folder)
389
-
390
- # Then you can do what you want with this path, you can use the send_file method from rails in your controller
391
- send_file path_to_zip
392
-
393
- # Don't forget to delete the zip file after the user has downloaded it (when his session end for instance)
394
- # I created a method how delete all the download file path
395
- user1.delete_download_path()
396
- ```
397
-
398
- You can directly download the folder (without permission control):
399
-
400
- ```ruby
401
- # Directly download all the folder
402
- path = the_folder.download
403
-
404
- # You can delete the zip file with
405
- the_folder.delete_zip
406
- ```
407
-
408
- ## TODO
409
-
410
- - Write the methods : move, copy, share_link, rename.
411
- - Snapshot the file if possible
412
- - Versioning
413
- - ...
414
-
415
-
416
- ## License
417
-
418
- This project rocks and uses MIT-LICENSE.
419
-
1
+ WORK IN PROGRESS, but it already works !
2
+
3
+ Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharing).
4
+
5
+ # RepositoryManager
6
+
7
+ This gem add fonctionalities to manage repositories. Each instance (users, groups, etc..) can have it own repository (with files and folders). It can manage them (edit, remove, add, etc) and share them with other objects.
8
+
9
+ This project is based on the need for a repository manager system for [Collaide](https://github.com/facenord-sud/collaide). A system for easily create/delete files and folders in a repository. For sharing these "repo items" easily with other object with a flexible and complete authorisations management.
10
+
11
+ Instead of creating my core repository manager system heavily
12
+ dependent on our development, I'm trying to implement a generic and potent repository gem.
13
+
14
+ After looking for a good gem to use I noticed the lack of repository gems
15
+ and flexibility in them. RepositoryManager tries to be the more flexible possible.
16
+
17
+ This gem is my informatics project for the Master in [University of Lausanne (CH)](http://www.unil.ch/index.html).
18
+
19
+ ## Installation
20
+
21
+
22
+ Add to your Gemfile:
23
+
24
+ ```ruby
25
+ gem 'repository-manager'
26
+ ```
27
+
28
+ Then run:
29
+
30
+ ```sh
31
+ $ bundle update
32
+ ```
33
+
34
+ Run install script:
35
+
36
+ ```sh
37
+ $ rails g repository_manager:install
38
+ ```
39
+
40
+ And don't forget to migrate your database:
41
+
42
+ ```sh
43
+ $ rake db:migrate
44
+ ```
45
+
46
+ ## Settings
47
+
48
+ You can edit the RepositoryManager settings in the initializer (/config/initializer/repository_manager.rb).
49
+
50
+ ```ruby
51
+ RepositoryManager.setup do |config|
52
+
53
+ # Default permissions that an object has on the repo_item after a sharing.
54
+ config.default_repo_item_permissions = { can_read: true, can_create: false, can_update: false, can_delete: false, can_sharing: false }
55
+
56
+ # Default permissions that an object has when he is added in a sharing.
57
+ config.default_sharing_permissions = { can_add: false, can_remove: false }
58
+
59
+ # Default path for generating the zip file when a user want to download a folder
60
+ # Default is : "download/#{member.class.to_s.underscore}/#{member.id}/#{self.class.to_s.underscore}/#{self.id}/"
61
+ #config.default_zip_path = true
62
+ end
63
+ ```
64
+
65
+ For instance, if you want that a default sharing is totaly free (for edit, delete, etc), just put all default parameters to `true` :
66
+ ```ruby
67
+ RepositoryManager.setup do |config|
68
+ config.default_repo_item_permissions = { can_read: true, can_create: true, can_update: true, can_delete: true, can_share: true }
69
+ config.default_sharing_permissions = { can_add: true, can_remove: true }
70
+ end
71
+ ```
72
+
73
+
74
+ See the chapter [Authorisations](#authorisations) for more details about the permissions.
75
+
76
+ ## Preparing your models
77
+
78
+ You can choose wich model can have repository.
79
+
80
+ In your model:
81
+
82
+ ```ruby
83
+ class User < ActiveRecord::Base
84
+ has_repository
85
+ end
86
+ ```
87
+
88
+ You are not limited to the User model. You can use RepositoryManager in any other model and use it in serveral different models. If you have Groups and Houses in your application and you want to exchange `repo_items` as if they were the same, just add `has_repository` to each one and you will be able to sharing `repo_files`/`repo_folders` groups-groups, groups-users, users-groups and users-users. Of course, you can extend it for as many classes as you need.
89
+
90
+ Example:
91
+
92
+ ```ruby
93
+ class User < ActiveRecord::Base
94
+ has_repository
95
+ end
96
+ ```
97
+
98
+ ```ruby
99
+ class Group < ActiveRecord::Base
100
+ has_repository
101
+ end
102
+ ```
103
+
104
+ ## How to use RepositoryManager
105
+
106
+ ### Introduction
107
+
108
+ A `repo_item` is an item in a repository, it can be:
109
+ - A file (`repo_file`, class name : `RepoFile`)
110
+ - A folder (`repo_folder`, class name : `RepoFolder`).
111
+
112
+ A folder can contains files and folders. Like in a real tree files and folders.
113
+
114
+ A few methods are written in those two ways :
115
+ - method(arg, options)
116
+ - method!(arg, options) (note the "!")
117
+
118
+ The two methods do the same, but the one with the "!" returns an Exeption error if it is a problem (AuthorisationException for instance) and the method without "!" return false if it has a problem.
119
+
120
+ ### How can I create/delete/move a repo_item (file or folder)
121
+
122
+ You just have to call the `has_repository` methods `create_file`, `create_folder`, `move_repo_item` or `delete_repo_item`.
123
+
124
+ ```ruby
125
+ # user1 wants to create a folder in his repository
126
+
127
+ # Create a root folder on the user1 repository (you can have how many roots as you want)
128
+ source_folder = user1.create_folder('Root folder')
129
+
130
+ # user1 own repository :
131
+ # -- 'Root folder'
132
+
133
+ # source_folder is the directory in wich user1 wants to create the folder 'The new folder'
134
+ the_new_folder = user1.create_folder('The new folder', source_folder)
135
+
136
+ # user1 own repository :
137
+ # |-- 'Root folder'
138
+ # | |-- 'The new folder'
139
+
140
+ # Now we want to add a file into the_new_folder
141
+ # Note : user1 needs the ':can_create => true' permission in the folder : the_new_folder (else the method returns `false`).
142
+ user1.create_file(params[:file], the_new_folder)
143
+ # OR
144
+ user1.create_file(File.open('somewhere'), the_new_folder)
145
+
146
+ # user1 own repository :
147
+ # |-- 'Root folder'
148
+ # | |-- 'The new folder'
149
+ # | | |-- 'file.txt'
150
+
151
+ # user1 want to create a file on the root of his repository
152
+ file2 = user1.create_file(params[:file2])
153
+
154
+ # user1 own repository :
155
+ # |-- 'Root folder'
156
+ # | |-- 'The new folder'
157
+ # | | |-- 'file.txt'
158
+ # |-- 'file2.jpg'
159
+
160
+ # user1 want to create a folder on the root of his repository
161
+ test_folder = user1.create_folder('Test folder')
162
+
163
+ # user1 own repository :
164
+ # |-- 'Root folder'
165
+ # | |-- 'The new folder'
166
+ # | | |-- 'file.txt'
167
+ # |-- 'file2.jpg'
168
+ # |-- 'Test folder'
169
+
170
+ # user1 want to move 'The new folder' in 'Test folder'
171
+ user1.move_repo_item(the_new_folder, test_folder)
172
+
173
+ # user1 own repository :
174
+ # |-- 'Root folder'
175
+ # |-- 'file2.jpg'
176
+ # |-- 'Test folder'
177
+ # | |-- 'The new folder'
178
+ # | | |-- 'file.txt'
179
+
180
+ # Delete a repo_item
181
+ # Note : user1 needs the ':can_delete => true' permission in the folder : the_new_folder (else the method returns `false`).
182
+ user1.delete_repo_item(test_folder)
183
+
184
+ # user1 own repository :
185
+ # |-- 'Root folder'
186
+ # |-- 'file2.jpg'
187
+
188
+ user1.delete_repo_item(file2)
189
+
190
+ # user1 own repository :
191
+ # |-- 'Root folder'
192
+
193
+ ```
194
+
195
+ ### How can I share a repo_item (file/folder)
196
+
197
+ Now, user1 want to share his folder 'The new folder' with a Group object `group1` et another User object `user2`. You can use the `has_repository` method `share(repo_item, member, options = nil)`.
198
+
199
+
200
+ ```ruby
201
+ # user1 wants to share the_new_folder with group1 and user2
202
+
203
+ members = []
204
+ # You can add other instances (who `has_repository`) in this array to share with more than one instance
205
+ member << group1
206
+ members << user2
207
+
208
+ sharing = user1.share(the_new_folder, members)
209
+
210
+ # If you want to customize your sharing options, you can do it like this:
211
+ options = {sharing_permissions: {can_add: true, can_remove: true}, repo_item_permissions: {can_read: true, can_create: true, can_update: true, can_delete: true, can_share: true}}
212
+
213
+ sharing = user1.share(the_new_folder, members, options)
214
+ ```
215
+
216
+ `repo_item_permissions` specifies what kind of permissions you give on the repo_item in a specific sharing.
217
+
218
+ `sharing_permissions` specifies if the member selectionned can add or remove other members in this sharing.
219
+
220
+ See the chapter [Authorisations](#authorisations) for more details.
221
+
222
+ ### Repository Manager and the nested sharing
223
+
224
+ Repository Manager actualy don't accept nested sharing.
225
+
226
+ ```ruby
227
+
228
+ parent = @user1.create_folder('Parent')
229
+ nested = @user1.create_folder('Nested', parent)
230
+ children = @user1.create_folder('Children', nested)
231
+
232
+ # @user1 own repository :
233
+ # |-- 'Parent'
234
+ # | |-- 'Nested'
235
+ # | | |-- 'Children'
236
+
237
+ @user1.share(nested, @user2)
238
+
239
+ nested.has_nested_sharing? # Returns false (because `nested` is shared but there is no nested sharing)
240
+ parent.has_nested_sharing? # Returns true (because there is a sharing on one of his descendants)
241
+ children.has_nested_sharing? # Returns true (because there is a sharing on one of his ancestors)
242
+
243
+ # Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
244
+ @user1.share(parent, @user2) # Returns false
245
+ @user1.share!(parent, @user2) # Raise a NestedSharingException (note the "!")
246
+ @user1.share!(children, @user2) # Raise a NestedSharingException (note the "!")
247
+ ```
248
+
249
+ ### How can I see my repo_items
250
+
251
+ You can have two kind of repo_items:
252
+ - Your own repo_items
253
+ - The repo_items shared with you.
254
+
255
+ ```ruby
256
+ # user1 want to get his own repository
257
+ user1.repo_items.all # => You get the repo_items that user1 has created
258
+
259
+ # user2 want to get his shared repo_items
260
+ user2.shared_repo_items.all
261
+ ```
262
+
263
+ If you only want to have the folders or the files, you can do it like that:
264
+
265
+ ```ruby
266
+ # return only the own folders of user1
267
+ user1.repo_items.folders.all # => You get the repo_folders that user1 has created
268
+
269
+ # user2 want to get his shared repo_files
270
+ user2.shared_repo_items.files.all
271
+ ```
272
+
273
+ Recall: a repo_item can be:
274
+ - A file
275
+ - A folder
276
+
277
+ ```ruby
278
+ # We want to know if the object repo_item is a file or a folder:
279
+ if repo_item.type == 'RepoFolder'
280
+ repo_item.name #=> Returns the name of the folder (for instance : 'New folder').
281
+ elsif repo_item.type == 'RepoFile'
282
+ repo_item.name #=> Returns the name of the file (for instance : 'file.png').
283
+ # Here is the file
284
+ repo_item.file.url # => '/url/to/file.png'
285
+ repo_item.file.current_path # => 'path/to/file.png'
286
+ end
287
+ ```
288
+
289
+ For file informations, more infos on [the documentation of the carrierwave gem](https://github.com/carrierwaveuploader/carrierwave).
290
+
291
+
292
+ ### How can I manage a sharing
293
+
294
+
295
+ If it has the authorisation, an object can add members to a sharing.
296
+
297
+ ```ruby
298
+ # user1 want to add members to his sharing
299
+ # NOTE: The action is done only if user1 has the ':can_add' permission.
300
+ user1.can_add_to?(sharing) # => true
301
+
302
+ # Add members
303
+ members = []
304
+ members << user3
305
+ members << group2
306
+ ...
307
+
308
+ user1.add_members_to(sharing, members)
309
+
310
+ # You can change the default sharing permissions options :
311
+ options = {can_add: true, can_remove: false}
312
+ user1.add_members_to(sharing, members, options)
313
+
314
+
315
+ # Here user3 and group2 can add members in this sharing, but they can't remove a member.
316
+ group2.can_add_to?(sharing) # => true
317
+ group2.can_remove_from?(sharing) # => false
318
+
319
+ # If user2 add a member in the sharing, he can choose if the permission ':can_add' is true or false, but he can't put ':can_remove' to true (because he don't have this permission himself).
320
+ ```
321
+
322
+ If an object has the authorisation, it can remove members from a sharing, else the method return `false`.
323
+
324
+ ```ruby
325
+ # user1 want to remove group2 from the sharing `sharing`
326
+ user1.remove_members_from(sharing, group2) # The second parameter can be an object or an array of object
327
+ ```
328
+
329
+ You can directly work with the `sharing`. Be carefull, there is NO authorisation control !
330
+
331
+ ```ruby
332
+ # Add a member to the sharing `sharing`
333
+ sharing.add_members(member)
334
+ # Or with options :
335
+ sharing.add_members(member, {can_add: true, can_remove: false})
336
+
337
+
338
+ # Remove members from the sharing
339
+ sharing.remove_members({user2, group1})
340
+ ```
341
+
342
+ ### Authorisations
343
+
344
+ #### Repository authorisations
345
+
346
+ 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 :
347
+ - `can_read?(repo_item)` : The member can read (=download) this file/folder.
348
+ - `can_create?(repo_item)` : Can create in the repo_item (Note: if repo_item is nil (= root), always true).
349
+ - `can_update?(repo_item)` : Can update a repo_item.
350
+ - `can_delete?(repo_item)` : Can delete a repo_item.
351
+ - `can_share?(repo_item)` : Can share a repo_item.
352
+
353
+ 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`).
354
+
355
+ NOTICE : An object who can share a repo_item, can't set new permissions that it doesn't have.
356
+ For instance: `user3` has a sharing of `repo_item1` with `:can_delete => false` and `:can_share => true`. He can share `repo_item1` with `user4`, but he can't put `:can_delete => true` in this new share.
357
+
358
+ You can get all the authorisations with this method: `user1.get_authorisations(repo_item)`
359
+
360
+ ```ruby
361
+ # Gets the repo authorisations
362
+ # Return false if the entity has not the authorisation to share this rep
363
+ # Return true if the entity can share this rep with all the authorisations
364
+ # Return an Array if the entity can share but with restriction
365
+ # Return true if the repo_item is nil (he as all authorisations on his own rep)
366
+ def get_authorisations(repo_item = nil)
367
+ [...]
368
+ end
369
+ ```
370
+
371
+ #### Sharing permissions
372
+
373
+ You can manage the permissions of a member in a sharing. The owner of the sharing has all the permissions. The permissions are:
374
+ - `can_add_to?(sharing)` : The member can add a new instance in this sharing.
375
+ - `can_remove_from?(sharing)` : Can remove an instance from this sharing.
376
+
377
+ 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`).
378
+
379
+ Like the repo_item authorisations, you can get the sharing authorisations with : `group1.get_sharing_authorisations(sharing)`.
380
+
381
+ ### Download a repository
382
+
383
+ 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).
384
+ 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.
385
+
386
+ ```ruby
387
+ # user1 want to download the_folder
388
+ path_to_zip = user1.download(the_folder)
389
+
390
+ # Then you can do what you want with this path, you can use the send_file method from rails in your controller
391
+ send_file path_to_zip
392
+
393
+ # Don't forget to delete the zip file after the user has downloaded it (when his session end for instance)
394
+ # I created a method how delete all the download file path
395
+ user1.delete_download_path()
396
+ ```
397
+
398
+ You can directly download the folder (without permission control):
399
+
400
+ ```ruby
401
+ # Directly download all the folder
402
+ path = the_folder.download
403
+
404
+ # You can delete the zip file with
405
+ the_folder.delete_zip
406
+ ```
407
+
408
+ ## TODO
409
+
410
+ - Test the rename folder method
411
+ - Donner un nom UNIQUE de dossier par default
412
+ - Verifier que le nom du dossier n'existe pas dans la racine du repo
413
+ - Do the rename file method
414
+ - Write the documentation for the rename method
415
+ - Write the methods : copy, share_link.
416
+ - Snapshot the file if possible
417
+ - Versioning
418
+ - ...
419
+
420
+
421
+ ## License
422
+
423
+ This project rocks and uses MIT-LICENSE.
424
+