Просмотр исходного кода

Maintenance: Improve DataPrivacyTask error messages

Mantas Masalskis 1 год назад
Родитель
Сommit
5f3df11107

+ 20 - 20
i18n/zammad.pot

@@ -3188,6 +3188,10 @@ msgstr ""
 msgid "Data Privacy"
 msgstr ""
 
+#: lib/validations/data_privacy_task_validator.rb
+msgid "Data privacy task allows to delete a user or a ticket only."
+msgstr ""
+
 #: app/assets/javascripts/app/controllers/data_privacy.coffee
 msgid "DataPrivacyTask"
 msgstr ""
@@ -6667,6 +6671,18 @@ msgstr ""
 msgid "Ionicons"
 msgstr ""
 
+#: lib/validations/data_privacy_task_validator.rb
+msgid "It is not possible to delete the last account with admin permissions."
+msgstr ""
+
+#: lib/validations/data_privacy_task_validator.rb
+msgid "It is not possible to delete the system user."
+msgstr ""
+
+#: lib/validations/data_privacy_task_validator.rb
+msgid "It is not possible to delete your current account."
+msgstr ""
+
 #: app/models/ticket.rb
 msgid "It is not possible to merge into an already merged ticket."
 msgstr ""
@@ -10232,6 +10248,10 @@ msgstr ""
 msgid "Selected conditions"
 msgstr ""
 
+#: lib/validations/data_privacy_task_validator.rb
+msgid "Selected object is already queued for deletion."
+msgstr ""
+
 #: app/assets/javascripts/app/controllers/widget/ticket_batch.coffee
 msgid "Selected tickets do not match any macros."
 msgstr ""
@@ -15038,10 +15058,6 @@ msgstr ""
 msgid "has already been taken"
 msgstr ""
 
-#: lib/validations/data_privacy_task_validator.rb
-msgid "has an existing DataPrivacyTask queued"
-msgstr ""
-
 #: app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee
 #: app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee
 #: app/assets/javascripts/app/controllers/_ui_element/object_selector.coffee
@@ -15211,10 +15227,6 @@ msgstr ""
 msgid "is larger than the allowed maximum value of %{max_value}"
 msgstr ""
 
-#: lib/validations/data_privacy_task_validator.rb
-msgid "is last account with admin permissions"
-msgstr ""
-
 #: lib/validations/object_manager/attribute_validator/max_length.rb
 msgid "is longer than the allowed length %{maxlength}"
 msgstr ""
@@ -15231,10 +15243,6 @@ msgstr ""
 msgid "is not"
 msgstr ""
 
-#: lib/validations/data_privacy_task_validator.rb
-msgid "is not a User or Ticket"
-msgstr ""
-
 #: lib/validations/color_validator.rb
 msgid "is not a color. Only Hex, RGB and HSL colors are supported."
 msgstr ""
@@ -15298,14 +15306,6 @@ msgstr ""
 msgid "is too short (minimum is 1 character)"
 msgstr ""
 
-#: lib/validations/data_privacy_task_validator.rb
-msgid "is undeletable system User with ID 1"
-msgstr ""
-
-#: lib/validations/data_privacy_task_validator.rb
-msgid "is your current account"
-msgstr ""
-
 #: app/assets/javascripts/app/lib/app_post/pretty_date.coffee
 msgid "just now"
 msgstr ""

+ 5 - 5
lib/validations/data_privacy_task_validator.rb

@@ -20,7 +20,7 @@ class Validations::DataPrivacyTaskValidator < ActiveModel::Validator
     return if !record.deletable_type_changed?
     return if [User, Ticket].any? { deletable.is_a?(_1) }
 
-    record.errors.add(:deletable, __('is not a User or Ticket'))
+    record.errors.add(:base, __('Data privacy task allows to delete a user or a ticket only.'))
   end
 
   def check_for_user
@@ -35,26 +35,26 @@ class Validations::DataPrivacyTaskValidator < ActiveModel::Validator
   def check_for_system_user
     return if deletable.id != 1
 
-    record.errors.add(:deletable, __('is undeletable system User with ID 1'))
+    record.errors.add(:base, __('It is not possible to delete the system user.'))
   end
 
   def check_for_current_user
     return if deletable.id != UserInfo.current_user_id
 
-    record.errors.add(:deletable, __('is your current account'))
+    record.errors.add(:base, __('It is not possible to delete your current account.'))
   end
 
   def check_for_last_admin
     return if !last_admin?
 
-    record.errors.add(:deletable, __('is last account with admin permissions'))
+    record.errors.add(:base, __('It is not possible to delete the last account with admin permissions.'))
   end
 
   def check_for_existing_task
     return if !record.deletable_id_changed?
     return if !tasks_exists?
 
-    record.errors.add(:deletable, __('has an existing DataPrivacyTask queued'))
+    record.errors.add(:base, __('Selected object is already queued for deletion.'))
   end
 
   def tasks_exists?

+ 6 - 6
spec/lib/validations/data_privacy_task_validator_spec.rb

@@ -42,7 +42,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
       it 'adds error' do
         task.validate(record)
 
-        expect(record.errors.first.message).to include('is not a ')
+        expect(record.errors.full_messages).to include('Data privacy task allows to delete a user or a ticket only.')
       end
     end
   end
@@ -53,7 +53,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
 
       task.validate(record)
 
-      expect(record.errors.first.message).to include('has an existing')
+      expect(record.errors.full_messages).to include('Selected object is already queued for deletion.')
     end
 
     it 'passes if existing task is marked as failed' do
@@ -77,7 +77,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
     it 'adds error if deleting current user', current_user_id: -> { deletable.id } do
       task.validate(record)
 
-      expect(record.errors.first.message).to include('is your current account')
+      expect(record.errors.full_messages).to include('It is not possible to delete your current account.')
     end
 
     context 'when deleting a system user' do
@@ -86,7 +86,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
       it 'adds error' do
         task.validate(record)
 
-        expect(record.errors.first.message).to include('system User')
+        expect(record.errors.full_messages).to include('It is not possible to delete the system user.')
       end
     end
 
@@ -98,7 +98,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
       it 'adds error if deleting last admin user' do
         task.validate(record)
 
-        expect(record.errors.first.message).to include('last account with admin')
+        expect(record.errors.full_messages).to include('It is not possible to delete the last account with admin permissions.')
       end
 
       context 'when other admin exists' do
@@ -117,7 +117,7 @@ RSpec.describe Validations::DataPrivacyTaskValidator do
 
           task.validate(record)
 
-          expect(record.errors.first.message).to include('last account with admin')
+          expect(record.errors.full_messages).to include('It is not possible to delete the last account with admin permissions.')
         end
       end
     end