aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorXinhui2016-08-05 13:23:21 +0200
committerXinhui2016-08-05 13:23:21 +0200
commitb536cc2e810908b2d3cabb50a7ab79f1d9fbdbcd (patch)
treec6b987040d5623c41d54679148c48fed55f6f42e /app
parentcab166128b905e61aea75c063e47c961f12b144f (diff)
parent5da381426eed3774f4eb17fe7ec104e9caf4eac2 (diff)
downloadchouette-core-b536cc2e810908b2d3cabb50a7ab79f1d9fbdbcd.tar.bz2
Merge branch 'sso'
Diffstat (limited to 'app')
-rw-r--r--app/models/organisation.rb8
-rw-r--r--app/models/user.rb16
2 files changed, 13 insertions, 11 deletions
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index 9d6e92825..c219bcbc9 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -21,4 +21,12 @@ class Organisation < ActiveRecord::Base
def add_rule_parameter_set
RuleParameterSet.default_for_all_modes( self).save
end
+
+ def self.sync_or_create code:, name:
+ find_or_create_by(code: code) do |org|
+ org.name = name
+ org.code = code
+ org.synced_at = Time.now
+ end
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index e00b6a35a..a8b8a01a0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,8 +6,7 @@ class User < ActiveRecord::Base
cattr_reader :authentication_type
devise :invitable, :registerable, :validatable,
- :recoverable, :rememberable, :trackable,
- :confirmable, :async, authentication_type
+ :recoverable, :rememberable, :trackable, :async, authentication_type
# FIXME https://github.com/nbudin/devise_cas_authenticatable/issues/53
# Work around :validatable, when database_authenticatable is diabled.
@@ -30,15 +29,10 @@ class User < ActiveRecord::Base
after_destroy :check_destroy_organisation
def cas_extra_attributes=(extra_attributes)
- extra_attributes.each do |name, value|
- # case name.to_sym
- # Extra attributes
- # when :fullname
- # self.fullname = value
- # when :email
- # self.email = value
- # end
- end
+ extra = extra_attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
+ self.name = extra[:full_name]
+ self.email = extra[:email]
+ self.organisation = Organisation.sync_or_create code: extra[:organisation_code], name: extra[:organisation_name]
end
private