From bf4b4384590c271d1dfadf874d185c2f6130ad0e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 6 May 2015 14:33:39 -0700 Subject: Fix bug where avatar filenames were not actually deleted from the database during removal. This would result in a 404 error in certain views. The `save` call was being rolled back due to an error in the validation step. Relax the validation step so that this works. Closes #1570 --- app/models/group.rb | 2 +- app/models/project.rb | 2 +- app/models/user.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/group.rb b/app/models/group.rb index 1386a9eccc9..687458adac4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -20,7 +20,7 @@ class Group < Namespace has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember' has_many :users, through: :group_members - validate :avatar_type, if: ->(user) { user.avatar_changed? } + validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } validates :avatar, file_size: { maximum: 200.kilobytes.to_i } mount_uploader :avatar, AvatarUploader diff --git a/app/models/project.rb b/app/models/project.rb index e866681aab9..6a2d7895446 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -144,7 +144,7 @@ class Project < ActiveRecord::Base validates :star_count, numericality: { greater_than_or_equal_to: 0 } validate :check_limit, on: :create validate :avatar_type, - if: ->(project) { project.avatar && project.avatar_changed? } + if: ->(project) { project.avatar.present? && project.avatar_changed? } validates :avatar, file_size: { maximum: 200.kilobytes.to_i } mount_uploader :avatar, AvatarUploader diff --git a/app/models/user.rb b/app/models/user.rb index 1cf7cfea974..703a7d32705 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -137,7 +137,7 @@ class User < ActiveRecord::Base validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true validate :namespace_uniq, if: ->(user) { user.username_changed? } - validate :avatar_type, if: ->(user) { user.avatar_changed? } + validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } validate :unique_email, if: ->(user) { user.email_changed? } validate :owns_notification_email, if: ->(user) { user.notification_email_changed? } validate :owns_public_email, if: ->(user) { user.public_email_changed? } @@ -298,7 +298,7 @@ class User < ActiveRecord::Base if primary_email_record primary_email_record.destroy self.emails.create(email: self.email_was) - + self.update_secondary_emails! end end -- cgit v1.2.1