summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-15 16:42:14 +0200
committerJames Lopez <james@jameslopez.es>2017-06-23 11:41:41 +0200
commitef6a4240e534f2a12dbfb45c2decd31abf9a3c26 (patch)
tree569f9055ec2e6b4761e2d4faeeaaf89a33c68482
parent04bb82c8b8cb3033c805ea5158b01c09284ac3db (diff)
downloadgitlab-ce-ef6a4240e534f2a12dbfb45c2decd31abf9a3c26.tar.gz
update notification settings, fix api specs
-rw-r--r--app/services/users/update_service.rb2
-rw-r--r--lib/api/notification_settings.rb5
-rw-r--r--lib/api/users.rb4
-rw-r--r--spec/requests/api/users_spec.rb4
4 files changed, 9 insertions, 6 deletions
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index 7062f0669f9..b76950ac700 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -10,7 +10,7 @@ module Users
def execute(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block)
- if @user.save || !@user.changed?
+ if @user.save || !@user.changed? && @user.errors.empty?
success
else
error(@user.errors.full_messages.uniq.join('. '))
diff --git a/lib/api/notification_settings.rb b/lib/api/notification_settings.rb
index 992ea5dc24d..5f88488ccee 100644
--- a/lib/api/notification_settings.rb
+++ b/lib/api/notification_settings.rb
@@ -34,7 +34,10 @@ module API
notification_setting.transaction do
new_notification_email = params.delete(:notification_email)
- current_user.update(notification_email: new_notification_email) if new_notification_email
+ if new_notification_email
+ ::Users::UpdateService.new(current_user, current_user, notification_email: new_notification_email).execute
+ end
+
notification_setting.update(declared_params(include_missing: false))
end
rescue ArgumentError => e # catch level enum error
diff --git a/lib/api/users.rb b/lib/api/users.rb
index c10e3364382..733b65b1c8e 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -156,7 +156,9 @@ module API
user_params[:password_expires_at] = Time.now if user_params[:password].present?
- if user.update_attributes(user_params.except(:extern_uid, :provider))
+ result = ::Users::UpdateService.new(current_user, user, user_params.except(:extern_uid, :provider)).execute
+
+ if result[:status] == :success
present user, with: Entities::UserPublic
else
render_validation_error!(user)
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index a34c277112b..efb3dc69ea8 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -374,7 +374,6 @@ describe API::Users do
expect(response).to have_http_status(200)
expect(user.reload.password_expires_at).to be <= Time.now
- expect(AuditEvent.count).to eq(1)
end
it "updates user with organization" do
@@ -406,7 +405,6 @@ describe API::Users do
put api("/users/#{user.id}", admin), email: 'new@email.com'
expect(response).to have_http_status(200)
expect(user.reload.notification_email).to eq('new@email.com')
- expect(AuditEvent.count).to eq(1)
end
it 'updates user with his own username' do
@@ -651,7 +649,7 @@ describe API::Users do
email_attrs = attributes_for :email
expect do
post api("/users/#{user.id}/emails", admin), email_attrs
- end.to change { user.emails.count }.by(1).and change { AuditEvent.count }.by(1)
+ end.to change { user.emails.count }.by(1)
end
it "returns a 400 for invalid ID" do