Module: RepositoryManager::HasRepository::LocalInstanceMethods
- Defined in:
- lib/repository_manager/has_repository.rb
Instance Method Summary collapse
- #add_members_to(sharing, members, options = RepositoryManager.default_sharing_permissions) ⇒ Object
-
#add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions) ⇒ Object
Add new members in the sharing Param member could be an object or an array of object.
-
#can_add_to?(sharing) ⇒ Boolean
Return true if you can add a member in this sharing, false else.
-
#can_create?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can create in the repo, false else.
-
#can_delete?(repo_item, permissions = nil) ⇒ Boolean
Returns true if you can delete the repo, false else.
-
#can_download?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can download the repo, else false Read = Download for the moment.
-
#can_read?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can read the repo, else false.
-
#can_remove_from?(sharing) ⇒ Boolean
Return true if you can remove a member in this sharing, false else.
-
#can_share?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can share the repo, else false You can give the permissions or the repo_item as params.
-
#can_update?(repo_item, permissions = nil) ⇒ Boolean
Returns true if you can edit the repo, false else.
- #copy_repo_item(repo_item, options = {}) ⇒ Object
-
#copy_repo_item!(repo_item, options = {}) ⇒ Object
Copy the repo_item in the source_folder or in own root options :source_folder => the folder in witch we want to copy the repo item :sender => the new sender (by default => still the old sender) :overwrite = overwrite an item with the same name (default : see config ‘auto_overwrite_item’).
- #create_file(file, options = {}) ⇒ Object
-
#create_file!(file, options = {}) ⇒ Object
Param file can be a File, or a instance of RepoFile Returns the object of the file created if it is ok Returns an Exception if the folder is not created RepositoryManagerException if the file already exist PermissionException if the object don’t have the permission.
-
#create_folder(name = '', options = {}) ⇒ Object
Like create_folder! Returns false if the folder is not created instead of an exception.
-
#create_folder!(name = '', options = {}) ⇒ Object
Create a folder with the name (name) options : :source_folder = The directory in with the folder is created :sender = The object of the sender (ex : current_user) :overwrite = overwrite an item with the same name (default : see config ‘auto_overwrite_item’) Returns the object of the folder created if it is ok Returns an Exception if the folder is not created RepositoryManagerException if the name already exist PermissionException if the object don’t have the permission.
-
#delete_download_path ⇒ Object
Delete the download folder of the user.
- #delete_repo_item(repo_item) ⇒ Object
-
#delete_repo_item!(repo_item) ⇒ Object
Delete the repo_item.
- #download_repo_item(repo_item, options = {}) ⇒ Object
-
#download_repo_item!(repo_item, options = {}) ⇒ Object
Download a repo_item if the object can_read it If it is a file, he download the file If it is a folder, we check witch repo_item is in it, and witch he can_read We zip all the content that the object has access.
-
#get_default_download_path(prefix = "#{Rails.root.join('download')}/") ⇒ Object
Get the download path of the member.
- #get_item_in_root_by_name(name) ⇒ Object
-
#get_or_create_by_path_array(path_array, options = {}) ⇒ Object
Get or create the folder with this name options :sender = the sender of the item.
-
#get_permissions(repo_item = nil) ⇒ Object
Gets the repo permissions Return false if the entity has not the permission to share this rep Return true if the entity can share this rep with all the permissions Return an Array if the entity can share but with restriction Return true if the repo_item is nil (he as all permissions on his own rep).
-
#get_sharing_permissions(sharing) ⇒ Object
Return the permissions of the sharing (can_add, can_remove).
- #move_repo_item(repo_item, options = {}) ⇒ Object
-
#move_repo_item!(repo_item, options = {}) ⇒ Object
Move the repo_item options :source_folder => move into this source_folder if :source_folder == nil, move to the root :overwrite = overwrite an item with the same name (default : see config ‘auto_overwrite_item’).
- #remove_members_from(sharing, members) ⇒ Object
-
#remove_members_from!(sharing, members) ⇒ Object
Remove members in the sharing Param member could be an object or an array of object.
-
#rename_repo_item(repo_item, new_name) ⇒ Object
Rename the repo_item with the new_name.
-
#rename_repo_item!(repo_item, new_name) ⇒ Object
Rename the repo_item with the new_name.
-
#repo_item_name_exist_in_root?(name) ⇒ Boolean
Returns true of false if the name exist in the root path of this instance.
- #share_repo_item(repo_item, members, options = {}) ⇒ Object
-
#share_repo_item!(repo_item, members, options = {}) ⇒ Object
Sharing the repo_item with the members, with the options options contains :
:can_read
- Member can download the repo_item:can_create
- Member can create a new repo_item on it:can_edit
- Member can edit the repo_item:can_delete
- Member can delete the repo_item:can_share
- Member can share the repo_item options contains ::can_add
- Specify if the member can add objects to the sharing:can_remove
- Specify if the member can remove object to the sharing. - #unzip_repo_item(repo_item, options = {}) ⇒ Object
-
#unzip_repo_item!(repo_item, options = {}) ⇒ Object
Unzip the compressed file and create the repo_items options :source_folder = the folder in witch you unzip this archive :sender = the sender of the item (if you don’t specify sender.. The sender is still the same) :overwrite = overwrite an item with the same name (default : see config ‘auto_overwrite_item’).
Instance Method Details
#add_members_to(sharing, members, options = RepositoryManager.default_sharing_permissions) ⇒ Object
559 560 561 562 563 564 565 |
# File 'lib/repository_manager/has_repository.rb', line 559 def add_members_to(sharing, members, = RepositoryManager.) begin add_members_to!(sharing, members, = RepositoryManager.) rescue RepositoryManager::PermissionException false end end |
#add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions) ⇒ Object
Add new members in the sharing Param member could be an object or an array of object
548 549 550 551 552 553 554 555 556 557 |
# File 'lib/repository_manager/has_repository.rb', line 548 def add_members_to!(sharing, members, = RepositoryManager.) = (sharing) if can_add_to?(sharing) = (, ) sharing.add_members(members, ) else sharing.errors.add(:add, I18n.t('repository_manager.errors.sharing.add.no_permission')) raise RepositoryManager::PermissionException.new("add members failed. You don't have the permission to add a member in this sharing") end end |
#can_add_to?(sharing) ⇒ Boolean
Return true if you can add a member in this sharing, false else
537 538 539 |
# File 'lib/repository_manager/has_repository.rb', line 537 def can_add_to?(sharing) can_do_to?('add', sharing) end |
#can_create?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can create in the repo, false else
506 507 508 |
# File 'lib/repository_manager/has_repository.rb', line 506 def can_create?(repo_item, = nil) can_do?('create', repo_item, ) end |
#can_delete?(repo_item, permissions = nil) ⇒ Boolean
Returns true if you can delete the repo, false else
516 517 518 |
# File 'lib/repository_manager/has_repository.rb', line 516 def can_delete?(repo_item, = nil) can_do?('delete', repo_item, ) end |
#can_download?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can download the repo, else false Read = Download for the moment
501 502 503 |
# File 'lib/repository_manager/has_repository.rb', line 501 def can_download?(repo_item, = nil) can_do?('read', repo_item, ) end |
#can_read?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can read the repo, else false
495 496 497 |
# File 'lib/repository_manager/has_repository.rb', line 495 def can_read?(repo_item, = nil) can_do?('read', repo_item, ) end |
#can_remove_from?(sharing) ⇒ Boolean
Return true if you can remove a member in this sharing, false else
542 543 544 |
# File 'lib/repository_manager/has_repository.rb', line 542 def can_remove_from?(sharing) can_do_to?('remove', sharing) end |
#can_share?(repo_item, permissions = nil) ⇒ Boolean
Return true if you can share the repo, else false You can give the permissions or the repo_item as params
490 491 492 |
# File 'lib/repository_manager/has_repository.rb', line 490 def can_share?(repo_item, = nil) can_do?('share', repo_item, ) end |
#can_update?(repo_item, permissions = nil) ⇒ Boolean
Returns true if you can edit the repo, false else
511 512 513 |
# File 'lib/repository_manager/has_repository.rb', line 511 def can_update?(repo_item, = nil) can_do?('update', repo_item, ) end |
#copy_repo_item(repo_item, options = {}) ⇒ Object
402 403 404 405 406 407 408 409 410 411 |
# File 'lib/repository_manager/has_repository.rb', line 402 def copy_repo_item(repo_item, = {}) begin copy_repo_item!(repo_item, ) rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException false rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.not_copied')) false end end |
#copy_repo_item!(repo_item, options = {}) ⇒ Object
Copy the repo_item in the source_folder or in own root options
:source_folder => the folder in witch we want to copy the repo item
:sender => the new sender (by default => still the old sender)
:overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/repository_manager/has_repository.rb', line 376 def copy_repo_item!(repo_item, = {}) !![:overwrite] == [:overwrite] ? overwrite = [:overwrite] : overwrite = RepositoryManager.auto_overwrite_item target = [:source_folder] unless can_read?(repo_item) repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.no_permission')) raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'") end if target && !can_create?(target) repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.no_permission')) raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to create in the source_folder '#{target.name}'") end # The new owner #if target # owner = target.owner #else owner = self #end # If it has the permission, we copy the repo_item in the source_folder repo_item.copy!(source_folder: target, owner: owner, sender: [:sender], overwrite: overwrite) end |
#create_file(file, options = {}) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/repository_manager/has_repository.rb', line 260 def create_file(file, = {}) [:errors] = [] begin create_file!(file, ) rescue RepositoryManager::PermissionException [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_file.create.no_permission') false rescue RepositoryManager::ItemExistException [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_file.item_exist') false rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_file.create.not_created') false end end |
#create_file!(file, options = {}) ⇒ Object
Param file can be a File, or a instance of RepoFile Returns the object of the file created if it is ok Returns an Exception if the folder is not created
RepositoryManagerException if the file already exist
PermissionException if the object don't have the permission
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/repository_manager/has_repository.rb', line 200 def create_file!(file, = {}) source_folder = [:source_folder] if source_folder unless source_folder.is_folder? raise RepositoryManager::RepositoryManagerException.new("create file failed. The source folder must be a repo_folder.") end end !![:overwrite] == [:overwrite] ? overwrite = [:overwrite] : overwrite = RepositoryManager.auto_overwrite_item # If he want to create a file in a directory, we have to check if he have the permission if can_create?(source_folder) if file.class.name == 'RepositoryManager::RepoFile' repo_file = file elsif file.class.name == 'File' || file.class.name == 'ActionDispatch::Http::UploadedFile' repo_file = RepositoryManager::RepoFile.new() repo_file.file = file else # "ActionController::Parameters" repo_file = RepositoryManager::RepoFile.new(file) end [:filename] ? file_name = [:filename] : file_name = repo_file.file.url.split('/').last repo_file.name = file_name repo_file.owner = self repo_file.sender = [:sender] # If we are in root path we check if we can add this file name if !source_folder repo_item_with_same_name = get_item_in_root_by_name(file_name) if repo_item_with_same_name && !overwrite raise RepositoryManager::ItemExistException.new("create file failed. The repo_item '#{file_name}' already exist in the root folder.") elsif repo_item_with_same_name && overwrite #We do not destroy, we update it ! # We update the file if file.class.name == 'RepositoryManager::RepoFile' repo_item_with_same_name.file = file.file elsif file.class.name == 'File' || file.class.name == 'ActionDispatch::Http::UploadedFile' repo_item_with_same_name.file = file else # "ActionController::Parameters" repo_item_with_same_name.assign_attributes(file) end repo_item_with_same_name.sender = [:sender] #p "source: updates the file #{repo_item_with_same_name.name}" repo_file = repo_item_with_same_name end else # It raise an error if name already exist and destroy the file repo_file = source_folder.add!(repo_file, do_not_save: true, overwrite: overwrite) end repo_file.save! else raise RepositoryManager::PermissionException.new("create_file failed. You don't have the permission to create a file") end repo_file end |
#create_folder(name = '', options = {}) ⇒ Object
Like create_folder! Returns false if the folder is not created instead of an exception
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/repository_manager/has_repository.rb', line 154 def create_folder(name = '', = {}) [:errors] = [] begin create_folder!(name, ) rescue RepositoryManager::PermissionException [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_folder.create.no_permission') false rescue RepositoryManager::ItemExistException [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_folder.item_exist') false rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved [:errors].push(I18n.t'repository_manager.errors.repo_item.repo_folder.create.not_created') false end end |
#create_folder!(name = '', options = {}) ⇒ Object
Create a folder with the name (name) options :
:source_folder = The directory in with the folder is created
:sender = The object of the sender (ex : current_user)
:overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
Returns the object of the folder created if it is ok Returns an Exception if the folder is not created
RepositoryManagerException if the name already exist
PermissionException if the object don't have the permission
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/repository_manager/has_repository.rb', line 109 def create_folder!(name = '', = {}) source_folder = [:source_folder] if source_folder unless source_folder.is_folder? raise RepositoryManager::RepositoryManagerException.new("create folder failed. The source folder must be a repo_folder.") end end !![:overwrite] == [:overwrite] ? overwrite = [:overwrite] : overwrite = RepositoryManager.auto_overwrite_item # If he want to create a folder in a directory, we have to check if he have the permission if can_create?(source_folder) folder = RepoFolder.new if name == '' || name == nil || name == false || name.blank? folder.name = default_folder_name(source_folder) else folder.name = name end folder.owner = self folder.sender = [:sender] # If we are in root path we check if we can add this folder name if !source_folder repo_item_with_same_name = get_item_in_root_by_name(name) if repo_item_with_same_name && !overwrite raise RepositoryManager::ItemExistException.new("create folder failed. The repo_item '#{name}' already exist in the root folder.") elsif repo_item_with_same_name && overwrite # We destroy the item with same name for overwrite it repo_item_with_same_name.destroy! end else # It raise an error if name already exist and destroy the folder source_folder.add!(folder, do_not_save: true, overwrite: overwrite) end folder.save! else raise RepositoryManager::PermissionException.new("create_folder failed. You don't have the permission to create a folder in '#{source_folder.name}'") end folder end |
#delete_download_path ⇒ Object
Delete the download folder of the user
439 440 441 |
# File 'lib/repository_manager/has_repository.rb', line 439 def delete_download_path FileUtils.rm_rf(self.get_default_download_path()) end |
#delete_repo_item(repo_item) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/repository_manager/has_repository.rb', line 180 def delete_repo_item(repo_item) begin delete_repo_item!(repo_item) rescue RepositoryManager::PermissionException false end end |
#delete_repo_item!(repo_item) ⇒ Object
Delete the repo_item
171 172 173 174 175 176 177 178 |
# File 'lib/repository_manager/has_repository.rb', line 171 def delete_repo_item!(repo_item) if can_delete?(repo_item) repo_item.destroy else repo_item.errors.add(:delete, I18n.t('repository_manager.errors.repo_item.delete.no_permission')) raise RepositoryManager::PermissionException.new("delete_repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'") end end |
#download_repo_item(repo_item, options = {}) ⇒ Object
430 431 432 433 434 435 436 |
# File 'lib/repository_manager/has_repository.rb', line 430 def download_repo_item(repo_item, = {}) begin download_repo_item!(repo_item, ) rescue RepositoryManager::PermissionException false end end |
#download_repo_item!(repo_item, options = {}) ⇒ Object
Download a repo_item if the object can_read it If it is a file, he download the file If it is a folder, we check witch repo_item is in it, and witch he can_read We zip all the content that the object has access. options
:path => 'path/to/zip'
419 420 421 422 423 424 425 426 427 428 |
# File 'lib/repository_manager/has_repository.rb', line 419 def download_repo_item!(repo_item, = {}) if can_download?(repo_item) path = [:path] if [:path] repo_item.download!({object: self, path: path}) else repo_item.errors.add(:download, I18n.t('repository_manager.errors.repo_item.download.no_permission')) raise RepositoryManager::PermissionException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'") end end |
#get_default_download_path(prefix = "#{Rails.root.join('download')}/") ⇒ Object
Get the download path of the member
587 588 589 |
# File 'lib/repository_manager/has_repository.rb', line 587 def get_default_download_path(prefix = "#{Rails.root.join('download')}/") "#{prefix}#{self.class.base_class.to_s.underscore}/#{self.id}/" end |
#get_item_in_root_by_name(name) ⇒ Object
596 597 598 |
# File 'lib/repository_manager/has_repository.rb', line 596 def get_item_in_root_by_name(name) RepoItem.where('name = ?', name).where(owner: self).where(ancestry: nil).first end |
#get_or_create_by_path_array(path_array, options = {}) ⇒ Object
Get or create the folder with this name options
:sender = the sender of the item
603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/repository_manager/has_repository.rb', line 603 def get_or_create_by_path_array(path_array, = {}) name = path_array[0] children = self.get_item_in_root_by_name(name) unless children children = RepositoryManager::RepoFolder.new(name: name) children.owner = self children.sender = [:sender] children.save! end # remove the first element path_array.shift children = children.get_or_create_by_path_array(path_array, sender: [:sender], owner: self) children end |
#get_permissions(repo_item = nil) ⇒ Object
Gets the repo permissions Return false if the entity has not the permission to share this rep Return true if the entity can share this rep with all the permissions Return an Array if the entity can share but with restriction Return true if the repo_item is nil (he as all permissions on his own rep)
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/repository_manager/has_repository.rb', line 281 def (repo_item = nil) # If repo_item is nil, he can do what he want return true if repo_item == nil # If the member is the owner, he can do what he want ! if repo_item.owner == self # You can do what ever you want :) return true # Find if a sharing of this rep exist for the self instance or it ancestors else path_ids = repo_item.path_ids # Check the nearest sharing if it exist if s = self.sharings.where(repo_item_id: path_ids).last 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} end end # Else, false return false end |
#get_sharing_permissions(sharing) ⇒ Object
Return the permissions of the sharing (can_add, can_remove)
484 485 486 |
# File 'lib/repository_manager/has_repository.rb', line 484 def (sharing) sharing.(self) end |
#move_repo_item(repo_item, options = {}) ⇒ Object
360 361 362 363 364 365 366 367 368 369 |
# File 'lib/repository_manager/has_repository.rb', line 360 def move_repo_item(repo_item, = {}) begin move_repo_item!(repo_item, ) rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException false rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.not_moved')) false end end |
#move_repo_item!(repo_item, options = {}) ⇒ Object
Move the repo_item options
:source_folder => move into this source_folder
if :source_folder == nil, move to the root
:overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/repository_manager/has_repository.rb', line 324 def move_repo_item!(repo_item, = {}) !![:overwrite] == [:overwrite] ? overwrite = [:overwrite] : overwrite = RepositoryManager.auto_overwrite_item target = [:source_folder] if !can_read?(repo_item) repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission')) raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'") end # If we want to change the owner we have to have the can_delete permission if target # If want to change the owner, we have to check if we have the permission if target.owner != repo_item.owner && !can_delete?(repo_item) repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission')) raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'") end # If we don't want to change the owner, we look if we can_update if target.owner == repo_item.owner && !can_update?(repo_item) repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission')) raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to update the '#{repo_item.name}'") end # We check if we can_create in the source_folder unless can_create?(target) repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission')) raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to create in the source_folder '#{[:source_folder].name}'") end else # Else if there is no source_folder, we check if we can delete the repo_item, if the owner change if self != repo_item.owner && !can_delete?(repo_item) repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission')) raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'") end end # If it has the permission, we move the repo_item in the source_folder repo_item.move!(source_folder: target, overwrite: overwrite) end |
#remove_members_from(sharing, members) ⇒ Object
578 579 580 581 582 583 584 |
# File 'lib/repository_manager/has_repository.rb', line 578 def remove_members_from(sharing, members) begin remove_members_from!(sharing, members) rescue RepositoryManager::PermissionException false end end |
#remove_members_from!(sharing, members) ⇒ Object
Remove members in the sharing Param member could be an object or an array of object
569 570 571 572 573 574 575 576 |
# File 'lib/repository_manager/has_repository.rb', line 569 def remove_members_from!(sharing, members) if can_remove_from?(sharing) sharing.remove_members(members) else sharing.errors.add(:remove, I18n.t('repository_manager.errors.sharing.remove.no_permission')) raise RepositoryManager::PermissionException.new("remove members failed. You don't have the permission to remove a member on this sharing") end end |
#rename_repo_item(repo_item, new_name) ⇒ Object
Rename the repo_item with the new_name
311 312 313 314 315 316 317 |
# File 'lib/repository_manager/has_repository.rb', line 311 def rename_repo_item(repo_item, new_name) begin rename_repo_item!(repo_item, new_name) rescue RepositoryManager::PermissionException false end end |
#rename_repo_item!(repo_item, new_name) ⇒ Object
Rename the repo_item with the new_name
302 303 304 305 306 307 308 |
# File 'lib/repository_manager/has_repository.rb', line 302 def rename_repo_item!(repo_item, new_name) unless can_update?(repo_item) repo_item.errors.add(:rename, I18n.t('repository_manager.errors.repo_item.rename.no_permission')) raise RepositoryManager::PermissionException.new("rename repo_item failed. You don't have the permission to update the repo_item '#{repo_item.name}'") end repo_item.rename!(new_name) end |
#repo_item_name_exist_in_root?(name) ⇒ Boolean
Returns true of false if the name exist in the root path of this instance
592 593 594 |
# File 'lib/repository_manager/has_repository.rb', line 592 def repo_item_name_exist_in_root?(name) get_item_in_root_by_name(name) ? true : false end |
#share_repo_item(repo_item, members, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/repository_manager/has_repository.rb', line 89 def share_repo_item(repo_item, members, = {}) begin share_repo_item!(repo_item, members, ) rescue RepositoryManager::PermissionException, RepositoryManager::NestedSharingException, RepositoryManager::RepositoryManagerException false rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.not_created')) false end end |
#share_repo_item!(repo_item, members, options = {}) ⇒ Object
Sharing the repo_item with the members, with the options options contains :
<tt>:can_read</tt> - Member can download the repo_item
<tt>:can_create</tt> - Member can create a new repo_item on it
<tt>:can_edit</tt> - Member can edit the repo_item
<tt>:can_delete</tt> - Member can delete the repo_item
<tt>:can_share</tt> - Member can share the repo_item
options contains :
<tt>:can_add</tt> - Specify if the member can add objects to the sharing
<tt>:can_remove</tt> - Specify if the member can remove object to the sharing
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/repository_manager/has_repository.rb', line 46 def share_repo_item!(repo_item, members, = {}) # Nested sharing are not accepted if !RepositoryManager.accept_nested_sharing # Check if no other sharing exist in the path unless repo_item.can_be_shared_without_nesting? repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.nested_sharing')) raise RepositoryManager::NestedSharingException.new("sharing failed. Another sharing already exist on the subtree or an ancestor of '#{repo_item.name}'") end end = (repo_item) # Here we look if the instance has the permission for making a sharing if can_share?(nil, ) # We put the default options = RepositoryManager. = RepositoryManager. # If there is options, we have to take it = [:repo_item_permissions] if [:repo_item_permissions] = [:sharing_permissions] if [:sharing_permissions] # Correct the item permission with accepted permissions = (, ) sharing = RepositoryManager::Sharing.new() sharing.owner = self sharing.creator = [:creator] sharing.add_members(members, ) repo_item.sharings << sharing repo_item.save! sharing else # No permission => No sharing repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.no_permission')) raise RepositoryManager::PermissionException.new("sharing failed. You don't have the permission to share the repo_item '#{repo_item.name}'") end end |
#unzip_repo_item(repo_item, options = {}) ⇒ Object
472 473 474 475 476 477 478 479 480 481 |
# File 'lib/repository_manager/has_repository.rb', line 472 def unzip_repo_item(repo_item, = {}) begin unzip_repo_item!(repo_item, ) rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException false rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.unzip.not_unzipped')) false end end |
#unzip_repo_item!(repo_item, options = {}) ⇒ Object
Unzip the compressed file and create the repo_items options
:source_folder = the folder in witch you unzip this archive
:sender = the sender of the item (if you don't specify sender.. The sender is still the same)
:overwrite = overwrite an item with the same name (default : see config 'auto_overwrite_item')
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/repository_manager/has_repository.rb', line 448 def unzip_repo_item!(repo_item, = {}) target = [:source_folder] unless can_read?(repo_item) repo_item.errors.add(:unzip, I18n.t('repository_manager.errors.repo_item.unzip.no_permission')) raise RepositoryManager::PermissionException.new("unzip repo_file failed. You don't have the permission to read the repo_file '#{repo_item.name}'") end if target && !can_create?(target) repo_item.errors.add(:unzip, I18n.t('repository_manager.errors.repo_item.unzip.no_permission')) raise RepositoryManager::PermissionException.new("unzip repo_file failed. You don't have the permission to create in the source_folder '#{target.name}'") end if !target parent = repo_item.parent if parent && !can_create?(parent) repo_item.errors.add(:unzip, I18n.t('repository_manager.errors.repo_item.unzip.no_permission')) raise RepositoryManager::PermissionException.new("unzip repo_file failed. You don't have the permission to create in the source_folder '#{parent.name}'") end end repo_item.unzip!(source_folder: target, owner: self, sender: [:sender], overwrite: [:overwrite]) end |