g5_authenticatable 0.8.1.pre → 0.9.1.pre.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2681284b02e32d9dc6051f38729fb16024ed6d9
4
- data.tar.gz: 5154f962c52742c5c50ee2b489818a0009e7f771
3
+ metadata.gz: e4ea16474bb9af27d71cc19d0860500e289b1183
4
+ data.tar.gz: 888f2f21d3516ef5832df070d3da0c193c9bb8f8
5
5
  SHA512:
6
- metadata.gz: 248b32c72eb20e0d1e112f14b02fb34b34cddfe94f6068302f33ce9803cbe777797eaae7fb5778be97226388f58ea687d3f5acb3d98603ba53d29ba844f246b5
7
- data.tar.gz: d0b18a377ccd9e152ef287327151ebb45271d9f4cc6aa908a71020eb79f20a8c7846527875d2bad5ad70eccb4e5295cde7d42530dc529f7bfbdb539427ac75c9
6
+ metadata.gz: a1390a2a326b668987b0b1dd78a8a131b24f4a092f746776605dbfde284aabe7df899d9507d76ec170980510f293453042864183576054edc5e770e5270e05c9
7
+ data.tar.gz: fc5a84542730f57401d3080e6fb8682a7b5f6cac0c00bdb31281a4424ab57b37420de941cfed4d7931749d7b3e34790243934e90f5f847c158ff046356fcfd56
data/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
+ ## v0.9.0 (2016-11-03)
2
+
3
+ * Refactor custom mapping logic into devise_g5_authenticatable callbacks
4
+ ([#47](https://github.com/G5/g5_authenticatable/pull/47))
5
+
6
+ ## v0.8.0 (2016-03-07)
7
+
8
+ * Location role policies
9
+ ([#46](https://github.com/G5/g5_authenticatable/pull/46))
10
+
1
11
  ## v0.7.5.beta (2016-01-15)
2
12
 
3
13
  * Fixes bug that granted higher permissions when the resource for a scoped roles didn't exist.
4
14
 
5
-
6
15
  ## v0.7.4 (2015-12-09)
7
16
 
8
17
  * Adds Impersonate (Assume) Devise Strategy and Concern to handle access to session stored values
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem 'rails', '4.2.0'
10
10
  gem 'jquery-rails'
11
11
  gem 'pg'
12
12
  gem 'grape'
13
+ gem 'active_model_serializers', '<= 0.10.0' # For compatibility with ruby 2.0.0
13
14
 
14
15
  group :test, :development do
15
16
  gem 'rspec-rails', '~> 3.1'
data/README.md CHANGED
@@ -18,7 +18,7 @@ library in isolation.
18
18
 
19
19
  ## Current Version
20
20
 
21
- 0.7.4
21
+ 0.9.0
22
22
 
23
23
  ## Requirements
24
24
 
@@ -9,25 +9,14 @@ module G5Authenticatable
9
9
 
10
10
  GLOBAL_ROLE = 'GLOBAL'
11
11
 
12
- def self.new_with_session(params, session)
13
- user = super(params, session)
14
- auth_data = session['omniauth.auth']
15
-
16
- if auth_data
17
- user.assign_attributes(extended_auth_attributes(auth_data))
18
- user.update_roles_from_auth(auth_data)
19
- end
20
- user
21
- end
22
-
23
- def self.find_and_update_for_g5_oauth(auth_data)
24
- user = super(auth_data)
25
- if user
26
- user.update_attributes(extended_auth_attributes(auth_data))
27
- user.update_roles_from_auth(auth_data)
28
- end
29
-
30
- user
12
+ def attributes_from_auth(auth_data)
13
+ super(auth_data).merge({
14
+ first_name: auth_data.info.first_name,
15
+ last_name: auth_data.info.last_name,
16
+ phone_number: auth_data.info.phone,
17
+ title: auth_data.extra.title,
18
+ organization_name: auth_data.extra.organization_name
19
+ })
31
20
  end
32
21
 
33
22
  def update_roles_from_auth(auth_data)
@@ -50,18 +39,6 @@ module G5Authenticatable
50
39
  end
51
40
 
52
41
  private
53
-
54
- def self.extended_auth_attributes(auth_data)
55
- h = {
56
- first_name: auth_data.info.first_name,
57
- last_name: auth_data.info.last_name,
58
- phone_number: auth_data.info.phone,
59
- title: auth_data.extra.title,
60
- organization_name: auth_data.extra.organization_name
61
- }
62
- auth_data.uid.present? ? h.merge!(uid: auth_data.uid) : h
63
- end
64
-
65
42
  def add_scoped_role(role)
66
43
  the_class = Object.const_get(role.type)
67
44
  resource = the_class.where(urn: role.urn).first
@@ -20,7 +20,7 @@ module G5Updatable
20
20
 
21
21
  def locations_from_client_roles
22
22
  G5Updatable::Location
23
- .joins('INNER JOIN g5_updatable_clients as c on g5_updatable_locations.client_uid=c.uid')
23
+ .joins('INNER JOIN g5_updatable_clients as c on g5_updatable_locations.client_urn=c.urn')
24
24
  .joins('INNER JOIN g5_authenticatable_roles as r on r.resource_id=c.id')
25
25
  .joins('INNER JOIN g5_authenticatable_users_roles as ur on r.id=ur.role_id')
26
26
  .where('ur.user_id=?',user.id)
@@ -33,8 +33,6 @@ module G5Updatable
33
33
  location_ids = locations_from_client_roles.map(&:id) | location_roles.map(&:resource_id)
34
34
  G5Updatable::Location.where(id: location_ids)
35
35
  end
36
-
37
36
  end
38
-
39
37
  end
40
38
  end
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'devise_g5_authenticatable', '~> 0.2.5.beta'
23
+ spec.add_dependency 'devise_g5_authenticatable', '~> 0.3.0'
24
24
  spec.add_dependency 'omniauth-g5', '~> 0.3.1'
25
25
  spec.add_dependency 'g5_authenticatable_api', '~> 0.4.1'
26
26
  spec.add_dependency 'rolify', '~> 4.0'
27
27
  spec.add_dependency 'pundit', '~> 1.0'
28
- spec.add_dependency 'g5_updatable', '> 0.6.0'
28
+ spec.add_dependency 'g5_updatable', '~> 0.20.3.pre.1'
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module G5Authenticatable
2
- VERSION = '0.8.1.pre'
2
+ VERSION = '0.9.1-2'
3
3
  end
@@ -0,0 +1,25 @@
1
+ class AddAmenities < ActiveRecord::Migration
2
+ def change
3
+ create_table :g5_updatable_hub_amenities do |t|
4
+ t.integer :external_id
5
+ t.string :name
6
+ t.string :icon
7
+ t.timestamp :external_updated_at
8
+ t.timestamp :external_created_at
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :g5_updatable_hub_amenities, :external_id, unique: true
13
+
14
+ create_table :g5_updatable_hub_amenities_locations do |t|
15
+ t.belongs_to :g5_updatable_hub_amenity
16
+ t.belongs_to :g5_updatable_location
17
+ end
18
+
19
+ add_index :g5_updatable_hub_amenities_locations, :g5_updatable_hub_amenity_id, name: 'updatable_amenities_loc_amen_id'
20
+ add_index :g5_updatable_hub_amenities_locations, :g5_updatable_location_id, name: 'updatable_amenities_loc_loc_id'
21
+
22
+ # we need this for queries that require a location to have ALL amenities in a list
23
+ add_column :g5_updatable_locations, :flat_amenity_names, :string
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ class AddClientUrnToLocations < ActiveRecord::Migration
2
+ def change
3
+ add_column :g5_updatable_locations, :client_urn, :string
4
+ add_index :g5_updatable_locations, :client_urn
5
+ end
6
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150603224036) do
14
+ ActiveRecord::Schema.define(version: 20161209070749) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
@@ -69,6 +69,26 @@ ActiveRecord::Schema.define(version: 20150603224036) do
69
69
  add_index "g5_updatable_clients", ["uid"], name: "index_g5_updatable_clients_on_uid", using: :btree
70
70
  add_index "g5_updatable_clients", ["urn"], name: "index_g5_updatable_clients_on_urn", using: :btree
71
71
 
72
+ create_table "g5_updatable_hub_amenities", force: :cascade do |t|
73
+ t.integer "external_id"
74
+ t.string "name"
75
+ t.string "icon"
76
+ t.datetime "external_updated_at"
77
+ t.datetime "external_created_at"
78
+ t.datetime "created_at"
79
+ t.datetime "updated_at"
80
+ end
81
+
82
+ add_index "g5_updatable_hub_amenities", ["external_id"], name: "index_g5_updatable_hub_amenities_on_external_id", unique: true, using: :btree
83
+
84
+ create_table "g5_updatable_hub_amenities_locations", force: :cascade do |t|
85
+ t.integer "g5_updatable_hub_amenity_id"
86
+ t.integer "g5_updatable_location_id"
87
+ end
88
+
89
+ add_index "g5_updatable_hub_amenities_locations", ["g5_updatable_hub_amenity_id"], name: "updatable_amenities_loc_amen_id", using: :btree
90
+ add_index "g5_updatable_hub_amenities_locations", ["g5_updatable_location_id"], name: "updatable_amenities_loc_loc_id", using: :btree
91
+
72
92
  create_table "g5_updatable_locations", force: :cascade do |t|
73
93
  t.string "uid"
74
94
  t.string "urn"
@@ -77,8 +97,11 @@ ActiveRecord::Schema.define(version: 20150603224036) do
77
97
  t.datetime "created_at"
78
98
  t.datetime "updated_at"
79
99
  t.string "name"
100
+ t.string "flat_amenity_names"
101
+ t.string "client_urn"
80
102
  end
81
103
 
104
+ add_index "g5_updatable_locations", ["client_urn"], name: "index_g5_updatable_locations_on_client_urn", using: :btree
82
105
  add_index "g5_updatable_locations", ["name"], name: "index_g5_updatable_locations_on_name", using: :btree
83
106
  add_index "g5_updatable_locations", ["uid"], name: "index_g5_updatable_locations_on_uid", using: :btree
84
107
  add_index "g5_updatable_locations", ["urn"], name: "index_g5_updatable_locations_on_urn", using: :btree
@@ -59,6 +59,71 @@ describe G5Authenticatable::User do
59
59
  expect(user.organization_name).to eq(user_attributes[:organization_name])
60
60
  end
61
61
 
62
+ describe '#attributes_from_auth' do
63
+ subject(:attributes_from_auth) { user.attributes_from_auth(auth_data) }
64
+
65
+ let(:auth_data) do
66
+ OmniAuth::AuthHash.new(
67
+ 'uid' => new_user_attributes[:uid],
68
+ 'provider' => new_user_attributes[:provider],
69
+ 'info' => {
70
+ 'email' => new_user_attributes[:email],
71
+ 'name' => "#{new_user_attributes[:first_name]} #{new_user_attributes[:last_name]}",
72
+ 'first_name' => new_user_attributes[:first_name],
73
+ 'last_name' => new_user_attributes[:last_name],
74
+ 'phone' => new_user_attributes[:phone_number]
75
+ },
76
+ 'credentials' => {
77
+ 'token' => new_user_attributes[:g5_access_token],
78
+ 'expires' => true,
79
+ 'expires_at' => Time.now + 1000
80
+ },
81
+ 'extra' => {
82
+ 'title' => new_user_attributes[:title],
83
+ 'organization_name' => new_user_attributes[:organization_name],
84
+ 'roles' => [
85
+ { 'name' => new_role_attributes[:name], 'type' => 'GLOBAL', 'urn' => nil }
86
+ ],
87
+ 'raw_info' => {}
88
+ })
89
+ end
90
+
91
+ let(:new_user_attributes) { FactoryGirl.attributes_for(:g5_authenticatable_user) }
92
+ let(:new_role_attributes) { FactoryGirl.attributes_for(:g5_authenticatable_role) }
93
+
94
+ it 'has the correct uid' do
95
+ expect(attributes_from_auth[:uid]).to eq(new_user_attributes[:uid])
96
+ end
97
+
98
+ it 'has the correct provider' do
99
+ expect(attributes_from_auth[:provider]).to eq(new_user_attributes[:provider])
100
+ end
101
+
102
+ it 'has the correct first_name' do
103
+ expect(attributes_from_auth[:first_name]).to eq(new_user_attributes[:first_name])
104
+ end
105
+
106
+ it 'has the correct last_name' do
107
+ expect(attributes_from_auth[:last_name]).to eq(new_user_attributes[:last_name])
108
+ end
109
+
110
+ it 'has the correct email' do
111
+ expect(attributes_from_auth[:email]).to eq(new_user_attributes[:email])
112
+ end
113
+
114
+ it 'has the correct phone_number' do
115
+ expect(attributes_from_auth[:phone_number]).to eq(new_user_attributes[:phone_number])
116
+ end
117
+
118
+ it 'has the correct title' do
119
+ expect(attributes_from_auth[:title]).to eq(new_user_attributes[:title])
120
+ end
121
+
122
+ it 'has the correct organization_name' do
123
+ expect(attributes_from_auth[:organization_name]).to eq(new_user_attributes[:organization_name])
124
+ end
125
+ end
126
+
62
127
  describe '.new_with_session' do
63
128
  subject(:new_user) { G5Authenticatable::User.new_with_session(params, session) }
64
129
 
@@ -275,6 +340,7 @@ describe G5Authenticatable::User do
275
340
  {
276
341
  uid: user.uid,
277
342
  provider: user.provider,
343
+ email: 'updated.email@test.host',
278
344
  g5_access_token: 'updatedtoken42',
279
345
  first_name: 'Updated First Name',
280
346
  last_name: 'Updated Last Name',
@@ -302,8 +368,8 @@ describe G5Authenticatable::User do
302
368
  expect { updated_user }.to_not change { user.reload.provider }
303
369
  end
304
370
 
305
- it 'should not change the email' do
306
- expect { updated_user }.to_not change { user.reload.email }
371
+ it 'should update the email' do
372
+ expect { updated_user }.to change { user.reload.email }.to(updated_attributes[:email])
307
373
  end
308
374
 
309
375
  it 'should update the first name' do
@@ -19,17 +19,14 @@ describe 'Default role-based authorization API' do
19
19
  end
20
20
 
21
21
  it 'includes all posts' do
22
- expected = {
23
- 'posts'=> [
24
- hash_including('id' => post.id,
25
- 'author_id' => post.author.id,
26
- 'content' => post.content),
27
- hash_including('id' => other_post.id,
28
- 'author_id' => other_post.author.id,
29
- 'content' => other_post.content)
30
- ]
31
- }
32
- expect(json).to include(expected)
22
+ expect(json['posts']).to include(
23
+ hash_including('id' => post.id,
24
+ 'author_id' => post.author.id,
25
+ 'content' => post.content),
26
+ hash_including('id' => other_post.id,
27
+ 'author_id' => other_post.author.id,
28
+ 'content' => other_post.content)
29
+ )
33
30
  end
34
31
  end
35
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g5_authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1.pre
4
+ version: 0.9.1.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-05 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise_g5_authenticatable
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.5.beta
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.5.beta
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: omniauth-g5
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: g5_updatable
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">"
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.6.0
89
+ version: 0.20.3.pre.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">"
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.6.0
96
+ version: 0.20.3.pre.1
97
97
  description: |-
98
98
  An engine that provides a basic User model,
99
99
  authentication logic, and remote credential
@@ -216,6 +216,8 @@ files:
216
216
  - spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb
217
217
  - spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb
218
218
  - spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb
219
+ - spec/dummy/db/migrate/20161122070749_add_amenities.rb
220
+ - spec/dummy/db/migrate/20161209070749_add_client_urn_to_locations.rb
219
221
  - spec/dummy/db/schema.rb
220
222
  - spec/dummy/lib/assets/.gitkeep
221
223
  - spec/dummy/log/.gitkeep
@@ -274,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
276
  version: 1.3.1
275
277
  requirements: []
276
278
  rubyforge_project:
277
- rubygems_version: 2.6.4
279
+ rubygems_version: 2.2.2
278
280
  signing_key:
279
281
  specification_version: 4
280
282
  summary: An authentication engine for G5 applications.
@@ -338,6 +340,8 @@ test_files:
338
340
  - spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb
339
341
  - spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb
340
342
  - spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb
343
+ - spec/dummy/db/migrate/20161122070749_add_amenities.rb
344
+ - spec/dummy/db/migrate/20161209070749_add_client_urn_to_locations.rb
341
345
  - spec/dummy/db/schema.rb
342
346
  - spec/dummy/lib/assets/.gitkeep
343
347
  - spec/dummy/log/.gitkeep