diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb index d35e37935fb0bb7f4634ad5d390625ded08a1c9f..318df11727e2d93d90332b53763f8e78a884b44e 100644 --- a/app/models/concerns/avatarable.rb +++ b/app/models/concerns/avatarable.rb @@ -21,7 +21,7 @@ module Avatarable def avatar_type unless self.avatar.image? - self.errors.add :avatar, "only images allowed" + errors.add :avatar, "file format is not supported. Please try one of the following supported formats: #{AvatarUploader::IMAGE_EXT.join(', ')}" end end diff --git a/app/models/group.rb b/app/models/group.rb index 8d183006c658bb1c6a2320ca1974cec9ef09f1e6..8e391412b521248e9855baf8ff845971053bae89 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -189,12 +189,6 @@ class Group < Namespace owners.include?(user) && owners.size == 1 end - def avatar_type - unless self.avatar.image? - self.errors.add :avatar, "only images allowed" - end - end - def post_create_hook Gitlab::AppLogger.info("Group \"#{name}\" was created") diff --git a/changelogs/unreleased/43771-improve-avatar-error-message.yml b/changelogs/unreleased/43771-improve-avatar-error-message.yml new file mode 100644 index 0000000000000000000000000000000000000000..1fae10f4d1f28565a6bd056e5a4fdf2593affc4a --- /dev/null +++ b/changelogs/unreleased/43771-improve-avatar-error-message.yml @@ -0,0 +1,5 @@ +--- +title: Change avatar error message to include allowed file formats +merge_request: 17747 +author: Fabian Schneider +type: changed diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index abfc0896a4119366a8519fc4b6928fa0a1dc5664..d620943693c879da0759dc048c2fbbd5e480b635 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -240,7 +240,7 @@ describe Group do it "is false if avatar is html page" do group.update_attribute(:avatar, 'uploads/avatar.html') - expect(group.avatar_type).to eq(["only images allowed"]) + expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff"]) end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e970cd7dfdb33b02d8a47215a583623d4b79d420..943b27f285dd2af319335e6d1d52a682d6e64053 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -922,7 +922,7 @@ describe Project do it 'is false if avatar is html page' do project.update_attribute(:avatar, 'uploads/avatar.html') - expect(project.avatar_type).to eq(['only images allowed']) + expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff']) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5680eb249852554f57a5035d6cd68d310d6b8288..c61674fff13836b98ad09ad0d23e984b71a79a87 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1222,7 +1222,7 @@ describe User do it 'is false if avatar is html page' do user.update_attribute(:avatar, 'uploads/avatar.html') - expect(user.avatar_type).to eq(['only images allowed']) + expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff']) end end