repository-manager 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -12
- data/lib/generators/repository_manager/install_generator.rb +6 -1
- data/lib/generators/repository_manager/templates/initializer.rb +13 -4
- data/lib/repository-manager.rb +6 -0
- data/lib/repository_manager/has_repository.rb +18 -8
- data/lib/repository_manager/version.rb +2 -2
- data/spec/has_repository_spec.rb +23 -23
- data/spec/models/share_spec.rb +8 -8
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
WORK
|
1
|
+
WORK IN PROGRESS, but it already works !
|
2
2
|
|
3
3
|
Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions).
|
4
4
|
|
@@ -74,7 +74,7 @@ end
|
|
74
74
|
|
75
75
|
### How can I create/delete a repository (file or folder)
|
76
76
|
|
77
|
-
You just have to call the
|
77
|
+
You just have to call the `has_repository` methods `create_file`, `create_folder`, or `delete_repository`.
|
78
78
|
|
79
79
|
```ruby
|
80
80
|
# user1 wants to create a folder in his repository
|
@@ -87,7 +87,7 @@ source_folder = user1.create_folder('Root folder')
|
|
87
87
|
|
88
88
|
# sourceFolder is the directory in wich user1 wants to create the folder 'The new folder'
|
89
89
|
name = 'The new folder'
|
90
|
-
the_folder = user1.create_folder(name,
|
90
|
+
the_folder = user1.create_folder(name, source_folder)
|
91
91
|
|
92
92
|
# user1 own repository :
|
93
93
|
# 'Root folder'
|
@@ -97,7 +97,7 @@ the_folder = user1.create_folder(name, sourceFolder)
|
|
97
97
|
# Note : user1 needs the ':can_create => true' permission in the folder : the_folder.
|
98
98
|
user1.create_file(params[:file], the_folder)
|
99
99
|
# OR
|
100
|
-
|
100
|
+
user1.create_file(File.open('somewhere'), the_folder)
|
101
101
|
|
102
102
|
# user1 own repository :
|
103
103
|
# 'Root folder'
|
@@ -129,7 +129,7 @@ user1.delete_repository(file2)
|
|
129
129
|
|
130
130
|
### How can I share a repository (file/folder)
|
131
131
|
|
132
|
-
Now, user1 want to share his folder 'The new folder' with a Group object et another User object.
|
132
|
+
Now, user1 want to share his folder 'The new folder' with a Group object et another User object. You can use the `has_repository` method `share(repository, to, options = nil)`.
|
133
133
|
|
134
134
|
```ruby
|
135
135
|
# user1 wants to share the_folder with group1 and user2
|
@@ -139,17 +139,24 @@ items = []
|
|
139
139
|
item << group1
|
140
140
|
items << user2
|
141
141
|
|
142
|
+
share = user1.share(the_folder, items)
|
143
|
+
|
144
|
+
|
145
|
+
# If you want to customize your share options, you can do it like this:
|
146
|
+
|
142
147
|
# Default shares permisions are : {can_add: false, can_remove: false}
|
143
148
|
share_permissions = {can_add: true, can_remove: true}
|
144
|
-
# Default reposiroty permissions are: {can_read:
|
145
|
-
repo_permissions = {can_read: true, can_create: true, can_update:true, can_delete:true, can_share: true}
|
149
|
+
# Default reposiroty permissions are: {can_read: true, can_create: false, can_update: false, can_delete: false, can_share: false}
|
150
|
+
repo_permissions = {can_read: true, can_create: true, can_update: true, can_delete: true, can_share: true}
|
151
|
+
|
152
|
+
options = {share_permissions: share_permissions, repo_permissions: repo_permissions}
|
146
153
|
|
147
|
-
share = user1.share(the_folder, items,
|
154
|
+
share = user1.share(the_folder, items, options)
|
148
155
|
```
|
149
156
|
|
150
157
|
`share_permissions` specifies if the item who receive the share can add or remove items in this share.
|
151
158
|
|
152
|
-
`repo_permissions` specifies what kind of permission do you give at this share. If all the params are false
|
159
|
+
`repo_permissions` specifies what kind of permission do you give at this share. If all the params are false, the share is useless, because the items have no more permissions in the repository selectionned.
|
153
160
|
|
154
161
|
See the chapter Authorisations for more details.
|
155
162
|
|
@@ -194,13 +201,13 @@ If it has the authorisation, an object can add items to a share.
|
|
194
201
|
# user1 want to add items to his share (the actions are done only if user1 has the ':can_add' permission)
|
195
202
|
user1.can_add_to?(share) # => true
|
196
203
|
|
197
|
-
|
204
|
+
options = {can_add: true, can_remove: false}
|
198
205
|
# Add items
|
199
206
|
items = []
|
200
207
|
items << user3
|
201
208
|
items << group2
|
202
209
|
...
|
203
|
-
|
210
|
+
user1.add_items_to(share, items, options)
|
204
211
|
|
205
212
|
# Here user3 and group2 can add items in this share, but they can't remove an item.
|
206
213
|
group2.can_add_to?(share) # => true
|
@@ -260,7 +267,7 @@ end
|
|
260
267
|
|
261
268
|
You can manage the permissions of an instance in a share. The owner of the share has all the permissions. The permissions are:
|
262
269
|
- can_add_to?(share) : The item can add a new instance in this share.
|
263
|
-
- can_remove_from(share) : Can remove an instance from this share.
|
270
|
+
- can_remove_from?(share) : Can remove an instance from this share.
|
264
271
|
|
265
272
|
To check if the object can add or remove an instance in the share, just write : `group1.can_add_to?(share)` or `group1.can_remove_from?(share)` (it returns `true` or `false`).
|
266
273
|
|
@@ -13,6 +13,10 @@ module RepositoryManager #:nodoc:
|
|
13
13
|
@prev_migration_nr.to_s
|
14
14
|
end
|
15
15
|
|
16
|
+
def create_initializer_file
|
17
|
+
template 'initializer.rb', 'config/initializers/repository_manager.rb'
|
18
|
+
end
|
19
|
+
|
16
20
|
# all public methods in here will be run in order
|
17
21
|
#def copy_initializer_file
|
18
22
|
# copy_file "initializer.rb", "config/initializers/repository_manager_initializer.rb"
|
@@ -20,7 +24,8 @@ module RepositoryManager #:nodoc:
|
|
20
24
|
|
21
25
|
def copy_migrations
|
22
26
|
migrations = [["20131018214212_create_repository_manager.rb","create_repository_manager.rb"],
|
23
|
-
["20131025085844_add_file_to_repositories.rb","add_file_to_repositories.rb"]
|
27
|
+
["20131025085844_add_file_to_repositories.rb","add_file_to_repositories.rb"],
|
28
|
+
["20131025085845_add_file_to_files", "add_file_to_files.rb"]
|
24
29
|
]
|
25
30
|
migrations.each do |migration|
|
26
31
|
migration_template "../../../../db/migrate/" + migration[0], "db/migrate/" + migration[1]
|
@@ -1,4 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
1
|
+
RepositoryManager.setup do |config|
|
2
|
+
|
3
|
+
# Default repository permissions that an object has on the repository after a share.
|
4
|
+
config.default_repo_permissions = { can_read: true, can_create: false, can_update:false, can_delete:false, can_share: false }
|
5
|
+
|
6
|
+
# Default share permissions thant an object has when he is added in a share.
|
7
|
+
config.default_share_permissions = { can_add: false, can_remove: false }
|
8
|
+
end
|
9
|
+
|
10
|
+
#Rails.application.configure do
|
11
|
+
# # Uncomment this to turn on verbose mode
|
12
|
+
# # config.my_gem.verbose = true
|
13
|
+
#end
|
data/lib/repository-manager.rb
CHANGED
@@ -2,6 +2,12 @@ require 'repository_manager/has_repository'
|
|
2
2
|
|
3
3
|
module RepositoryManager
|
4
4
|
|
5
|
+
mattr_accessor :default_repo_permissions
|
6
|
+
@@default_repo_permissions = { can_read: true, can_create: false, can_update:false, can_delete:false, can_share: false }
|
7
|
+
|
8
|
+
mattr_accessor :default_share_permissions
|
9
|
+
@@default_share_permissions = { can_add: false, can_remove: false }
|
10
|
+
|
5
11
|
class << self
|
6
12
|
def setup
|
7
13
|
yield self
|
@@ -28,22 +28,32 @@ module RepositoryManager
|
|
28
28
|
|
29
29
|
module LocalInstanceMethods
|
30
30
|
|
31
|
-
# Share the repository with the items, with the
|
32
|
-
# repo_permissions contains :
|
31
|
+
# Share the repository with the items, with the options
|
32
|
+
# options[:repo_permissions] contains :
|
33
33
|
# <tt>:can_read</tt> - Item can download the repository
|
34
34
|
# <tt>:can_create</tt> - Item can create a new repository on it
|
35
35
|
# <tt>:can_edit</tt> - Item can edit the repository
|
36
36
|
# <tt>:can_delete</tt> - Item can delete the repository
|
37
37
|
# <tt>:can_share</tt> - Item can share the repository
|
38
|
-
# share_permissions contains :
|
38
|
+
# options[:share_permissions] contains :
|
39
39
|
# <tt>:can_add</tt> - Specify if the item can add objects to the share
|
40
40
|
# <tt>:can_remove</tt> - Specify if the item can remove object to the share
|
41
|
-
def share(repository, items,
|
41
|
+
def share(repository, items, options = nil)
|
42
42
|
authorisations = get_authorisations(repository)
|
43
43
|
|
44
44
|
# Here we look if the instance has the authorisation for making a share
|
45
45
|
if can_share?(nil, authorisations)
|
46
46
|
|
47
|
+
# We put the default options
|
48
|
+
repo_permissions = RepositoryManager.default_repo_permissions
|
49
|
+
share_permissions = RepositoryManager.default_share_permissions
|
50
|
+
|
51
|
+
# If there is options, we have to take it
|
52
|
+
if options
|
53
|
+
repo_permissions = options[:repo_permissions] if options[:repo_permissions]
|
54
|
+
share_permissions = options[:share_permissions] if options[:share_permissions]
|
55
|
+
end
|
56
|
+
|
47
57
|
repo_permissions = make_repo_permissions(repo_permissions, authorisations)
|
48
58
|
|
49
59
|
share = Share.new(repo_permissions)
|
@@ -52,7 +62,7 @@ module RepositoryManager
|
|
52
62
|
share.add_items(items, share_permissions)
|
53
63
|
|
54
64
|
repository.shares << share
|
55
|
-
repository.save
|
65
|
+
repository.save
|
56
66
|
share
|
57
67
|
else
|
58
68
|
# No permission => No share
|
@@ -127,7 +137,7 @@ module RepositoryManager
|
|
127
137
|
# Return true if the entity can share this rep with all the authorisations
|
128
138
|
# Return an Array if the entity can share but with restriction
|
129
139
|
# Return true if the repository is nil (he as all authorisations on his own rep)
|
130
|
-
def get_authorisations(repository=nil)
|
140
|
+
def get_authorisations(repository = nil)
|
131
141
|
# If repository is nil, he can do what he want
|
132
142
|
return true if repository == nil
|
133
143
|
|
@@ -213,10 +223,10 @@ module RepositoryManager
|
|
213
223
|
|
214
224
|
# You can here add new items in the share
|
215
225
|
# Param item could be an object or an array of object
|
216
|
-
def add_items_to(share, items,
|
226
|
+
def add_items_to(share, items, options = nil)
|
217
227
|
authorisations = get_share_authorisations(share)
|
218
228
|
if can_add_to?(share)
|
219
|
-
share_permissions = make_share_permissions(
|
229
|
+
share_permissions = make_share_permissions(options, authorisations)
|
220
230
|
share.add_items(items, share_permissions)
|
221
231
|
else
|
222
232
|
return false
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RepositoryManager
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.7'
|
3
|
+
end
|
data/spec/has_repository_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'HasRepository' do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@user1 = FactoryGirl.create(:user)
|
@@ -99,10 +99,10 @@ describe "HasRepository" do
|
|
99
99
|
items << @user2
|
100
100
|
|
101
101
|
#Here user3 let user2 share this repo too
|
102
|
-
|
102
|
+
options = {repo_permissions: {can_share: true}}
|
103
103
|
|
104
104
|
# here user3 can share because he is the owner
|
105
|
-
@user3.share(rep, items,
|
105
|
+
@user3.share(rep, items, options)
|
106
106
|
# here user2 should can share because he has the authorisation
|
107
107
|
items = []
|
108
108
|
items << @user1
|
@@ -121,10 +121,10 @@ describe "HasRepository" do
|
|
121
121
|
items << @user2
|
122
122
|
|
123
123
|
#Here user3 let user2 share this repo too
|
124
|
-
|
124
|
+
options = {repo_permissions: {can_read: true, can_share: true}}
|
125
125
|
|
126
126
|
# here user3 can share because he is the owner
|
127
|
-
@user3.share(rep, items,
|
127
|
+
@user3.share(rep, items, options)
|
128
128
|
# here user2 should can share because he has the authorisation
|
129
129
|
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
130
130
|
items = []
|
@@ -134,9 +134,9 @@ describe "HasRepository" do
|
|
134
134
|
|
135
135
|
share_of_user_1 = @user1.shares.last
|
136
136
|
|
137
|
-
expect(share_of_user_1.can_read).to eq(false)
|
138
|
-
expect(share_of_user_1.can_update).to eq(false)
|
139
|
-
expect(share_of_user_1.can_share).to eq(false)
|
137
|
+
expect(share_of_user_1.can_read?).to eq(false)
|
138
|
+
expect(share_of_user_1.can_update?).to eq(false)
|
139
|
+
expect(share_of_user_1.can_share?).to eq(false)
|
140
140
|
#expect(@user1.shares.count).to eq(1)
|
141
141
|
#expect(@user2.shares_owners.count).to eq(1)
|
142
142
|
end
|
@@ -150,25 +150,25 @@ describe "HasRepository" do
|
|
150
150
|
items << @user2
|
151
151
|
|
152
152
|
#Here user3 let user2 share this repo too
|
153
|
-
|
153
|
+
options = {repo_permissions: {can_read: true, can_share: true}}
|
154
154
|
|
155
155
|
# here user3 can share because he is the owner
|
156
|
-
@user3.share(rep, items,
|
156
|
+
@user3.share(rep, items, options)
|
157
157
|
# here user2 should can share because he has the authorisation
|
158
158
|
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
159
159
|
items = []
|
160
160
|
items << @user1
|
161
161
|
|
162
|
-
|
162
|
+
options = {repo_permissions: {can_read: true, can_update: true, can_share: true}}
|
163
163
|
|
164
164
|
#Here the permissions should be : :can_read => true, :can_share => true and all others false
|
165
|
-
@user2.share(rep, items,
|
165
|
+
@user2.share(rep, items, options)
|
166
166
|
|
167
167
|
share_of_user_1 = @user1.shares.last
|
168
168
|
|
169
|
-
expect(share_of_user_1.can_read).to eq(true)
|
170
|
-
expect(share_of_user_1.can_update).to eq(false)
|
171
|
-
expect(share_of_user_1.can_share).to eq(true)
|
169
|
+
expect(share_of_user_1.can_read?).to eq(true)
|
170
|
+
expect(share_of_user_1.can_update?).to eq(false)
|
171
|
+
expect(share_of_user_1.can_share?).to eq(true)
|
172
172
|
#expect(@user1.shares.count).to eq(1)
|
173
173
|
#expect(@user2.shares_owners.count).to eq(1)
|
174
174
|
end
|
@@ -181,15 +181,15 @@ describe "HasRepository" do
|
|
181
181
|
items = []
|
182
182
|
items << @user2
|
183
183
|
|
184
|
-
|
184
|
+
options = {share_permissions: {can_add: true, can_remove: false}}
|
185
185
|
|
186
186
|
# here user3 can share because he is the owner
|
187
|
-
@user3.share(rep, items,
|
187
|
+
@user3.share(rep, items, options)
|
188
188
|
|
189
189
|
share_item_of_user_2 = @user2.shares_items.last
|
190
190
|
|
191
|
-
expect(share_item_of_user_2.can_add).to eq(true)
|
192
|
-
expect(share_item_of_user_2.can_remove).to eq(false)
|
191
|
+
expect(share_item_of_user_2.can_add?).to eq(true)
|
192
|
+
expect(share_item_of_user_2.can_remove?).to eq(false)
|
193
193
|
#expect(@user1.shares.count).to eq(1)
|
194
194
|
#expect(@user2.shares_owners.count).to eq(1)
|
195
195
|
end
|
@@ -206,11 +206,11 @@ describe "HasRepository" do
|
|
206
206
|
|
207
207
|
children.add_repository(file)
|
208
208
|
|
209
|
-
|
210
|
-
@user3.share(parent, @user1,
|
209
|
+
options = {repo_permissions: {can_read: true, can_update: true, can_share: false}}
|
210
|
+
@user3.share(parent, @user1, options)
|
211
211
|
|
212
|
-
|
213
|
-
@user3.share(children, @user1,
|
212
|
+
options = {repo_permissions: {can_read: true, can_update: true, can_share: true}}
|
213
|
+
@user3.share(children, @user1, options)
|
214
214
|
|
215
215
|
@user1.share(middle, @user2)
|
216
216
|
expect(@user2.shares.count).to eq(0)
|
data/spec/models/share_spec.rb
CHANGED
@@ -12,45 +12,45 @@ describe 'Share' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'can add a item in his own share' do
|
15
|
-
share = @user1.share(@user1_file, @user2,
|
15
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: false, can_remove: false}})
|
16
16
|
@user1.add_items_to(share, @user3)
|
17
17
|
expect(@user3.shared_repositories.count).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'can\'t add an item in a share without permission' do
|
21
|
-
share = @user1.share(@user1_file, @user2,
|
21
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: false, can_remove: false}})
|
22
22
|
@user2.add_items_to(share, @user3)
|
23
23
|
expect(@user3.shared_repositories.count).to eq(0)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'can add an item in a share with permission' do
|
27
|
-
share = @user1.share(@user1_file, @user2,
|
27
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: true, can_remove: false}})
|
28
28
|
@user2.add_items_to(share, @user3)
|
29
29
|
expect(@user3.shared_repositories.count).to eq(1)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'can remove an item in his own share' do
|
33
|
-
share = @user1.share(@user1_file, @user2,
|
33
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: false, can_remove: false}})
|
34
34
|
@user1.remove_items_from(share, @user2)
|
35
35
|
expect(@user2.shared_repositories.count).to eq(0)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'can remove an item in a share with permission' do
|
39
|
-
share = @user1.share(@user1_file, @user2,
|
39
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: false, can_remove: true}})
|
40
40
|
@user1.add_items_to(share, @user3)
|
41
41
|
@user2.remove_items_from(share, @user3)
|
42
42
|
expect(@user3.shared_repositories.count).to eq(0)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'can\'t remove an item in a share without permission' do
|
46
|
-
share = @user1.share(@user1_file, @user2,
|
46
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: false, can_remove: false}})
|
47
47
|
@user1.add_items_to(share, @user3)
|
48
48
|
@user2.remove_items_from(share, @user3)
|
49
49
|
expect(@user3.shared_repositories.count).to eq(1)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'can remove and add an array of items in a share with permission' do
|
53
|
-
share = @user1.share(@user1_file, @user2,
|
53
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: true, can_remove: true}})
|
54
54
|
user4 = FactoryGirl.create(:user)
|
55
55
|
@user2.add_items_to(share, [@user3, user4])
|
56
56
|
expect(user4.shared_repositories.count).to eq(1)
|
@@ -59,7 +59,7 @@ describe 'Share' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'can\'t add an items in a share with permission that he has not' do
|
62
|
-
share = @user1.share(@user1_file, @user2,
|
62
|
+
share = @user1.share(@user1_file, @user2, {share_permissions:{can_add: true, can_remove: false}})
|
63
63
|
@user2.add_items_to(share, @user3, {can_add:true, can_remove:true})
|
64
64
|
@user3.remove_items_from(share, @user2)
|
65
65
|
expect(@user2.shared_repositories.count).to eq(1)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repository-manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|