repository-manager 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 100d27b38ccdae4cf8578994a54f4ded2705f2a3
4
- data.tar.gz: 1b5f7ca71b23258a36f2e7fee35971583b5783f3
3
+ metadata.gz: 50b78ee29a456a6211cc629dbfc3f6b4615eb3e3
4
+ data.tar.gz: 59d453429c31b032a41ad838458a9abd6001fcc4
5
5
  SHA512:
6
- metadata.gz: 2d7c6b095dc637a81eb23b627fa1dbb0ddb4296d7758b9689d081d1c759898d7c830f1bf1b98fbf3358806e084b7c2e78daa23d3a0584907f3cee20fbc0a7d02
7
- data.tar.gz: edf8bcb6178667f215a2c44e1192e3fa98d1d9eb512db9ebb63fc46c5b4b9daaeeb3ba983fed9b766a854738d00c3d60774ad182ac8eb7bb2ed8b401ae0b6159
6
+ metadata.gz: dc3b40e3c529e73ac7548609563dfbd6cf9b80b0d3dba434ca6d7e6eba966bc355d80a787248a111753e1822aa71097042d4c0121ac087802579afa658de48e3
7
+ data.tar.gz: ce8bd6910fc8349ed60512af898efc8e95f1a8107ad965a962ff5e2e97604d0c8a827abe3023bb6eb7351d493ad1e2a9e9b8bf3c95b27b76bcf758078834d79a
data/README.md CHANGED
@@ -106,8 +106,8 @@ end
106
106
  ### Introduction
107
107
 
108
108
  A `repo_item` is an item in a repository, it can be:
109
- - A file (`repo_file`, class name : `RepoFile`)
110
- - A folder (`repo_folder`, class name : `RepoFolder`).
109
+ - A file (`repo_file`, class name : `RepositoryManager::RepoFile`)
110
+ - A folder (`repo_folder`, class name : `RepositoryManager::RepoFolder`).
111
111
 
112
112
  A folder can contains files and folders. Like in a real tree files and folders.
113
113
 
@@ -115,7 +115,7 @@ A few methods are written in those two ways :
115
115
  - method(arg, options)
116
116
  - method!(arg, options) (note the "!")
117
117
 
118
- The two methods do the same, but the one with the "!" returns an Exception error if it is a problem (AuthorisationException for instance) and the method without "!" return false if it has a problem.
118
+ The two methods do the same, but the one with the "!" returns an Exception error if it is a problem (AuthorisationException or RepositoryManagerException for instance) and the method without "!" return false if it has a problem.
119
119
 
120
120
  ### How can I create/delete/move a repo_item (file or folder)
121
121
 
@@ -192,6 +192,22 @@ user1.delete_repo_item(file2)
192
192
 
193
193
  ```
194
194
 
195
+ If a user (sender of the file/folder) send a file or folder into a group (owner of the file/folder), you can specify the owner and the sender like this :
196
+
197
+ ```ruby
198
+ # user1 wants to create a folder and a file into group1
199
+ folder = group1.create_folder('Folder created by user1', sender: user1)
200
+
201
+ # Now he send the file into the folder
202
+ file = group1.create_file(params[:file], source_folder: params[:file], sender: user1)
203
+
204
+ file.owner # Returns group1
205
+ file.sender # Returns user1
206
+
207
+ # If you don't specify the sender, the owner becomes the sender
208
+
209
+ ```
210
+
195
211
  ### How can I share a repo_item (file/folder)
196
212
 
197
213
  Now, user1 want to share his folder 'The new folder' with a Group object `group1` et another User object `user2`. You can use the `has_repository` method `share(repo_item, member, options = nil)`.
@@ -3,6 +3,8 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
3
3
 
4
4
  attr_accessible :type if RepositoryManager.protected_attributes?
5
5
 
6
+ before_save :put_sender
7
+
6
8
  has_ancestry
7
9
 
8
10
  # Associate with the User Class
@@ -67,4 +69,9 @@ class RepositoryManager::RepoItem < ActiveRecord::Base
67
69
  false
68
70
  end
69
71
  end
72
+
73
+ private
74
+ def put_sender
75
+ self.sender = owner unless sender
76
+ end
70
77
  end
@@ -84,7 +84,10 @@ module RepositoryManager
84
84
  end
85
85
  end
86
86
 
87
- # Create a folder with the name (name) in the directory (source_folder)
87
+ # Create a folder with the name (name)
88
+ # options :
89
+ # :source_folder = The directory in with the folder is created
90
+ # :sender = The object of the sender (ex : current_user)
88
91
  # Returns the object of the folder created if it is ok
89
92
  # Returns an Exception if the folder is not created
90
93
  # RepositoryManagerException if the name already exist
@@ -102,7 +105,7 @@ module RepositoryManager
102
105
  folder.name = name
103
106
  end
104
107
  folder.owner = self
105
- #folder.user = RepositoryManager.user_model.constantize.find(session[:user_id]) if RepositoryManager.user_model
108
+ folder.sender = options[:sender]
106
109
 
107
110
  # If we are in root path we check if we can add this folder name
108
111
  if !source_folder && repo_item_name_exist_in_root?(name)
@@ -121,6 +124,8 @@ module RepositoryManager
121
124
  folder
122
125
  end
123
126
 
127
+ # Like create_folder!
128
+ # Returns false if the folder is not created instead of an exception
124
129
  def create_folder(name = '', options = {})
125
130
  begin
126
131
  create_folder!(name, options)
@@ -147,9 +152,15 @@ module RepositoryManager
147
152
  end
148
153
 
149
154
  # Create the file (file) in the directory (source_folder)
155
+ # options :
156
+ # :source_folder = The directory in with the folder is created
157
+ # :sender = The object of the sender (ex : current_user)
158
+ #
150
159
  # Param file can be a File, or a instance of RepoFile
151
- # Return the object of the file created if it is ok
152
- # Return false if the file is not created (no authorisation)
160
+ # Returns the object of the file created if it is ok
161
+ # Returns an Exception if the folder is not created
162
+ # RepositoryManagerException if the file already exist
163
+ # AuthorisationException if the object don't have the permission
153
164
  def create_file!(file, options = {})
154
165
  source_folder = options[:source_folder]
155
166
  # If he want to create a file in a directory, we have to check if he have the authorisation
@@ -162,7 +173,7 @@ module RepositoryManager
162
173
  end
163
174
 
164
175
  repo_file.owner = self
165
- #repo_file.user = RepositoryManager.user_model.constantize.find(session[:user_id]) if RepositoryManager.user_model
176
+ repo_file.sender = options[:sender]
166
177
 
167
178
 
168
179
  # If we are in root path we check if we can add this file name
@@ -1,3 +1,3 @@
1
1
  module RepositoryManager
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -200,4 +200,24 @@ describe 'RepoItem' do
200
200
 
201
201
  #@user1.create_file!(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
202
202
  end
203
+
204
+ it 'sender is equal to owner if no sender in create_folder' do
205
+ folder = @user1.create_folder('test')
206
+ expect(folder.sender).to eq(@user1)
207
+ end
208
+
209
+ it 'sender is equal to owner if no sender in create_file' do
210
+ file = @user2.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
211
+ expect(file.sender).to eq(@user2)
212
+ end
213
+
214
+ it 'can specify a sender in create_folder method' do
215
+ folder = @user1.create_folder('test', sender: @user2)
216
+ expect(folder.sender).to eq(@user2)
217
+ end
218
+
219
+ it 'can specify a sender in create_file method' do
220
+ file = @user2.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), sender: @user1)
221
+ expect(file.sender).to eq(@user1)
222
+ end
203
223
  end
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.0
4
+ version: 0.1.1
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-04 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails