repository-manager 0.0.13 → 0.0.22
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 +5 -13
- data/.rspec +1 -1
- data/README.md +424 -419
- data/app/models/repo_file.rb +29 -29
- data/app/models/repo_folder.rb +134 -114
- data/app/models/repo_item.rb +65 -64
- data/app/models/sharing.rb +58 -58
- data/app/models/sharings_member.rb +5 -5
- data/config/locales/en/repository_manager.en.yml +19 -0
- data/config/locales/fr/repository_manager.fr.yml +19 -0
- data/db/migrate/20131018214212_create_repository_manager.rb +32 -31
- data/lib/generators/repository_manager/install_generator.rb +32 -32
- data/lib/generators/repository_manager/templates/initializer.rb +11 -11
- data/lib/repository_manager/exceptions.rb +9 -9
- data/lib/repository_manager/has_repository.rb +506 -452
- data/lib/repository_manager/version.rb +1 -1
- data/repository-manager.gemspec +30 -30
- data/spec/dummy/db/migrate/20131016193722_create_users.rb +10 -10
- data/spec/dummy/db/migrate/20131016193834_create_groups.rb +9 -9
- data/spec/dummy/db/migrate/20131016194207_create_groups_users.rb +4 -4
- data/spec/dummy/db/migrate/20131018214212_create_repository_manager.rb +31 -31
- data/spec/dummy/db/schema.rb +66 -66
- data/spec/factories/group.rb +7 -7
- data/spec/factories/repo_file.rb +12 -12
- data/spec/factories/repo_folder.rb +7 -7
- data/spec/factories/user.rb +13 -13
- data/spec/has_repository_spec.rb +280 -281
- data/spec/models/associations_spec.rb +88 -88
- data/spec/models/repository_spec.rb +176 -144
- data/spec/models/share_spec.rb +67 -67
- metadata +34 -37
data/repository-manager.gemspec
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
$:.push File.expand_path("../lib", __FILE__)
|
2
|
-
|
3
|
-
# Maintain your gem's version:
|
4
|
-
require "repository_manager/version"
|
5
|
-
|
6
|
-
# Describe your gem and declare its dependencies:
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = 'repository-manager'
|
9
|
-
s.version = RepositoryManager::VERSION
|
10
|
-
s.authors = ['Yves Baumann']
|
11
|
-
s.email = ['texicitys@gmail.com']
|
12
|
-
s.homepage = 'https://github.com/Texicitys/repository-manager'
|
13
|
-
s.summary = "Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharings)."
|
14
|
-
s.description = "This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete authorisations management.
|
15
|
-
Each instance (users, groups, etc..) can have it own repositories (with files and folders). It can manage them easily (edit, remove, add, etc) and sharing them with other instance."
|
16
|
-
|
17
|
-
#s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
20
|
-
#s.test_files = Dir["spec/**/*"]
|
21
|
-
s.license = 'MIT'
|
22
|
-
|
23
|
-
s.add_runtime_dependency
|
24
|
-
|
25
|
-
s.add_development_dependency '
|
26
|
-
s.add_development_dependency 'sqlite3'
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_runtime_dependency 'ancestry'
|
29
|
-
s.add_runtime_dependency
|
30
|
-
s.add_runtime_dependency 'rubyzip'
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "repository_manager/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'repository-manager'
|
9
|
+
s.version = RepositoryManager::VERSION
|
10
|
+
s.authors = ['Yves Baumann']
|
11
|
+
s.email = ['texicitys@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/Texicitys/repository-manager'
|
13
|
+
s.summary = "Ruby on Rails plugin (gem) for managing repositories (files/folders/permissions/sharings)."
|
14
|
+
s.description = "This project is based on the need for a repository manager system for Collaide. A system for easily create/delete files and folders in a repository. For sharing these repositories easily with other object with a flexible and complete authorisations management.
|
15
|
+
Each instance (users, groups, etc..) can have it own repositories (with files and folders). It can manage them easily (edit, remove, add, etc) and sharing them with other instance."
|
16
|
+
|
17
|
+
#s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
20
|
+
#s.test_files = Dir["spec/**/*"]
|
21
|
+
s.license = 'MIT'
|
22
|
+
|
23
|
+
s.add_runtime_dependency('rails', '> 3.0.0')
|
24
|
+
|
25
|
+
s.add_development_dependency('factory_girl', '>= 2.6.0')
|
26
|
+
s.add_development_dependency 'sqlite3'
|
27
|
+
s.add_development_dependency('rspec-rails', '>= 2.6.1')
|
28
|
+
s.add_runtime_dependency 'ancestry'
|
29
|
+
s.add_runtime_dependency('carrierwave', '>= 0.5.8')
|
30
|
+
s.add_runtime_dependency 'rubyzip', '>= 1.0.0'#, :require => 'zip/zip'
|
31
31
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :users do |t|
|
4
|
-
t.string :nickname
|
5
|
-
t.string :password
|
6
|
-
t.string :email
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :nickname
|
5
|
+
t.string :password
|
6
|
+
t.string :email
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
11
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class CreateGroups < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :groups do |t|
|
4
|
-
t.string :name
|
5
|
-
t.text :description
|
6
|
-
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
end
|
1
|
+
class CreateGroups < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :groups do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :description
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class CreateGroupsUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_join_table :groups, :users
|
4
|
-
end
|
1
|
+
class CreateGroupsUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_join_table :groups, :users
|
4
|
+
end
|
5
5
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
class CreateRepositoryManager < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def change
|
4
|
-
|
5
|
-
create_table :sharings do |t|
|
6
|
-
t.references :owner, polymorphic: true
|
7
|
-
t.references :repo_item
|
8
|
-
t.boolean :can_create, :default => false
|
9
|
-
t.boolean :can_read, :default => false
|
10
|
-
t.boolean :can_update, :default => false
|
11
|
-
t.boolean :can_delete, :default => false
|
12
|
-
t.boolean :can_share, :default => false
|
13
|
-
end
|
14
|
-
|
15
|
-
create_table :sharings_members do |t|
|
16
|
-
t.references :sharing
|
17
|
-
t.references :member, polymorphic: true
|
18
|
-
t.boolean :can_add, :default => false
|
19
|
-
t.boolean :can_remove, :default => false
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table :repo_items do |t|
|
23
|
-
t.references :owner, polymorphic: true
|
24
|
-
t.string :ancestry
|
25
|
-
t.string :name
|
26
|
-
t.float :file_size
|
27
|
-
t.string :content_type
|
28
|
-
t.string :file
|
29
|
-
t.string :type
|
30
|
-
end
|
31
|
-
end
|
1
|
+
class CreateRepositoryManager < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
|
5
|
+
create_table :sharings do |t|
|
6
|
+
t.references :owner, polymorphic: true
|
7
|
+
t.references :repo_item
|
8
|
+
t.boolean :can_create, :default => false
|
9
|
+
t.boolean :can_read, :default => false
|
10
|
+
t.boolean :can_update, :default => false
|
11
|
+
t.boolean :can_delete, :default => false
|
12
|
+
t.boolean :can_share, :default => false
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :sharings_members do |t|
|
16
|
+
t.references :sharing
|
17
|
+
t.references :member, polymorphic: true
|
18
|
+
t.boolean :can_add, :default => false
|
19
|
+
t.boolean :can_remove, :default => false
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :repo_items do |t|
|
23
|
+
t.references :owner, polymorphic: true
|
24
|
+
t.string :ancestry
|
25
|
+
t.string :name
|
26
|
+
t.float :file_size
|
27
|
+
t.string :content_type
|
28
|
+
t.string :file
|
29
|
+
t.string :type
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended that you check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(version: 20131018214212) do
|
15
|
-
|
16
|
-
create_table "groups", force: true do |t|
|
17
|
-
t.string "name"
|
18
|
-
t.text "description"
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
21
|
-
end
|
22
|
-
|
23
|
-
create_table "groups_users", id: false, force: true do |t|
|
24
|
-
t.integer "group_id", null: false
|
25
|
-
t.integer "user_id", null: false
|
26
|
-
end
|
27
|
-
|
28
|
-
create_table "repo_items", force: true do |t|
|
29
|
-
t.integer "owner_id"
|
30
|
-
t.string "owner_type"
|
31
|
-
t.string "ancestry"
|
32
|
-
t.string "name"
|
33
|
-
t.float "file_size"
|
34
|
-
t.string "content_type"
|
35
|
-
t.string "file"
|
36
|
-
t.string "type"
|
37
|
-
end
|
38
|
-
|
39
|
-
create_table "sharings", force: true do |t|
|
40
|
-
t.integer "owner_id"
|
41
|
-
t.string "owner_type"
|
42
|
-
t.integer "repo_item_id"
|
43
|
-
t.boolean "can_create", default: false
|
44
|
-
t.boolean "can_read", default: false
|
45
|
-
t.boolean "can_update", default: false
|
46
|
-
t.boolean "can_delete", default: false
|
47
|
-
t.boolean "can_share", default: false
|
48
|
-
end
|
49
|
-
|
50
|
-
create_table "sharings_members", force: true do |t|
|
51
|
-
t.integer "sharing_id"
|
52
|
-
t.integer "member_id"
|
53
|
-
t.string "member_type"
|
54
|
-
t.boolean "can_add", default: false
|
55
|
-
t.boolean "can_remove", default: false
|
56
|
-
end
|
57
|
-
|
58
|
-
create_table "users", force: true do |t|
|
59
|
-
t.string "nickname"
|
60
|
-
t.string "password"
|
61
|
-
t.string "email"
|
62
|
-
t.datetime "created_at"
|
63
|
-
t.datetime "updated_at"
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20131018214212) do
|
15
|
+
|
16
|
+
create_table "groups", force: true do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.text "description"
|
19
|
+
t.datetime "created_at"
|
20
|
+
t.datetime "updated_at"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "groups_users", id: false, force: true do |t|
|
24
|
+
t.integer "group_id", null: false
|
25
|
+
t.integer "user_id", null: false
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table "repo_items", force: true do |t|
|
29
|
+
t.integer "owner_id"
|
30
|
+
t.string "owner_type"
|
31
|
+
t.string "ancestry"
|
32
|
+
t.string "name"
|
33
|
+
t.float "file_size"
|
34
|
+
t.string "content_type"
|
35
|
+
t.string "file"
|
36
|
+
t.string "type"
|
37
|
+
end
|
38
|
+
|
39
|
+
create_table "sharings", force: true do |t|
|
40
|
+
t.integer "owner_id"
|
41
|
+
t.string "owner_type"
|
42
|
+
t.integer "repo_item_id"
|
43
|
+
t.boolean "can_create", default: false
|
44
|
+
t.boolean "can_read", default: false
|
45
|
+
t.boolean "can_update", default: false
|
46
|
+
t.boolean "can_delete", default: false
|
47
|
+
t.boolean "can_share", default: false
|
48
|
+
end
|
49
|
+
|
50
|
+
create_table "sharings_members", force: true do |t|
|
51
|
+
t.integer "sharing_id"
|
52
|
+
t.integer "member_id"
|
53
|
+
t.string "member_type"
|
54
|
+
t.boolean "can_add", default: false
|
55
|
+
t.boolean "can_remove", default: false
|
56
|
+
end
|
57
|
+
|
58
|
+
create_table "users", force: true do |t|
|
59
|
+
t.string "nickname"
|
60
|
+
t.string "password"
|
61
|
+
t.string "email"
|
62
|
+
t.datetime "created_at"
|
63
|
+
t.datetime "updated_at"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/factories/group.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :group do
|
3
|
-
sequence :name do |n|
|
4
|
-
"Group #{ n }"
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :group do
|
3
|
+
sequence :name do |n|
|
4
|
+
"Group #{ n }"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
data/spec/factories/repo_file.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :repo_file do
|
3
|
-
file { fixture_file }
|
4
|
-
#sequence :password do |n|
|
5
|
-
# 'secret'
|
6
|
-
#end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def fixture_file
|
11
|
-
File.open("#{Rails.root}/../fixture/textfile.txt")
|
12
|
-
end
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :repo_file do
|
3
|
+
file { fixture_file }
|
4
|
+
#sequence :password do |n|
|
5
|
+
# 'secret'
|
6
|
+
#end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def fixture_file
|
11
|
+
File.open("#{Rails.root}/../fixture/textfile.txt")
|
12
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :repo_folder do
|
3
|
-
sequence :name do |n|
|
4
|
-
'Folder'
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :repo_folder do
|
3
|
+
sequence :name do |n|
|
4
|
+
'Folder'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
data/spec/factories/user.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :user do
|
3
|
-
sequence :nickname do |n|
|
4
|
-
"User #{ n }"
|
5
|
-
end
|
6
|
-
sequence :email do |n|
|
7
|
-
"user#{ n }@user.com"
|
8
|
-
end
|
9
|
-
sequence :password do |n|
|
10
|
-
'secret'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :user do
|
3
|
+
sequence :nickname do |n|
|
4
|
+
"User #{ n }"
|
5
|
+
end
|
6
|
+
sequence :email do |n|
|
7
|
+
"user#{ n }@user.com"
|
8
|
+
end
|
9
|
+
sequence :password do |n|
|
10
|
+
'secret'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/has_repository_spec.rb
CHANGED
@@ -1,282 +1,281 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'HasRepository' do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@user1 = FactoryGirl.create(:user)
|
7
|
-
@user2 = FactoryGirl.create(:user)
|
8
|
-
@user3 = FactoryGirl.create(:user)
|
9
|
-
@group1 = FactoryGirl.create(:group)
|
10
|
-
#@group2 = FactoryGirl.create(:group)
|
11
|
-
#@group3 = FactoryGirl.create(:group)
|
12
|
-
#@fileAlone = FactoryGirl.create(:app_file)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be associate with shares" do
|
16
|
-
sharing = Sharing.create
|
17
|
-
@user1.sharings << sharing
|
18
|
-
expect(@user1.sharings.last).to eq(sharing)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "can add a file to repo_item" do
|
22
|
-
#TODO
|
23
|
-
end
|
24
|
-
|
25
|
-
it "can add a folder to repo_item" do
|
26
|
-
#TODO
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'can share his own repo_item with other users' do
|
30
|
-
rep = FactoryGirl.create(:repo_file)
|
31
|
-
rep.owner = @user1
|
32
|
-
rep.save
|
33
|
-
|
34
|
-
#expect(@user1.sharings.count).to eq(0)
|
35
|
-
#expect(@user2.sharings.count).to eq(0)
|
36
|
-
#expect(@user3.sharings.count).to eq(0)
|
37
|
-
#expect(@user1.sharings_owners.count).to eq(0)
|
38
|
-
#expect(@user2.sharings_owners.count).to eq(0)
|
39
|
-
#expect(@user3.sharings_owners.count).to eq(0)
|
40
|
-
|
41
|
-
#Add the 2 users to members
|
42
|
-
members = []
|
43
|
-
members << @user2
|
44
|
-
members << @user3
|
45
|
-
|
46
|
-
@user1.share(rep, members)
|
47
|
-
|
48
|
-
#expect(@user1.sharings.count).to eq(0)
|
49
|
-
expect(@user2.sharings.count).to eq(1)
|
50
|
-
expect(@user3.sharings.count).to eq(1)
|
51
|
-
expect(@user1.sharings_owners.count).to eq(1)
|
52
|
-
expect(@user2.repo_items.count).to eq(0)
|
53
|
-
#expect(@user2.sharingd_repo_items.count).to eq(1)
|
54
|
-
|
55
|
-
#expect(@user2.sharings_owners.count).to eq(0)
|
56
|
-
#expect(@user3.sharings_owners.count).to eq(0)
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'can not share a repo_item without sharings and without the permission' do
|
61
|
-
rep = FactoryGirl.create(:repo_file)
|
62
|
-
rep.owner = @user3
|
63
|
-
rep.save
|
64
|
-
|
65
|
-
members = []
|
66
|
-
members << @user2
|
67
|
-
|
68
|
-
@user1.share(rep, members)
|
69
|
-
|
70
|
-
expect(@user2.sharings.count).to eq(0)
|
71
|
-
expect(@user1.sharings_owners.count).to eq(0)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'can not share a repo_item with sharing but without the permission' do
|
75
|
-
rep = FactoryGirl.create(:repo_folder)
|
76
|
-
rep.owner = @user3
|
77
|
-
rep.save
|
78
|
-
|
79
|
-
members = []
|
80
|
-
members << @user2
|
81
|
-
|
82
|
-
# here user3 can share because he is the owner
|
83
|
-
@user3.share(rep, members)
|
84
|
-
# here user2 should can share because he has the authorisation
|
85
|
-
members = []
|
86
|
-
members << @user1
|
87
|
-
@user2.share(rep, members)
|
88
|
-
|
89
|
-
expect(@user1.sharings.count).to eq(0)
|
90
|
-
expect(@user2.sharings_owners.count).to eq(0)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'can share a repo_item with sharing and with the permission' do
|
94
|
-
rep = FactoryGirl.create(:repo_folder)
|
95
|
-
rep.owner = @user3
|
96
|
-
rep.save
|
97
|
-
|
98
|
-
members = []
|
99
|
-
members << @user2
|
100
|
-
|
101
|
-
#Here user3 let user2 share this repo too
|
102
|
-
options = {repo_item_permissions: {can_share: true}}
|
103
|
-
|
104
|
-
# here user3 can share because he is the owner
|
105
|
-
@user3.share(rep, members, options)
|
106
|
-
# here user2 should can share because he has the authorisation
|
107
|
-
members = []
|
108
|
-
members << @user1
|
109
|
-
@user2.share(rep, members)
|
110
|
-
|
111
|
-
expect(@user1.sharings.count).to eq(1)
|
112
|
-
expect(@user2.sharings_owners.count).to eq(1)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'default sharings permissions are to false' do
|
116
|
-
rep = FactoryGirl.create(:repo_folder)
|
117
|
-
rep.owner = @user3
|
118
|
-
rep.save
|
119
|
-
|
120
|
-
members = []
|
121
|
-
members << @user2
|
122
|
-
|
123
|
-
#Here user3 let user2 share this repo too
|
124
|
-
options = {repo_item_permissions: {can_read: true, can_share: true}}
|
125
|
-
|
126
|
-
# here user3 can share because he is the owner
|
127
|
-
@user3.share(rep, members, options)
|
128
|
-
# here user2 should can share because he has the authorisation
|
129
|
-
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
130
|
-
members = []
|
131
|
-
members << @user1
|
132
|
-
#Here the permissions should be : :can_read => true, and all others false
|
133
|
-
@user2.share(rep, members)
|
134
|
-
|
135
|
-
sharing_of_user_1 = @user1.sharings.last
|
136
|
-
|
137
|
-
expect(sharing_of_user_1.can_read?).to eq(false)
|
138
|
-
expect(sharing_of_user_1.can_update?).to eq(false)
|
139
|
-
expect(sharing_of_user_1.can_share?).to eq(false)
|
140
|
-
#expect(@user1.sharings.count).to eq(1)
|
141
|
-
#expect(@user2.sharings_owners.count).to eq(1)
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'can share a repo_item with sharing and with restricted permissions' do
|
145
|
-
rep = FactoryGirl.create(:repo_folder)
|
146
|
-
rep.owner = @user3
|
147
|
-
rep.save
|
148
|
-
|
149
|
-
members = []
|
150
|
-
members << @user2
|
151
|
-
|
152
|
-
#Here user3 let user2 share this repo too
|
153
|
-
options = {repo_item_permissions: {can_read: true, can_share: true}}
|
154
|
-
|
155
|
-
# here user3 can share because he is the owner
|
156
|
-
@user3.share(rep, members, options)
|
157
|
-
# here user2 should can share because he has the authorisation
|
158
|
-
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
159
|
-
members = []
|
160
|
-
members << @user1
|
161
|
-
|
162
|
-
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
163
|
-
|
164
|
-
#Here the permissions should be : :can_read => true, :can_share => true and all others false
|
165
|
-
@user2.share(rep, members, options)
|
166
|
-
|
167
|
-
sharing_of_user_1 = @user1.sharings.last
|
168
|
-
|
169
|
-
# TODO correct this, sharing is nil
|
170
|
-
expect(sharing_of_user_1.can_read?).to eq(true)
|
171
|
-
expect(sharing_of_user_1.can_update?).to eq(false)
|
172
|
-
expect(sharing_of_user_1.can_share?).to eq(true)
|
173
|
-
#expect(@user1.sharings.count).to eq(1)
|
174
|
-
#expect(@user2.sharings_owners.count).to eq(1)
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'can share a repo_item with sharing permissions' do
|
178
|
-
rep = FactoryGirl.create(:repo_folder)
|
179
|
-
rep.owner = @user3
|
180
|
-
rep.save
|
181
|
-
|
182
|
-
members = []
|
183
|
-
members << @user2
|
184
|
-
|
185
|
-
options = {sharing_permissions: {can_add: true, can_remove: false}}
|
186
|
-
|
187
|
-
# here user3 can share because he is the owner
|
188
|
-
@user3.share(rep, members, options)
|
189
|
-
|
190
|
-
sharing_member_of_user_2 = @user2.sharings_members.last
|
191
|
-
|
192
|
-
expect(sharing_member_of_user_2.can_add?).to eq(true)
|
193
|
-
expect(sharing_member_of_user_2.can_remove?).to eq(false)
|
194
|
-
#expect(@user1.sharings.count).to eq(1)
|
195
|
-
#expect(@user2.sharings_owners.count).to eq(1)
|
196
|
-
end
|
197
|
-
|
198
|
-
# Todo implement with accepting nested set to true
|
199
|
-
#it 'can share a repo_item with ancestor sharing permissions' do
|
200
|
-
# parent = FactoryGirl.create(:repo_folder)
|
201
|
-
# parent.owner = @user3
|
202
|
-
# middle = @user3.create_folder('Middle', parent)
|
203
|
-
# children = @user3.create_folder('Children', middle)
|
204
|
-
#
|
205
|
-
# file = FactoryGirl.build(:repo_file)
|
206
|
-
# file.owner = @user3
|
207
|
-
# file.save
|
208
|
-
#
|
209
|
-
# children.add(file)
|
210
|
-
#
|
211
|
-
# options = {repo_item_permissions: {can_read: true, can_update: true, can_share: false}}
|
212
|
-
# @user3.share(parent, @user1, options)
|
213
|
-
#
|
214
|
-
# options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
215
|
-
# @user3.share(children, @user1, options)
|
216
|
-
#
|
217
|
-
# @user1.share(middle, @user2)
|
218
|
-
# expect(@user2.sharings.count).to eq(0)
|
219
|
-
# @user1.share(file, @user2)
|
220
|
-
# expect(@user2.sharings.count).to eq(1)
|
221
|
-
#end
|
222
|
-
|
223
|
-
it 'can\'t share a nested sharing' do
|
224
|
-
parent = @user1.create_folder('Parent')
|
225
|
-
nested = @user1.create_folder('Nested', parent)
|
226
|
-
children = @user1.create_folder('Children', nested)
|
227
|
-
|
228
|
-
# @user1 own repository :
|
229
|
-
# |-- 'Parent'
|
230
|
-
# | |-- 'Nested'
|
231
|
-
# | | |-- 'Children'
|
232
|
-
|
233
|
-
@user1.share(nested, @user2)
|
234
|
-
|
235
|
-
expect(nested.has_nested_sharing?).to eq(false) # Returns false (because `nested` is shared but there is no nested sharing)
|
236
|
-
expect(parent.has_nested_sharing?).to eq(true) # Returns true (because there is a sharing on one of his descendants)
|
237
|
-
expect(parent.has_nested_sharing?).to eq(true) # Returns true (because there is a sharing on one of his ancestors)
|
238
|
-
|
239
|
-
# Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
|
240
|
-
expect(@user1.share(parent, @user2)).to eq(false) # Returns false
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'can\'t share a repo_item with ancestor sharing permissions' do
|
244
|
-
parent = FactoryGirl.create(:repo_folder)
|
245
|
-
parent.owner = @user3
|
246
|
-
middle = @user3.create_folder('Middle', parent)
|
247
|
-
children = @user3.create_folder('Children', middle)
|
248
|
-
|
249
|
-
file = FactoryGirl.build(:repo_file)
|
250
|
-
file.owner = @user3
|
251
|
-
file.save
|
252
|
-
|
253
|
-
children.add(file)
|
254
|
-
|
255
|
-
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
256
|
-
@user3.share(parent, @user1, options)
|
257
|
-
|
258
|
-
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
259
|
-
@user3.share(children, @user1, options)
|
260
|
-
|
261
|
-
@user1.share(middle, @user2)
|
262
|
-
expect(@user2.sharings.count).to eq(0)
|
263
|
-
@user1.share(file, @user2)
|
264
|
-
expect(@user2.sharings.count).to eq(0)
|
265
|
-
end
|
266
|
-
|
267
|
-
it "can create a folder" do
|
268
|
-
folder = @user1.create_folder('test folder')
|
269
|
-
#folder = @user1.repo_items.last
|
270
|
-
expect(folder.name).to eq('test folder')
|
271
|
-
expect(folder.type).to eq('RepoFolder')
|
272
|
-
expect(@user1.repo_items.folders.count).to eq(1)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "can create a file" do
|
276
|
-
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
|
277
|
-
expect(file.name).to eq('textfile.txt')
|
278
|
-
expect(@user1.repo_items.count).to eq(1)
|
279
|
-
expect(@user1.repo_items.files.count).to eq(1)
|
280
|
-
end
|
281
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'HasRepository' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@user1 = FactoryGirl.create(:user)
|
7
|
+
@user2 = FactoryGirl.create(:user)
|
8
|
+
@user3 = FactoryGirl.create(:user)
|
9
|
+
@group1 = FactoryGirl.create(:group)
|
10
|
+
#@group2 = FactoryGirl.create(:group)
|
11
|
+
#@group3 = FactoryGirl.create(:group)
|
12
|
+
#@fileAlone = FactoryGirl.create(:app_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be associate with shares" do
|
16
|
+
sharing = Sharing.create
|
17
|
+
@user1.sharings << sharing
|
18
|
+
expect(@user1.sharings.last).to eq(sharing)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can add a file to repo_item" do
|
22
|
+
#TODO
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can add a folder to repo_item" do
|
26
|
+
#TODO
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can share his own repo_item with other users' do
|
30
|
+
rep = FactoryGirl.create(:repo_file)
|
31
|
+
rep.owner = @user1
|
32
|
+
rep.save
|
33
|
+
|
34
|
+
#expect(@user1.sharings.count).to eq(0)
|
35
|
+
#expect(@user2.sharings.count).to eq(0)
|
36
|
+
#expect(@user3.sharings.count).to eq(0)
|
37
|
+
#expect(@user1.sharings_owners.count).to eq(0)
|
38
|
+
#expect(@user2.sharings_owners.count).to eq(0)
|
39
|
+
#expect(@user3.sharings_owners.count).to eq(0)
|
40
|
+
|
41
|
+
#Add the 2 users to members
|
42
|
+
members = []
|
43
|
+
members << @user2
|
44
|
+
members << @user3
|
45
|
+
|
46
|
+
@user1.share(rep, members)
|
47
|
+
|
48
|
+
#expect(@user1.sharings.count).to eq(0)
|
49
|
+
expect(@user2.sharings.count).to eq(1)
|
50
|
+
expect(@user3.sharings.count).to eq(1)
|
51
|
+
expect(@user1.sharings_owners.count).to eq(1)
|
52
|
+
expect(@user2.repo_items.count).to eq(0)
|
53
|
+
#expect(@user2.sharingd_repo_items.count).to eq(1)
|
54
|
+
|
55
|
+
#expect(@user2.sharings_owners.count).to eq(0)
|
56
|
+
#expect(@user3.sharings_owners.count).to eq(0)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can not share a repo_item without sharings and without the permission' do
|
61
|
+
rep = FactoryGirl.create(:repo_file)
|
62
|
+
rep.owner = @user3
|
63
|
+
rep.save
|
64
|
+
|
65
|
+
members = []
|
66
|
+
members << @user2
|
67
|
+
|
68
|
+
@user1.share(rep, members)
|
69
|
+
|
70
|
+
expect(@user2.sharings.count).to eq(0)
|
71
|
+
expect(@user1.sharings_owners.count).to eq(0)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can not share a repo_item with sharing but without the permission' do
|
75
|
+
rep = FactoryGirl.create(:repo_folder)
|
76
|
+
rep.owner = @user3
|
77
|
+
rep.save
|
78
|
+
|
79
|
+
members = []
|
80
|
+
members << @user2
|
81
|
+
|
82
|
+
# here user3 can share because he is the owner
|
83
|
+
@user3.share(rep, members)
|
84
|
+
# here user2 should can share because he has the authorisation
|
85
|
+
members = []
|
86
|
+
members << @user1
|
87
|
+
@user2.share(rep, members)
|
88
|
+
|
89
|
+
expect(@user1.sharings.count).to eq(0)
|
90
|
+
expect(@user2.sharings_owners.count).to eq(0)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'can share a repo_item with sharing and with the permission' do
|
94
|
+
rep = FactoryGirl.create(:repo_folder)
|
95
|
+
rep.owner = @user3
|
96
|
+
rep.save
|
97
|
+
|
98
|
+
members = []
|
99
|
+
members << @user2
|
100
|
+
|
101
|
+
#Here user3 let user2 share this repo too
|
102
|
+
options = {repo_item_permissions: {can_share: true}}
|
103
|
+
|
104
|
+
# here user3 can share because he is the owner
|
105
|
+
@user3.share(rep, members, options)
|
106
|
+
# here user2 should can share because he has the authorisation
|
107
|
+
members = []
|
108
|
+
members << @user1
|
109
|
+
@user2.share(rep, members)
|
110
|
+
|
111
|
+
expect(@user1.sharings.count).to eq(1)
|
112
|
+
expect(@user2.sharings_owners.count).to eq(1)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'default sharings permissions are to false' do
|
116
|
+
rep = FactoryGirl.create(:repo_folder)
|
117
|
+
rep.owner = @user3
|
118
|
+
rep.save
|
119
|
+
|
120
|
+
members = []
|
121
|
+
members << @user2
|
122
|
+
|
123
|
+
#Here user3 let user2 share this repo too
|
124
|
+
options = {repo_item_permissions: {can_read: true, can_share: true}}
|
125
|
+
|
126
|
+
# here user3 can share because he is the owner
|
127
|
+
@user3.share(rep, members, options)
|
128
|
+
# here user2 should can share because he has the authorisation
|
129
|
+
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
130
|
+
members = []
|
131
|
+
members << @user1
|
132
|
+
#Here the permissions should be : :can_read => true, and all others false
|
133
|
+
@user2.share(rep, members)
|
134
|
+
|
135
|
+
sharing_of_user_1 = @user1.sharings.last
|
136
|
+
|
137
|
+
expect(sharing_of_user_1.can_read?).to eq(false)
|
138
|
+
expect(sharing_of_user_1.can_update?).to eq(false)
|
139
|
+
expect(sharing_of_user_1.can_share?).to eq(false)
|
140
|
+
#expect(@user1.sharings.count).to eq(1)
|
141
|
+
#expect(@user2.sharings_owners.count).to eq(1)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'can share a repo_item with sharing and with restricted permissions' do
|
145
|
+
rep = FactoryGirl.create(:repo_folder)
|
146
|
+
rep.owner = @user3
|
147
|
+
rep.save
|
148
|
+
|
149
|
+
members = []
|
150
|
+
members << @user2
|
151
|
+
|
152
|
+
#Here user3 let user2 share this repo too
|
153
|
+
options = {repo_item_permissions: {can_read: true, can_share: true}}
|
154
|
+
|
155
|
+
# here user3 can share because he is the owner
|
156
|
+
@user3.share(rep, members, options)
|
157
|
+
# here user2 should can share because he has the authorisation
|
158
|
+
# But he has only the authorisation of read (can_read = true), He can't share with more permissions
|
159
|
+
members = []
|
160
|
+
members << @user1
|
161
|
+
|
162
|
+
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
163
|
+
|
164
|
+
#Here the permissions should be : :can_read => true, :can_share => true and all others false
|
165
|
+
@user2.share(rep, members, options)
|
166
|
+
|
167
|
+
sharing_of_user_1 = @user1.sharings.last
|
168
|
+
|
169
|
+
# TODO correct this, sharing is nil
|
170
|
+
expect(sharing_of_user_1.can_read?).to eq(true)
|
171
|
+
expect(sharing_of_user_1.can_update?).to eq(false)
|
172
|
+
expect(sharing_of_user_1.can_share?).to eq(true)
|
173
|
+
#expect(@user1.sharings.count).to eq(1)
|
174
|
+
#expect(@user2.sharings_owners.count).to eq(1)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'can share a repo_item with sharing permissions' do
|
178
|
+
rep = FactoryGirl.create(:repo_folder)
|
179
|
+
rep.owner = @user3
|
180
|
+
rep.save
|
181
|
+
|
182
|
+
members = []
|
183
|
+
members << @user2
|
184
|
+
|
185
|
+
options = {sharing_permissions: {can_add: true, can_remove: false}}
|
186
|
+
|
187
|
+
# here user3 can share because he is the owner
|
188
|
+
@user3.share(rep, members, options)
|
189
|
+
|
190
|
+
sharing_member_of_user_2 = @user2.sharings_members.last
|
191
|
+
|
192
|
+
expect(sharing_member_of_user_2.can_add?).to eq(true)
|
193
|
+
expect(sharing_member_of_user_2.can_remove?).to eq(false)
|
194
|
+
#expect(@user1.sharings.count).to eq(1)
|
195
|
+
#expect(@user2.sharings_owners.count).to eq(1)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Todo implement with accepting nested set to true
|
199
|
+
#it 'can share a repo_item with ancestor sharing permissions' do
|
200
|
+
# parent = FactoryGirl.create(:repo_folder)
|
201
|
+
# parent.owner = @user3
|
202
|
+
# middle = @user3.create_folder('Middle', parent)
|
203
|
+
# children = @user3.create_folder('Children', middle)
|
204
|
+
#
|
205
|
+
# file = FactoryGirl.build(:repo_file)
|
206
|
+
# file.owner = @user3
|
207
|
+
# file.save
|
208
|
+
#
|
209
|
+
# children.add(file)
|
210
|
+
#
|
211
|
+
# options = {repo_item_permissions: {can_read: true, can_update: true, can_share: false}}
|
212
|
+
# @user3.share(parent, @user1, options)
|
213
|
+
#
|
214
|
+
# options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
215
|
+
# @user3.share(children, @user1, options)
|
216
|
+
#
|
217
|
+
# @user1.share(middle, @user2)
|
218
|
+
# expect(@user2.sharings.count).to eq(0)
|
219
|
+
# @user1.share(file, @user2)
|
220
|
+
# expect(@user2.sharings.count).to eq(1)
|
221
|
+
#end
|
222
|
+
|
223
|
+
it 'can\'t share a nested sharing' do
|
224
|
+
parent = @user1.create_folder('Parent')
|
225
|
+
nested = @user1.create_folder('Nested', parent)
|
226
|
+
children = @user1.create_folder('Children', nested)
|
227
|
+
|
228
|
+
# @user1 own repository :
|
229
|
+
# |-- 'Parent'
|
230
|
+
# | |-- 'Nested'
|
231
|
+
# | | |-- 'Children'
|
232
|
+
|
233
|
+
@user1.share(nested, @user2)
|
234
|
+
|
235
|
+
expect(nested.has_nested_sharing?).to eq(false) # Returns false (because `nested` is shared but there is no nested sharing)
|
236
|
+
expect(parent.has_nested_sharing?).to eq(true) # Returns true (because there is a sharing on one of his descendants)
|
237
|
+
expect(parent.has_nested_sharing?).to eq(true) # Returns true (because there is a sharing on one of his ancestors)
|
238
|
+
|
239
|
+
# Here we can't share 'Parent' or 'Children' because it already exist a nested sharing.
|
240
|
+
expect(@user1.share(parent, @user2)).to eq(false) # Returns false
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'can\'t share a repo_item with ancestor sharing permissions' do
|
244
|
+
parent = FactoryGirl.create(:repo_folder)
|
245
|
+
parent.owner = @user3
|
246
|
+
middle = @user3.create_folder('Middle', parent)
|
247
|
+
children = @user3.create_folder('Children', middle)
|
248
|
+
|
249
|
+
file = FactoryGirl.build(:repo_file)
|
250
|
+
file.owner = @user3
|
251
|
+
file.save
|
252
|
+
|
253
|
+
children.add(file)
|
254
|
+
|
255
|
+
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
256
|
+
@user3.share(parent, @user1, options)
|
257
|
+
|
258
|
+
options = {repo_item_permissions: {can_read: true, can_update: true, can_share: true}}
|
259
|
+
@user3.share(children, @user1, options)
|
260
|
+
|
261
|
+
@user1.share(middle, @user2)
|
262
|
+
expect(@user2.sharings.count).to eq(0)
|
263
|
+
@user1.share(file, @user2)
|
264
|
+
expect(@user2.sharings.count).to eq(0)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "can create a folder" do
|
268
|
+
folder = @user1.create_folder('test folder')
|
269
|
+
#folder = @user1.repo_items.last
|
270
|
+
expect(folder.name).to eq('test folder')
|
271
|
+
expect(folder.type).to eq('RepoFolder')
|
272
|
+
expect(@user1.repo_items.folders.count).to eq(1)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "can create a file" do
|
276
|
+
file = @user1.create_file(File.open("#{Rails.root}/../fixture/textfile.txt"))
|
277
|
+
expect(file.name).to eq('textfile.txt')
|
278
|
+
expect(@user1.repo_items.count).to eq(1)
|
279
|
+
expect(@user1.repo_items.files.count).to eq(1)
|
280
|
+
end
|
282
281
|
end
|