repository-manager 0.1.18 → 0.1.19
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -21
- data/app/models/repository_manager/repo_file.rb +1 -1
- data/app/models/repository_manager/repo_folder.rb +1 -2
- data/app/models/repository_manager/sharing.rb +2 -2
- data/lib/repository_manager/exceptions.rb +1 -1
- data/lib/repository_manager/has_repository.rb +86 -86
- data/lib/repository_manager/version.rb +1 -1
- data/repository-manager.gemspec +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/has_repository_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4887b6bdb653d978499c8da9c904af411cdcdf
|
4
|
+
data.tar.gz: 30bcb1450fc36c85e7f45146ddd6d355bcc06032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a4fad797cc95fd161805a8c226baa52d3a8f209871b3679b27aa68f32629cdc3bfb79d39dfed2797f03453ab604be590a527b45b527cdf6e11f16af6370ece3
|
7
|
+
data.tar.gz: 01f74b128f2f88026bd078479a0a81268608b9c77ef3830797df2a433c3da52a98edb2df2c022ca8432b567853161abb876d40e3a1d1ee6a796583ee32a663f6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/
|
|
6
6
|
|
7
7
|
This gem add functionalities 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
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
|
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 permissions management.
|
10
10
|
|
11
11
|
Instead of creating my core repository manager system heavily
|
12
12
|
dependent on our development, I'm trying to implement a generic and potent repository gem.
|
@@ -72,7 +72,7 @@ end
|
|
72
72
|
```
|
73
73
|
|
74
74
|
|
75
|
-
See the chapter [
|
75
|
+
See the chapter [Permissions](#permissions) for more details about the permissions.
|
76
76
|
|
77
77
|
## Preparing your models
|
78
78
|
|
@@ -116,7 +116,7 @@ A few methods are written in those two ways :
|
|
116
116
|
- method(arg, options)
|
117
117
|
- method!(arg, options) (note the "!")
|
118
118
|
|
119
|
-
The two methods do the same, but the one with the "!" returns an Exception error if it is a problem (
|
119
|
+
The two methods do the same, but the one with the "!" returns an Exception error if it is a problem (PermissionException or RepositoryManagerException for instance) and the method without "!" return false if it has a problem.
|
120
120
|
|
121
121
|
### How can I create/delete/move a repo_item (file or folder)
|
122
122
|
|
@@ -227,7 +227,7 @@ file.sender # Returns user1
|
|
227
227
|
|
228
228
|
```
|
229
229
|
|
230
|
-
WARNING : There is no verification if the user has the
|
230
|
+
WARNING : There is no verification if the user 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 AUTHORISATION on it !
|
231
231
|
|
232
232
|
### How can I share a repo_item (file/folder)
|
233
233
|
|
@@ -254,7 +254,7 @@ sharing = user1.share(the_new_folder, members, options)
|
|
254
254
|
|
255
255
|
`sharing_permissions` specifies if the member of the sharing can add or remove other members in this sharing.
|
256
256
|
|
257
|
-
See the chapter [
|
257
|
+
See the chapter [Permissions](#permissions) for more details.
|
258
258
|
|
259
259
|
### Repository Manager and the nested sharing
|
260
260
|
|
@@ -338,7 +338,7 @@ For file details, more infos on [the documentation of the carrierwave gem](https
|
|
338
338
|
### How can I manage a sharing
|
339
339
|
|
340
340
|
|
341
|
-
If it has the
|
341
|
+
If it has the permission, an object can add members to a sharing.
|
342
342
|
|
343
343
|
```ruby
|
344
344
|
# user1 want to add members to his sharing
|
@@ -365,14 +365,14 @@ group2.can_remove_from?(sharing) # => false
|
|
365
365
|
# If user2 (the user who was add with the sharing permissions : {can_add: true, can_remove: false}) 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).
|
366
366
|
```
|
367
367
|
|
368
|
-
If an object has the
|
368
|
+
If an object has the permission, it can remove members from a sharing, else the method return `false` (or raise an PermissionException if you user the `remove_members_from!` method).
|
369
369
|
|
370
370
|
```ruby
|
371
371
|
# user1 want to remove group2 from the sharing `sharing`
|
372
372
|
user1.remove_members_from(sharing, group2) # The second parameter can be an object or an array of object
|
373
373
|
```
|
374
374
|
|
375
|
-
You can directly work with the `sharing`. Be careful, there is NO
|
375
|
+
You can directly work with the `sharing`. Be careful, there is NO permission control !
|
376
376
|
|
377
377
|
```ruby
|
378
378
|
# Add a member to the sharing `sharing`
|
@@ -385,36 +385,36 @@ sharing.add_members(member, {can_add: true, can_remove: false})
|
|
385
385
|
sharing.remove_members([user2, group1])
|
386
386
|
```
|
387
387
|
|
388
|
-
###
|
388
|
+
### Permissions
|
389
389
|
|
390
|
-
#### Repository
|
390
|
+
#### Repository permissions
|
391
391
|
|
392
|
-
The owner of a `repo_item` (file or folder) has all the
|
392
|
+
The owner of a `repo_item` (file or folder) has all the permissions on it. When he share this `repo_item`, he can choose what permission he gives to the share. The permissions are :
|
393
393
|
- `can_read?(repo_item)` : The member can read (=download) this file/folder.
|
394
394
|
- `can_create?(repo_item)` : Can create in the repo_item (Note: if repo_item is nil (= own root), always true).
|
395
395
|
- `can_update?(repo_item)` : Can update a repo_item (ex: rename).
|
396
396
|
- `can_delete?(repo_item)` : Can delete a repo_item.
|
397
397
|
- `can_share?(repo_item)` : Can share a repo_item.
|
398
398
|
|
399
|
-
To check if a user has one of this
|
399
|
+
To check if a user has one of this permission, you just have to write : `user1.can_read?(repo_item)`, `user1.can_share?(repo_item)`, etc (it returns `true` or `false`).
|
400
400
|
|
401
401
|
NOTICE : An object who can share a repo_item, can't set new permissions that it doesn't have.
|
402
402
|
For instance: `user3` has a `sharing` of `repo_item1` in which it `:can_delete => false` and `:can_share => true`. He can share `repo_item1` with `user4`, but he can't put `:can_delete => true` in the `repo_item_permission` of this new share.
|
403
403
|
|
404
|
-
You can get all the
|
404
|
+
You can get all the permissions of an `object` in a `repo_item` with this method: `object.get_permissions(repo_item)`
|
405
405
|
|
406
406
|
```ruby
|
407
|
-
# Gets the repo
|
408
|
-
# Return false if the entity has not the
|
409
|
-
# Return true if the entity can share this rep with all the
|
407
|
+
# Gets the repo permissions
|
408
|
+
# Return false if the entity has not the permission to share this rep
|
409
|
+
# Return true if the entity can share this rep with all the permissions
|
410
410
|
# Return an Array if the entity can share but with restriction
|
411
|
-
# Return true if the repo_item is nil (he as all
|
412
|
-
def
|
411
|
+
# Return true if the repo_item is nil (he as all permissions on his own rep)
|
412
|
+
def get_permissions(repo_item = nil)
|
413
413
|
[...]
|
414
414
|
end
|
415
415
|
```
|
416
416
|
|
417
|
-
#### Sharing
|
417
|
+
#### Sharing permissions
|
418
418
|
|
419
419
|
You can manage the permissions of a member in a sharing. The owner of the sharing has all the permissions. The sharing permissions are:
|
420
420
|
- `can_add_to?(sharing)` : The member can add a new instance in this sharing.
|
@@ -422,7 +422,7 @@ You can manage the permissions of a member in a sharing. The owner of the sharin
|
|
422
422
|
|
423
423
|
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`).
|
424
424
|
|
425
|
-
Like the repo_item
|
425
|
+
Like the repo_item permissions, you can get the sharing permissions of an `object` in a `sharing` with : `object.get_sharing_permissions(sharing)`.
|
426
426
|
|
427
427
|
### Download a repository
|
428
428
|
|
@@ -456,7 +456,6 @@ the_folder.delete_zip
|
|
456
456
|
## TODO
|
457
457
|
|
458
458
|
- Do the rename file method
|
459
|
-
- Test the copy method
|
460
459
|
- Configure path to save files
|
461
460
|
- Write the methods : share_link.
|
462
461
|
- Snapshot the file if possible
|
@@ -50,7 +50,7 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem
|
|
50
50
|
def copy(options = {})
|
51
51
|
begin
|
52
52
|
copy!(options)
|
53
|
-
rescue RepositoryManager::
|
53
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
54
54
|
false
|
55
55
|
end
|
56
56
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'zip'
|
2
2
|
|
3
3
|
class RepositoryManager::RepoFolder < RepositoryManager::RepoItem
|
4
|
-
#attr_accessible :name if RepositoryManager.protected_attributes?
|
5
4
|
|
6
5
|
validates :name, presence: true
|
7
6
|
|
@@ -84,7 +83,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem
|
|
84
83
|
def copy(options = {})
|
85
84
|
begin
|
86
85
|
copy!(options)
|
87
|
-
rescue RepositoryManager::
|
86
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
88
87
|
false
|
89
88
|
end
|
90
89
|
end
|
@@ -19,8 +19,8 @@ class RepositoryManager::Sharing < ActiveRecord::Base
|
|
19
19
|
# joins(:sharings_members).where('sharings_members.member_id' => member.id,'sharings_members.member_type' => member.class.base_class.to_s)
|
20
20
|
#}
|
21
21
|
|
22
|
-
# Return the
|
23
|
-
def
|
22
|
+
# Return the permissions of the sharing for the member
|
23
|
+
def get_permissions(member)
|
24
24
|
# If the member is the owner, he can do what he want !
|
25
25
|
if self.owner == member
|
26
26
|
return true
|
@@ -53,10 +53,10 @@ module RepositoryManager
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
permissions = get_permissions(repo_item)
|
57
57
|
|
58
|
-
# Here we look if the instance has the
|
59
|
-
if can_share?(nil,
|
58
|
+
# Here we look if the instance has the permission for making a sharing
|
59
|
+
if can_share?(nil, permissions)
|
60
60
|
|
61
61
|
# We put the default options
|
62
62
|
repo_item_permissions = RepositoryManager.default_repo_item_permissions
|
@@ -67,7 +67,7 @@ module RepositoryManager
|
|
67
67
|
sharing_permissions = options[:sharing_permissions] if options[:sharing_permissions]
|
68
68
|
|
69
69
|
# Correct the item permission with accepted permissions
|
70
|
-
repo_item_permissions = make_repo_item_permissions(repo_item_permissions,
|
70
|
+
repo_item_permissions = make_repo_item_permissions(repo_item_permissions, permissions)
|
71
71
|
|
72
72
|
sharing = RepositoryManager::Sharing.new(repo_item_permissions)
|
73
73
|
sharing.owner = self
|
@@ -80,14 +80,14 @@ module RepositoryManager
|
|
80
80
|
sharing
|
81
81
|
else
|
82
82
|
# No permission => No sharing
|
83
|
-
raise RepositoryManager::
|
83
|
+
raise RepositoryManager::PermissionException.new("sharing failed. You don't have the permission to share the repo_item '#{repo_item.name}'")
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
def share(repo_item, members, options = {})
|
88
88
|
begin
|
89
89
|
share!(repo_item, members, options)
|
90
|
-
rescue RepositoryManager::
|
90
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::NestedSharingException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
91
91
|
false
|
92
92
|
end
|
93
93
|
end
|
@@ -99,7 +99,7 @@ module RepositoryManager
|
|
99
99
|
# Returns the object of the folder created if it is ok
|
100
100
|
# Returns an Exception if the folder is not created
|
101
101
|
# RepositoryManagerException if the name already exist
|
102
|
-
#
|
102
|
+
# PermissionException if the object don't have the permission
|
103
103
|
def create_folder!(name = '', options = {})
|
104
104
|
source_folder = options[:source_folder]
|
105
105
|
if source_folder
|
@@ -108,7 +108,7 @@ module RepositoryManager
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
# If he want to create a folder in a directory, we have to check if he have the
|
111
|
+
# If he want to create a folder in a directory, we have to check if he have the permission
|
112
112
|
if can_create?(source_folder)
|
113
113
|
|
114
114
|
folder = RepoFolder.new
|
@@ -130,7 +130,7 @@ module RepositoryManager
|
|
130
130
|
|
131
131
|
folder.save!
|
132
132
|
else
|
133
|
-
raise RepositoryManager::
|
133
|
+
raise RepositoryManager::PermissionException.new("create_folder failed. You don't have the permission to create a folder in '#{source_folder.name}'")
|
134
134
|
end
|
135
135
|
folder
|
136
136
|
end
|
@@ -140,7 +140,7 @@ module RepositoryManager
|
|
140
140
|
def create_folder(name = '', options = {})
|
141
141
|
begin
|
142
142
|
create_folder!(name, options)
|
143
|
-
rescue RepositoryManager::
|
143
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
144
144
|
false
|
145
145
|
end
|
146
146
|
end
|
@@ -150,14 +150,14 @@ module RepositoryManager
|
|
150
150
|
if can_delete?(repo_item)
|
151
151
|
repo_item.destroy
|
152
152
|
else
|
153
|
-
raise RepositoryManager::
|
153
|
+
raise RepositoryManager::PermissionException.new("delete_repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
def delete_repo_item(repo_item)
|
158
158
|
begin
|
159
159
|
delete_repo_item!(repo_item)
|
160
|
-
rescue RepositoryManager::
|
160
|
+
rescue RepositoryManager::PermissionException
|
161
161
|
false
|
162
162
|
end
|
163
163
|
end
|
@@ -171,7 +171,7 @@ module RepositoryManager
|
|
171
171
|
# Returns the object of the file created if it is ok
|
172
172
|
# Returns an Exception if the folder is not created
|
173
173
|
# RepositoryManagerException if the file already exist
|
174
|
-
#
|
174
|
+
# PermissionException if the object don't have the permission
|
175
175
|
def create_file!(file, options = {})
|
176
176
|
source_folder = options[:source_folder]
|
177
177
|
if source_folder
|
@@ -180,7 +180,7 @@ module RepositoryManager
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
# If he want to create a file in a directory, we have to check if he have the
|
183
|
+
# If he want to create a file in a directory, we have to check if he have the permission
|
184
184
|
if can_create?(source_folder)
|
185
185
|
|
186
186
|
if file.class.name == 'RepositoryManager::RepoFile'
|
@@ -206,7 +206,7 @@ module RepositoryManager
|
|
206
206
|
|
207
207
|
repo_file.save!
|
208
208
|
else
|
209
|
-
raise RepositoryManager::
|
209
|
+
raise RepositoryManager::PermissionException.new("create_file failed. You don't have the permission to create a file")
|
210
210
|
end
|
211
211
|
repo_file
|
212
212
|
end
|
@@ -214,17 +214,17 @@ module RepositoryManager
|
|
214
214
|
def create_file(file, options = {})
|
215
215
|
begin
|
216
216
|
create_file!(file, options)
|
217
|
-
rescue RepositoryManager::
|
217
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
218
218
|
false
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
|
-
# Gets the repo
|
223
|
-
# Return false if the entity has not the
|
224
|
-
# Return true if the entity can share this rep with all the
|
222
|
+
# Gets the repo permissions
|
223
|
+
# Return false if the entity has not the permission to share this rep
|
224
|
+
# Return true if the entity can share this rep with all the permissions
|
225
225
|
# Return an Array if the entity can share but with restriction
|
226
|
-
# Return true if the repo_item is nil (he as all
|
227
|
-
def
|
226
|
+
# Return true if the repo_item is nil (he as all permissions on his own rep)
|
227
|
+
def get_permissions(repo_item = nil)
|
228
228
|
# If repo_item is nil, he can do what he want
|
229
229
|
return true if repo_item == nil
|
230
230
|
|
@@ -256,14 +256,14 @@ module RepositoryManager
|
|
256
256
|
|
257
257
|
repo_item.download!({object: self, path: path})
|
258
258
|
else
|
259
|
-
raise RepositoryManager::
|
259
|
+
raise RepositoryManager::PermissionException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'")
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
263
|
def download(repo_item, options = {})
|
264
264
|
begin
|
265
265
|
download!(repo_item, options)
|
266
|
-
rescue RepositoryManager::
|
266
|
+
rescue RepositoryManager::PermissionException
|
267
267
|
false
|
268
268
|
end
|
269
269
|
end
|
@@ -271,7 +271,7 @@ module RepositoryManager
|
|
271
271
|
# Rename the repo_item with the new_name
|
272
272
|
def rename_repo_item!(repo_item, new_name)
|
273
273
|
unless can_update?(repo_item)
|
274
|
-
raise RepositoryManager::
|
274
|
+
raise RepositoryManager::PermissionException.new("rename repo_item failed. You don't have the permission to update the repo_item '#{repo_item.name}'")
|
275
275
|
end
|
276
276
|
repo_item.rename!(new_name)
|
277
277
|
end
|
@@ -280,7 +280,7 @@ module RepositoryManager
|
|
280
280
|
def rename_repo_item(repo_item, new_name)
|
281
281
|
begin
|
282
282
|
rename_repo_item!(repo_item, new_name)
|
283
|
-
rescue RepositoryManager::
|
283
|
+
rescue RepositoryManager::PermissionException
|
284
284
|
false
|
285
285
|
end
|
286
286
|
end
|
@@ -290,26 +290,26 @@ module RepositoryManager
|
|
290
290
|
# if target == nil, move to the root
|
291
291
|
def move_repo_item!(repo_item, target = nil)
|
292
292
|
if !can_read?(repo_item)
|
293
|
-
raise RepositoryManager::
|
293
|
+
raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
|
294
294
|
end
|
295
|
-
# If we want to change the owner we have to have the can_delete
|
295
|
+
# If we want to change the owner we have to have the can_delete permission
|
296
296
|
if target
|
297
|
-
# If want to change the owner, we have to check if we have the
|
297
|
+
# If want to change the owner, we have to check if we have the permission
|
298
298
|
if target.owner != repo_item.owner && !can_delete?(repo_item)
|
299
|
-
raise RepositoryManager::
|
299
|
+
raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
300
300
|
end
|
301
301
|
# If we don't want to change the owner, we look if we can_update
|
302
302
|
if target.owner == repo_item.owner && !can_update?(repo_item)
|
303
|
-
raise RepositoryManager::
|
303
|
+
raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to update the '#{repo_item.name}'")
|
304
304
|
end
|
305
305
|
# We check if we can_create in the source_folder
|
306
306
|
unless can_create?(target)
|
307
|
-
raise RepositoryManager::
|
307
|
+
raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to create in the source_folder '#{options[:source_folder].name}'")
|
308
308
|
end
|
309
309
|
else
|
310
310
|
# Else if there is no source_folder, we check if we can delete the repo_item, if the owner change
|
311
311
|
if self != repo_item.owner && !can_delete?(repo_item)
|
312
|
-
raise RepositoryManager::
|
312
|
+
raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
313
313
|
end
|
314
314
|
end
|
315
315
|
# If it has the permission, we move the repo_item in the source_folder
|
@@ -330,11 +330,11 @@ module RepositoryManager
|
|
330
330
|
# :sender => the new sender (by default => still the old sender)
|
331
331
|
def copy_repo_item!(repo_item, target = nil, options = {})
|
332
332
|
unless can_read?(repo_item)
|
333
|
-
raise RepositoryManager::
|
333
|
+
raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
|
334
334
|
end
|
335
335
|
|
336
336
|
if target && !can_create?(target)
|
337
|
-
raise RepositoryManager::
|
337
|
+
raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to create in the source_folder '#{target.name}'")
|
338
338
|
end
|
339
339
|
|
340
340
|
# The new owner
|
@@ -351,7 +351,7 @@ module RepositoryManager
|
|
351
351
|
def copy_repo_item(repo_item, target = nil, options = {})
|
352
352
|
begin
|
353
353
|
copy_repo_item!(repo_item, target, options)
|
354
|
-
rescue RepositoryManager::
|
354
|
+
rescue RepositoryManager::PermissionException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
355
355
|
false
|
356
356
|
end
|
357
357
|
end
|
@@ -361,41 +361,41 @@ module RepositoryManager
|
|
361
361
|
FileUtils.rm_rf(self.get_default_download_path())
|
362
362
|
end
|
363
363
|
|
364
|
-
#Return the
|
365
|
-
def
|
366
|
-
sharing.
|
364
|
+
#Return the permissions of the sharing (can_add, can_remove)
|
365
|
+
def get_sharing_permissions(sharing)
|
366
|
+
sharing.get_permissions(self)
|
367
367
|
end
|
368
368
|
|
369
369
|
# Return true if you can share the repo, else false
|
370
|
-
# You can give the
|
371
|
-
def can_share?(repo_item,
|
372
|
-
can_do?('share', repo_item,
|
370
|
+
# You can give the permissions or the repo_item as params
|
371
|
+
def can_share?(repo_item, permissions = nil)
|
372
|
+
can_do?('share', repo_item, permissions)
|
373
373
|
end
|
374
374
|
|
375
375
|
# Return true if you can read the repo, else false
|
376
|
-
def can_read?(repo_item,
|
377
|
-
can_do?('read', repo_item,
|
376
|
+
def can_read?(repo_item, permissions = nil)
|
377
|
+
can_do?('read', repo_item, permissions)
|
378
378
|
end
|
379
379
|
|
380
380
|
# Return true if you can download the repo, else false
|
381
381
|
# Read = Download for the moment
|
382
|
-
def can_download?(repo_item,
|
383
|
-
can_do?('read', repo_item,
|
382
|
+
def can_download?(repo_item, permissions = nil)
|
383
|
+
can_do?('read', repo_item, permissions)
|
384
384
|
end
|
385
385
|
|
386
386
|
# Return true if you can create in the repo, false else
|
387
|
-
def can_create?(repo_item,
|
388
|
-
can_do?('create', repo_item,
|
387
|
+
def can_create?(repo_item, permissions = nil)
|
388
|
+
can_do?('create', repo_item, permissions)
|
389
389
|
end
|
390
390
|
|
391
391
|
# Returns true if you can edit the repo, false else
|
392
|
-
def can_update?(repo_item,
|
393
|
-
can_do?('update', repo_item,
|
392
|
+
def can_update?(repo_item, permissions = nil)
|
393
|
+
can_do?('update', repo_item, permissions)
|
394
394
|
end
|
395
395
|
|
396
396
|
# Returns true if you can delete the repo, false else
|
397
|
-
def can_delete?(repo_item,
|
398
|
-
can_do?('delete', repo_item,
|
397
|
+
def can_delete?(repo_item, permissions = nil)
|
398
|
+
can_do?('delete', repo_item, permissions)
|
399
399
|
end
|
400
400
|
|
401
401
|
## Returns true if it exist a sharing in the ancestors of descendant_ids of the repo_item (without itself)
|
@@ -427,19 +427,19 @@ module RepositoryManager
|
|
427
427
|
# You can here add new members in the sharing
|
428
428
|
# Param member could be an object or an array of object
|
429
429
|
def add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions)
|
430
|
-
|
430
|
+
permissions = get_sharing_permissions(sharing)
|
431
431
|
if can_add_to?(sharing)
|
432
|
-
sharing_permissions = make_sharing_permissions(options,
|
432
|
+
sharing_permissions = make_sharing_permissions(options, permissions)
|
433
433
|
sharing.add_members(members, sharing_permissions)
|
434
434
|
else
|
435
|
-
raise RepositoryManager::
|
435
|
+
raise RepositoryManager::PermissionException.new("add members failed. You don't have the permission to add a member in this sharing")
|
436
436
|
end
|
437
437
|
end
|
438
438
|
|
439
439
|
def add_members_to(sharing, members, options = RepositoryManager.default_sharing_permissions)
|
440
440
|
begin
|
441
441
|
add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions)
|
442
|
-
rescue RepositoryManager::
|
442
|
+
rescue RepositoryManager::PermissionException
|
443
443
|
false
|
444
444
|
end
|
445
445
|
end
|
@@ -450,14 +450,14 @@ module RepositoryManager
|
|
450
450
|
if can_remove_from?(sharing)
|
451
451
|
sharing.remove_members(members)
|
452
452
|
else
|
453
|
-
raise RepositoryManager::
|
453
|
+
raise RepositoryManager::PermissionException.new("remove members failed. You don't have the permission to remove a member on this sharing")
|
454
454
|
end
|
455
455
|
end
|
456
456
|
|
457
457
|
def remove_members_from(sharing, members)
|
458
458
|
begin
|
459
459
|
remove_members_from!(sharing, members)
|
460
|
-
rescue RepositoryManager::
|
460
|
+
rescue RepositoryManager::PermissionException
|
461
461
|
false
|
462
462
|
end
|
463
463
|
end
|
@@ -475,53 +475,53 @@ module RepositoryManager
|
|
475
475
|
private
|
476
476
|
|
477
477
|
# Return if you can do or not this action in the sharing
|
478
|
-
def can_do_to?(what, sharing,
|
479
|
-
if
|
480
|
-
|
478
|
+
def can_do_to?(what, sharing, permissions = nil)
|
479
|
+
if permissions == nil
|
480
|
+
permissions = sharing.get_permissions(self)
|
481
481
|
end
|
482
482
|
case what
|
483
483
|
when 'add'
|
484
|
-
|
484
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_add] == true)
|
485
485
|
when 'remove'
|
486
|
-
|
486
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_remove] == true)
|
487
487
|
end
|
488
488
|
end
|
489
489
|
|
490
490
|
# reflexion: can_do?(what, options)
|
491
491
|
# options
|
492
|
-
# hash :
|
493
|
-
# class: RepoItem =>
|
492
|
+
# hash : permissions hash
|
493
|
+
# class: RepoItem => get_permissions
|
494
494
|
# class: has_repository => regarder si on peu déplacer dans root (question: non pas possible ?)
|
495
495
|
|
496
496
|
# Return if you can do or not this action (what)
|
497
|
-
def can_do?(what, repo_item,
|
498
|
-
# If we pass no
|
499
|
-
if
|
500
|
-
|
497
|
+
def can_do?(what, repo_item, permissions = nil)
|
498
|
+
# If we pass no permissions we have to get it
|
499
|
+
if permissions == nil
|
500
|
+
permissions = get_permissions(repo_item)
|
501
501
|
end
|
502
502
|
|
503
503
|
case what
|
504
504
|
when 'read'
|
505
|
-
|
505
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_read] == true)
|
506
506
|
when 'delete'
|
507
507
|
if RepositoryManager.accept_nested_sharing
|
508
508
|
# TODO implement to look if he can delete all the folder
|
509
509
|
else
|
510
|
-
|
510
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_delete] == true)
|
511
511
|
end
|
512
512
|
when 'update'
|
513
|
-
|
513
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_update] == true)
|
514
514
|
when 'share'
|
515
515
|
if RepositoryManager.accept_nested_sharing
|
516
516
|
# TODO implement to look if he can delete all the folder
|
517
517
|
else
|
518
|
-
|
518
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_share] == true)
|
519
519
|
end
|
520
520
|
when 'create'
|
521
521
|
if RepositoryManager.accept_nested_sharing
|
522
522
|
# TODO implement to look if he can delete all the folder
|
523
523
|
else
|
524
|
-
|
524
|
+
permissions == true || (permissions.kind_of?(Hash) && permissions[:can_create] == true)
|
525
525
|
end
|
526
526
|
else
|
527
527
|
false
|
@@ -529,41 +529,41 @@ module RepositoryManager
|
|
529
529
|
|
530
530
|
end
|
531
531
|
|
532
|
-
# Correct the repo_item_permissions with the
|
533
|
-
def make_repo_item_permissions(wanted_permissions,
|
532
|
+
# Correct the repo_item_permissions with the permissions
|
533
|
+
def make_repo_item_permissions(wanted_permissions, permissions)
|
534
534
|
# If it is an array, we have restriction in the permissions
|
535
|
-
if
|
535
|
+
if permissions.kind_of?(Hash) && wanted_permissions
|
536
536
|
# Built the sharing with the accepted permissions
|
537
537
|
# We remove the permission if we can't sharing it
|
538
|
-
if wanted_permissions[:can_read] == true &&
|
538
|
+
if wanted_permissions[:can_read] == true && permissions[:can_read] == false
|
539
539
|
wanted_permissions[:can_read] = false
|
540
540
|
end
|
541
|
-
if wanted_permissions[:can_create] == true &&
|
541
|
+
if wanted_permissions[:can_create] == true && permissions[:can_create] == false
|
542
542
|
wanted_permissions[:can_create] = false
|
543
543
|
end
|
544
|
-
if wanted_permissions[:can_update] == true &&
|
544
|
+
if wanted_permissions[:can_update] == true && permissions[:can_update] == false
|
545
545
|
wanted_permissions[:can_update] = false
|
546
546
|
end
|
547
|
-
if wanted_permissions[:can_delete] == true &&
|
547
|
+
if wanted_permissions[:can_delete] == true && permissions[:can_delete] == false
|
548
548
|
wanted_permissions[:can_delete] = false
|
549
549
|
end
|
550
|
-
if wanted_permissions[:can_share] == true &&
|
550
|
+
if wanted_permissions[:can_share] == true && permissions[:can_share] == false
|
551
551
|
wanted_permissions[:can_share] = false
|
552
552
|
end
|
553
553
|
end
|
554
554
|
return wanted_permissions
|
555
555
|
end
|
556
556
|
|
557
|
-
# Correct the sharing_permissions with the
|
558
|
-
def make_sharing_permissions(wanted_permissions,
|
557
|
+
# Correct the sharing_permissions with the permissions
|
558
|
+
def make_sharing_permissions(wanted_permissions, permissions)
|
559
559
|
# If it is an array, we have restriction in the permissions
|
560
|
-
if
|
560
|
+
if permissions.kind_of?(Hash) && wanted_permissions
|
561
561
|
# Built the sharing with the accepted permissions
|
562
562
|
# We remove the permission if we can't share it
|
563
|
-
if wanted_permissions[:can_add] == true &&
|
563
|
+
if wanted_permissions[:can_add] == true && permissions[:can_add] == false
|
564
564
|
wanted_permissions[:can_add] = false
|
565
565
|
end
|
566
|
-
if wanted_permissions[:can_remove] == true &&
|
566
|
+
if wanted_permissions[:can_remove] == true && permissions[:can_remove] == false
|
567
567
|
wanted_permissions[:can_remove] = false
|
568
568
|
end
|
569
569
|
end
|
data/repository-manager.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.email = ['texicitys@gmail.com']
|
12
12
|
s.homepage = 'https://github.com/Texicitys/repository-manager'
|
13
13
|
s.summary = "Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharings)."
|
14
|
-
s.description = "This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete
|
14
|
+
s.description = "This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete permissions management.
|
15
15
|
Each instance (users, groups, etc..) can have it own repositories (with files and folders). It can manage them easily (edit, remove, add, etc) and sharing them with other instance."
|
16
16
|
|
17
17
|
#s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/has_repository_spec.rb
CHANGED
@@ -73,7 +73,7 @@ describe 'HasRepository' do
|
|
73
73
|
|
74
74
|
# here user3 can share because he is the owner
|
75
75
|
@user3.share(rep, members)
|
76
|
-
# here user2 should can share because he has the
|
76
|
+
# here user2 should can share because he has the permission
|
77
77
|
members = []
|
78
78
|
members << @user1
|
79
79
|
@user2.share(rep, members)
|
@@ -95,7 +95,7 @@ describe 'HasRepository' do
|
|
95
95
|
|
96
96
|
# here user3 can share because he is the owner
|
97
97
|
@user3.share(rep, members, options)
|
98
|
-
# here user2 should can share because he has the
|
98
|
+
# here user2 should can share because he has the permission
|
99
99
|
members = []
|
100
100
|
members << @user1
|
101
101
|
@user2.share(rep, members)
|
@@ -117,8 +117,8 @@ describe 'HasRepository' do
|
|
117
117
|
|
118
118
|
# here user3 can share because he is the owner
|
119
119
|
@user3.share(rep, members, options)
|
120
|
-
# here user2 should can share because he has the
|
121
|
-
# But he has only the
|
120
|
+
# here user2 should can share because he has the permission
|
121
|
+
# But he has only the permission of read (can_read = true), He can't share with more permissions
|
122
122
|
members = []
|
123
123
|
members << @user1
|
124
124
|
#Here the permissions should be : :can_read => true, and all others false
|
@@ -146,8 +146,8 @@ describe 'HasRepository' do
|
|
146
146
|
|
147
147
|
# here user3 can share because he is the owner
|
148
148
|
@user3.share(rep, members, options)
|
149
|
-
# here user2 should can share because he has the
|
150
|
-
# But he has only the
|
149
|
+
# here user2 should can share because he has the permission
|
150
|
+
# But he has only the permission of read (can_read = true), He can't share with more permissions
|
151
151
|
members = []
|
152
152
|
members << @user1
|
153
153
|
|
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.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Baumann
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.0.0
|
111
111
|
description: |-
|
112
|
-
This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete
|
112
|
+
This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete permissions management.
|
113
113
|
Each instance (users, groups, etc..) can have it own repositories (with files and folders). It can manage them easily (edit, remove, add, etc) and sharing them with other instance.
|
114
114
|
email:
|
115
115
|
- texicitys@gmail.com
|