repository-manager 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -19,7 +19,7 @@ This gem is my informatics project for the Master in [University of Lausanne (CH
19
19
  Add to your Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'RepositoryManager'
22
+ gem 'repository-manager'
23
23
  ```
24
24
 
25
25
  Then run:
@@ -1,4 +1,5 @@
1
1
  class AppFile < Repository
2
+ attr_accessible :name, :content_type, :file_size if RepositoryManager.protected_attributes?
2
3
 
3
4
  mount_uploader :name, RepositoryUploader
4
5
 
data/app/models/folder.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Folder < Repository
2
+ attr_accessible :name if RepositoryManager.protected_attributes?
2
3
 
3
4
  #Add a repository in the folder.
4
5
  def addRepository(repository)
@@ -1,13 +1,22 @@
1
1
  class Repository < ActiveRecord::Base
2
+ attr_accessible :type if RepositoryManager.protected_attributes?
3
+
4
+
2
5
  has_ancestry
3
6
 
4
7
  # Associate with the User Classe
5
8
  belongs_to :owner, :polymorphic => true
6
- has_many :shares, dependent: :destroy
9
+ has_many :shares, :dependent => :destroy
7
10
  #has_many :items, through: :shares
8
11
 
9
- scope :files, -> { where type: 'AppFile' }
10
- scope :folders, -> { where type: 'Folder' }
12
+ if Rails::VERSION::MAJOR == 4
13
+ scope :files, -> { where type: 'AppFile' }
14
+ scope :folders, -> { where type: 'Folder' }
15
+ else
16
+ # Rails 3 does it this way
17
+ scope :files, where(type: 'AppFile')
18
+ scope :folders, where(type: 'Folder')
19
+ end
11
20
 
12
21
  def copy(target_folder)
13
22
  #new_file = self.dup
data/app/models/share.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  class Share < ActiveRecord::Base
2
- has_many :shares_items, dependent: :destroy
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
3
6
  belongs_to :owner, :polymorphic => true
4
7
  belongs_to :repository
5
8
 
@@ -15,7 +18,7 @@ class Share < ActiveRecord::Base
15
18
  # If the item is the owner, he can do what he want !
16
19
  if self.owner == item
17
20
  return true
18
- elsif i = self.shares_items.where(item_id: item.id, item_type: item.class.base_class.to_s).take
21
+ elsif i = self.shares_items.where(item_id: item.id, item_type: item.class.base_class.to_s).first
19
22
  return {can_add: i.can_add, can_remove: i.can_remove}
20
23
  else
21
24
  return false
@@ -45,10 +48,10 @@ class Share < ActiveRecord::Base
45
48
  if items.kind_of?(Array)
46
49
  # Add each item to this share
47
50
  items.each do |item|
48
- self.shares_items.where(item_id: item.id, item_type: item.class.base_class.to_s).take.destroy
51
+ self.shares_items.where(:item_id => item.id, :item_type => item.class.base_class.to_s).first.destroy
49
52
  end
50
53
  else
51
- self.shares_items.where(item_id: items.id, item_type: items.class.base_class.to_s).take.destroy
54
+ self.shares_items.where(:item_id => items.id, :item_type => items.class.base_class.to_s).first.destroy
52
55
  end
53
56
  end
54
57
 
@@ -1,4 +1,5 @@
1
1
  class SharesItem < ActiveRecord::Base
2
+ attr_accessible :can_add, :can_remove if RepositoryManager.protected_attributes?
2
3
 
3
4
  belongs_to :item, polymorphic: true
4
5
  belongs_to :share
@@ -0,0 +1,17 @@
1
+ require 'repository_manager/has_repository'
2
+
3
+ module RepositoryManager
4
+
5
+ class << self
6
+ def setup
7
+ yield self
8
+ end
9
+
10
+ def protected_attributes?
11
+ Rails.version < '4' || defined?(ProtectedAttributes)
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ require 'repository_manager/engine'
@@ -19,7 +19,7 @@ module RepositoryManager
19
19
  #if Rails::VERSION::MAJOR == 4
20
20
  # has_many :shares_repositories, -> { where can_read: true }, as: :item, through: :shares_items, class_name: 'Repository'
21
21
  #else
22
- # Rails 3 does it this way
22
+ # Rails 3 does it this way
23
23
  has_many :shares_repositories, through: :shares, source: :repository, class_name: 'Repository'
24
24
  #end
25
25
 
@@ -90,7 +90,9 @@ module RepositoryManager
90
90
  # Delete the repository
91
91
  def deleteRepository(repository)
92
92
  if can_delete(repository)
93
- repository.destroy!
93
+ repository.destroy
94
+ else
95
+ return false
94
96
  end
95
97
  end
96
98
 
@@ -139,7 +141,7 @@ module RepositoryManager
139
141
  # You can do what ever you want :)
140
142
  return true
141
143
  # Find if a share of this rep exist for the self instance
142
- elsif s = self.shares.where(repository_id: repository.id).take
144
+ elsif s = self.shares.where(repository_id: repository.id).first
143
145
  # Ok, give an array with the permission of the actual share
144
146
  # (we can't share with more permission then we have)
145
147
  return {can_share: s.can_share, can_read: s.can_read, can_create: s.can_create, can_update: s.can_update, can_delete: s.can_delete}
@@ -209,6 +211,8 @@ module RepositoryManager
209
211
  if can_add_to_share(share)
210
212
  share_permissions = make_share_permissions(share_permissions, authorisations)
211
213
  share.addItems(items, share_permissions)
214
+ else
215
+ return false
212
216
  end
213
217
  end
214
218
 
@@ -217,6 +221,8 @@ module RepositoryManager
217
221
  def removeItemsToShare(share, items)
218
222
  if can_remove_to_share(share)
219
223
  share.removeItems(items)
224
+ else
225
+ return false
220
226
  end
221
227
  end
222
228
 
@@ -1,3 +1,3 @@
1
1
  module RepositoryManager
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.4'
3
3
  end
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "repository_manager"
6
+ require "repository-manager"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
Binary file
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.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -155,12 +155,12 @@ files:
155
155
  - db/migrate/20131025085844_add_file_to_repositories.rb
156
156
  - lib/generators/repository_manager/install_generator.rb
157
157
  - lib/generators/repository_manager/templates/initializer.rb
158
- - lib/repository_manager.rb
158
+ - lib/repository-manager.rb
159
159
  - lib/repository_manager/engine.rb
160
160
  - lib/repository_manager/has_repository.rb
161
161
  - lib/repository_manager/version.rb
162
162
  - lib/tasks/repository_manager_tasks.rake
163
- - repository_manager.gemspec
163
+ - repository-manager.gemspec
164
164
  - spec/dummy/Gemfile
165
165
  - spec/dummy/README.rdoc
166
166
  - spec/dummy/Rakefile
@@ -201,7 +201,6 @@ files:
201
201
  - spec/dummy/public/422.html
202
202
  - spec/dummy/public/500.html
203
203
  - spec/dummy/public/favicon.ico
204
- - spec/factories.rb
205
204
  - spec/factories/app_file.rb
206
205
  - spec/factories/folder.rb
207
206
  - spec/factories/group.rb
@@ -279,7 +278,6 @@ test_files:
279
278
  - spec/dummy/public/422.html
280
279
  - spec/dummy/public/500.html
281
280
  - spec/dummy/public/favicon.ico
282
- - spec/factories.rb
283
281
  - spec/factories/app_file.rb
284
282
  - spec/factories/folder.rb
285
283
  - spec/factories/group.rb
@@ -1,6 +0,0 @@
1
- require 'repository_manager/has_repository'
2
-
3
- module RepositoryManager
4
- end
5
-
6
- require 'repository_manager/engine'
data/spec/factories.rb DELETED
@@ -1,45 +0,0 @@
1
- FactoryGirl.define do
2
- factory :folder do
3
- sequence(:name) { |i| "test#{i}" }
4
- parent { Folder.where(:name => 'Root folder').first_or_create }
5
- end
6
- end
7
-
8
- FactoryGirl.define do
9
- factory :group do
10
- sequence(:name) { |i| "test#{i}" }
11
- end
12
- end
13
-
14
- FactoryGirl.define do
15
- factory :share_link do
16
- emails 'email1@domain.com, email2@domain.com'
17
- link_expires_at { 2.weeks.from_now.end_of_day }
18
- end
19
- end
20
-
21
- FactoryGirl.define do
22
- factory :user_file do
23
- attachment { fixture_file }
24
- sequence(:attachment_file_name) { |i| "test#{i}.txt" }
25
- folder { Folder.where(:name => 'Root folder').first_or_create }
26
- end
27
- end
28
-
29
- FactoryGirl.define do
30
- factory :user do
31
- sequence(:name) { |i| "test#{i}" }
32
- sequence(:email) { |i| "test#{i}@test.com" }
33
- password 'secret123'
34
- password_confirmation { |u| u.password }
35
- password_required true
36
- reset_password_token ''
37
- dont_clear_reset_password_token false
38
- remember_token ''
39
- is_admin false
40
- end
41
- end
42
-
43
- def fixture_file
44
- File.open("#{Rails.root}/test/fixtures/textfile.txt")
45
- end