repository-manager 0.1.25 → 0.1.30
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -4
- data/app/models/repository_manager/repo_file.rb +17 -5
- data/app/models/repository_manager/repo_folder.rb +5 -33
- data/app/models/repository_manager/repo_item.rb +32 -1
- data/app/models/repository_manager/sharing.rb +2 -2
- data/lib/repository_manager/has_repository.rb +22 -23
- data/lib/repository_manager/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/models/repository_spec.rb +9 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 145f1e8967f2e0ab92b1b3e4956a9c24d6630275
         | 
| 4 | 
            +
              data.tar.gz: 0e532d15212ec9cd2594796bb7238c6ca38d2d12
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: eb7cb764141c843c0ad2df051c3a6da2d50d82bc15465bbf01bf4ad52a5928772c4cc7378a458efff6b45f5a3c09039365325e35f035bf873387080bef31283c
         | 
| 7 | 
            +
              data.tar.gz: 329f18f7c9dfd9b4ae4bc0f3808b8156dfa392da5b4ab2a7ae9f08fefc95289dceacced4dcd0aa7ffaffe9865d1ce24f2dfc3a103f7ef1597f0711d377b2516e
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -183,7 +183,7 @@ user1.move_repo_item(the_new_folder, test_folder) | |
| 183 183 | 
             
            #   |  |-- 'The new folder'
         | 
| 184 184 | 
             
            #   |  |  |-- 'file.txt'
         | 
| 185 185 |  | 
| 186 | 
            -
            # user1 want to rename 'The new folder' to 'The renamed folder'
         | 
| 186 | 
            +
            # user1 want to rename 'The new folder' to 'The renamed folder' (it also can change the name of a file)
         | 
| 187 187 | 
             
            user1.rename_repo_item(the_new_folder, 'The renamed folder')
         | 
| 188 188 |  | 
| 189 189 | 
             
            # user1 own repository :
         | 
| @@ -338,8 +338,8 @@ if repo_item.is_folder | |
| 338 338 | 
             
            elsif repo_item.is_file?
         | 
| 339 339 | 
             
              repo_item.name #=> Returns the name of the file (for instance : 'file.png').
         | 
| 340 340 | 
             
              # Here is the file
         | 
| 341 | 
            -
              repo_item.file.url # => '/url/to/ | 
| 342 | 
            -
              repo_item.file.current_path # => 'path/to/ | 
| 341 | 
            +
              repo_item.file.url # => '/url/to/stored_file.png'
         | 
| 342 | 
            +
              repo_item.file.current_path # => 'path/to/stored_file.png'
         | 
| 343 343 | 
             
            end
         | 
| 344 344 | 
             
            ```
         | 
| 345 345 |  | 
| @@ -442,6 +442,13 @@ RepositoryManager make the download of a `repo_item` easy. If the user want to d | |
| 442 442 | 
             
            If the `repo_item` is a file, the method returns you the path of this file.
         | 
| 443 443 | 
             
            If the `repo_item` is a folder, it automatically generates a zip file with all the constant that the user `can_read`. The method returns the path of this zip file.
         | 
| 444 444 |  | 
| 445 | 
            +
            ```ruby
         | 
| 446 | 
            +
            # user1 want to download the_file
         | 
| 447 | 
            +
            path_to_file = user1.download(the_file)
         | 
| 448 | 
            +
            # don't forget to specify the name of the file (it could have been changed since uploaded)
         | 
| 449 | 
            +
            send_file path_to_file, filename: the_file.name
         | 
| 450 | 
            +
            ```
         | 
| 451 | 
            +
             | 
| 445 452 | 
             
            ```ruby
         | 
| 446 453 | 
             
            # user1 want to download the_folder
         | 
| 447 454 | 
             
            path_to_zip = user1.download(the_folder)
         | 
| @@ -507,7 +514,7 @@ end | |
| 507 514 |  | 
| 508 515 | 
             
            ## TODO
         | 
| 509 516 |  | 
| 510 | 
            -
            -  | 
| 517 | 
            +
            - Test the rename file method
         | 
| 511 518 | 
             
            - Write the methods : share_link.
         | 
| 512 519 | 
             
            - Snapshot the file if possible
         | 
| 513 520 | 
             
            - Versioning
         | 
| @@ -4,11 +4,16 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem | |
| 4 4 | 
             
              validates_presence_of :file
         | 
| 5 5 | 
             
              mount_uploader :file, RepoFileUploader
         | 
| 6 6 | 
             
              before_save :update_asset_attributes
         | 
| 7 | 
            +
              before_create :default_name
         | 
| 7 8 |  | 
| 8 | 
            -
               | 
| 9 | 
            -
              def name
         | 
| 10 | 
            -
             | 
| 11 | 
            -
               | 
| 9 | 
            +
              ## Return the name of the file with his extension
         | 
| 10 | 
            +
              #def name
         | 
| 11 | 
            +
              #  if self.name.blank?
         | 
| 12 | 
            +
              #    file.url.split('/').last
         | 
| 13 | 
            +
              #  else
         | 
| 14 | 
            +
              #    self.name
         | 
| 15 | 
            +
              #  end
         | 
| 16 | 
            +
              #end
         | 
| 12 17 |  | 
| 13 18 | 
             
              def download(options = {})
         | 
| 14 19 | 
             
                self.download!(options)
         | 
| @@ -31,6 +36,7 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem | |
| 31 36 | 
             
                if options[:source_folder]
         | 
| 32 37 | 
             
                  options[:source_folder].add!(new_item)
         | 
| 33 38 | 
             
                elsif options[:owner].repo_item_name_exist_in_root?(new_item.name)
         | 
| 39 | 
            +
                  self.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 34 40 | 
             
                  raise RepositoryManager::ItemExistException.new("copy failed. The repo_file '#{new_item.name}' already exist in root.")
         | 
| 35 41 | 
             
                end
         | 
| 36 42 |  | 
| @@ -50,7 +56,7 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem | |
| 50 56 | 
             
              def copy(options = {})
         | 
| 51 57 | 
             
                begin
         | 
| 52 58 | 
             
                  copy!(options)
         | 
| 53 | 
            -
                rescue RepositoryManager:: | 
| 59 | 
            +
                rescue RepositoryManager::ItemExistException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 54 60 | 
             
                  false
         | 
| 55 61 | 
             
                end
         | 
| 56 62 | 
             
              end
         | 
| @@ -64,4 +70,10 @@ class RepositoryManager::RepoFile < RepositoryManager::RepoItem | |
| 64 70 | 
             
                end
         | 
| 65 71 | 
             
              end
         | 
| 66 72 |  | 
| 73 | 
            +
              def default_name
         | 
| 74 | 
            +
                if name.blank?
         | 
| 75 | 
            +
                  self.name = file.url.split('/').last
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 67 79 | 
             
            end
         | 
| @@ -21,27 +21,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem | |
| 21 21 | 
             
              def add(repo_item)
         | 
| 22 22 | 
             
                begin
         | 
| 23 23 | 
             
                  add!(repo_item)
         | 
| 24 | 
            -
                rescue RepositoryManager:: | 
| 25 | 
            -
                  false
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              # Rename the item
         | 
| 30 | 
            -
              def rename!(new_name)
         | 
| 31 | 
            -
                if name_exist_in_siblings?(new_name)
         | 
| 32 | 
            -
                  raise RepositoryManager::ItemExistException.new("rename failed. The repo_item '#{new_name}' already exist.'")
         | 
| 33 | 
            -
                else
         | 
| 34 | 
            -
                  self.name = new_name
         | 
| 35 | 
            -
                  # TODO see if I have to save or not
         | 
| 36 | 
            -
                  save!
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
              # Rename the item
         | 
| 41 | 
            -
              def rename(new_name)
         | 
| 42 | 
            -
                begin
         | 
| 43 | 
            -
                  rename!(new_name)
         | 
| 44 | 
            -
                rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 24 | 
            +
                rescue RepositoryManager::ItemExistException
         | 
| 45 25 | 
             
                  false
         | 
| 46 26 | 
             
                end
         | 
| 47 27 | 
             
              end
         | 
| @@ -58,6 +38,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem | |
| 58 38 | 
             
                if options[:source_folder]
         | 
| 59 39 | 
             
                  options[:source_folder].add!(new_item)
         | 
| 60 40 | 
             
                elsif options[:owner].repo_item_name_exist_in_root?(new_item.name)
         | 
| 41 | 
            +
                  self.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 61 42 | 
             
                  raise RepositoryManager::ItemExistException.new("copy failed. The repo_folder '#{new_item.name}' already exist in root.")
         | 
| 62 43 | 
             
                end
         | 
| 63 44 |  | 
| @@ -83,7 +64,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem | |
| 83 64 | 
             
              def copy(options = {})
         | 
| 84 65 | 
             
                begin
         | 
| 85 66 | 
             
                  copy!(options)
         | 
| 86 | 
            -
                rescue RepositoryManager:: | 
| 67 | 
            +
                rescue RepositoryManager::ItemExistException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 87 68 | 
             
                  false
         | 
| 88 69 | 
             
                end
         | 
| 89 70 | 
             
              end
         | 
| @@ -124,7 +105,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem | |
| 124 105 |  | 
| 125 106 | 
             
                File.chmod(0444, full_path)
         | 
| 126 107 |  | 
| 127 | 
            -
             | 
| 108 | 
            +
                return full_path
         | 
| 128 109 | 
             
                #else
         | 
| 129 110 | 
             
                #  # Nothing to download here
         | 
| 130 111 | 
             
                #  raise RepositoryManager::RepositoryManagerException.new("download failed. Folder #{name} is empty")
         | 
| @@ -153,16 +134,7 @@ class RepositoryManager::RepoFolder < RepositoryManager::RepoItem | |
| 153 134 | 
             
              # Returns true or false if the name exist in this folder
         | 
| 154 135 | 
             
              def name_exist_in_children?(name)
         | 
| 155 136 | 
             
                #RepositoryManager::RepoItem.where(name: name).where(id: child_ids).first ? true : false
         | 
| 156 | 
            -
                RepositoryManager::RepoItem.where('name = ? | 
| 157 | 
            -
              end
         | 
| 158 | 
            -
             | 
| 159 | 
            -
              # Returns true or false if the name exist in siblings
         | 
| 160 | 
            -
              def name_exist_in_siblings?(name)
         | 
| 161 | 
            -
                # We take all siblings without itself
         | 
| 162 | 
            -
                sibling_ids_without_itself = self.sibling_ids.delete(self.id)
         | 
| 163 | 
            -
                # We check if another item has the same name
         | 
| 164 | 
            -
                #RepositoryManager::RepoItem.where(name: name).where(id: sibling_ids_without_itself).first ? true : false
         | 
| 165 | 
            -
                RepositoryManager::RepoItem.where('name = ? OR file = ?', name, name).where(id: sibling_ids_without_itself).first ? true : false
         | 
| 137 | 
            +
                RepositoryManager::RepoItem.where('name = ?', name).where(id: child_ids).first ? true : false
         | 
| 166 138 | 
             
              end
         | 
| 167 139 |  | 
| 168 140 | 
             
              private
         | 
| @@ -39,11 +39,13 @@ class RepositoryManager::RepoItem < ActiveRecord::Base | |
| 39 39 | 
             
                    raise RepositoryManager::RepositoryManagerException.new("move failed. target '#{options[:source_folder].name}' can't be a file")
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 | 
             
                  if options[:source_folder].name_exist_in_children?(self.name)
         | 
| 42 | 
            +
                    self.errors.add(:move, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 42 43 | 
             
                    raise RepositoryManager::ItemExistException.new("move failed. The repo_item '#{name}' already exist ine the folder '#{options[:source_folder].name}'")
         | 
| 43 44 | 
             
                  end
         | 
| 44 45 | 
             
                # We are in root, we check if name exist in root
         | 
| 45 46 | 
             
                # We stay in the same owner
         | 
| 46 47 | 
             
                elsif self.owner.repo_item_name_exist_in_root?(self.name)
         | 
| 48 | 
            +
                  self.errors.add(:move, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 47 49 | 
             
                  raise RepositoryManager::ItemExistException.new("move failed. The repo_item '#{name}' already exist ine the root")
         | 
| 48 50 | 
             
                end
         | 
| 49 51 | 
             
                # here, all is ok
         | 
| @@ -62,7 +64,27 @@ class RepositoryManager::RepoItem < ActiveRecord::Base | |
| 62 64 | 
             
              def move(options = {})
         | 
| 63 65 | 
             
                begin
         | 
| 64 66 | 
             
                  move!(options)
         | 
| 65 | 
            -
                rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 67 | 
            +
                rescue RepositoryManager::RepositoryManagerException, RepositoryManager::ItemExistException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 68 | 
            +
                  false
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              # Rename the item
         | 
| 73 | 
            +
              def rename!(new_name)
         | 
| 74 | 
            +
                if name_exist_in_siblings?(new_name)
         | 
| 75 | 
            +
                  self.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 76 | 
            +
                  raise RepositoryManager::ItemExistException.new("rename failed. The repo_item '#{new_name}' already exist.'")
         | 
| 77 | 
            +
                else
         | 
| 78 | 
            +
                  self.name = new_name
         | 
| 79 | 
            +
                  save!
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              # Rename the item
         | 
| 84 | 
            +
              def rename(new_name)
         | 
| 85 | 
            +
                begin
         | 
| 86 | 
            +
                  rename!(new_name)
         | 
| 87 | 
            +
                rescue RepositoryManager::ItemExistException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 66 88 | 
             
                  false
         | 
| 67 89 | 
             
                end
         | 
| 68 90 | 
             
              end
         | 
| @@ -92,6 +114,15 @@ class RepositoryManager::RepoItem < ActiveRecord::Base | |
| 92 114 | 
             
                self.type == 'RepositoryManager::RepoFile'
         | 
| 93 115 | 
             
              end
         | 
| 94 116 |  | 
| 117 | 
            +
              # Returns true or false if the name exist in siblings
         | 
| 118 | 
            +
              def name_exist_in_siblings?(name)
         | 
| 119 | 
            +
                # We take all siblings without itself
         | 
| 120 | 
            +
                sibling_ids_without_itself = self.sibling_ids.delete(self.id)
         | 
| 121 | 
            +
                # We check if another item has the same name
         | 
| 122 | 
            +
                #RepositoryManager::RepoItem.where(name: name).where(id: sibling_ids_without_itself).first ? true : false
         | 
| 123 | 
            +
                RepositoryManager::RepoItem.where('name = ?', name).where(id: sibling_ids_without_itself).first ? true : false
         | 
| 124 | 
            +
              end
         | 
| 125 | 
            +
             | 
| 95 126 | 
             
              private
         | 
| 96 127 | 
             
              def put_sender
         | 
| 97 128 | 
             
                self.sender = owner unless sender
         | 
| @@ -36,7 +36,7 @@ class RepositoryManager::Sharing < ActiveRecord::Base | |
| 36 36 | 
             
                if members.kind_of?(Array)
         | 
| 37 37 | 
             
                  # Add each member to this sharing
         | 
| 38 38 | 
             
                  members.each do |i|
         | 
| 39 | 
            -
                    unless i.respond_to? : | 
| 39 | 
            +
                    unless i.respond_to? :create_folder # Check if this object "has_repository"
         | 
| 40 40 | 
             
                      raise RepositoryManager::RepositoryManagerException.new("add members failed. The object passed into members should be a model who 'has_repository'")
         | 
| 41 41 | 
             
                    end
         | 
| 42 42 | 
             
                    sharing_member = RepositoryManager::SharingsMember.new(sharing_permissions)
         | 
| @@ -45,7 +45,7 @@ class RepositoryManager::Sharing < ActiveRecord::Base | |
| 45 45 | 
             
                    self.sharings_members << sharing_member
         | 
| 46 46 | 
             
                  end
         | 
| 47 47 | 
             
                else
         | 
| 48 | 
            -
                  unless members.respond_to? : | 
| 48 | 
            +
                  unless members.respond_to? :create_folder # Check if this object "has_repository"
         | 
| 49 49 | 
             
                    raise RepositoryManager::RepositoryManagerException.new("add members failed. The object passed into members should be a model who 'has_repository'")
         | 
| 50 50 | 
             
                  end
         | 
| 51 51 | 
             
                  sharing_member = RepositoryManager::SharingsMember.new(sharing_permissions)
         | 
| @@ -49,6 +49,7 @@ module RepositoryManager | |
| 49 49 | 
             
                    if !RepositoryManager.accept_nested_sharing
         | 
| 50 50 | 
             
                      # Check if no other sharing exist in the path
         | 
| 51 51 | 
             
                      unless repo_item.can_be_shared_without_nesting?
         | 
| 52 | 
            +
                        repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.nested_sharing'))
         | 
| 52 53 | 
             
                        raise RepositoryManager::NestedSharingException.new("sharing failed. Another sharing already exist on the subtree or an ancestor of '#{repo_item.name}'")
         | 
| 53 54 | 
             
                      end
         | 
| 54 55 | 
             
                    end
         | 
| @@ -80,6 +81,7 @@ module RepositoryManager | |
| 80 81 | 
             
                      sharing
         | 
| 81 82 | 
             
                    else
         | 
| 82 83 | 
             
                      # No permission => No sharing
         | 
| 84 | 
            +
                      repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.no_permission'))
         | 
| 83 85 | 
             
                      raise RepositoryManager::PermissionException.new("sharing failed. You don't have the permission to share the repo_item '#{repo_item.name}'")
         | 
| 84 86 | 
             
                    end
         | 
| 85 87 | 
             
                  end
         | 
| @@ -87,11 +89,7 @@ module RepositoryManager | |
| 87 89 | 
             
                  def share(repo_item, members, options = {})
         | 
| 88 90 | 
             
                    begin
         | 
| 89 91 | 
             
                      share!(repo_item, members, options)
         | 
| 90 | 
            -
                    rescue RepositoryManager::PermissionException
         | 
| 91 | 
            -
                      repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.no_permission'))
         | 
| 92 | 
            -
                      false
         | 
| 93 | 
            -
                    rescue RepositoryManager::NestedSharingException
         | 
| 94 | 
            -
                      repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.nested_sharing'))
         | 
| 92 | 
            +
                    rescue RepositoryManager::PermissionException, RepositoryManager::NestedSharingException, RepositoryManager::RepositoryManagerException
         | 
| 95 93 | 
             
                      false
         | 
| 96 94 | 
             
                    rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 97 95 | 
             
                      repo_item.errors.add(:sharing, I18n.t('repository_manager.errors.sharing.create.not_created'))
         | 
| @@ -165,6 +163,7 @@ module RepositoryManager | |
| 165 163 | 
             
                    if can_delete?(repo_item)
         | 
| 166 164 | 
             
                      repo_item.destroy
         | 
| 167 165 | 
             
                    else
         | 
| 166 | 
            +
                      repo_item.errors.add(:delete, I18n.t('repository_manager.errors.repo_item.delete.no_permission'))
         | 
| 168 167 | 
             
                      raise RepositoryManager::PermissionException.new("delete_repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
         | 
| 169 168 | 
             
                    end
         | 
| 170 169 | 
             
                  end
         | 
| @@ -173,7 +172,6 @@ module RepositoryManager | |
| 173 172 | 
             
                    begin
         | 
| 174 173 | 
             
                      delete_repo_item!(repo_item)
         | 
| 175 174 | 
             
                    rescue RepositoryManager::PermissionException
         | 
| 176 | 
            -
                      repo_item.errors.add(:delete, I18n.t('repository_manager.errors.repo_item.delete.no_permission'))
         | 
| 177 175 | 
             
                      false
         | 
| 178 176 | 
             
                    end
         | 
| 179 177 | 
             
                  end
         | 
| @@ -182,6 +180,7 @@ module RepositoryManager | |
| 182 180 | 
             
                  # options :
         | 
| 183 181 | 
             
                  #   :source_folder = The directory in with the folder is created
         | 
| 184 182 | 
             
                  #   :sender = The object of the sender (ex : current_user)
         | 
| 183 | 
            +
                  #   :filename = The name of the file (if you want to rename it directly)
         | 
| 185 184 | 
             
                  #
         | 
| 186 185 | 
             
                  # Param file can be a File, or a instance of RepoFile
         | 
| 187 186 | 
             
                  # Returns the object of the file created if it is ok
         | 
| @@ -208,6 +207,8 @@ module RepositoryManager | |
| 208 207 | 
             
                        repo_file = RepositoryManager::RepoFile.new(file)
         | 
| 209 208 | 
             
                      end
         | 
| 210 209 |  | 
| 210 | 
            +
                      options[:filename] ? repo_file.name = options[:filename] : repo_file.name = repo_file.file.url.split('/').last
         | 
| 211 | 
            +
             | 
| 211 212 | 
             
                      repo_file.owner = self
         | 
| 212 213 | 
             
                      repo_file.sender = options[:sender]
         | 
| 213 214 |  | 
| @@ -280,6 +281,7 @@ module RepositoryManager | |
| 280 281 |  | 
| 281 282 | 
             
                      repo_item.download!({object: self, path: path})
         | 
| 282 283 | 
             
                    else
         | 
| 284 | 
            +
                      repo_item.errors.add(:download, I18n.t('repository_manager.errors.repo_item.download.no_permission'))
         | 
| 283 285 | 
             
                      raise RepositoryManager::PermissionException.new("download failed. You don't have the permission to download the repo_item '#{repo_item.name}'")
         | 
| 284 286 | 
             
                    end
         | 
| 285 287 | 
             
                  end
         | 
| @@ -288,7 +290,6 @@ module RepositoryManager | |
| 288 290 | 
             
                    begin
         | 
| 289 291 | 
             
                      download!(repo_item, options)
         | 
| 290 292 | 
             
                    rescue RepositoryManager::PermissionException
         | 
| 291 | 
            -
                      repo_item.errors.add(:download, I18n.t('repository_manager.errors.repo_item.download.no_permission'))
         | 
| 292 293 | 
             
                      false
         | 
| 293 294 | 
             
                    end
         | 
| 294 295 | 
             
                  end
         | 
| @@ -296,6 +297,7 @@ module RepositoryManager | |
| 296 297 | 
             
                  # Rename the repo_item with the new_name
         | 
| 297 298 | 
             
                  def rename_repo_item!(repo_item, new_name)
         | 
| 298 299 | 
             
                    unless can_update?(repo_item)
         | 
| 300 | 
            +
                      repo_item.errors.add(:rename, I18n.t('repository_manager.errors.repo_item.rename.no_permission'))
         | 
| 299 301 | 
             
                      raise RepositoryManager::PermissionException.new("rename repo_item failed. You don't have the permission to update the repo_item '#{repo_item.name}'")
         | 
| 300 302 | 
             
                    end
         | 
| 301 303 | 
             
                    repo_item.rename!(new_name)
         | 
| @@ -306,7 +308,6 @@ module RepositoryManager | |
| 306 308 | 
             
                    begin
         | 
| 307 309 | 
             
                      rename_repo_item!(repo_item, new_name)
         | 
| 308 310 | 
             
                    rescue RepositoryManager::PermissionException
         | 
| 309 | 
            -
                      repo_item.errors.add(:rename, I18n.t('repository_manager.errors.repo_item.rename.no_permission'))
         | 
| 310 311 | 
             
                      false
         | 
| 311 312 | 
             
                    end
         | 
| 312 313 | 
             
                  end
         | 
| @@ -316,25 +317,30 @@ module RepositoryManager | |
| 316 317 | 
             
                  # if target == nil, move to the root
         | 
| 317 318 | 
             
                  def move_repo_item!(repo_item, target = nil)
         | 
| 318 319 | 
             
                    if !can_read?(repo_item)
         | 
| 320 | 
            +
                      repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 319 321 | 
             
                      raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
         | 
| 320 322 | 
             
                    end
         | 
| 321 323 | 
             
                    # If we want to change the owner we have to have the can_delete permission
         | 
| 322 324 | 
             
                    if target
         | 
| 323 325 | 
             
                      # If want to change the owner, we have to check if we have the permission
         | 
| 324 326 | 
             
                      if target.owner != repo_item.owner && !can_delete?(repo_item)
         | 
| 327 | 
            +
                        repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 325 328 | 
             
                        raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
         | 
| 326 329 | 
             
                      end
         | 
| 327 330 | 
             
                      # If we don't want to change the owner, we look if we can_update
         | 
| 328 331 | 
             
                      if target.owner == repo_item.owner && !can_update?(repo_item)
         | 
| 332 | 
            +
                        repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 329 333 | 
             
                        raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to update the '#{repo_item.name}'")
         | 
| 330 334 | 
             
                      end
         | 
| 331 335 | 
             
                      # We check if we can_create in the source_folder
         | 
| 332 336 | 
             
                      unless can_create?(target)
         | 
| 337 | 
            +
                        repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 333 338 | 
             
                        raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to create in the source_folder '#{options[:source_folder].name}'")
         | 
| 334 339 | 
             
                      end
         | 
| 335 340 | 
             
                    else
         | 
| 336 341 | 
             
                      # Else if there is no source_folder, we check if we can delete the repo_item, if the owner change
         | 
| 337 342 | 
             
                      if self != repo_item.owner && !can_delete?(repo_item)
         | 
| 343 | 
            +
                        repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 338 344 | 
             
                        raise RepositoryManager::PermissionException.new("move repo_item failed. You don't have the permission to delete the repo_item '#{repo_item.name}'")
         | 
| 339 345 | 
             
                      end
         | 
| 340 346 | 
             
                    end
         | 
| @@ -345,11 +351,7 @@ module RepositoryManager | |
| 345 351 | 
             
                  def move_repo_item(repo_item, target = nil)
         | 
| 346 352 | 
             
                    begin
         | 
| 347 353 | 
             
                      move_repo_item!(repo_item, target)
         | 
| 348 | 
            -
                    rescue RepositoryManager::PermissionException
         | 
| 349 | 
            -
                      repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.no_permission'))
         | 
| 350 | 
            -
                      false
         | 
| 351 | 
            -
                    rescue RepositoryManager::ItemExistException
         | 
| 352 | 
            -
                      repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 354 | 
            +
                    rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException
         | 
| 353 355 | 
             
                      false
         | 
| 354 356 | 
             
                    rescue RepositoryManager::RepositoryManagerException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 355 357 | 
             
                      repo_item.errors.add(:move, I18n.t('repository_manager.errors.repo_item.move.not_moved'))
         | 
| @@ -363,10 +365,12 @@ module RepositoryManager | |
| 363 365 | 
             
                  #   :sender => the new sender (by default => still the old sender)
         | 
| 364 366 | 
             
                  def copy_repo_item!(repo_item, target = nil, options = {})
         | 
| 365 367 | 
             
                    unless can_read?(repo_item)
         | 
| 368 | 
            +
                      repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.no_permission'))
         | 
| 366 369 | 
             
                      raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to read the repo_item '#{repo_item.name}'")
         | 
| 367 370 | 
             
                    end
         | 
| 368 371 |  | 
| 369 372 | 
             
                    if target &&  !can_create?(target)
         | 
| 373 | 
            +
                      repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.no_permission'))
         | 
| 370 374 | 
             
                      raise RepositoryManager::PermissionException.new("copy repo_item failed. You don't have the permission to create in the source_folder '#{target.name}'")
         | 
| 371 375 | 
             
                    end
         | 
| 372 376 |  | 
| @@ -384,13 +388,9 @@ module RepositoryManager | |
| 384 388 | 
             
                  def copy_repo_item(repo_item, target = nil, options = {})
         | 
| 385 389 | 
             
                    begin
         | 
| 386 390 | 
             
                      copy_repo_item!(repo_item, target, options)
         | 
| 387 | 
            -
                    rescue RepositoryManager::PermissionException
         | 
| 388 | 
            -
                      repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.no_permission'))
         | 
| 389 | 
            -
                      false
         | 
| 390 | 
            -
                    rescue RepositoryManager::ItemExistException
         | 
| 391 | 
            -
                      repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.item_exist'))
         | 
| 391 | 
            +
                    rescue RepositoryManager::PermissionException, RepositoryManager::ItemExistException
         | 
| 392 392 | 
             
                      false
         | 
| 393 | 
            -
                    rescue  | 
| 393 | 
            +
                    rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
         | 
| 394 394 | 
             
                      repo_item.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.copy.not_copied'))
         | 
| 395 395 | 
             
                      false
         | 
| 396 396 | 
             
                    end
         | 
| @@ -472,6 +472,7 @@ module RepositoryManager | |
| 472 472 | 
             
                      sharing_permissions = make_sharing_permissions(options, permissions)
         | 
| 473 473 | 
             
                      sharing.add_members(members, sharing_permissions)
         | 
| 474 474 | 
             
                    else
         | 
| 475 | 
            +
                      sharing.errors.add(:add, I18n.t('repository_manager.errors.sharing.add.no_permission'))
         | 
| 475 476 | 
             
                      raise RepositoryManager::PermissionException.new("add members failed. You don't have the permission to add a member in this sharing")
         | 
| 476 477 | 
             
                    end
         | 
| 477 478 | 
             
                  end
         | 
| @@ -480,7 +481,6 @@ module RepositoryManager | |
| 480 481 | 
             
                    begin
         | 
| 481 482 | 
             
                      add_members_to!(sharing, members, options = RepositoryManager.default_sharing_permissions)
         | 
| 482 483 | 
             
                    rescue RepositoryManager::PermissionException
         | 
| 483 | 
            -
                      sharing.errors.add(:add, I18n.t('repository_manager.errors.sharing.add.no_permission'))
         | 
| 484 484 | 
             
                      false
         | 
| 485 485 | 
             
                    end
         | 
| 486 486 | 
             
                  end
         | 
| @@ -491,6 +491,7 @@ module RepositoryManager | |
| 491 491 | 
             
                    if can_remove_from?(sharing)
         | 
| 492 492 | 
             
                      sharing.remove_members(members)
         | 
| 493 493 | 
             
                    else
         | 
| 494 | 
            +
                      sharing.errors.add(:remove, I18n.t('repository_manager.errors.sharing.remove.no_permission'))
         | 
| 494 495 | 
             
                      raise RepositoryManager::PermissionException.new("remove members failed. You don't have the permission to remove a member on this sharing")
         | 
| 495 496 | 
             
                    end
         | 
| 496 497 | 
             
                  end
         | 
| @@ -499,7 +500,6 @@ module RepositoryManager | |
| 499 500 | 
             
                    begin
         | 
| 500 501 | 
             
                      remove_members_from!(sharing, members)
         | 
| 501 502 | 
             
                    rescue RepositoryManager::PermissionException
         | 
| 502 | 
            -
                      sharing.errors.add(:remove, I18n.t('repository_manager.errors.sharing.remove.no_permission'))
         | 
| 503 503 | 
             
                      false
         | 
| 504 504 | 
             
                    end
         | 
| 505 505 | 
             
                  end
         | 
| @@ -511,7 +511,7 @@ module RepositoryManager | |
| 511 511 |  | 
| 512 512 | 
             
                  # Returns true of false if the name exist in the root path of this instance
         | 
| 513 513 | 
             
                  def repo_item_name_exist_in_root?(name)
         | 
| 514 | 
            -
                    RepoItem.where('name = ? | 
| 514 | 
            +
                    RepoItem.where('name = ?', name).where(owner: self).where(ancestry: nil).first ? true : false
         | 
| 515 515 | 
             
                  end
         | 
| 516 516 |  | 
| 517 517 | 
             
                  private
         | 
| @@ -541,7 +541,6 @@ module RepositoryManager | |
| 541 541 | 
             
                    if permissions == nil
         | 
| 542 542 | 
             
                      permissions = get_permissions(repo_item)
         | 
| 543 543 | 
             
                    end
         | 
| 544 | 
            -
             | 
| 545 544 | 
             
                    case what
         | 
| 546 545 | 
             
                      when 'read'
         | 
| 547 546 | 
             
                        permissions == true || (permissions.kind_of?(Hash) && permissions[:can_read] == true)
         | 
    
        data/spec/dummy/db/test.sqlite3
    CHANGED
    
    | Binary file | 
| @@ -247,9 +247,17 @@ describe 'RepoItem' do | |
| 247 247 | 
             
                file2 = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), options)
         | 
| 248 248 | 
             
                expect(file2).to eq(false)
         | 
| 249 249 | 
             
                expect(options[:errors]).to eq(['This file already exist'])
         | 
| 250 | 
            +
              end
         | 
| 250 251 |  | 
| 252 | 
            +
              it "can rename a file" do
         | 
| 253 | 
            +
                file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
         | 
| 254 | 
            +
                @user1.rename_repo_item(file, 'lol.txt')
         | 
| 255 | 
            +
                expect(file.reload.name).to eq('lol.txt')
         | 
| 256 | 
            +
                @user1.create_file!(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder)
         | 
| 257 | 
            +
                file2 = @user1.create_file!(File.open("#{Rails.root}/../fixture/textfile.txt"), source_folder: @user1_folder, filename: 'haha.txt')
         | 
| 251 258 |  | 
| 252 | 
            -
                 | 
| 259 | 
            +
                expect(file2.reload.name).to eq('haha.txt')
         | 
| 260 | 
            +
                expect(@user1_folder.children.count).to eq(3)
         | 
| 253 261 | 
             
              end
         | 
| 254 262 |  | 
| 255 263 | 
             
              it 'sender is equal to owner if no sender in create_folder' do
         | 
    
        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. | 
| 4 | 
            +
              version: 0.1.30
         | 
| 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-03- | 
| 11 | 
            +
            date: 2014-03-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |