repository-manager 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/README.md +48 -30
- data/app/models/app_file.rb +18 -6
- data/app/models/folder.rb +48 -2
- data/app/models/share.rb +8 -8
- data/app/uploaders/repository_uploader.rb +4 -0
- data/db/migrate/20131025085845_add_file_to_files.rb +5 -0
- data/lib/repository_manager/has_repository.rb +65 -58
- data/lib/repository_manager/version.rb +1 -1
- data/repository-manager.gemspec +3 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131025085845_add_file_to_files.rb +5 -0
- data/spec/dummy/db/schema.rb +2 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/app_file.rb +1 -1
- data/spec/has_repository_spec.rb +8 -8
- data/spec/models/repository_spec.rb +33 -13
- data/spec/models/share_spec.rb +21 -21
- metadata +27 -9
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
repository-manager (0.0.
|
4
|
+
repository-manager (0.0.5)
|
5
5
|
ancestry
|
6
6
|
carrierwave
|
7
7
|
enumerize
|
8
8
|
rails (> 3.0.0)
|
9
|
+
rubyzip
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
@@ -90,6 +91,7 @@ GEM
|
|
90
91
|
rspec-core (~> 2.14.0)
|
91
92
|
rspec-expectations (~> 2.14.0)
|
92
93
|
rspec-mocks (~> 2.14.0)
|
94
|
+
rubyzip (0.9.9)
|
93
95
|
sprockets (2.10.0)
|
94
96
|
hike (~> 1.2)
|
95
97
|
multi_json (~> 1.0)
|
data/README.md
CHANGED
@@ -74,37 +74,37 @@ end
|
|
74
74
|
|
75
75
|
### How can I create/delete a repository (file or folder)
|
76
76
|
|
77
|
-
You just have to call the method `
|
77
|
+
You just have to call the method `create_file`, `create_folder`, or `delete_repository`.
|
78
78
|
|
79
79
|
```ruby
|
80
80
|
# user1 wants to create a folder in his repository
|
81
81
|
|
82
82
|
# Create a root folder on the user1 repository (you can have how many roots as you want)
|
83
|
-
|
83
|
+
source_folder = user1.create_folder('Root folder')
|
84
84
|
|
85
85
|
# user1 own repository :
|
86
86
|
# '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
|
-
|
90
|
+
the_folder = user1.create_folder(name, sourceFolder)
|
91
91
|
|
92
92
|
# user1 own repository :
|
93
93
|
# 'Root folder'
|
94
94
|
# 'The new folder'
|
95
95
|
|
96
|
-
# Now we want to add a file into
|
97
|
-
# Note : user1 needs the ':can_create => true' permission in the folder :
|
98
|
-
user1.
|
96
|
+
# Now we want to add a file into the_folder
|
97
|
+
# Note : user1 needs the ':can_create => true' permission in the folder : the_folder.
|
98
|
+
user1.create_file(params[:file], the_folder)
|
99
99
|
# OR
|
100
|
-
#user1.
|
100
|
+
#user1.create_file(File.open('somewhere'), the_folder)
|
101
101
|
|
102
102
|
# user1 own repository :
|
103
103
|
# 'Root folder'
|
104
104
|
# 'The new folder'
|
105
105
|
# 'file'
|
106
106
|
|
107
|
-
file2 = user1.
|
107
|
+
file2 = user1.create_file(params[:file2])
|
108
108
|
|
109
109
|
# user1 own repository :
|
110
110
|
# 'Root folder'
|
@@ -113,14 +113,14 @@ file2 = user1.createFile(params[:file2])
|
|
113
113
|
# 'file2'
|
114
114
|
|
115
115
|
# Delete a repository
|
116
|
-
# Note : user1 needs the ':can_delete => true' permission in the folder :
|
117
|
-
user1.
|
116
|
+
# Note : user1 needs the ':can_delete => true' permission in the folder : the_folder
|
117
|
+
user1.delete_repository(the_folder)
|
118
118
|
|
119
119
|
# user1 own repository :
|
120
120
|
# 'Root folder'
|
121
121
|
# 'file2'
|
122
122
|
|
123
|
-
user1.
|
123
|
+
user1.delete_repository(file2)
|
124
124
|
|
125
125
|
# user1 own repository :
|
126
126
|
# 'Root folder'
|
@@ -132,7 +132,7 @@ user1.deleteRepository(file2)
|
|
132
132
|
Now, user1 want to share his folder 'The new folder' with a Group object et another User object.
|
133
133
|
|
134
134
|
```ruby
|
135
|
-
# user1 wants to share
|
135
|
+
# user1 wants to share the_folder with group1 and user2
|
136
136
|
|
137
137
|
items = []
|
138
138
|
# You can add other instance (who has_repository) in this array to share with more than one instance
|
@@ -144,7 +144,7 @@ share_permissions = {can_add: true, can_remove: true}
|
|
144
144
|
# Default reposiroty permissions are: {can_read: false, can_create: false, can_update:false, can_delete:false, can_share: false}
|
145
145
|
repo_permissions = {can_read: true, can_create: true, can_update:true, can_delete:true, can_share: true}
|
146
146
|
|
147
|
-
share = user1.share(
|
147
|
+
share = user1.share(the_folder, items, repo_permissions, share_permissions)
|
148
148
|
```
|
149
149
|
|
150
150
|
`share_permissions` specifies if the item who receive the share can add or remove items in this share.
|
@@ -164,9 +164,27 @@ There is two king of repository:
|
|
164
164
|
user1.repositories.all # => You get the repository that user1 has created
|
165
165
|
|
166
166
|
# user2 want to get his shared repository
|
167
|
-
user2.
|
167
|
+
user2.shared_repositories.all
|
168
168
|
```
|
169
169
|
|
170
|
+
A repository can be:
|
171
|
+
- A file
|
172
|
+
- A folder
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
# We want to know if the object repository is a file or a folder:
|
176
|
+
if repository.type == 'Folder'
|
177
|
+
repository.name #=> Returns the name of the folder ('New folder').
|
178
|
+
elsif repository.type == 'AppFile'
|
179
|
+
repository.name #=> Returns the name of the file ('file.png').
|
180
|
+
# Here is the file
|
181
|
+
repository.file.url # => '/url/to/file.png'
|
182
|
+
repository.file.current_path # => 'path/to/file.png'
|
183
|
+
repository.file.identifier # => 'file.png'
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
|
170
188
|
### How can I manage a share
|
171
189
|
|
172
190
|
|
@@ -174,7 +192,7 @@ If it has the authorisation, an object can add items to a share.
|
|
174
192
|
|
175
193
|
```ruby
|
176
194
|
# user1 want to add items to his share (the actions are done only if user1 has the ':can_add' permission)
|
177
|
-
user1.
|
195
|
+
user1.can_add_to?(share) # => true
|
178
196
|
|
179
197
|
share_permissions = {can_add: true, can_remove: false}
|
180
198
|
# Add items
|
@@ -182,11 +200,11 @@ items = []
|
|
182
200
|
items << user3
|
183
201
|
items << group2
|
184
202
|
...
|
185
|
-
@user1.
|
203
|
+
@user1.add_items_to(share, items, share_permissions)
|
186
204
|
|
187
205
|
# Here user3 and group2 can add items in this share, but they can't remove an item.
|
188
|
-
group2.
|
189
|
-
group2.
|
206
|
+
group2.can_add_to?(share) # => true
|
207
|
+
group2.can_remove_from?(share) # => false
|
190
208
|
|
191
209
|
# If user2 add an item in the share, 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).
|
192
210
|
```
|
@@ -195,17 +213,17 @@ If it has the authorisation, an object can remove items from a share.
|
|
195
213
|
|
196
214
|
```ruby
|
197
215
|
# user1 want to remove group2 from this share
|
198
|
-
user1.
|
216
|
+
user1.remove_items_from(share, group2)
|
199
217
|
```
|
200
218
|
|
201
219
|
As admin, you can directly work with the share. Be carefull, there is NO authorisation verification !
|
202
220
|
|
203
221
|
```ruby
|
204
222
|
# Add an item to the share
|
205
|
-
share.
|
223
|
+
share.add_items(item, share_permissions)
|
206
224
|
|
207
225
|
# Delete items from the share
|
208
|
-
share.
|
226
|
+
share.remove_items(items)
|
209
227
|
```
|
210
228
|
|
211
229
|
### Authorisations
|
@@ -213,13 +231,13 @@ share.removeItems(items)
|
|
213
231
|
#### Repository authorisations
|
214
232
|
|
215
233
|
The owner of a repository (file or folder) has all the authorisations on it. When he share this repository, he can choose what authorisation he gives to the share. The authorisations are :
|
216
|
-
- can_read(repository) : The item can read (=download) this file/folder.
|
217
|
-
- can_create(repository) : Can create in the repository (if repository is nil (= root), always true).
|
218
|
-
- can_update(repository) : Can update a repository.
|
219
|
-
- can_delete(repository) : Can delete a repository.
|
220
|
-
- can_share(repository) : Can share a repository.
|
234
|
+
- can_read?(repository) : The item can read (=download) this file/folder.
|
235
|
+
- can_create?(repository) : Can create in the repository (if repository is nil (= root), always true).
|
236
|
+
- can_update?(repository) : Can update a repository.
|
237
|
+
- can_delete?(repository) : Can delete a repository.
|
238
|
+
- can_share?(repository) : Can share a repository.
|
221
239
|
|
222
|
-
To check if a user has one of this authorisation, you just have to write : `user1.can_read(repository)`, `user1.can_share(repository)`, etc (it returns `true` or `false`).
|
240
|
+
To check if a user has one of this authorisation, you just have to write : `user1.can_read?(repository)`, `user1.can_share?(repository)`, etc (it returns `true` or `false`).
|
223
241
|
|
224
242
|
NOTICE : An object who can share a repository, can't set new permissions that it doesn't have.
|
225
243
|
For instance, `user3` has a share of `repository1` with `:can_delete => false` and `:can_share => true`. He can share `repository1` with `user4`, but he can't put `:can_delete => true` in this new share.
|
@@ -241,10 +259,10 @@ end
|
|
241
259
|
#### Share permissions
|
242
260
|
|
243
261
|
You can manage the permissions of an instance in a share. The owner of the share has all the permissions. The permissions are:
|
244
|
-
-
|
245
|
-
-
|
262
|
+
- 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.
|
246
264
|
|
247
|
-
To check if the object can add or remove an instance in the share, just write : `group1.
|
265
|
+
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`).
|
248
266
|
|
249
267
|
Like the repository authorisations, you can get the share authorisations with : `group1.get_share_authorisations(share)`.
|
250
268
|
|
data/app/models/app_file.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
1
|
class AppFile < Repository
|
2
|
-
attr_accessible :
|
3
|
-
|
4
|
-
mount_uploader :name, RepositoryUploader
|
2
|
+
attr_accessible :file, :content_type, :file_size if RepositoryManager.protected_attributes?
|
5
3
|
|
4
|
+
validates :file, presence: true
|
5
|
+
mount_uploader :file, RepositoryUploader
|
6
6
|
before_save :update_asset_attributes
|
7
7
|
|
8
|
+
# Return the name of the file with his extension
|
9
|
+
def name
|
10
|
+
file.identifier
|
11
|
+
end
|
12
|
+
|
13
|
+
# Downloading this file
|
14
|
+
def download(object = nil)
|
15
|
+
path = file.path
|
16
|
+
#render status: :bad_request and return unless File.exist?(path)
|
17
|
+
#send_file(path)
|
18
|
+
end
|
19
|
+
|
8
20
|
private
|
9
21
|
|
10
22
|
def update_asset_attributes
|
11
|
-
if
|
12
|
-
self.content_type =
|
13
|
-
self.file_size =
|
23
|
+
if file.present? && file_changed?
|
24
|
+
self.content_type = file.file.content_type
|
25
|
+
self.file_size = file.file.size
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
data/app/models/folder.rb
CHANGED
@@ -1,8 +1,54 @@
|
|
1
1
|
class Folder < Repository
|
2
2
|
attr_accessible :name if RepositoryManager.protected_attributes?
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
validates :name, presence: true
|
5
|
+
|
6
|
+
# Add a repository in the folder.
|
7
|
+
def add_repository(repository)
|
6
8
|
repository.update_attribute :parent, self
|
7
9
|
end
|
10
|
+
|
11
|
+
# Download this folder (zip it first)
|
12
|
+
# If object = nil, it download all the folder
|
13
|
+
# if object is set, it download only the folder that the user can_read.
|
14
|
+
def download(object = nil)
|
15
|
+
# Get all the children
|
16
|
+
children = Repository.find(child_ids)
|
17
|
+
|
18
|
+
# The array that will contain all the children to zip
|
19
|
+
children_to_add = []
|
20
|
+
|
21
|
+
if children
|
22
|
+
# If we have an object, we have to look at his permissions
|
23
|
+
if object
|
24
|
+
# For all repositories, we check if the object has the permission to read it
|
25
|
+
children.each do |child|
|
26
|
+
# If he can read it, add to the array
|
27
|
+
children_to_add << child if object.can_read?(child)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# Simply add all
|
31
|
+
children_to_add = children
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# If something is in the array to add, we zip it
|
36
|
+
if children_to_add.length > 1
|
37
|
+
# We create the zip here
|
38
|
+
Zip::File.open("#{name}.zip", Zip::File::CREATE) do |zipfile|
|
39
|
+
children_to_add.each do |child|
|
40
|
+
# Two arguments:
|
41
|
+
# - The name of the file as it will appear in the archive
|
42
|
+
# - The original file, including the path to find it
|
43
|
+
zipfile.add(child.file.identifier, child.file.current_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
elsif children_to_add.length == 1
|
47
|
+
children_to_add.first.file.path
|
48
|
+
else
|
49
|
+
# Nothing to download here
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
8
54
|
end
|
data/app/models/share.rb
CHANGED
@@ -26,25 +26,25 @@ class Share < ActiveRecord::Base
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Add items to the share
|
29
|
-
def
|
29
|
+
def add_items(items, share_permissions = nil)
|
30
30
|
if items.kind_of?(Array)
|
31
31
|
# Add each item to this share
|
32
32
|
items.each do |i|
|
33
|
-
|
34
|
-
|
33
|
+
share_item = SharesItem.new(share_permissions)
|
34
|
+
share_item.item = i
|
35
35
|
# Add the shares items in the share
|
36
|
-
self.shares_items <<
|
36
|
+
self.shares_items << share_item
|
37
37
|
end
|
38
38
|
else
|
39
|
-
|
40
|
-
|
39
|
+
share_item = SharesItem.new(share_permissions)
|
40
|
+
share_item.item = items
|
41
41
|
# Add the shares items in the share
|
42
|
-
self.shares_items <<
|
42
|
+
self.shares_items << share_item
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
# Remove items to the share
|
47
|
-
def
|
47
|
+
def remove_items(items)
|
48
48
|
if items.kind_of?(Array)
|
49
49
|
# Add each item to this share
|
50
50
|
items.each do |item|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'carrierwave/processing/mime_types'
|
2
3
|
|
3
4
|
class RepositoryUploader < CarrierWave::Uploader::Base
|
5
|
+
include CarrierWave::MimeTypes
|
6
|
+
|
7
|
+
process :set_content_type
|
4
8
|
|
5
9
|
# Include RMagick or MiniMagick support:
|
6
10
|
# include CarrierWave::RMagick
|
@@ -14,16 +14,10 @@ module RepositoryManager
|
|
14
14
|
|
15
15
|
# The own repositories
|
16
16
|
has_many :repositories, as: :owner #, dependent: :destroy
|
17
|
+
# The share repositories
|
18
|
+
has_many :shared_repositories, through: :shares, source: :repository, class_name: 'Repository'
|
17
19
|
|
18
|
-
#
|
19
|
-
#if Rails::VERSION::MAJOR == 4
|
20
|
-
# has_many :shares_repositories, -> { where can_read: true }, as: :item, through: :shares_items, class_name: 'Repository'
|
21
|
-
#else
|
22
|
-
# Rails 3 does it this way
|
23
|
-
has_many :shares_repositories, through: :shares, source: :repository, class_name: 'Repository'
|
24
|
-
#end
|
25
|
-
|
26
|
-
#scope :all_repositories, -> { self.repositories.shares_repositories }
|
20
|
+
#scope :all_repositories, -> { self.repositories.shared_repositories }
|
27
21
|
|
28
22
|
#All repositories (own and shares)
|
29
23
|
#has_many :all_repositories
|
@@ -33,6 +27,7 @@ module RepositoryManager
|
|
33
27
|
end
|
34
28
|
|
35
29
|
module LocalInstanceMethods
|
30
|
+
|
36
31
|
# Share the repository with the items, with the repo_permissions
|
37
32
|
# repo_permissions contains :
|
38
33
|
# <tt>:can_read</tt> - Item can download the repository
|
@@ -47,14 +42,14 @@ module RepositoryManager
|
|
47
42
|
authorisations = get_authorisations(repository)
|
48
43
|
|
49
44
|
# Here we look if the instance has the authorisation for making a share
|
50
|
-
if can_share(nil, authorisations)
|
45
|
+
if can_share?(nil, authorisations)
|
51
46
|
|
52
47
|
repo_permissions = make_repo_permissions(repo_permissions, authorisations)
|
53
48
|
|
54
49
|
share = Share.new(repo_permissions)
|
55
50
|
share.owner = self
|
56
51
|
|
57
|
-
share.
|
52
|
+
share.add_items(items, share_permissions)
|
58
53
|
|
59
54
|
repository.shares << share
|
60
55
|
repository.save!
|
@@ -65,20 +60,20 @@ module RepositoryManager
|
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
68
|
-
# Create a folder with the name (name) in the directory (
|
63
|
+
# Create a folder with the name (name) in the directory (source_folder)
|
69
64
|
# Returns the object of the folder created if it is ok
|
70
65
|
# Returns false if the folder is not created (no authorisation)
|
71
|
-
def
|
66
|
+
def create_folder(name = 'New folder', source_folder = nil)
|
72
67
|
# If he want to create a folder in a directory, we have to check if he have the authorisation
|
73
|
-
if can_create(
|
68
|
+
if can_create?(source_folder)
|
74
69
|
|
75
70
|
folder = Folder.new(name: name)
|
76
71
|
folder.owner = self
|
77
72
|
folder.save
|
78
73
|
|
79
74
|
# If we want to create a folder in a folder, we have to check if we have the authorisation
|
80
|
-
if
|
81
|
-
|
75
|
+
if source_folder
|
76
|
+
source_folder.add_repository(folder)
|
82
77
|
end
|
83
78
|
|
84
79
|
return folder
|
@@ -88,40 +83,40 @@ module RepositoryManager
|
|
88
83
|
end
|
89
84
|
|
90
85
|
# Delete the repository
|
91
|
-
def
|
92
|
-
if can_delete(repository)
|
86
|
+
def delete_repository(repository)
|
87
|
+
if can_delete?(repository)
|
93
88
|
repository.destroy
|
94
89
|
else
|
95
90
|
return false
|
96
91
|
end
|
97
92
|
end
|
98
93
|
|
99
|
-
# Create the file (file) in the directory (
|
94
|
+
# Create the file (file) in the directory (source_folder)
|
100
95
|
# Param file can be a File, or a instance of AppFile
|
101
96
|
# Return the object of the file created if it is ok
|
102
97
|
# Return false if the file is not created (no authorisation)
|
103
|
-
def
|
98
|
+
def create_file(file, source_folder = nil)
|
104
99
|
# If he want to create a file in a directory, we have to check if he have the authorisation
|
105
|
-
if can_create(
|
100
|
+
if can_create?(source_folder)
|
106
101
|
if file.class.name == 'File'
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
102
|
+
app_file = AppFile.new
|
103
|
+
app_file.file = file
|
104
|
+
app_file.owner = self
|
105
|
+
app_file.save
|
111
106
|
elsif file.class.name == 'AppFile'
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
app_file = file
|
108
|
+
app_file.owner = self
|
109
|
+
app_file.save
|
115
110
|
else
|
116
111
|
return false
|
117
112
|
end
|
118
113
|
|
119
|
-
# Add the file into the
|
120
|
-
if
|
121
|
-
|
114
|
+
# Add the file into the source_folder
|
115
|
+
if source_folder
|
116
|
+
source_folder.add_repository(file)
|
122
117
|
end
|
123
118
|
|
124
|
-
return
|
119
|
+
return app_file
|
125
120
|
else
|
126
121
|
return false
|
127
122
|
end
|
@@ -134,7 +129,7 @@ module RepositoryManager
|
|
134
129
|
# Return true if the repository is nil (he as all authorisations on his own rep)
|
135
130
|
def get_authorisations(repository=nil)
|
136
131
|
# If repository is nil, he can do what he want
|
137
|
-
return true if repository==nil
|
132
|
+
return true if repository == nil
|
138
133
|
|
139
134
|
# If the item is the owner, he can do what he want !
|
140
135
|
if repository.owner == self
|
@@ -157,6 +152,18 @@ module RepositoryManager
|
|
157
152
|
return false
|
158
153
|
end
|
159
154
|
|
155
|
+
# Download a repository if the object can_read it
|
156
|
+
# If it is a file, he download the file
|
157
|
+
# If it is a folder, we check witch repository is in it, and witch he can_read
|
158
|
+
# We zip all the content that the object has access.
|
159
|
+
def download(repository)
|
160
|
+
if can_download?(repository)
|
161
|
+
repository.download(self)
|
162
|
+
else
|
163
|
+
false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
160
167
|
#Return the authorisations of the share (can_add, can_remove)
|
161
168
|
def get_share_authorisations(share)
|
162
169
|
share.get_authorisations(self)
|
@@ -164,53 +171,53 @@ module RepositoryManager
|
|
164
171
|
|
165
172
|
# Return true if you can share the repo, else false
|
166
173
|
# You can give the authorisations or the repository as params
|
167
|
-
def can_share(repository, authorisations = nil)
|
168
|
-
can_do('share', repository, authorisations)
|
174
|
+
def can_share?(repository, authorisations = nil)
|
175
|
+
can_do?('share', repository, authorisations)
|
169
176
|
end
|
170
177
|
|
171
178
|
# Return true if you can read the repo, else false
|
172
|
-
def can_read(repository, authorisations = nil)
|
173
|
-
can_do('read', repository, authorisations)
|
179
|
+
def can_read?(repository, authorisations = nil)
|
180
|
+
can_do?('read', repository, authorisations)
|
174
181
|
end
|
175
182
|
|
176
183
|
# Return true if you can download the repo, else false
|
177
184
|
# Read = Download for the moment
|
178
|
-
def can_download(repository, authorisations = nil)
|
179
|
-
can_do('read', repository, authorisations)
|
185
|
+
def can_download?(repository, authorisations = nil)
|
186
|
+
can_do?('read', repository, authorisations)
|
180
187
|
end
|
181
188
|
|
182
189
|
# Return true if you can create in the repo, false else
|
183
|
-
def can_create(repository, authorisations = nil)
|
184
|
-
can_do('create', repository, authorisations)
|
190
|
+
def can_create?(repository, authorisations = nil)
|
191
|
+
can_do?('create', repository, authorisations)
|
185
192
|
end
|
186
193
|
|
187
194
|
# Return true if you can edit the repo, false else
|
188
|
-
def can_update(repository, authorisations = nil)
|
189
|
-
can_do('update', repository, authorisations)
|
195
|
+
def can_update?(repository, authorisations = nil)
|
196
|
+
can_do?('update', repository, authorisations)
|
190
197
|
end
|
191
198
|
|
192
199
|
# Return true if you can delete the repo, false else
|
193
|
-
def can_delete(repository, authorisations = nil)
|
194
|
-
can_do('delete', repository, authorisations)
|
200
|
+
def can_delete?(repository, authorisations = nil)
|
201
|
+
can_do?('delete', repository, authorisations)
|
195
202
|
end
|
196
203
|
|
197
204
|
# Return true if you can add an item in this share, false else
|
198
|
-
def
|
199
|
-
|
205
|
+
def can_add_to?(share)
|
206
|
+
can_do_to?('add', share)
|
200
207
|
end
|
201
208
|
|
202
209
|
# Return true if you can remove an item in this share, false else
|
203
|
-
def
|
204
|
-
|
210
|
+
def can_remove_from?(share)
|
211
|
+
can_do_to?('remove', share)
|
205
212
|
end
|
206
213
|
|
207
214
|
# You can here add new items in the share
|
208
215
|
# Param item could be an object or an array of object
|
209
|
-
def
|
216
|
+
def add_items_to(share, items, share_permissions = nil)
|
210
217
|
authorisations = get_share_authorisations(share)
|
211
|
-
if
|
218
|
+
if can_add_to?(share)
|
212
219
|
share_permissions = make_share_permissions(share_permissions, authorisations)
|
213
|
-
share.
|
220
|
+
share.add_items(items, share_permissions)
|
214
221
|
else
|
215
222
|
return false
|
216
223
|
end
|
@@ -218,9 +225,9 @@ module RepositoryManager
|
|
218
225
|
|
219
226
|
# You can here add new items in the share
|
220
227
|
# Param item could be an object or an array of object
|
221
|
-
def
|
222
|
-
if
|
223
|
-
share.
|
228
|
+
def remove_items_from(share, items)
|
229
|
+
if can_remove_from?(share)
|
230
|
+
share.remove_items(items)
|
224
231
|
else
|
225
232
|
return false
|
226
233
|
end
|
@@ -229,8 +236,8 @@ module RepositoryManager
|
|
229
236
|
private
|
230
237
|
|
231
238
|
# Return if you can do or not this action in the share
|
232
|
-
def
|
233
|
-
if authorisations
|
239
|
+
def can_do_to?(what, share, authorisations = nil)
|
240
|
+
if authorisations == nil
|
234
241
|
authorisations = share.get_authorisations(self)
|
235
242
|
end
|
236
243
|
case what
|
@@ -242,7 +249,7 @@ module RepositoryManager
|
|
242
249
|
end
|
243
250
|
|
244
251
|
# Return if you can do or not this action (what)
|
245
|
-
def can_do(what, repository, authorisations = nil)
|
252
|
+
def can_do?(what, repository, authorisations = nil)
|
246
253
|
#If we pass no authorisations we have to get it
|
247
254
|
if authorisations === nil
|
248
255
|
authorisations = get_authorisations(repository)
|
data/repository-manager.gemspec
CHANGED
@@ -11,9 +11,8 @@ 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/shares)."
|
14
|
-
s.description = "This project is based on the need for a repository manager system for Collaide.
|
15
|
-
|
16
|
-
This gem is my informatics project for the Master in University of Lausanne (CH)."
|
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 share these repositories easily with other object with a flexible and complete authorisations management.
|
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 share them with other instance."
|
17
16
|
|
18
17
|
#s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
19
18
|
s.files = `git ls-files`.split("\n")
|
@@ -29,4 +28,5 @@ Gem::Specification.new do |s|
|
|
29
28
|
s.add_runtime_dependency 'ancestry'
|
30
29
|
s.add_runtime_dependency 'carrierwave'
|
31
30
|
s.add_runtime_dependency 'enumerize'
|
31
|
+
s.add_runtime_dependency 'rubyzip'
|
32
32
|
end
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20131025085845) do
|
15
15
|
|
16
16
|
create_table "groups", force: true do |t|
|
17
17
|
t.string "name"
|
@@ -33,6 +33,7 @@ ActiveRecord::Schema.define(version: 20131025085844) do
|
|
33
33
|
t.string "type"
|
34
34
|
t.float "file_size"
|
35
35
|
t.string "content_type"
|
36
|
+
t.string "file"
|
36
37
|
end
|
37
38
|
|
38
39
|
create_table "shares", force: true do |t|
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/factories/app_file.rb
CHANGED
data/spec/has_repository_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "HasRepository" do
|
|
14
14
|
|
15
15
|
it "should be associate with shares" do
|
16
16
|
share = Share.create
|
17
|
-
@user1.shares<<share
|
17
|
+
@user1.shares << share
|
18
18
|
expect(@user1.shares.last).to eq(share)
|
19
19
|
end
|
20
20
|
|
@@ -50,7 +50,7 @@ describe "HasRepository" do
|
|
50
50
|
expect(@user3.shares.count).to eq(1)
|
51
51
|
expect(@user1.shares_owners.count).to eq(1)
|
52
52
|
expect(@user2.repositories.count).to eq(0)
|
53
|
-
#expect(@user2.
|
53
|
+
#expect(@user2.shared_repositories.count).to eq(1)
|
54
54
|
|
55
55
|
#expect(@user2.shares_owners.count).to eq(0)
|
56
56
|
#expect(@user3.shares_owners.count).to eq(0)
|
@@ -197,14 +197,14 @@ describe "HasRepository" do
|
|
197
197
|
it 'can share a repository with ancestor share permissions' do
|
198
198
|
parent = FactoryGirl.create(:folder)
|
199
199
|
parent.owner = @user3
|
200
|
-
middle = @user3.
|
201
|
-
children = @user3.
|
200
|
+
middle = @user3.create_folder('Middle', parent)
|
201
|
+
children = @user3.create_folder('Children', middle)
|
202
202
|
|
203
203
|
file = FactoryGirl.build(:app_file)
|
204
204
|
file.owner = @user3
|
205
205
|
file.save
|
206
206
|
|
207
|
-
children.
|
207
|
+
children.add_repository(file)
|
208
208
|
|
209
209
|
repo_permissions = {can_read: true, can_update: true, can_share: false}
|
210
210
|
@user3.share(parent, @user1, repo_permissions)
|
@@ -219,15 +219,15 @@ describe "HasRepository" do
|
|
219
219
|
end
|
220
220
|
|
221
221
|
it "can create a folder" do
|
222
|
-
folder = @user1.
|
222
|
+
folder = @user1.create_folder('test folder')
|
223
223
|
#folder = @user1.repositories.last
|
224
224
|
expect(folder.name).to eq('test folder')
|
225
225
|
expect(folder.type).to eq('Folder')
|
226
226
|
end
|
227
227
|
|
228
228
|
it "can create a file" do
|
229
|
-
file = @user1.
|
230
|
-
expect(file.name
|
229
|
+
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
|
230
|
+
expect(file.name).to eq('textfile.txt')
|
231
231
|
expect(@user1.repositories.count).to eq(1)
|
232
232
|
end
|
233
233
|
|
@@ -14,13 +14,13 @@ describe 'Repository' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'can create a folder in it own folder' do
|
17
|
-
folder = @user1.
|
17
|
+
folder = @user1.create_folder('Folder1', @user1_folder)
|
18
18
|
|
19
19
|
expect(@user1_folder.has_children?).to eq(true)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'can\'t create a folder in another folder without permission' do
|
23
|
-
folder = @user2.
|
23
|
+
folder = @user2.create_folder('Folder1', @user1_folder)
|
24
24
|
|
25
25
|
expect(@user1_folder.has_children?).to eq(false)
|
26
26
|
expect(folder).to eq(false)
|
@@ -28,32 +28,32 @@ describe 'Repository' do
|
|
28
28
|
|
29
29
|
it 'can create a file into a folder' do
|
30
30
|
file = FactoryGirl.build(:app_file)
|
31
|
-
theFile = @user1.
|
31
|
+
theFile = @user1.create_file(file, @user1_folder)
|
32
32
|
|
33
33
|
expect(@user1_folder.has_children?).to eq(true)
|
34
34
|
expect(file).to eq(theFile)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'can\'t create a repo into a file' do
|
38
|
-
file = @user2.
|
38
|
+
file = @user2.create_folder('Folder1', @user1_file)
|
39
39
|
|
40
40
|
expect(@user1_file.has_children?).to eq(false)
|
41
41
|
expect(file).to eq(false)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can delete a file' do
|
45
|
-
@user1.
|
45
|
+
@user1.delete_repository(@user1_file)
|
46
46
|
expect(@user1.repositories.count).to eq(1)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'can delete a folder an his files' do
|
50
|
-
@user1_folder.
|
51
|
-
@user1.
|
50
|
+
@user1_folder.add_repository(@user1_file)
|
51
|
+
@user1.delete_repository(@user1_folder)
|
52
52
|
expect(@user1.repositories.count).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'can\'t delete a repository without permission' do
|
56
|
-
@user2.
|
56
|
+
@user2.delete_repository(@user1_file)
|
57
57
|
expect(@user1.repositories.count).to eq(2)
|
58
58
|
end
|
59
59
|
|
@@ -70,15 +70,35 @@ describe 'Repository' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'can return only the share repositories' do
|
73
|
-
#expect(@user2.
|
73
|
+
#expect(@user2.shared_repositories.count).to eq(0)
|
74
74
|
@user1.share(@user1_file, @user2)
|
75
|
-
expect(@user2.
|
75
|
+
expect(@user2.shared_repositories.count).to eq(1)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'can download a file' do
|
79
|
-
#expect(@user2.
|
80
|
-
|
81
|
-
#expect(@user2.
|
79
|
+
#expect(@user2.shared_repositories.count).to eq(0)
|
80
|
+
@user1_file.download
|
81
|
+
#expect(@user2.shared_repositories.count).to eq(1)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'user can download a file with permission' do
|
85
|
+
@user1.download(@user1_file)
|
86
|
+
#expect(@user2.shared_repositories.count).to eq(1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'user can\'t download a file without permission' do
|
90
|
+
path = @user2.download(@user1_file)
|
91
|
+
expect(path).to eq(false)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'download the file if there is just one in a folder (no zip)' do
|
95
|
+
@user1_folder.add_repository(@user1_file)
|
96
|
+
@user1.download(@user1_folder)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'user can download a folder' do
|
100
|
+
folder = @user1.create_folder('Folder1', @user1_folder)
|
101
|
+
|
82
102
|
end
|
83
103
|
|
84
104
|
end
|
data/spec/models/share_spec.rb
CHANGED
@@ -13,56 +13,56 @@ describe 'Share' do
|
|
13
13
|
|
14
14
|
it 'can add a item in his own share' do
|
15
15
|
share = @user1.share(@user1_file, @user2, nil, {can_add: false, can_remove: false})
|
16
|
-
@user1.
|
17
|
-
expect(@user3.
|
16
|
+
@user1.add_items_to(share, @user3)
|
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
21
|
share = @user1.share(@user1_file, @user2, nil, {can_add: false, can_remove: false})
|
22
|
-
@user2.
|
23
|
-
expect(@user3.
|
22
|
+
@user2.add_items_to(share, @user3)
|
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
27
|
share = @user1.share(@user1_file, @user2, nil, {can_add: true, can_remove: false})
|
28
|
-
@user2.
|
29
|
-
expect(@user3.
|
28
|
+
@user2.add_items_to(share, @user3)
|
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
33
|
share = @user1.share(@user1_file, @user2, nil, {can_add: false, can_remove: false})
|
34
|
-
@user1.
|
35
|
-
expect(@user2.
|
34
|
+
@user1.remove_items_from(share, @user2)
|
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
39
|
share = @user1.share(@user1_file, @user2, nil, {can_add: false, can_remove: true})
|
40
|
-
@user1.
|
41
|
-
@user2.
|
42
|
-
expect(@user3.
|
40
|
+
@user1.add_items_to(share, @user3)
|
41
|
+
@user2.remove_items_from(share, @user3)
|
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
46
|
share = @user1.share(@user1_file, @user2, nil, {can_add: false, can_remove: false})
|
47
|
-
@user1.
|
48
|
-
@user2.
|
49
|
-
expect(@user3.
|
47
|
+
@user1.add_items_to(share, @user3)
|
48
|
+
@user2.remove_items_from(share, @user3)
|
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
53
|
share = @user1.share(@user1_file, @user2, nil, {can_add: true, can_remove: true})
|
54
54
|
user4 = FactoryGirl.create(:user)
|
55
|
-
@user2.
|
56
|
-
expect(user4.
|
57
|
-
@user2.
|
58
|
-
expect(user4.
|
55
|
+
@user2.add_items_to(share, [@user3, user4])
|
56
|
+
expect(user4.shared_repositories.count).to eq(1)
|
57
|
+
@user2.remove_items_from(share, [@user3, user4])
|
58
|
+
expect(user4.shared_repositories.count).to eq(0)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'can\'t add an items in a share with permission that he has not' do
|
62
62
|
share = @user1.share(@user1_file, @user2, nil, {can_add: true, can_remove: false})
|
63
|
-
@user2.
|
64
|
-
@user3.
|
65
|
-
expect(@user2.
|
63
|
+
@user2.add_items_to(share, @user3, {can_add:true, can_remove:true})
|
64
|
+
@user3.remove_items_from(share, @user2)
|
65
|
+
expect(@user2.shared_repositories.count).to eq(1)
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
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.6
|
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-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,15 +123,30 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubyzip
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: ! 'This project is based on the need for a repository manager system
|
143
|
+
for Collaide. A system for easily create/delete files and folders in a repository.
|
144
|
+
For share these repositories easily with other object with a flexible and complete
|
145
|
+
authorisations management.
|
146
|
+
|
131
147
|
Each instance (users, groups, etc..) can have it own repositories (with files and
|
132
148
|
folders). It can manage them easily (edit, remove, add, etc) and share them with
|
133
|
-
other instance
|
134
|
-
Master in University of Lausanne (CH)."
|
149
|
+
other instance.'
|
135
150
|
email:
|
136
151
|
- texicitys@gmail.com
|
137
152
|
executables: []
|
@@ -153,6 +168,7 @@ files:
|
|
153
168
|
- app/uploaders/repository_uploader.rb
|
154
169
|
- db/migrate/20131018214212_create_repository_manager.rb
|
155
170
|
- db/migrate/20131025085844_add_file_to_repositories.rb
|
171
|
+
- db/migrate/20131025085845_add_file_to_files.rb
|
156
172
|
- lib/generators/repository_manager/install_generator.rb
|
157
173
|
- lib/generators/repository_manager/templates/initializer.rb
|
158
174
|
- lib/repository-manager.rb
|
@@ -194,6 +210,7 @@ files:
|
|
194
210
|
- spec/dummy/db/migrate/20131016194207_create_groups_users.rb
|
195
211
|
- spec/dummy/db/migrate/20131018214212_create_repository_manager.rb
|
196
212
|
- spec/dummy/db/migrate/20131025085844_add_file_to_repositories.rb
|
213
|
+
- spec/dummy/db/migrate/20131025085845_add_file_to_files.rb
|
197
214
|
- spec/dummy/db/schema.rb
|
198
215
|
- spec/dummy/db/test.sqlite3
|
199
216
|
- spec/dummy/log/.keep
|
@@ -271,6 +288,7 @@ test_files:
|
|
271
288
|
- spec/dummy/db/migrate/20131016194207_create_groups_users.rb
|
272
289
|
- spec/dummy/db/migrate/20131018214212_create_repository_manager.rb
|
273
290
|
- spec/dummy/db/migrate/20131025085844_add_file_to_repositories.rb
|
291
|
+
- spec/dummy/db/migrate/20131025085845_add_file_to_files.rb
|
274
292
|
- spec/dummy/db/schema.rb
|
275
293
|
- spec/dummy/db/test.sqlite3
|
276
294
|
- spec/dummy/log/.keep
|