biola_wcms_components 0.25.0 → 0.25.1

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: 902d9f02e6d86c98d95c2fe8ca85cb2524d0d93b
4
- data.tar.gz: 7e56291ccb737692f32719f21d0b06b9a4f0ea48
3
+ metadata.gz: 5f29ca233d7b9c38afa355bd466d740f5b2188ba
4
+ data.tar.gz: b771c11af719e321462160be334c0d2e89ed515e
5
5
  SHA512:
6
- metadata.gz: a87e029c0bd2155300eda9945104c265975055cfd296da92d40854bac1dc88796e6878dbd227af2fec86e0ab08e25ed5a56697dc6f7355432dc058dc01743685
7
- data.tar.gz: 4f9f252b0c983a5191920365d96fd483ec2b0f72ac0950bdbf047bc1f6af069ad909c2c8375f12bd73152eae644c4418f314f964c6f0b4e0ef9cb77c47d1a7fc
6
+ metadata.gz: 924c1c3508a2f0362586af92b03f981d1cdaf9654689116bc60c86b5df97bd97912e883a3cc97864e647a0bb00271f916ba4f11de501e1d29d7ce8362f5db4a6
7
+ data.tar.gz: c809523c4be832ad7e473cc3e89afc35efaac121fcd96c77f8bfe05a4cbbb728d4577a03ea7eea47492122c52612c4b07acea56a946c2cf33c3a03c871370122
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### Master (unreleased)
4
4
 
5
+ ### 0.25.1
6
+
7
+ * Enforce extra attributes to be the right type
8
+
5
9
  ### 0.25.0
6
10
 
7
11
  * Removes support for RubyCAS
@@ -1,3 +1,3 @@
1
1
  module BiolaWcmsComponents
2
- VERSION = "0.25.0"
2
+ VERSION = '0.25.1'.freeze
3
3
  end
@@ -5,16 +5,6 @@ class CasAuthentication
5
5
  @session = session
6
6
  end
7
7
 
8
- USER_CAS_MAP = {
9
- biola_id: :employeeId,
10
- first_name: :eduPersonNickname,
11
- last_name: :sn,
12
- email: :mail,
13
- photo_url: :url,
14
- entitlements: :eduPersonEntitlement,
15
- affiliations: :eduPersonAffiliation
16
- }.freeze
17
-
18
8
  def user
19
9
  return unless username.present?
20
10
  @user ||= User.find_or_initialize_by(username: username)
@@ -36,6 +26,16 @@ class CasAuthentication
36
26
 
37
27
  attr_reader :session
38
28
 
29
+ USER_CAS_MAP = {
30
+ biola_id: { employeeId: Integer },
31
+ first_name: :eduPersonNickname,
32
+ last_name: :sn,
33
+ email: :mail,
34
+ photo_url: :url,
35
+ entitlements: { eduPersonEntitlement: Array },
36
+ affiliations: { eduPersonAffiliation: Array }
37
+ }.freeze
38
+
39
39
  def present?
40
40
  session['cas'].present?
41
41
  end
@@ -58,23 +58,35 @@ class CasAuthentication
58
58
 
59
59
  def update_extra_attributes!
60
60
  USER_CAS_MAP.each do |k, v|
61
- value = extra_attrs.fetch(v, nil)
62
- user[k] = value unless value.blank?
61
+ user[k] = attr_value(v, extra_attrs)
63
62
  end
64
-
65
63
  user.save
66
64
  end
67
65
  alias create_user! update_extra_attributes!
68
66
 
69
67
  def username
70
- (session[:username] || attrs['user']).downcase
68
+ (session[:username] || attrs[:user]).downcase
71
69
  end
72
70
 
73
71
  def attrs
74
- @attrs ||= (session['cas'] || {}).with_indifferent_access
72
+ @attrs ||= (session[:cas] || {}).with_indifferent_access
75
73
  end
76
74
 
77
75
  def extra_attrs
78
76
  @extra_attrs ||= (attrs[:extra_attributes] || {}).with_indifferent_access
79
77
  end
78
+
79
+ def attr_value(key, opts = {})
80
+ return String(opts[key]) if key.is_a? Symbol
81
+ attr_hash(key, opts)
82
+ end
83
+
84
+ def attr_hash(hash, opts = {})
85
+ return unless hash.is_a? Hash
86
+
87
+ key, type = hash.first
88
+ return Array(opts.try(:[], key)).compact if type == Array
89
+ return Integer(opts.try(:[], key)) if type == Integer &&
90
+ /\A\d+\z/ =~ opts[key].to_s
91
+ end
80
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biola_wcms_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Hall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ace-rails-ap