repository-manager 0.1.16 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +8 -6
- data/app/models/repository_manager/repo_file.rb +36 -0
- data/app/models/repository_manager/repo_folder.rb +42 -0
- data/app/models/repository_manager/repo_item.rb +16 -51
- data/app/models/repository_manager/sharing.rb +9 -3
- data/lib/repository_manager/has_repository.rb +39 -46
- data/lib/repository_manager/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/has_repository_spec.rb +3 -4
- data/spec/models/repository_spec.rb +51 -5
- data/spec/models/share_spec.rb +1 -0
- 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: 5570145fdab6a68044c23360f2cda512bbff93da
|
4
|
+
data.tar.gz: 63ac568cef21b1e6e1c69f34ec14701a811e393b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa7875fc7c3cbcb7653af770e548eade784c6d10dc35bb6e86a8baffcd5c3764acf9133d3cf86386cb1fc98ae33a5ec7c757c4f88ea7723bbb52930bf05a208
|
7
|
+
data.tar.gz: 82b701bd769e352108cbcf7c25773d1e48ad0b7b068056c6f75f2956429f74cc238124b5182393f8af7228c626aba9f8c65e019f75fa278d81534ca8a8dd54d8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
repository-manager (0.1.
|
4
|
+
repository-manager (0.1.17)
|
5
5
|
ancestry
|
6
6
|
carrierwave (>= 0.5.8)
|
7
7
|
rails (> 3.0.0)
|
@@ -36,7 +36,7 @@ GEM
|
|
36
36
|
tzinfo (~> 0.3.37)
|
37
37
|
ancestry (2.0.0)
|
38
38
|
activerecord (>= 3.0.0)
|
39
|
-
arel (4.0.
|
39
|
+
arel (4.0.2)
|
40
40
|
atomic (1.1.14)
|
41
41
|
builder (3.1.4)
|
42
42
|
carrierwave (0.9.0)
|
data/README.md
CHANGED
@@ -273,9 +273,9 @@ children = @user1.create_folder('Children', nested)
|
|
273
273
|
|
274
274
|
@user1.share(nested, @user2)
|
275
275
|
|
276
|
-
nested.
|
277
|
-
parent.
|
278
|
-
children.
|
276
|
+
nested.can_be_shared_without_nesting? # Returns true (because `nested` is shared but there exist no nested sharing)
|
277
|
+
parent.can_be_shared_without_nesting? # Returns false (because there is a sharing on one of his descendants)
|
278
|
+
children.can_be_shared_without_nesting? # Returns false (because there is a sharing on one of his ancestors)
|
279
279
|
|
280
280
|
# Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
|
281
281
|
@user1.share(parent, @user2) # Returns false
|
@@ -382,7 +382,7 @@ sharing.add_members(member, {can_add: true, can_remove: false})
|
|
382
382
|
|
383
383
|
|
384
384
|
# Remove members from the sharing
|
385
|
-
sharing.remove_members(
|
385
|
+
sharing.remove_members([user2, group1])
|
386
386
|
```
|
387
387
|
|
388
388
|
### Authorisations
|
@@ -414,7 +414,7 @@ You can get all the authorisations of an `object` in a `repo_item` with this met
|
|
414
414
|
end
|
415
415
|
```
|
416
416
|
|
417
|
-
#### Sharing
|
417
|
+
#### Sharing authorisations
|
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.
|
@@ -456,7 +456,9 @@ the_folder.delete_zip
|
|
456
456
|
## TODO
|
457
457
|
|
458
458
|
- Do the rename file method
|
459
|
-
-
|
459
|
+
- Test the copy method
|
460
|
+
- Configure path to save files
|
461
|
+
- Write the methods : share_link.
|
460
462
|
- Snapshot the file if possible
|
461
463
|
- Versioning
|
462
464
|
- ...
|
@@ -19,6 +19,42 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem
|
|
19
19
|
path = file.path
|
20
20
|
end
|
21
21
|
|
22
|
+
# Copy itself into the source_folder
|
23
|
+
# options
|
24
|
+
# :source_folder = the folder in witch you copy this item
|
25
|
+
# :owner = the owner of the item
|
26
|
+
# :sender = the sender of the item (if you don't specify sender.. The sender is still the same)
|
27
|
+
def copy!(options = {})
|
28
|
+
new_item = RepositoryManager::RepoFile.new
|
29
|
+
new_item.file = File.open(self.file.current_path)
|
30
|
+
|
31
|
+
if options[:source_folder]
|
32
|
+
options[:source_folder].add!(new_item)
|
33
|
+
elsif options[:owner].repo_item_name_exist_in_root?(new_item.name)
|
34
|
+
raise RepositoryManager::RepositoryManagerException.new("copy failed. The repo_file '#{new_item.name}' already exist in root.")
|
35
|
+
end
|
36
|
+
|
37
|
+
options[:owner] ? new_item.owner = options[:owner] : new_item.owner = self.owner
|
38
|
+
if options[:sender]
|
39
|
+
new_item.sender = options[:sender]
|
40
|
+
#elsif options[:owner]
|
41
|
+
# new_item.sender = options[:owner]
|
42
|
+
else
|
43
|
+
new_item.sender = self.sender
|
44
|
+
end
|
45
|
+
|
46
|
+
new_item.save!
|
47
|
+
new_item
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy(options = {})
|
51
|
+
begin
|
52
|
+
copy!(options)
|
53
|
+
rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
22
58
|
private
|
23
59
|
|
24
60
|
def update_asset_attributes
|
@@ -47,6 +47,48 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
# Copy itself into the source_folder
|
51
|
+
# options
|
52
|
+
# :source_folder = the folder in witch you copy this item
|
53
|
+
# :owner = the owner of the item
|
54
|
+
# :sender = the sender of the item (if you don't specify sender.. The sender is still the same)
|
55
|
+
def copy!(options = {})
|
56
|
+
new_item = RepositoryManager::RepoFolder.new
|
57
|
+
new_item.name = self.name
|
58
|
+
|
59
|
+
if options[:source_folder]
|
60
|
+
options[:source_folder].add!(new_item)
|
61
|
+
elsif options[:owner].repo_item_name_exist_in_root?(new_item.name)
|
62
|
+
raise RepositoryManager::RepositoryManagerException.new("copy failed. The repo_folder '#{new_item.name}' already exist in root.")
|
63
|
+
end
|
64
|
+
|
65
|
+
options[:owner] ? new_item.owner = options[:owner] : new_item.owner = self.owner
|
66
|
+
if options[:sender]
|
67
|
+
new_item.sender = options[:sender]
|
68
|
+
#elsif options[:owner]
|
69
|
+
# new_item.sender = options[:owner]
|
70
|
+
else
|
71
|
+
new_item.sender = self.sender
|
72
|
+
end
|
73
|
+
|
74
|
+
new_item.save!
|
75
|
+
|
76
|
+
# Recursive method who copy all children.
|
77
|
+
children.each do |c|
|
78
|
+
c.copy!(source_folder: new_item, owner: options[:owner], sender: options[:sender])
|
79
|
+
end
|
80
|
+
|
81
|
+
new_item
|
82
|
+
end
|
83
|
+
|
84
|
+
def copy(options = {})
|
85
|
+
begin
|
86
|
+
copy!(options)
|
87
|
+
rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
88
|
+
false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
50
92
|
# Download this folder (zip it first)
|
51
93
|
# Return the path to the folder.zip
|
52
94
|
# options can have :
|
@@ -27,47 +27,11 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
|
|
27
27
|
scope :folders, where(type: 'RepositoryManager::RepoFolder')
|
28
28
|
end
|
29
29
|
|
30
|
-
#
|
30
|
+
# Move itself into the target or root
|
31
31
|
# options
|
32
32
|
# :source_folder = the folder in witch you copy this item
|
33
33
|
# :owner = the owner of the item
|
34
|
-
#
|
35
|
-
def copy!(options = {})
|
36
|
-
new_item = RepoItem.new
|
37
|
-
new_item.type = self.type
|
38
|
-
new_item.file = self.file
|
39
|
-
new_item.content_type = self.content_type
|
40
|
-
new_item.file_size = self.file_size
|
41
|
-
new_item.name = self.name
|
42
|
-
options[:owner] ? new_item.owner = options[:owner] : new_item.owner = self.owner
|
43
|
-
if options[:sender]
|
44
|
-
new_item.sender = options[:sender]
|
45
|
-
elsif options[:owner]
|
46
|
-
new_item.sender = options[:owner]
|
47
|
-
else
|
48
|
-
new_item.sender = self.sender
|
49
|
-
end
|
50
|
-
|
51
|
-
if options[:source_folder]
|
52
|
-
options[:source_folder].add!(new_item)
|
53
|
-
end
|
54
|
-
|
55
|
-
new_item.save!
|
56
|
-
new_item
|
57
|
-
end
|
58
|
-
|
59
|
-
def copy(options = {})
|
60
|
-
begin
|
61
|
-
copy!(options)
|
62
|
-
rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
63
|
-
false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Move itself into the source_folder or root
|
68
|
-
# options
|
69
|
-
# :source_folder => move into this source_folder
|
70
|
-
# :owner = the owner of the item
|
34
|
+
# If :source_folder = nil, move to the root (of same owner)
|
71
35
|
def move!(options = {})
|
72
36
|
# If we are in source_folder, we check if it's ok
|
73
37
|
if options[:source_folder]
|
@@ -77,18 +41,19 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
|
|
77
41
|
if options[:source_folder].name_exist_in_children?(self.name)
|
78
42
|
raise RepositoryManager::RepositoryManagerException.new("move failed. The repo_item '#{name}' already exist ine the folder '#{options[:source_folder].name}'")
|
79
43
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
raise RepositoryManager::RepositoryManagerException.new("move failed. The repo_item '#{name}' already exist ine the root")
|
85
|
-
elsif self.owner.repo_item_name_exist_in_root?(self.name)
|
86
|
-
raise RepositoryManager::RepositoryManagerException.new("move failed. The repo_item '#{name}' already exist ine the root")
|
87
|
-
end
|
88
|
-
end
|
44
|
+
# We are in root, we check if name exist in root
|
45
|
+
# We stay in the same owner
|
46
|
+
elsif self.owner.repo_item_name_exist_in_root?(self.name)
|
47
|
+
raise RepositoryManager::RepositoryManagerException.new("move failed. The repo_item '#{name}' already exist ine the root")
|
89
48
|
end
|
90
49
|
# here, all is ok
|
91
|
-
|
50
|
+
# We change the owner if another one is specify
|
51
|
+
if options[:owner]
|
52
|
+
self.owner = options[:owner]
|
53
|
+
elsif options[:source_folder]
|
54
|
+
self.owner = options[:source_folder].owner
|
55
|
+
end
|
56
|
+
# we update the tree with the new parent
|
92
57
|
self.update_attribute :parent, options[:source_folder]
|
93
58
|
self.save!
|
94
59
|
self
|
@@ -103,7 +68,7 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
|
|
103
68
|
end
|
104
69
|
|
105
70
|
# Returns true if it exist a sharing in the ancestors of descendant_ids of the repo_item (without itself)
|
106
|
-
def
|
71
|
+
def can_be_shared_without_nesting?
|
107
72
|
# An array with the ids of all ancestors and descendants
|
108
73
|
ancestor_and_descendant_ids = []
|
109
74
|
ancestor_and_descendant_ids << self.descendant_ids if self.is_folder? && !self.descendant_ids.empty?
|
@@ -111,9 +76,9 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
|
|
111
76
|
|
112
77
|
# If it exist a sharing, it returns true
|
113
78
|
if RepositoryManager::Sharing.where(repo_item_id: ancestor_and_descendant_ids).count > 0
|
114
|
-
true
|
115
|
-
else
|
116
79
|
false
|
80
|
+
else
|
81
|
+
true
|
117
82
|
end
|
118
83
|
end
|
119
84
|
|
@@ -15,9 +15,9 @@ class RepositoryManager::Sharing < ActiveRecord::Base
|
|
15
15
|
#scope :recipient, lambda { |recipient|
|
16
16
|
# joins(:receipts).where('receipts.receiver_id' => recipient.id,'receipts.receiver_type' => recipient.class.base_class.to_s)
|
17
17
|
#}
|
18
|
-
scope :members, lambda { |member|
|
19
|
-
|
20
|
-
}
|
18
|
+
#scope :members, lambda { |member|
|
19
|
+
# joins(:sharings_members).where('sharings_members.member_id' => member.id,'sharings_members.member_type' => member.class.base_class.to_s)
|
20
|
+
#}
|
21
21
|
|
22
22
|
# Return the authorisations of the sharing for the member
|
23
23
|
def get_authorisations(member)
|
@@ -36,12 +36,18 @@ class RepositoryManager::Sharing < ActiveRecord::Base
|
|
36
36
|
if members.kind_of?(Array)
|
37
37
|
# Add each member to this sharing
|
38
38
|
members.each do |i|
|
39
|
+
unless i.respond_to? :share # Check if this object "has_repository"
|
40
|
+
raise RepositoryManager::RepositoryManagerException.new("add members failed. The object passed into members should be a model who 'has_repository'")
|
41
|
+
end
|
39
42
|
sharing_member = RepositoryManager::SharingsMember.new(sharing_permissions)
|
40
43
|
sharing_member.member = i
|
41
44
|
# Add the sharings members in the sharing
|
42
45
|
self.sharings_members << sharing_member
|
43
46
|
end
|
44
47
|
else
|
48
|
+
unless members.respond_to? :share # Check if this object "has_repository"
|
49
|
+
raise RepositoryManager::RepositoryManagerException.new("add members failed. The object passed into members should be a model who 'has_repository'")
|
50
|
+
end
|
45
51
|
sharing_member = RepositoryManager::SharingsMember.new(sharing_permissions)
|
46
52
|
sharing_member.member = members
|
47
53
|
# Add the sharings members in the sharing
|
@@ -48,7 +48,7 @@ module RepositoryManager
|
|
48
48
|
# Nested sharing are not accepted
|
49
49
|
if !RepositoryManager.accept_nested_sharing
|
50
50
|
# Check if no other sharing exist in the path
|
51
|
-
|
51
|
+
unless repo_item.can_be_shared_without_nesting?
|
52
52
|
raise RepositoryManager::NestedSharingException.new("sharing failed. Another sharing already exist on the subtree or an ancestor of '#{repo_item.name}'")
|
53
53
|
end
|
54
54
|
end
|
@@ -286,78 +286,71 @@ module RepositoryManager
|
|
286
286
|
end
|
287
287
|
|
288
288
|
# Move the repo_item. If you let all options empty, the item is moving into the self.root
|
289
|
-
#
|
290
|
-
#
|
291
|
-
|
292
|
-
|
289
|
+
# target => move into this source_folder
|
290
|
+
# if target == nil, move to the root
|
291
|
+
def move_repo_item!(repo_item, target = nil)
|
292
|
+
if !can_read?(repo_item)
|
293
|
+
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
|
294
|
+
end
|
293
295
|
# If we want to change the owner we have to have the can_delete authorisation
|
294
|
-
if
|
296
|
+
if target
|
295
297
|
# If want to change the owner, we have to check if we have the authorisation
|
296
|
-
if
|
298
|
+
if target.owner != repo_item.owner && !can_delete?(repo_item)
|
297
299
|
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
298
300
|
end
|
299
301
|
# If we don't want to change the owner, we look if we can_update
|
300
|
-
if
|
302
|
+
if target.owner == repo_item.owner && !can_update?(repo_item)
|
301
303
|
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to update the '#{repo_item.name}'")
|
302
304
|
end
|
303
305
|
# We check if we can_create in the source_folder
|
304
|
-
unless can_create?(
|
306
|
+
unless can_create?(target)
|
305
307
|
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to create in the source_folder '#{options[:source_folder].name}'")
|
306
308
|
end
|
307
|
-
elsif options[:owner]
|
308
|
-
# elsif there is no source_folder, but a specify owner, we check if we can delete, if owner change
|
309
|
-
if options[:owner] != repo_item.owner && !can_delete?(repo_item)
|
310
|
-
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
311
|
-
end
|
312
|
-
# If we don't want to change the owner, we look if we can_update
|
313
|
-
if options[:owner] == repo_item.owner && !can_update?(repo_item)
|
314
|
-
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to update the '#{repo_item.name}'")
|
315
|
-
end
|
316
309
|
else
|
317
310
|
# Else if there is no source_folder, we check if we can delete the repo_item, if the owner change
|
318
311
|
if self != repo_item.owner && !can_delete?(repo_item)
|
319
312
|
raise RepositoryManager::AuthorisationException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
|
320
313
|
end
|
321
314
|
end
|
322
|
-
# We put the owner
|
323
|
-
if options[:source_folder]
|
324
|
-
owner = options[:source_folder].owner
|
325
|
-
elsif options[:owner]
|
326
|
-
owner = options[:owner].owner
|
327
|
-
else
|
328
|
-
owner = self
|
329
|
-
end
|
330
315
|
# If it has the permission, we move the repo_item in the source_folder
|
331
|
-
repo_item.move!(source_folder:
|
316
|
+
repo_item.move!(source_folder: target)
|
332
317
|
end
|
333
318
|
|
334
|
-
def move_repo_item(repo_item,
|
319
|
+
def move_repo_item(repo_item, target = nil)
|
335
320
|
begin
|
336
|
-
move_repo_item!(repo_item,
|
321
|
+
move_repo_item!(repo_item, target)
|
337
322
|
rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
338
323
|
false
|
339
324
|
end
|
340
325
|
end
|
341
326
|
|
342
|
-
# Copy the repo_item in the source_folder or in
|
327
|
+
# Copy the repo_item in the source_folder or in own root
|
328
|
+
# target => the folder in witch we want to copy the repo item
|
343
329
|
# options
|
344
|
-
# :
|
345
|
-
|
346
|
-
def copy_repo_item!(repo_item, options = {})
|
330
|
+
# :sender => the new sender (by default => still the old sender)
|
331
|
+
def copy_repo_item!(repo_item, target = nil, options = {})
|
347
332
|
unless can_read?(repo_item)
|
348
333
|
raise RepositoryManager::AuthorisationException.new("copy repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
|
349
334
|
end
|
350
335
|
|
351
|
-
if
|
352
|
-
raise RepositoryManager::AuthorisationException.new("copy repo_item failed. You don't have the permission to create in the source_folder '#{
|
336
|
+
if target && !can_create?(target)
|
337
|
+
raise RepositoryManager::AuthorisationException.new("copy repo_item failed. You don't have the permission to create in the source_folder '#{target.name}'")
|
353
338
|
end
|
339
|
+
|
340
|
+
# The new owner
|
341
|
+
if target
|
342
|
+
owner = target.owner
|
343
|
+
else
|
344
|
+
owner = self
|
345
|
+
end
|
346
|
+
|
354
347
|
# If it has the permission, we move the repo_item in the source_folder
|
355
|
-
repo_item.copy!(source_folder:
|
348
|
+
repo_item.copy!(source_folder: target, owner: owner, sender: options[:sender])
|
356
349
|
end
|
357
350
|
|
358
|
-
def copy_repo_item(repo_item, options = {})
|
351
|
+
def copy_repo_item(repo_item, target = nil, options = {})
|
359
352
|
begin
|
360
|
-
copy_repo_item!(repo_item, options)
|
353
|
+
copy_repo_item!(repo_item, target, options)
|
361
354
|
rescue RepositoryManager::AuthorisationException, RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
362
355
|
false
|
363
356
|
end
|
@@ -451,7 +444,7 @@ module RepositoryManager
|
|
451
444
|
end
|
452
445
|
end
|
453
446
|
|
454
|
-
|
447
|
+
# You can here remove members in the sharing
|
455
448
|
# Param member could be an object or an array of object
|
456
449
|
def remove_members_from!(sharing, members)
|
457
450
|
if can_remove_from?(sharing)
|
@@ -476,13 +469,7 @@ module RepositoryManager
|
|
476
469
|
|
477
470
|
# Returns true of false if the name exist in the root path of this instance
|
478
471
|
def repo_item_name_exist_in_root?(name)
|
479
|
-
# add : or file : name
|
480
|
-
#RepoItem.where(name: name).where(owner: self).where(ancestry: nil).first ? true : false
|
481
|
-
#puts RepoItem.where('name = ? OR file = ?', name, name).where(owner: self).where(ancestry: nil).first.inspect
|
482
|
-
#puts self.inspect
|
483
|
-
|
484
472
|
RepoItem.where('name = ? OR file = ?', name, name).where(owner: self).where(ancestry: nil).first ? true : false
|
485
|
-
|
486
473
|
end
|
487
474
|
|
488
475
|
private
|
@@ -500,6 +487,12 @@ module RepositoryManager
|
|
500
487
|
end
|
501
488
|
end
|
502
489
|
|
490
|
+
# reflexion: can_do?(what, options)
|
491
|
+
# options
|
492
|
+
# hash : authorisations hash
|
493
|
+
# class: RepoItem => get_authorisations
|
494
|
+
# class: has_repository => regarder si on peu déplacer dans root (question: non pas possible ?)
|
495
|
+
|
503
496
|
# Return if you can do or not this action (what)
|
504
497
|
def can_do?(what, repo_item, authorisations = nil)
|
505
498
|
# If we pass no authorisations we have to get it
|
@@ -612,4 +605,4 @@ module RepositoryManager
|
|
612
605
|
end
|
613
606
|
end
|
614
607
|
|
615
|
-
ActiveRecord::Base.send :include, RepositoryManager::HasRepository
|
608
|
+
ActiveRecord::Base.send :include, RepositoryManager::HasRepository
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/has_repository_spec.rb
CHANGED
@@ -18,7 +18,6 @@ describe 'HasRepository' do
|
|
18
18
|
expect(@user2.sharings.last).to eq(sharing)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
it 'can share his own repo_item with other users' do
|
23
22
|
rep = FactoryGirl.build(:rm_repo_file)
|
24
23
|
rep.owner = @user1
|
@@ -224,9 +223,9 @@ describe 'HasRepository' do
|
|
224
223
|
|
225
224
|
@user1.share(nested, @user2)
|
226
225
|
|
227
|
-
expect(nested.
|
228
|
-
expect(parent.
|
229
|
-
expect(parent.
|
226
|
+
expect(nested.can_be_shared_without_nesting?).to eq(true) # Returns true (because `nested` is shared but there is no nested sharing)
|
227
|
+
expect(parent.can_be_shared_without_nesting?).to eq(false) # Returns false (because there is a sharing on one of his descendants)
|
228
|
+
expect(parent.can_be_shared_without_nesting?).to eq(false) # Returns false (because there is a sharing on one of his ancestors)
|
230
229
|
|
231
230
|
# Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
|
232
231
|
expect(@user1.share(parent, @user2)).to eq(false) # Returns false
|
@@ -143,6 +143,24 @@ describe 'RepoItem' do
|
|
143
143
|
@user2.delete_download_path()
|
144
144
|
end
|
145
145
|
|
146
|
+
it 'can copy a hard folder (nested folders and files)' do
|
147
|
+
nested = @user2.create_folder!('a')
|
148
|
+
a = @user2.create_folder!('a', source_folder: nested)
|
149
|
+
b = @user2.create_folder!('b', source_folder: a)
|
150
|
+
c = @user2.create_folder!('c', source_folder: b)
|
151
|
+
d = @user2.create_folder!('a', source_folder: c)
|
152
|
+
e = @user2.create_folder!('a', source_folder: d)
|
153
|
+
|
154
|
+
file = FactoryGirl.build(:rm_repo_file)
|
155
|
+
#@user2.create_file!(file, source_folder: a)
|
156
|
+
#@user2.create_file!(file, source_folder: nested)
|
157
|
+
@user2.create_file!(file, source_folder: c)
|
158
|
+
@user2.share!(nested, @user1, repo_item_permissions: {can_read: true})
|
159
|
+
copy = @user1.copy_repo_item!(nested)
|
160
|
+
@user1.download(copy)
|
161
|
+
@user1.delete_download_path()
|
162
|
+
end
|
163
|
+
|
146
164
|
it 'can\'t add a repo_item with the same name in a folder' do
|
147
165
|
root_folder = @user1.create_folder('Root folder')
|
148
166
|
root_folder.add(@user1_folder)
|
@@ -151,7 +169,7 @@ describe 'RepoItem' do
|
|
151
169
|
test_folder = @user1.create_folder('Test folder', source_folder: root_test_folder)
|
152
170
|
@user1.create_folder('Nested test folder', source_folder: test_folder)
|
153
171
|
|
154
|
-
@user1.move_repo_item(test_folder,
|
172
|
+
@user1.move_repo_item(test_folder, @user1_folder)
|
155
173
|
|
156
174
|
expect(test_folder.parent_id).to eq(@user1_folder.id)
|
157
175
|
end
|
@@ -244,15 +262,15 @@ describe 'RepoItem' do
|
|
244
262
|
file = @user2.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
|
245
263
|
folder = @user2.create_folder('folder')
|
246
264
|
|
247
|
-
@user2.move_repo_item!(file,
|
265
|
+
@user2.move_repo_item!(file, folder)
|
248
266
|
|
249
267
|
expect(folder.children).to eq([file])
|
250
268
|
end
|
251
269
|
|
252
|
-
it "can move a folder
|
270
|
+
it "can move a folder into a folder" do
|
253
271
|
folder = @user2.create_folder('folder')
|
254
272
|
folder2 = @user2.create_folder('folder2')
|
255
|
-
@user2.move_repo_item!(folder,
|
273
|
+
@user2.move_repo_item!(folder, folder2)
|
256
274
|
|
257
275
|
expect(folder2.children).to eq([folder])
|
258
276
|
end
|
@@ -261,7 +279,35 @@ describe 'RepoItem' do
|
|
261
279
|
file = @user2.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
|
262
280
|
folder = @user2.create_folder('folder')
|
263
281
|
|
264
|
-
expect(@user2.move_repo_item
|
282
|
+
expect(@user2.move_repo_item(folder, file)).to eq(false)
|
283
|
+
end
|
284
|
+
|
285
|
+
it "move_repo_item default to the root of the self owner" do
|
286
|
+
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
|
287
|
+
|
288
|
+
@user1.delete_repo_item!(@user1_file)
|
289
|
+
#expect(@user1.root_repo_items.count).to eq(1)
|
290
|
+
@user1.move_repo_item!(file)
|
291
|
+
expect(@user1.root_repo_items.count).to eq(2)
|
292
|
+
end
|
293
|
+
|
294
|
+
it "move_repo_item can't move a file into a root if file already exist" do
|
295
|
+
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
|
296
|
+
expect(@user1.move_repo_item(file)).to eq(false)
|
265
297
|
end
|
266
298
|
|
299
|
+
it "move_repo_item can't move if no permission" do
|
300
|
+
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
|
301
|
+
expect(@user2.move_repo_item(file)).to eq(false)
|
302
|
+
end
|
303
|
+
|
304
|
+
it "can't copy a file withour permission" do
|
305
|
+
expect(@user2.copy_repo_item(@user1_file)).to eq(false)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "can copy a file with read permission" do
|
309
|
+
@user1.share(@user1_file, @user2, repo_item_permissions: {can_read:true})
|
310
|
+
@user2.copy_repo_item(@user1_file)
|
311
|
+
expect(@user2.root_repo_items.count).to eq(1)
|
312
|
+
end
|
267
313
|
end
|
data/spec/models/share_spec.rb
CHANGED
@@ -35,6 +35,7 @@ describe 'Sharing' do
|
|
35
35
|
expect(@user2.shared_repo_items.count).to eq(0)
|
36
36
|
end
|
37
37
|
|
38
|
+
|
38
39
|
it 'can remove a member in a sharing with permission' do
|
39
40
|
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: true}})
|
40
41
|
@user1.add_members_to(sharing, @user3)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repository-manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Baumann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|