repository-manager 0.0.7 → 0.0.8
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.
- data/Gemfile.lock +9 -12
- data/README.md +152 -115
- data/app/models/{app_file.rb → repo_file.rb} +3 -3
- data/app/models/repo_folder.rb +60 -0
- data/app/models/{repository.rb → repo_item.rb} +10 -10
- data/app/models/sharing.rb +58 -0
- data/app/models/sharings_member.rb +6 -0
- data/app/uploaders/{repository_uploader.rb → repo_file_uploader.rb} +1 -1
- data/db/migrate/20131018214212_create_repository_manager.rb +9 -17
- data/lib/generators/repository_manager/install_generator.rb +1 -3
- data/lib/generators/repository_manager/templates/initializer.rb +5 -10
- data/lib/repository-manager.rb +4 -4
- data/lib/repository_manager/engine.rb +0 -1
- data/lib/repository_manager/has_repository.rb +140 -129
- data/lib/repository_manager/version.rb +1 -1
- data/repository-manager.gemspec +4 -5
- data/spec/dummy/config/locales/en.yml +1 -8
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131016193722_create_users.rb +11 -11
- data/spec/dummy/db/migrate/20131016193834_create_groups.rb +10 -10
- data/spec/dummy/db/migrate/20131016194207_create_groups_users.rb +5 -5
- data/spec/dummy/db/migrate/20131018214212_create_repository_manager.rb +9 -17
- data/spec/dummy/db/schema.rb +16 -16
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/{app_file.rb → repo_file.rb} +1 -1
- data/spec/factories/{folder.rb → repo_folder.rb} +1 -1
- data/spec/has_repository_spec.rb +107 -107
- data/spec/models/associations_spec.rb +45 -45
- data/spec/models/repository_spec.rb +51 -27
- data/spec/models/share_spec.rb +39 -39
- metadata +15 -37
- data/app/models/folder.rb +0 -54
- data/app/models/share.rb +0 -58
- data/app/models/shares_item.rb +0 -10
- data/db/migrate/20131025085844_add_file_to_repositories.rb +0 -8
- data/db/migrate/20131025085845_add_file_to_files.rb +0 -5
- data/spec/dummy/db/migrate/20131025085844_add_file_to_repositories.rb +0 -8
- data/spec/dummy/db/migrate/20131025085845_add_file_to_files.rb +0 -5
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RepoItem' do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@user1 = FactoryGirl.create(:user)
|
7
7
|
@user2 = FactoryGirl.create(:user)
|
8
|
-
@user1_file = FactoryGirl.build(:
|
8
|
+
@user1_file = FactoryGirl.build(:repo_file)
|
9
9
|
@user1_file.owner = @user1
|
10
|
-
@user1_folder = FactoryGirl.build(:
|
10
|
+
@user1_folder = FactoryGirl.build(:repo_folder)
|
11
11
|
@user1_folder.owner = @user1
|
12
12
|
@user1_folder.save
|
13
13
|
@user1_file.save
|
@@ -27,7 +27,7 @@ describe 'Repository' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'can create a file into a folder' do
|
30
|
-
file = FactoryGirl.build(:
|
30
|
+
file = FactoryGirl.build(:repo_file)
|
31
31
|
theFile = @user1.create_file(file, @user1_folder)
|
32
32
|
|
33
33
|
expect(@user1_folder.has_children?).to eq(true)
|
@@ -42,48 +42,48 @@ describe 'Repository' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can delete a file' do
|
45
|
-
@user1.
|
46
|
-
expect(@user1.
|
45
|
+
@user1.delete_repo_item(@user1_file)
|
46
|
+
expect(@user1.repo_items.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.
|
52
|
-
expect(@user1.
|
50
|
+
@user1_folder.add(@user1_file)
|
51
|
+
@user1.delete_repo_item(@user1_folder)
|
52
|
+
expect(@user1.repo_items.count).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
|
-
it 'can\'t delete a
|
56
|
-
@user2.
|
57
|
-
expect(@user1.
|
55
|
+
it 'can\'t delete a repo_item without permission' do
|
56
|
+
@user2.delete_repo_item(@user1_file)
|
57
|
+
expect(@user1.repo_items.count).to eq(2)
|
58
58
|
end
|
59
59
|
|
60
|
-
it 'return all the own
|
61
|
-
expect(@user1.
|
60
|
+
it 'return all the own repo_items' do
|
61
|
+
expect(@user1.repo_items.count()).to eq(2)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'return only the own files' do
|
65
|
-
expect(@user1.
|
65
|
+
expect(@user1.repo_items.files.count()).to eq(1)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'return only the own folders' do
|
69
|
-
expect(@user1.
|
69
|
+
expect(@user1.repo_items.folders.count()).to eq(1)
|
70
70
|
end
|
71
71
|
|
72
|
-
it 'can return only the
|
73
|
-
#expect(@user2.
|
72
|
+
it 'can return only the sharing repo_items' do
|
73
|
+
#expect(@user2.shared_repo_items.count).to eq(0)
|
74
74
|
@user1.share(@user1_file, @user2)
|
75
|
-
expect(@user2.
|
75
|
+
expect(@user2.shared_repo_items.count).to eq(1)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'can download a file' do
|
79
|
-
#expect(@user2.
|
79
|
+
#expect(@user2.shared_repo_items.count).to eq(0)
|
80
80
|
@user1_file.download
|
81
|
-
#expect(@user2.
|
81
|
+
#expect(@user2.shared_repo_items.count).to eq(1)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'user can download a file with permission' do
|
85
85
|
@user1.download(@user1_file)
|
86
|
-
#expect(@user2.
|
86
|
+
#expect(@user2.shared_repo_items.count).to eq(1)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'user can\'t download a file without permission' do
|
@@ -91,14 +91,38 @@ describe 'Repository' do
|
|
91
91
|
expect(path).to eq(false)
|
92
92
|
end
|
93
93
|
|
94
|
-
it 'download the file if there is just one in a folder (no zip)' do
|
95
|
-
|
96
|
-
|
97
|
-
end
|
94
|
+
#it 'download the file if there is just one in a folder (no zip)' do
|
95
|
+
# @user1_folder.add(@user1_file)
|
96
|
+
# @user1.download(@user1_folder)
|
97
|
+
#end
|
98
98
|
|
99
|
-
it 'user can download a folder' do
|
99
|
+
it 'user can download a folder with nested folder (zip)' do
|
100
100
|
folder = @user1.create_folder('Folder1', @user1_folder)
|
101
|
+
folder2 = @user1.create_folder('Folder2', folder)
|
102
|
+
@user1.create_file(@user1_file, folder)
|
103
|
+
|
104
|
+
user1_file2 = FactoryGirl.build(:repo_file)
|
105
|
+
user1_file2.owner = @user1
|
106
|
+
user1_file2.save
|
107
|
+
@user1.create_file(user1_file2, folder2)
|
108
|
+
|
109
|
+
user1_file3 = FactoryGirl.build(:repo_file)
|
110
|
+
user1_file3.owner = @user1
|
111
|
+
user1_file3.save
|
112
|
+
@user1.create_file(user1_file3, @user1_folder)
|
113
|
+
|
101
114
|
|
115
|
+
pp @user1.download(@user1_folder)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'can\'t add a repo_item with the same name in a folder' do
|
119
|
+
folder = @user1.create_folder('Folder1', @user1_folder)
|
120
|
+
expect(@user1.repo_items.count).to eq(3)
|
121
|
+
folder2 = @user1.create_folder('Folder1', @user1_folder)
|
122
|
+
expect(folder2).to eq(false)
|
123
|
+
expect(@user1.repo_items.count).to eq(3)
|
124
|
+
folder3 = @user1.create_folder('Folder2', @user1_folder)
|
125
|
+
expect(@user1.repo_items.count).to eq(4)
|
102
126
|
end
|
103
127
|
|
104
128
|
end
|
data/spec/models/share_spec.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'Sharing' do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@user1 = FactoryGirl.create(:user)
|
7
7
|
@user2 = FactoryGirl.create(:user)
|
8
8
|
@user3 = FactoryGirl.create(:user)
|
9
|
-
@user1_file = FactoryGirl.build(:
|
9
|
+
@user1_file = FactoryGirl.build(:repo_file)
|
10
10
|
@user1_file.owner = @user1
|
11
11
|
@user1_file.save
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'can add a
|
15
|
-
|
16
|
-
@user1.
|
17
|
-
expect(@user3.
|
14
|
+
it 'can add a member in his own sharing' do
|
15
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: false}})
|
16
|
+
@user1.add_members_to(sharing, @user3)
|
17
|
+
expect(@user3.shared_repo_items.count).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'can\'t add
|
21
|
-
|
22
|
-
@user2.
|
23
|
-
expect(@user3.
|
20
|
+
it 'can\'t add a member in a sharing without permission' do
|
21
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: false}})
|
22
|
+
@user2.add_members_to(sharing, @user3)
|
23
|
+
expect(@user3.shared_repo_items.count).to eq(0)
|
24
24
|
end
|
25
25
|
|
26
|
-
it 'can add
|
27
|
-
|
28
|
-
@user2.
|
29
|
-
expect(@user3.
|
26
|
+
it 'can add a member in a sharing with permission' do
|
27
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: true, can_remove: false}})
|
28
|
+
@user2.add_members_to(sharing, @user3)
|
29
|
+
expect(@user3.shared_repo_items.count).to eq(1)
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'can remove
|
33
|
-
|
34
|
-
@user1.
|
35
|
-
expect(@user2.
|
32
|
+
it 'can remove a member in his own sharing' do
|
33
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: false}})
|
34
|
+
@user1.remove_members_from(sharing, @user2)
|
35
|
+
expect(@user2.shared_repo_items.count).to eq(0)
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'can remove
|
39
|
-
|
40
|
-
@user1.
|
41
|
-
@user2.
|
42
|
-
expect(@user3.
|
38
|
+
it 'can remove a member in a sharing with permission' do
|
39
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: true}})
|
40
|
+
@user1.add_members_to(sharing, @user3)
|
41
|
+
@user2.remove_members_from(sharing, @user3)
|
42
|
+
expect(@user3.shared_repo_items.count).to eq(0)
|
43
43
|
end
|
44
44
|
|
45
|
-
it 'can\'t remove
|
46
|
-
|
47
|
-
@user1.
|
48
|
-
@user2.
|
49
|
-
expect(@user3.
|
45
|
+
it 'can\'t remove a member in a sharing without permission' do
|
46
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: false, can_remove: false}})
|
47
|
+
@user1.add_members_to(sharing, @user3)
|
48
|
+
@user2.remove_members_from(sharing, @user3)
|
49
|
+
expect(@user3.shared_repo_items.count).to eq(1)
|
50
50
|
end
|
51
51
|
|
52
|
-
it 'can remove and add an array of
|
53
|
-
|
52
|
+
it 'can remove and add an array of members in a sharing with permission' do
|
53
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{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_members_to(sharing, [@user3, user4])
|
56
|
+
expect(user4.shared_repo_items.count).to eq(1)
|
57
|
+
@user2.remove_members_from(sharing, [@user3, user4])
|
58
|
+
expect(user4.shared_repo_items.count).to eq(0)
|
59
59
|
end
|
60
60
|
|
61
|
-
it 'can\'t add
|
62
|
-
|
63
|
-
@user2.
|
64
|
-
@user3.
|
65
|
-
expect(@user2.
|
61
|
+
it 'can\'t add a members in a sharing with permission that he has not' do
|
62
|
+
sharing = @user1.share(@user1_file, @user2, {sharing_permissions:{can_add: true, can_remove: false}})
|
63
|
+
@user2.add_members_to(sharing, @user3, {can_add:true, can_remove:true})
|
64
|
+
@user3.remove_members_from(sharing, @user2)
|
65
|
+
expect(@user2.shared_repo_items.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.8
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -107,22 +107,6 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: enumerize
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
110
|
- !ruby/object:Gem::Dependency
|
127
111
|
name: rubyzip
|
128
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,11 +125,11 @@ dependencies:
|
|
141
125
|
version: '0'
|
142
126
|
description: ! 'This project is based on the need for a repository manager system
|
143
127
|
for Collaide. A system for easily create/delete files and folders in a repository.
|
144
|
-
For
|
128
|
+
For sharing these repositories easily with other object with a flexible and complete
|
145
129
|
authorisations management.
|
146
130
|
|
147
131
|
Each instance (users, groups, etc..) can have it own repositories (with files and
|
148
|
-
folders). It can manage them easily (edit, remove, add, etc) and
|
132
|
+
folders). It can manage them easily (edit, remove, add, etc) and sharing them with
|
149
133
|
other instance.'
|
150
134
|
email:
|
151
135
|
- texicitys@gmail.com
|
@@ -160,15 +144,13 @@ files:
|
|
160
144
|
- MIT-LICENSE
|
161
145
|
- README.md
|
162
146
|
- Rakefile
|
163
|
-
- app/models/
|
164
|
-
- app/models/
|
165
|
-
- app/models/
|
166
|
-
- app/models/
|
167
|
-
- app/models/
|
168
|
-
- app/uploaders/
|
147
|
+
- app/models/repo_file.rb
|
148
|
+
- app/models/repo_folder.rb
|
149
|
+
- app/models/repo_item.rb
|
150
|
+
- app/models/sharing.rb
|
151
|
+
- app/models/sharings_member.rb
|
152
|
+
- app/uploaders/repo_file_uploader.rb
|
169
153
|
- db/migrate/20131018214212_create_repository_manager.rb
|
170
|
-
- db/migrate/20131025085844_add_file_to_repositories.rb
|
171
|
-
- db/migrate/20131025085845_add_file_to_files.rb
|
172
154
|
- lib/generators/repository_manager/install_generator.rb
|
173
155
|
- lib/generators/repository_manager/templates/initializer.rb
|
174
156
|
- lib/repository-manager.rb
|
@@ -209,8 +191,6 @@ files:
|
|
209
191
|
- spec/dummy/db/migrate/20131016193834_create_groups.rb
|
210
192
|
- spec/dummy/db/migrate/20131016194207_create_groups_users.rb
|
211
193
|
- spec/dummy/db/migrate/20131018214212_create_repository_manager.rb
|
212
|
-
- spec/dummy/db/migrate/20131025085844_add_file_to_repositories.rb
|
213
|
-
- spec/dummy/db/migrate/20131025085845_add_file_to_files.rb
|
214
194
|
- spec/dummy/db/schema.rb
|
215
195
|
- spec/dummy/db/test.sqlite3
|
216
196
|
- spec/dummy/log/.keep
|
@@ -218,9 +198,9 @@ files:
|
|
218
198
|
- spec/dummy/public/422.html
|
219
199
|
- spec/dummy/public/500.html
|
220
200
|
- spec/dummy/public/favicon.ico
|
221
|
-
- spec/factories/app_file.rb
|
222
|
-
- spec/factories/folder.rb
|
223
201
|
- spec/factories/group.rb
|
202
|
+
- spec/factories/repo_file.rb
|
203
|
+
- spec/factories/repo_folder.rb
|
224
204
|
- spec/factories/user.rb
|
225
205
|
- spec/fixture/textfile.txt
|
226
206
|
- spec/has_repository_spec.rb
|
@@ -253,7 +233,7 @@ rubyforge_project:
|
|
253
233
|
rubygems_version: 1.8.24
|
254
234
|
signing_key:
|
255
235
|
specification_version: 3
|
256
|
-
summary: Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/
|
236
|
+
summary: Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharings).
|
257
237
|
test_files:
|
258
238
|
- spec/dummy/Gemfile
|
259
239
|
- spec/dummy/README.rdoc
|
@@ -287,8 +267,6 @@ test_files:
|
|
287
267
|
- spec/dummy/db/migrate/20131016193834_create_groups.rb
|
288
268
|
- spec/dummy/db/migrate/20131016194207_create_groups_users.rb
|
289
269
|
- spec/dummy/db/migrate/20131018214212_create_repository_manager.rb
|
290
|
-
- spec/dummy/db/migrate/20131025085844_add_file_to_repositories.rb
|
291
|
-
- spec/dummy/db/migrate/20131025085845_add_file_to_files.rb
|
292
270
|
- spec/dummy/db/schema.rb
|
293
271
|
- spec/dummy/db/test.sqlite3
|
294
272
|
- spec/dummy/log/.keep
|
@@ -296,9 +274,9 @@ test_files:
|
|
296
274
|
- spec/dummy/public/422.html
|
297
275
|
- spec/dummy/public/500.html
|
298
276
|
- spec/dummy/public/favicon.ico
|
299
|
-
- spec/factories/app_file.rb
|
300
|
-
- spec/factories/folder.rb
|
301
277
|
- spec/factories/group.rb
|
278
|
+
- spec/factories/repo_file.rb
|
279
|
+
- spec/factories/repo_folder.rb
|
302
280
|
- spec/factories/user.rb
|
303
281
|
- spec/fixture/textfile.txt
|
304
282
|
- spec/has_repository_spec.rb
|
data/app/models/folder.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
class Folder < Repository
|
2
|
-
attr_accessible :name if RepositoryManager.protected_attributes?
|
3
|
-
|
4
|
-
validates :name, presence: true
|
5
|
-
|
6
|
-
# Add a repository in the folder.
|
7
|
-
def add_repository(repository)
|
8
|
-
repository.update_attribute :parent, self
|
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
|
-
|
54
|
-
end
|
data/app/models/share.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
class Share < ActiveRecord::Base
|
2
|
-
attr_accessible :can_read, :can_create, :can_update, :can_delete, :can_share if RepositoryManager.protected_attributes?
|
3
|
-
|
4
|
-
|
5
|
-
has_many :shares_items, :dependent => :destroy
|
6
|
-
belongs_to :owner, :polymorphic => true
|
7
|
-
belongs_to :repository
|
8
|
-
|
9
|
-
#scope :recipient, lambda { |recipient|
|
10
|
-
# joins(:receipts).where('receipts.receiver_id' => recipient.id,'receipts.receiver_type' => recipient.class.base_class.to_s)
|
11
|
-
#}
|
12
|
-
scope :items, lambda { |item|
|
13
|
-
joins(:shares_items).where('shares_items.item_id' => item.id,'shares_items.item_type' => item.class.base_class.to_s)
|
14
|
-
}
|
15
|
-
|
16
|
-
# Return the authorisations of the share for the item
|
17
|
-
def get_authorisations(item)
|
18
|
-
# If the item is the owner, he can do what he want !
|
19
|
-
if self.owner == item
|
20
|
-
return true
|
21
|
-
elsif i = self.shares_items.where(item_id: item.id, item_type: item.class.base_class.to_s).first
|
22
|
-
return {can_add: i.can_add, can_remove: i.can_remove}
|
23
|
-
else
|
24
|
-
return false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Add items to the share
|
29
|
-
def add_items(items, share_permissions = nil)
|
30
|
-
if items.kind_of?(Array)
|
31
|
-
# Add each item to this share
|
32
|
-
items.each do |i|
|
33
|
-
share_item = SharesItem.new(share_permissions)
|
34
|
-
share_item.item = i
|
35
|
-
# Add the shares items in the share
|
36
|
-
self.shares_items << share_item
|
37
|
-
end
|
38
|
-
else
|
39
|
-
share_item = SharesItem.new(share_permissions)
|
40
|
-
share_item.item = items
|
41
|
-
# Add the shares items in the share
|
42
|
-
self.shares_items << share_item
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Remove items to the share
|
47
|
-
def remove_items(items)
|
48
|
-
if items.kind_of?(Array)
|
49
|
-
# Add each item to this share
|
50
|
-
items.each do |item|
|
51
|
-
self.shares_items.where(:item_id => item.id, :item_type => item.class.base_class.to_s).first.destroy
|
52
|
-
end
|
53
|
-
else
|
54
|
-
self.shares_items.where(:item_id => items.id, :item_type => items.class.base_class.to_s).first.destroy
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
data/app/models/shares_item.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
class AddFileToRepositories < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
#add_column :repositories, :file, :string
|
4
|
-
add_column :repositories, :file_size, :float
|
5
|
-
add_column :repositories, :content_type, :string
|
6
|
-
#add_column :repositories, :repository_type, :string
|
7
|
-
end
|
8
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
class AddFileToRepositories < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
#add_column :repositories, :file, :string
|
4
|
-
add_column :repositories, :file_size, :float
|
5
|
-
add_column :repositories, :content_type, :string
|
6
|
-
#add_column :repositories, :repository_type, :string
|
7
|
-
end
|
8
|
-
end
|