private_person 0.3.1 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ea4a8f4f6cabb8537ca689a8b83f58b09822b2f
4
- data.tar.gz: ff11f0adc4df97999397aaeaec63893019c713d5
3
+ metadata.gz: 8fc5ea2ff01d3b1c9aa4fdf1d08b1e89d4b59fda
4
+ data.tar.gz: 53cdaee285d896caf9591c4bfed3d4897af94e40
5
5
  SHA512:
6
- metadata.gz: 4b68dbebec12d3ce0cd05873c0adb64bec4e2159f1f1c9faaa1f602ac706577cc388c6a084f28963fbc29359f8e431913e5f6c3a68e8c4bc3dbcfbf255bccd3c
7
- data.tar.gz: dbab508ccb006ca7907b91a82310af472f5d35d84f9446c33dafcecc1564d0b400f9b36952812838f837f5df5e5a29c193d4c76c404c081fb1181010514ff7c2
6
+ metadata.gz: f7fa47f819e68afc2931b7cf9a0f8ac845fe559dee7948b3616e51498957a9f5d7ae42490a263593a850abc656e4e9cbbdfae91c13bb31aef23964d0daaabdf4
7
+ data.tar.gz: f760e1935c191e8f78fbde750decc436dcd80993b70eb080a2ecd9e3a50a0900308e9e0323b6c12b58c5f57e1a6875b5f03c4e104c4762a2eeeeb7d010c9d461
data/Gemfile CHANGED
@@ -3,19 +3,8 @@ source 'http://rubygems.org'
3
3
  # Example:
4
4
  # gem 'activesupport', '>= 2.3.5'
5
5
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development, :test do
9
- gem 'rdoc'
10
- gem 'bundler'
11
- gem 'jeweler'
12
- gem 'sqlite3'
13
- gem 'rspec'
14
- gem 'rspec-rails'
15
- gem 'shoulda-matchers'
16
- gem 'factory_girl_rails'
17
- gem 'database_cleaner'
18
- gem 'chalk_dust', :git => 'git://github.com/nerakdon/chalk_dust.git'
19
- end
6
+ gem 'rails', '>= 4.0'
7
+ gem 'activerecord', '>= 4.0'
8
+ gem 'chalk_dust', group: :test, git: 'https://github.com/nerakdon/chalk_dust.git'
20
9
 
21
- gem 'rails'
10
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Sour Cherry Web
1
+ Copyright (c) 2013-2014 Gem Vein
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,8 +1,12 @@
1
1
  = PrivatePerson
2
2
 
3
+ {<img src="https://badge.fury.io/rb/private_person.svg" alt="Gem Version" />}[http://badge.fury.io/rb/private_person]
4
+ {<img src="https://travis-ci.org/gemvein/private_person.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/gemvein/private_person]
5
+ {<img src="https://coveralls.io/repos/gemvein/private_person/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/gemvein/private_person]
6
+
3
7
  Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies.
4
8
 
5
- == Contributing to Person
9
+ == Contributing to Private Person
6
10
 
7
11
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
12
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -14,5 +18,5 @@ Private person is an active record extension gem that allows a model to be given
14
18
 
15
19
  == Copyright
16
20
 
17
- Copyright (c) 2013 Sour Cherry Web. See LICENSE.txt for further details.
21
+ Copyright (c) 2013-2014 Gem Vein. See LICENSE.txt for further details.
18
22
 
data/Rakefile CHANGED
@@ -15,11 +15,11 @@ require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
16
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
17
  gem.name = "private_person"
18
- gem.homepage = "http://github.com/nerakdon/private_person"
18
+ gem.homepage = "http://www.gemvein.com/museum/cases/private_person"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Private person puts your users in control of their own privacy policies.}
21
21
  gem.description = %Q{Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies.}
22
- gem.email = "webmaster@sourcherryweb.com"
22
+ gem.email = "karen.e.lundgren@gmail.com"
23
23
  gem.authors = ["Karen Lundgren"]
24
24
  # dependencies defined in Gemfile
25
25
  end
@@ -37,13 +37,3 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
37
  end
38
38
 
39
39
  task :default => :spec
40
-
41
- require 'rdoc/task'
42
- Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
-
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "private_person #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -1,14 +1,14 @@
1
1
  module PrivatePerson
2
2
  require 'rails'
3
3
  require 'private_person/version'
4
- require 'private_person/models/permissor'
5
4
  require 'private_person/models/permission'
6
- require 'private_person/models/permissible'
7
- require 'private_person/models/permitted'
8
- end
5
+ require 'private_person/extensions/acts_as_permissor'
6
+ require 'private_person/extensions/acts_as_permissible'
7
+ require 'private_person/extensions/acts_as_permitted'
9
8
 
10
- if defined?(ActiveRecord::Base)
11
- ActiveRecord::Base.extend PrivatePerson::Permitted
12
- ActiveRecord::Base.extend PrivatePerson::Permissor
13
- ActiveRecord::Base.extend PrivatePerson::Permissible
9
+ if defined?(ActiveRecord::Base)
10
+ ActiveRecord::Base.send(:include, ActsAsPermitted)
11
+ ActiveRecord::Base.send(:include, ActsAsPermissor)
12
+ ActiveRecord::Base.send(:include, ActsAsPermissible)
13
+ end
14
14
  end
@@ -0,0 +1,27 @@
1
+ module PrivatePerson
2
+ module ActsAsPermissible
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def acts_as_permissible(params = {})
8
+ if params[:by].nil?
9
+ raise 'Called acts_as_permissible, but without a :by parameter.'
10
+ end
11
+ class_attribute :by
12
+ self.by = params[:by]
13
+
14
+ has_many :permissions, :as => :permissible, :class_name => 'PrivatePerson::Permission'
15
+ has_many :permissors, :through => :permissions, :as => :permissible
16
+
17
+ send :include, InstanceMethods
18
+ end
19
+ end
20
+
21
+ module InstanceMethods
22
+ def is_public?
23
+ !permissions.by_relationship_type(nil).empty?
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ module PrivatePerson
2
+ module ActsAsPermissor
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def acts_as_permissor(params = {})
8
+ if params[:of].nil?
9
+ raise 'Called acts_as_permissor, but without an :of parameter.'
10
+ end
11
+ class_attribute :of
12
+ self.of = params[:of]
13
+ class_name = params[:class_name] || params[:of].to_s.classify
14
+ class_name.constantize.acts_as_permitted
15
+
16
+ has_many :permissions_as_permissor, :as => :permissor, :class_name => 'PrivatePerson::Permission'
17
+ has_many :permissibles, :through => :permissions, :as => :permissor
18
+
19
+ send :include, InstanceMethods
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+ def permit!(whom, what)
25
+ existing = self.permissions_as_permissor.by_relationship_type(whom).by_permissible(what)
26
+
27
+ if existing.empty?
28
+ self.permissions_as_permissor.create!(permission_params(whom, what))
29
+ end
30
+ self.permissions_as_permissor.reload
31
+ end
32
+
33
+ def wildcard_permit!(whom, what)
34
+ existing = self.permissions_as_permissor.by_relationship_type(whom).where(:permissible_type, what)
35
+
36
+ # if existing.empty?
37
+ self.permissions_as_permissor.create!(wildcard_permission_params(whom, what))
38
+ # end
39
+ self.permissions_as_permissor.reload
40
+ end
41
+
42
+ def permission_params(whom, what)
43
+ ::ActionController::Parameters.new({
44
+ :relationship_type => whom,
45
+ :permissible_type => what.class.name,
46
+ :permissible_id => what.id
47
+ }).permit!
48
+ end
49
+
50
+ def wildcard_permission_params(whom, what)
51
+ ::ActionController::Parameters.new({
52
+ :relationship_type => whom,
53
+ :permissible_type => what
54
+ }).permit!
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ module PrivatePerson
2
+ module ActsAsPermitted
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def acts_as_permitted
8
+ send :include, InstanceMethods
9
+ end
10
+ end
11
+
12
+ module InstanceMethods
13
+ def is_permitted?(permissor, permissible)
14
+ if permissible.nil?
15
+ raise 'Called is_permitted? on nil. Does not compute. Preparing to self destruct.'
16
+ end
17
+ unless PrivatePerson::Permission.by_permissible(permissible).blocked.empty?
18
+ return false
19
+ end
20
+ wildcards = permissions_by(permissor).by_wildcard(permissible.class.name).legitimate
21
+ if wildcards.present?
22
+ return true
23
+ end
24
+ permissions = permissions_by(permissor).by_permissible(permissible).legitimate
25
+ if permissions.present?
26
+ return true
27
+ end
28
+ return false
29
+ end
30
+
31
+ def permissions_by(permissor)
32
+ PrivatePerson::Permission.by_permissor(permissor).by_relationship_type(relationship_to(permissor))
33
+ end
34
+
35
+ def relationship_to(permissor)
36
+ # First make sure we're not a new user
37
+ if self.new_record?
38
+ return 'public'
39
+ end
40
+ # Next check for an efficient method
41
+ for relationship_method in permissor.class.of
42
+ is_method = ('is_' + relationship_method.to_s.singularize + '_of?').to_sym
43
+ if respond_to?(is_method) and self.send(is_method, permissor)
44
+ return relationship_method.to_s
45
+ end
46
+ end
47
+ # Then check for a slow method
48
+ for relationship_method in permissor.class.of
49
+ relationship_members = permissor.send(relationship_method.to_sym)
50
+ if relationship_members.present? and relationship_members.include? self
51
+ return relationship_method.to_s
52
+ end
53
+ end
54
+ return 'public'
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,55 +1,57 @@
1
- class Permission < ActiveRecord::Base
2
- belongs_to :permissor, :polymorphic => true
3
- belongs_to :permissible, :polymorphic => true
1
+ module PrivatePerson
2
+ class Permission < ActiveRecord::Base
3
+ belongs_to :permissor, :polymorphic => true
4
+ belongs_to :permissible, :polymorphic => true
4
5
 
5
- def self.by_permissor(permissor)
6
- where("permissor_type = ? AND permissor_id = ?", permissor.class.name, permissor.id)
7
- end
8
-
9
- def self.by_permissible(permissible)
10
- where("permissible_type = ? AND permissible_id = ?", permissible.class.name, permissible.id)
11
- end
6
+ def self.by_permissor(permissor)
7
+ where("permissor_type = ? AND permissor_id = ?", permissor.class.name, permissor.id)
8
+ end
12
9
 
13
- def self.by_wildcard(permissible_type)
14
- where(:permissible_type => permissible_type, :permissible_id => nil)
15
- end
10
+ def self.by_permissible(permissible)
11
+ where("permissible_type = ? AND permissible_id = ?", permissible.class.name, permissible.id)
12
+ end
16
13
 
17
- def self.by_relationship_type(relationship_type)
18
- if relationship_type == 'public' or relationship_type.nil?
19
- return where("relationship_type = 'public'")
14
+ def self.by_wildcard(permissible_type)
15
+ where(:permissible_type => permissible_type, :permissible_id => nil)
20
16
  end
21
- if(self.permissible_types.include? relationship_type)
22
- return where("relationship_type = ? OR relationship_type = 'public'", relationship_type)
17
+
18
+ def self.by_relationship_type(relationship_type)
19
+ if relationship_type == 'public' or relationship_type.nil?
20
+ return where("relationship_type = 'public'")
21
+ end
22
+ if(self.permissible_types.include? relationship_type)
23
+ return where("relationship_type = ? OR relationship_type = 'public'", relationship_type)
24
+ end
25
+ return where(0)
23
26
  end
24
- return where(0)
25
- end
26
27
 
27
- def self.blocked
28
- where('NOT(relationship_type IN (?))', self.permissible_types)
29
- end
28
+ def self.blocked
29
+ where('NOT(relationship_type IN (?))', self.permissible_types)
30
+ end
30
31
 
31
- def self.legitimate
32
- where('relationship_type IN (?)', self.permissible_types)
33
- end
32
+ def self.legitimate
33
+ where('relationship_type IN (?)', self.permissible_types)
34
+ end
34
35
 
35
- def self.permissible_types
36
- permissible_types = ['public']
37
- for record in self.group('permissor_type').group('permissor_id')
38
- permissor = record.permissor_type.constantize.find(record.permissor_id)
39
- unless permissor.nil?
40
- for method in permissor.class.of
41
- permissible_types << method.to_s
36
+ def self.permissible_types
37
+ permissible_types = ['public']
38
+ for record in self.group('permissor_type').group('permissor_id')
39
+ permissor = record.permissor_type.constantize.find(record.permissor_id)
40
+ unless permissor.nil?
41
+ for method in permissor.class.of
42
+ permissible_types << method.to_s
43
+ end
42
44
  end
43
45
  end
46
+ permissible_types.compact
44
47
  end
45
- permissible_types.compact
46
- end
47
48
 
48
- def existing_types
49
- existing_types = ['public']
50
- for method in permissor.class.of
51
- existing_types << method.to_s
49
+ def existing_types
50
+ existing_types = ['public']
51
+ for method in permissor.class.of
52
+ existing_types << method.to_s
53
+ end
54
+ existing_types
52
55
  end
53
- existing_types
54
56
  end
55
57
  end
@@ -2,16 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: private_person 0.4.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "private_person"
8
- s.version = "0.3.1"
9
+ s.version = "0.4.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Karen Lundgren"]
12
- s.date = "2013-09-30"
14
+ s.date = "2014-10-10"
13
15
  s.description = "Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies."
14
- s.email = "webmaster@sourcherryweb.com"
16
+ s.email = "karen.e.lundgren@gmail.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
19
  "README.rdoc"
@@ -29,10 +31,10 @@ Gem::Specification.new do |s|
29
31
  "lib/generators/private_person/install/templates/migrate/create_permissions_table.rb",
30
32
  "lib/generators/private_person/utils.rb",
31
33
  "lib/private_person.rb",
32
- "lib/private_person/models/permissible.rb",
34
+ "lib/private_person/extensions/acts_as_permissible.rb",
35
+ "lib/private_person/extensions/acts_as_permissor.rb",
36
+ "lib/private_person/extensions/acts_as_permitted.rb",
33
37
  "lib/private_person/models/permission.rb",
34
- "lib/private_person/models/permissor.rb",
35
- "lib/private_person/models/permitted.rb",
36
38
  "lib/private_person/version.rb",
37
39
  "private_person.gemspec",
38
40
  "script/rails",
@@ -52,7 +54,6 @@ Gem::Specification.new do |s|
52
54
  "spec/dummy/config/initializers/mime_types.rb",
53
55
  "spec/dummy/config/initializers/secret_token.rb",
54
56
  "spec/dummy/config/initializers/session_store.rb",
55
- "spec/dummy/config/initializers/wrap_parameters.rb",
56
57
  "spec/dummy/config/locales/devise.en.yml",
57
58
  "spec/dummy/config/locales/en.yml",
58
59
  "spec/dummy/config/routes.rb",
@@ -74,52 +75,57 @@ Gem::Specification.new do |s|
74
75
  "spec/support/permissor_support.rb",
75
76
  "spec/support/users_support.rb"
76
77
  ]
77
- s.homepage = "http://github.com/nerakdon/private_person"
78
+ s.homepage = "http://www.gemvein.com/museum/cases/private_person"
78
79
  s.licenses = ["MIT"]
79
- s.require_paths = ["lib"]
80
- s.rubygems_version = "2.0.3"
80
+ s.rubygems_version = "2.2.2"
81
81
  s.summary = "Private person puts your users in control of their own privacy policies."
82
82
 
83
83
  if s.respond_to? :specification_version then
84
84
  s.specification_version = 4
85
85
 
86
86
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
87
- s.add_runtime_dependency(%q<rails>, [">= 0"])
87
+ s.add_runtime_dependency(%q<rails>, [">= 4.0"])
88
+ s.add_runtime_dependency(%q<activerecord>, [">= 4.0"])
89
+ s.add_runtime_dependency(%q<private_person>, [">= 0"])
88
90
  s.add_development_dependency(%q<rdoc>, [">= 0"])
89
91
  s.add_development_dependency(%q<bundler>, [">= 0"])
90
92
  s.add_development_dependency(%q<jeweler>, [">= 0"])
91
93
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
92
94
  s.add_development_dependency(%q<rspec>, [">= 0"])
93
95
  s.add_development_dependency(%q<rspec-rails>, [">= 0"])
96
+ s.add_development_dependency(%q<rspec-its>, [">= 0"])
94
97
  s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
95
98
  s.add_development_dependency(%q<factory_girl_rails>, [">= 0"])
96
99
  s.add_development_dependency(%q<database_cleaner>, [">= 0"])
97
- s.add_development_dependency(%q<chalk_dust>, [">= 0"])
98
100
  else
99
- s.add_dependency(%q<rails>, [">= 0"])
101
+ s.add_dependency(%q<rails>, [">= 4.0"])
102
+ s.add_dependency(%q<activerecord>, [">= 4.0"])
103
+ s.add_dependency(%q<private_person>, [">= 0"])
100
104
  s.add_dependency(%q<rdoc>, [">= 0"])
101
105
  s.add_dependency(%q<bundler>, [">= 0"])
102
106
  s.add_dependency(%q<jeweler>, [">= 0"])
103
107
  s.add_dependency(%q<sqlite3>, [">= 0"])
104
108
  s.add_dependency(%q<rspec>, [">= 0"])
105
109
  s.add_dependency(%q<rspec-rails>, [">= 0"])
110
+ s.add_dependency(%q<rspec-its>, [">= 0"])
106
111
  s.add_dependency(%q<shoulda-matchers>, [">= 0"])
107
112
  s.add_dependency(%q<factory_girl_rails>, [">= 0"])
108
113
  s.add_dependency(%q<database_cleaner>, [">= 0"])
109
- s.add_dependency(%q<chalk_dust>, [">= 0"])
110
114
  end
111
115
  else
112
- s.add_dependency(%q<rails>, [">= 0"])
116
+ s.add_dependency(%q<rails>, [">= 4.0"])
117
+ s.add_dependency(%q<activerecord>, [">= 4.0"])
118
+ s.add_dependency(%q<private_person>, [">= 0"])
113
119
  s.add_dependency(%q<rdoc>, [">= 0"])
114
120
  s.add_dependency(%q<bundler>, [">= 0"])
115
121
  s.add_dependency(%q<jeweler>, [">= 0"])
116
122
  s.add_dependency(%q<sqlite3>, [">= 0"])
117
123
  s.add_dependency(%q<rspec>, [">= 0"])
118
124
  s.add_dependency(%q<rspec-rails>, [">= 0"])
125
+ s.add_dependency(%q<rspec-its>, [">= 0"])
119
126
  s.add_dependency(%q<shoulda-matchers>, [">= 0"])
120
127
  s.add_dependency(%q<factory_girl_rails>, [">= 0"])
121
128
  s.add_dependency(%q<database_cleaner>, [">= 0"])
122
- s.add_dependency(%q<chalk_dust>, [">= 0"])
123
129
  end
124
130
  end
125
131
 
Binary file
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :permission do
2
+ factory :permission, class: PrivatePerson::Permission do
3
3
  relationship_type 'none'
4
4
  permissible
5
5
  permissor
@@ -2,5 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  describe Page do
4
4
  it { should have_many(:permissions) }
5
- it { should have_one(:permissor) }
5
+ it { should have_many(:permissors) }
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Permission do
3
+ describe PrivatePerson::Permission do
4
4
  # Check relationships
5
5
  it { should belong_to(:permissor) }
6
6
  it { should belong_to(:permissible) }
@@ -9,8 +9,8 @@ describe Permission do
9
9
  include_context 'permissions support'
10
10
 
11
11
  describe '.by_permissor' do
12
- subject { Permission.by_permissor(followed_user) }
13
- it { should have_exactly(8).items }
12
+ subject { PrivatePerson::Permission.by_permissor(followed_user) }
13
+ its(:count) { should be 8 }
14
14
  it { should include general_permission }
15
15
  it { should include following_users_permission }
16
16
  it { should include user_followers_permission }
@@ -22,33 +22,33 @@ describe Permission do
22
22
  end
23
23
 
24
24
  describe '.by_permissible' do
25
- subject { Permission.by_permissible(following_page) }
25
+ subject { PrivatePerson::Permission.by_permissible(following_page) }
26
26
  it { should eq [following_users_permission]}
27
27
  end
28
28
 
29
29
  describe '.by_wildcard' do
30
- subject { Permission.by_wildcard('Page') }
30
+ subject { PrivatePerson::Permission.by_wildcard('Page') }
31
31
  it { should eq [general_permission] }
32
32
  end
33
33
 
34
34
  describe '.by_relationship_type' do
35
- subject { Permission.by_relationship_type('following_users') }
36
- it { should have_exactly(3).items }
35
+ subject { PrivatePerson::Permission.by_relationship_type('following_users') }
36
+ its(:count) { should be 3 }
37
37
  it { should include general_permission }
38
38
  it { should include following_users_permission }
39
39
  it { should include public_permission }
40
40
  end
41
41
 
42
42
  describe '.blocked' do
43
- subject { Permission.blocked }
44
- it { should have_exactly(2).items }
43
+ subject { PrivatePerson::Permission.blocked }
44
+ its(:count) { should be 2 }
45
45
  it { should include none_permission }
46
46
  it { should include forbidden_permission }
47
47
  end
48
48
 
49
49
  describe '.legitimate' do
50
- subject { Permission.legitimate }
51
- it { should have_exactly(6).items }
50
+ subject { PrivatePerson::Permission.legitimate }
51
+ its(:count) { should be 6 }
52
52
  it { should include general_permission }
53
53
  it { should include following_users_permission }
54
54
  it { should include user_followers_permission }
@@ -58,7 +58,7 @@ describe Permission do
58
58
  end
59
59
 
60
60
  describe '.permissible_types' do
61
- subject { Permission.permissible_types.sort }
61
+ subject { PrivatePerson::Permission.permissible_types.sort }
62
62
  it { should be_an Array }
63
63
  it { should eq %w{following_users user_followers following_of_followings follower_of_followers public}.sort }
64
64
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe User do
4
4
 
5
- describe PrivatePerson::Permitted do
5
+ describe 'acts_as_permitted' do
6
6
  it { should have_many(:permissions_as_permissor) }
7
7
  it { should have_many(:permissibles) }
8
8
 
@@ -40,26 +40,26 @@ describe User do
40
40
  context 'when following' do
41
41
  subject { following_user.permissions_by(followed_user) }
42
42
  it { should be_an ActiveRecord::Relation }
43
- its(:first) { should be_a Permission }
43
+ its(:first) { should be_a PrivatePerson::Permission }
44
44
  it { should include following_users_permission }
45
45
  it { should include public_permission }
46
46
  end
47
47
  context 'when follower' do
48
48
  subject { follower_user.permissions_by(followed_user) }
49
49
  it { should be_an ActiveRecord::Relation }
50
- its(:first) { should be_a Permission }
50
+ its(:first) { should be_a PrivatePerson::Permission }
51
51
  it { should include user_followers_permission }
52
52
  end
53
53
  context 'when following_of_followings' do
54
54
  subject { following_of_following_user.permissions_by(followed_user) }
55
55
  it { should be_an ActiveRecord::Relation }
56
- its(:first) { should be_a Permission }
56
+ its(:first) { should be_a PrivatePerson::Permission }
57
57
  it { should include following_of_followings_permission }
58
58
  end
59
59
  context 'when follower_of_follower' do
60
60
  subject { follower_of_follower_user.permissions_by(followed_user) }
61
61
  it { should be_an ActiveRecord::Relation }
62
- its(:first) { should be_a Permission }
62
+ its(:first) { should be_a PrivatePerson::Permission }
63
63
  it { should include follower_of_followers_permission }
64
64
  end
65
65
  end
@@ -101,7 +101,7 @@ describe User do
101
101
  end
102
102
  end
103
103
 
104
- describe PrivatePerson::Permissor do
104
+ describe 'acts_as_permissor' do
105
105
  include_context 'users support'
106
106
  include_context 'permissor support'
107
107
  context 'Instance Methods' do
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ require 'rails/all'
7
7
  require 'sqlite3'
8
8
  require 'rspec'
9
9
  require 'rspec/rails'
10
+ require 'rspec/its'
10
11
 
11
12
  require 'factory_girl_rails'
12
13
  FactoryGirl.definition_file_paths = %w(spec/factories)
@@ -18,7 +18,7 @@ shared_context 'permissions support' do
18
18
  let!(:forbidden_permission) { FactoryGirl.create(:permission, :permissor => followed_user, :permissible => forbidden_page, :relationship_type => 'forbidden') }
19
19
  let!(:none_permission) { FactoryGirl.create(:permission, :permissor => followed_user, :permissible => none_page, :relationship_type => 'none') }
20
20
 
21
- let!(:permissions) { Permission.all }
22
- let!(:wildcards) { Permission.by_wildcard('Page') }
21
+ let!(:permissions) { PrivatePerson::Permission.all }
22
+ let!(:wildcards) { PrivatePerson::Permission.by_wildcard('Page') }
23
23
 
24
24
  end
metadata CHANGED
@@ -1,182 +1,210 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: private_person
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karen Lundgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: private_person
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
18
46
  - !ruby/object:Gem::Version
19
47
  version: '0'
20
48
  type: :runtime
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - '>='
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rdoc
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - '>='
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: jeweler
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - '>='
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - '>='
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: sqlite3
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - '>='
101
+ - - ">="
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - '>='
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rspec
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - '>='
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
117
  version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - '>='
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rspec-rails
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - '>='
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
131
  version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - '>='
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
- name: shoulda-matchers
140
+ name: rspec-its
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - '>='
143
+ - - ">="
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - '>='
150
+ - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
- name: factory_girl_rails
154
+ name: shoulda-matchers
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - '>='
157
+ - - ">="
130
158
  - !ruby/object:Gem::Version
131
159
  version: '0'
132
160
  type: :development
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
- - - '>='
164
+ - - ">="
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
- name: database_cleaner
168
+ name: factory_girl_rails
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
- - - '>='
171
+ - - ">="
144
172
  - !ruby/object:Gem::Version
145
173
  version: '0'
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
- - - '>='
178
+ - - ">="
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
- name: chalk_dust
182
+ name: database_cleaner
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
- - - '>='
185
+ - - ">="
158
186
  - !ruby/object:Gem::Version
159
187
  version: '0'
160
188
  type: :development
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
- - - '>='
192
+ - - ">="
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
167
195
  description: Private person is an active record extension gem that allows a model
168
196
  to be given privacy settings over arbitrary models and polymorphic relations, putting
169
197
  users' accounts in control of their own privacy policies.
170
- email: webmaster@sourcherryweb.com
198
+ email: karen.e.lundgren@gmail.com
171
199
  executables: []
172
200
  extensions: []
173
201
  extra_rdoc_files:
174
202
  - LICENSE.txt
175
203
  - README.rdoc
176
204
  files:
177
- - .document
178
- - .idea/scopes/scope_settings.xml
179
- - .rspec
205
+ - ".document"
206
+ - ".idea/scopes/scope_settings.xml"
207
+ - ".rspec"
180
208
  - Gemfile
181
209
  - LICENSE.txt
182
210
  - README.rdoc
@@ -186,10 +214,10 @@ files:
186
214
  - lib/generators/private_person/install/templates/migrate/create_permissions_table.rb
187
215
  - lib/generators/private_person/utils.rb
188
216
  - lib/private_person.rb
189
- - lib/private_person/models/permissible.rb
217
+ - lib/private_person/extensions/acts_as_permissible.rb
218
+ - lib/private_person/extensions/acts_as_permissor.rb
219
+ - lib/private_person/extensions/acts_as_permitted.rb
190
220
  - lib/private_person/models/permission.rb
191
- - lib/private_person/models/permissor.rb
192
- - lib/private_person/models/permitted.rb
193
221
  - lib/private_person/version.rb
194
222
  - private_person.gemspec
195
223
  - script/rails
@@ -209,7 +237,6 @@ files:
209
237
  - spec/dummy/config/initializers/mime_types.rb
210
238
  - spec/dummy/config/initializers/secret_token.rb
211
239
  - spec/dummy/config/initializers/session_store.rb
212
- - spec/dummy/config/initializers/wrap_parameters.rb
213
240
  - spec/dummy/config/locales/devise.en.yml
214
241
  - spec/dummy/config/locales/en.yml
215
242
  - spec/dummy/config/routes.rb
@@ -230,7 +257,7 @@ files:
230
257
  - spec/support/permissions_support.rb
231
258
  - spec/support/permissor_support.rb
232
259
  - spec/support/users_support.rb
233
- homepage: http://github.com/nerakdon/private_person
260
+ homepage: http://www.gemvein.com/museum/cases/private_person
234
261
  licenses:
235
262
  - MIT
236
263
  metadata: {}
@@ -240,17 +267,17 @@ require_paths:
240
267
  - lib
241
268
  required_ruby_version: !ruby/object:Gem::Requirement
242
269
  requirements:
243
- - - '>='
270
+ - - ">="
244
271
  - !ruby/object:Gem::Version
245
272
  version: '0'
246
273
  required_rubygems_version: !ruby/object:Gem::Requirement
247
274
  requirements:
248
- - - '>='
275
+ - - ">="
249
276
  - !ruby/object:Gem::Version
250
277
  version: '0'
251
278
  requirements: []
252
279
  rubyforge_project:
253
- rubygems_version: 2.0.3
280
+ rubygems_version: 2.2.2
254
281
  signing_key:
255
282
  specification_version: 4
256
283
  summary: Private person puts your users in control of their own privacy policies.
@@ -1,20 +0,0 @@
1
- module PrivatePerson
2
- module Permissible
3
- def acts_as_permissible(params = {})
4
- if params[:by].nil?
5
- raise 'Called acts_as_permissible, but without a :by parameter.'
6
- end
7
- class_attribute :by
8
- self.by = params[:by]
9
-
10
- class_eval do
11
- has_many :permissions, :as => :permissible
12
- has_one :permissor, :through => :permissions, :as => :permissor
13
-
14
- def is_public?
15
- !permissions.by_relationship_type(nil).empty?
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,43 +0,0 @@
1
- module PrivatePerson
2
- module Permissor
3
- def acts_as_permissor(params = {})
4
- if params[:of].nil?
5
- raise 'Called acts_as_permissor, but without an :of parameter.'
6
- end
7
- class_attribute :of
8
- self.of = params[:of]
9
- class_name = params[:class_name] || params[:of].to_s.classify
10
- class_name.constantize.acts_as_permitted
11
- class_eval do
12
- has_many :permissions_as_permissor, :as => :permissor, :class_name => 'Permission'
13
- has_many :permissibles, :through => :permissions, :as => :permissor
14
-
15
- def permit!(whom, what)
16
- existing = self.permissions_as_permissor.by_relationship_type(whom).by_permissible(what)
17
-
18
- if existing.empty?
19
- self.permissions_as_permissor.create!(permission_params(whom, what))
20
- end
21
- self.permissions_as_permissor.reload
22
- end
23
-
24
- def wildcard_permit!(whom, what)
25
- existing = self.permissions_as_permissor.by_relationship_type(whom).where(:permissible_type, what)
26
-
27
- if existing.empty?
28
- self.permissions_as_permissor.create!(wildcard_permission_params(whom, what))
29
- end
30
- self.permissions_as_permissor.reload
31
- end
32
-
33
- def permission_params(whom, what)
34
- ActionController::Parameters.new({:relationship_type => whom, :permissible_type => what.class.name, :permissible_id => what.id}).permit!
35
- end
36
-
37
- def wildcard_permission_params(whom, what)
38
- ActionController::Parameters.new({:relationship_type => whom, :permissible_type => what}).permit!
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,51 +0,0 @@
1
- module PrivatePerson
2
- module Permitted
3
- def acts_as_permitted
4
- class_eval do
5
- def is_permitted?(permissor, permissible)
6
- if permissible.nil?
7
- raise 'Called is_permitted? on nil. Does not compute. Preparing to self destruct.'
8
- end
9
- unless Permission.by_permissible(permissible).blocked.empty?
10
- return false
11
- end
12
- wildcards = permissions_by(permissor).by_wildcard(permissible.class.name).legitimate
13
- if wildcards.present?
14
- return true
15
- end
16
- permissions = permissions_by(permissor).by_permissible(permissible).legitimate
17
- if permissions.present?
18
- return true
19
- end
20
- return false
21
- end
22
-
23
- def permissions_by(permissor)
24
- Permission.by_permissor(permissor).by_relationship_type(relationship_to(permissor))
25
- end
26
-
27
- def relationship_to(permissor)
28
- # First make sure we're not a new user
29
- if self.new_record?
30
- return 'public'
31
- end
32
- # Next check for an efficient method
33
- for relationship_method in permissor.class.of
34
- is_method = ('is_' + relationship_method.to_s.singularize + '_of?').to_sym
35
- if respond_to?(is_method) and self.send(is_method, permissor)
36
- return relationship_method.to_s
37
- end
38
- end
39
- # Then check for a slow method
40
- for relationship_method in permissor.class.of
41
- relationship_members = permissor.send(relationship_method.to_sym)
42
- if relationship_members.present? and relationship_members.include? self
43
- return relationship_method.to_s
44
- end
45
- end
46
- return 'public'
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,14 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
- #
3
- # This file contains settings for ActionController::ParamsWrapper which
4
- # is enabled by default.
5
-
6
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
9
- end
10
-
11
- # Disable root element in JSON by default.
12
- ActiveSupport.on_load(:active_record) do
13
- self.include_root_in_json = false
14
- end