diff --git a/app/assets/javascripts/controllers/admin/authentications.coffee b/app/assets/javascripts/controllers/admin/authentications.coffee.erb similarity index 88% rename from app/assets/javascripts/controllers/admin/authentications.coffee rename to app/assets/javascripts/controllers/admin/authentications.coffee.erb index 0c6055f21..75f9ad02d 100644 --- a/app/assets/javascripts/controllers/admin/authentications.coffee +++ b/app/assets/javascripts/controllers/admin/authentications.coffee.erb @@ -103,8 +103,8 @@ Application.Controllers.controller "AuthentificationController", ["$scope", "$st ## # Page to add a new authentication provider ## -Application.Controllers.controller "NewAuthenticationController", ["$scope", "$state", "$rootScope", "dialogs", "growl", "mappingFieldsPromise", "authProvidersPromise", "AuthProvider", '_t' -, ($scope, $state, $rootScope, dialogs, growl, mappingFieldsPromise, authProvidersPromise, AuthProvider, _t) -> +Application.Controllers.controller "NewAuthenticationController", ["$scope", "$state", "$rootScope", "$uibModal", "dialogs", "growl", "mappingFieldsPromise", "authProvidersPromise", "AuthProvider", '_t' +, ($scope, $state, $rootScope, $uibModal, dialogs, growl, mappingFieldsPromise, authProvidersPromise, AuthProvider, _t) -> $scope.authMethods = METHODS @@ -178,6 +178,30 @@ Application.Controllers.controller "NewAuthenticationController", ["$scope", "$s $scope.cancel = -> $state.go('app.admin.members') + + + ## + # Open a modal allowing to specify the data mapping for the given field + ## + $scope.defineDataMapping = (mapping) -> + $uibModal.open + templateUrl: '<%= asset_path "admin/authentications/_data_mapping.html" %>' + size: 'md' + resolve: + field: -> mapping + controller: ['$scope', '$uibModalInstance', 'field', ($scope, $uibModalInstance, field) -> + ## parent field + $scope.field = field + + ## close and save the modifications + $scope.ok = -> + console.log('TODO') + $uibModalInstance.close() + + ## do not save the modifications + $scope.cancel = -> + $uibModalInstance.dismiss() + ] ] diff --git a/app/assets/templates/admin/authentications/_data_mapping.html.erb b/app/assets/templates/admin/authentications/_data_mapping.html.erb new file mode 100644 index 000000000..2f5aef2e6 --- /dev/null +++ b/app/assets/templates/admin/authentications/_data_mapping.html.erb @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/app/assets/templates/admin/authentications/_oauth2_mapping.html.erb b/app/assets/templates/admin/authentications/_oauth2_mapping.html.erb index bb16e52f1..4785bdb72 100644 --- a/app/assets/templates/admin/authentications/_oauth2_mapping.html.erb +++ b/app/assets/templates/admin/authentications/_oauth2_mapping.html.erb @@ -16,11 +16,14 @@ {{m.local_model}} - {{m.local_field}} + {{m.local_field[0]}} {{m.api_endpoint}} {{m.api_data_type}} {{m.api_field}} + @@ -38,7 +41,7 @@ diff --git a/app/models/profile.rb b/app/models/profile.rb index aa3097f4c..483fbee71 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -37,4 +37,16 @@ class Profile < ActiveRecord::Base def str_gender gender ? 'male' : 'female' end + + def self.mapping + # we protect some fields as they are designed to be managed by the system and must not be updated externally + blacklist = %w(id user_id created_at updated_at) + # model-relationships must be added manually + additional = [%w(avatar string), %w(address string), %w(organization_name string), %w(organization_address string)] + Profile.column_types + .map{|k,v| [k, v.type.to_s]} + .delete_if { |col| blacklist.include?(col[0]) } + .concat(additional) + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 2985cad0c..af040ab7c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -336,6 +336,17 @@ class User < ActiveRecord::Base end end + def self.mapping + # we protect some fields as they are designed to be managed by the system and must not be updated externally + blacklist = %w(id encrypted_password reset_password_token reset_password_sent_at remember_created_at + sign_in_count current_sign_in_at last_sign_in_at current_sign_in_ip last_sign_in_ip confirmation_token confirmed_at + confirmation_sent_at unconfirmed_email failed_attempts unlock_token locked_at created_at updated_at stp_customer_id slug + provider auth_token merged_at) + User.column_types + .map{|k,v| [k, v.type.to_s]} + .delete_if { |col| blacklist.include?(col[0]) } + end + protected def confirmation_required? false diff --git a/app/views/api/auth_providers/mapping_fields.json.jbuilder b/app/views/api/auth_providers/mapping_fields.json.jbuilder index b2683f523..7eb9615bf 100644 --- a/app/views/api/auth_providers/mapping_fields.json.jbuilder +++ b/app/views/api/auth_providers/mapping_fields.json.jbuilder @@ -1,9 +1,4 @@ -# we protect some fields are they are designed to be managed by the system and must not be updated externally +json.user User.mapping -json.user User.column_names - %w(id encrypted_password reset_password_token reset_password_sent_at remember_created_at -sign_in_count current_sign_in_at last_sign_in_at current_sign_in_ip last_sign_in_ip confirmation_token confirmed_at -confirmation_sent_at unconfirmed_email failed_attempts unlock_token locked_at created_at updated_at stp_customer_id slug -provider auth_token merged_at) - -json.profile Profile.column_names - %w(id user_id created_at updated_at) + %w(avatar address organization_name organization_address) \ No newline at end of file +json.profile Profile.mapping \ No newline at end of file diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index 34de8a913..1014fc37c 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -248,6 +248,8 @@ en: provider_name_is_required: "Provider name is required." authentication_type: "Authentication type" authentication_type_is_required: "Authentication type is required." + data_mapping: "Data mapping" + expected_data_type: "Expected data type" oauth2: # edition/creation form of an OAuth2 authentication provider diff --git a/config/locales/app.shared.fr.yml b/config/locales/app.shared.fr.yml index a6c7afc6f..b21ebb954 100644 --- a/config/locales/app.shared.fr.yml +++ b/config/locales/app.shared.fr.yml @@ -248,6 +248,8 @@ fr: provider_name_is_required: "Le nom du fournisseur est requis." authentication_type: "Type d'authentification" authentication_type_is_required: "Le type d'authentification est requis." + data_mapping: "Correspondance des données" + expected_data_type: "Type de données attendues" oauth2: # formulaire d'édition/création d'un fournisseur d'authentification de type OAuth2