mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
update users through CSV import
This commit is contained in:
parent
ff5de97c92
commit
ba3161589c
@ -203,7 +203,7 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco
|
|||||||
return Auth.login().then(function (user) {
|
return Auth.login().then(function (user) {
|
||||||
$scope.setCurrentUser(user);
|
$scope.setCurrentUser(user);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
console.error(`Authentication failed: ${error}`);
|
console.error(`Authentication failed: ${JSON.stringify(error)}`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -367,7 +367,7 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
, function (error) {
|
, function (error) {
|
||||||
console.error(`Authentication failed: ${error}`);
|
console.error(`Authentication failed: ${JSON.stringify(error)}`);
|
||||||
$scope.alerts = [];
|
$scope.alerts = [];
|
||||||
return $scope.alerts.push({
|
return $scope.alerts.push({
|
||||||
msg: _t('wrong_email_or_password'),
|
msg: _t('wrong_email_or_password'),
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-xs-1 col-xs-offset-1 col-md-offset-2 b-l">
|
<div class="col-xs-1 col-xs-offset-1 col-md-offset-2 b-l">
|
||||||
<section class="heading-actions wrapper">
|
<section class="heading-actions wrapper">
|
||||||
<a role="button" class="btn btn-default b-2x rounded m-t-sm m-r-lg pull-right" ui-sref="app.admin.members_import">
|
<a role="button" class="btn btn-default b-2x rounded m-t-sm" ui-sref="app.admin.members_import">
|
||||||
<i class="fa fa-cloud-upload"></i>
|
<i class="fa fa-cloud-upload"></i>
|
||||||
</a>
|
</a>
|
||||||
</section>
|
</section>
|
||||||
|
@ -8,11 +8,12 @@ class Members::ImportService
|
|||||||
log = []
|
log = []
|
||||||
CSV.foreach(import.attachment.url, headers: true, col_sep: ';') do |row|
|
CSV.foreach(import.attachment.url, headers: true, col_sep: ';') do |row|
|
||||||
begin
|
begin
|
||||||
|
password = hide_password(row)
|
||||||
log << { row: row.to_hash }
|
log << { row: row.to_hash }
|
||||||
|
|
||||||
# try to find member based on import.update_field
|
# try to find member based on import.update_field
|
||||||
user = User.find_by(import.update_field.to_sym => row[import.update_field])
|
user = User.find_by(import.update_field.to_sym => row[import.update_field])
|
||||||
params = row_to_params(row, user)
|
params = row_to_params(row, user, password)
|
||||||
if user
|
if user
|
||||||
service = Members::MembersService.new(user)
|
service = Members::MembersService.new(user)
|
||||||
res = service.update(params)
|
res = service.update(params)
|
||||||
@ -35,18 +36,24 @@ class Members::ImportService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def row_to_params(row, user)
|
def hashify(row, property, value: row[property], key: property.to_sym)
|
||||||
res = {
|
res = {}
|
||||||
id: row['id'],
|
res[key] = value if row[property]
|
||||||
username: row['username'],
|
res
|
||||||
email: row['email'],
|
end
|
||||||
password: row['password'],
|
|
||||||
password_confirmation: row['password'],
|
def row_to_params(row, user, password)
|
||||||
is_allow_contact: row['allow_contact'] == 'yes',
|
res = {}
|
||||||
is_allow_newsletter: row['allow_newsletter'] == 'yes',
|
|
||||||
group_id: group_id(row),
|
res.merge! hashify(row, 'id')
|
||||||
tag_ids: tag_ids(row)
|
res.merge! hashify(row, 'username')
|
||||||
}
|
res.merge! hashify(row, 'email')
|
||||||
|
res.merge! hashify(row, 'password', value: password)
|
||||||
|
res.merge! hashify(row, 'password', key: :password_confirmation, value: password)
|
||||||
|
res.merge! hashify(row, 'allow_contact', value: row['allow_contact'] == 'yes', key: :is_allow_contact)
|
||||||
|
res.merge! hashify(row, 'allow_newsletter', value: row['allow_newsletter'] == 'yes', key: :is_allow_newsletter)
|
||||||
|
res.merge! hashify(row, 'group', value: group_id(row), key: :group_id)
|
||||||
|
res.merge! hashify(row, 'tags', value: tag_ids(row), key: :tag_ids)
|
||||||
|
|
||||||
profile_attributes = profile(row, user)
|
profile_attributes = profile(row, user)
|
||||||
res[:profile_attributes] = profile_attributes if profile_attributes
|
res[:profile_attributes] = profile_attributes if profile_attributes
|
||||||
@ -73,29 +80,29 @@ class Members::ImportService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def profile(row, user)
|
def profile(row, user)
|
||||||
res = {
|
res = {}
|
||||||
first_name: row['first_name'],
|
|
||||||
last_name: row['last_name'],
|
res.merge! hashify(row, 'first_name')
|
||||||
phone: row['phone'],
|
res.merge! hashify(row, 'last_name')
|
||||||
interest: row['interests'],
|
res.merge! hashify(row, 'phone')
|
||||||
software_mastered: row['softwares'],
|
res.merge! hashify(row, 'interests', key: :interest)
|
||||||
website: row['website'],
|
res.merge! hashify(row, 'softwares', key: :software_mastered)
|
||||||
job: row['job'],
|
res.merge! hashify(row, 'website')
|
||||||
facebook: row['facebook'],
|
res.merge! hashify(row, 'job')
|
||||||
twitter: row['twitter'],
|
res.merge! hashify(row, 'facebook')
|
||||||
google_plus: row['googleplus'],
|
res.merge! hashify(row, 'twitter')
|
||||||
viadeo: row['viadeo'],
|
res.merge! hashify(row, 'googleplus', key: :google_plus)
|
||||||
linkedin: row['linkedin'],
|
res.merge! hashify(row, 'viadeo')
|
||||||
instagram: row['instagram'],
|
res.merge! hashify(row, 'linkedin')
|
||||||
youtube: row['youtube'],
|
res.merge! hashify(row, 'instagram')
|
||||||
vimeo: row['vimeo'],
|
res.merge! hashify(row, 'youtube')
|
||||||
dailymotion: row['dailymotion'],
|
res.merge! hashify(row, 'vimeo')
|
||||||
github: row['github'],
|
res.merge! hashify(row, 'dailymotion')
|
||||||
echosciences: row['echosciences'],
|
res.merge! hashify(row, 'github')
|
||||||
pinterest: row['pinterest'],
|
res.merge! hashify(row, 'echosciences')
|
||||||
lastfm: row['lastfm'],
|
res.merge! hashify(row, 'pinterest')
|
||||||
flickr: row['flickr']
|
res.merge! hashify(row, 'lastfm')
|
||||||
}
|
res.merge! hashify(row, 'flickr')
|
||||||
|
|
||||||
res[:id] = user.profile.id if user&.profile
|
res[:id] = user.profile.id if user&.profile
|
||||||
|
|
||||||
@ -117,10 +124,10 @@ class Members::ImportService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def statistic_profile(row, user)
|
def statistic_profile(row, user)
|
||||||
res = {
|
res = {}
|
||||||
gender: row['gender'] == 'male',
|
|
||||||
birthday: row['birthdate']
|
res.merge! hashify(row, 'gender', value: row['gender'] == 'male')
|
||||||
}
|
res.merge! hashify(row, 'birthdate', key: :birthday)
|
||||||
|
|
||||||
res[:id] = user.statistic_profile.id if user&.statistic_profile
|
res[:id] = user.statistic_profile.id if user&.statistic_profile
|
||||||
|
|
||||||
@ -143,9 +150,7 @@ class Members::ImportService
|
|||||||
def organization(row, user)
|
def organization(row, user)
|
||||||
return unless row['organization_name']
|
return unless row['organization_name']
|
||||||
|
|
||||||
res = {
|
res = { name: row['organization_name'] }
|
||||||
name: row['organization_name']
|
|
||||||
}
|
|
||||||
|
|
||||||
res[:id] = user.invoicing_profile.organization.id if user&.invoicing_profile&.organization
|
res[:id] = user.invoicing_profile.organization.id if user&.invoicing_profile&.organization
|
||||||
|
|
||||||
@ -170,5 +175,11 @@ class Members::ImportService
|
|||||||
|
|
||||||
Training.where(id: row['trainings'].split(',')).map(&:id)
|
Training.where(id: row['trainings'].split(',')).map(&:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide_password(row)
|
||||||
|
password = row['password']
|
||||||
|
row['password'] = '********' if row['password']
|
||||||
|
password
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user