aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorRobert2017-11-27 10:07:30 +0100
committerRobert2017-12-14 15:34:46 +0100
commit695d6604f12515507e2e8d435370d30df5fc820d (patch)
treeafbb8919268ea2a5cd96b232d64eb7dbc108de34 /app
parent1eacdd594ec0079372c7e8d0c32d283e2a20a05c (diff)
downloadchouette-core-695d6604f12515507e2e8d435370d30df5fc820d.tar.bz2
Refs: #5006@3h;
Working out how to check for allowed lines vs. foreign lines - Implement allowed_lines as `Organisation#lines_set` - Pushed line_id related stuff into `lib/stif/codif_line_id.rb` - Related Specs
Diffstat (limited to 'app')
-rw-r--r--app/models/organisation.rb63
1 files changed, 37 insertions, 26 deletions
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index f6fba2d67..0dab1fc16 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -18,36 +18,39 @@ class Organisation < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :code
- def self.portail_api_request
- conf = Rails.application.config.try(:stif_portail_api)
- raise 'Rails.application.config.stif_portail_api configuration is not defined' unless conf
-
- HTTPService.get_json_resource(
- host: conf[:url],
- path: '/api/v1/organizations',
- token: conf[:key])
- end
+ class << self
+
+ def portail_api_request
+ conf = Rails.application.config.try(:stif_portail_api)
+ raise 'Rails.application.config.stif_portail_api configuration is not defined' unless conf
- def self.sync_update code, name, scope
- org = Organisation.find_or_initialize_by(code: code)
- if scope
- org.sso_attributes ||= {}
- if org.sso_attributes['functional_scope'] != scope
- org.sso_attributes['functional_scope'] = scope
- # FIXME see #1941
- org.sso_attributes_will_change!
+ HTTPService.get_json_resource(
+ host: conf[:url],
+ path: '/api/v1/organizations',
+ token: conf[:key])
+ end
+
+ def sync_update code, name, scope
+ org = Organisation.find_or_initialize_by(code: code)
+ if scope
+ org.sso_attributes ||= {}
+ if org.sso_attributes['functional_scope'] != scope
+ org.sso_attributes['functional_scope'] = scope
+ # FIXME see #1941
+ org.sso_attributes_will_change!
+ end
end
+ org.name = name
+ org.synced_at = Time.now
+ org.save
+ org
end
- org.name = name
- org.synced_at = Time.now
- org.save
- org
- end
- def self.portail_sync
- self.portail_api_request.each do |el|
- org = self.sync_update el['code'], el['name'], el['functional_scope']
- puts "✓ Organisation #{org.name} has been updated" unless Rails.env.test?
+ def portail_sync
+ portail_api_request.each do |el|
+ org = self.sync_update el['code'], el['name'], el['functional_scope']
+ puts "✓ Organisation #{org.name} has been updated" unless Rails.env.test?
+ end
end
end
@@ -64,4 +67,12 @@ class Organisation < ActiveRecord::Base
raise ActiveRecord::RecordNotFound
end
+ def functional_scope
+ JSON.parse( (sso_attributes || {}).fetch('functional_scope', '[]') )
+ end
+
+ def lines_set
+ STIF::CodifLineId.lines_set_from_functional_scope( functional_scope )
+ end
+
end