OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add more informative watcher validation messages
Christophe Bliarde12b07b28fc8
diff --git a/app/models/watcher.rb b/app/models/watcher.rbindex 7beccd17203..772ee6f1505 100644--- a/app/models/watcher.rb+++ b/app/models/watcher.rb@@ -47,17 +47,18 @@ class Watcher < ApplicationRecordprotecteddef validate_active_user- # TODO add informative error messagereturn if user.blank?- errors.add :user_id, :invalid if user.locked?+ errors.add :user_id, :locked if user.locked?enddef validate_user_allowed_to_watch- # TODO add informative error messagereturn if user.blank? || watchable.blank?+ # No need to add a missing permission error on top of the user locked error+ # created by validate_active_user.+ return if user.locked?- errors.add :user_id, :invalid unless watchable.possible_watcher?(user)+ errors.add :user_id, :not_allowed_to_view unless watchable.possible_watcher?(user)endclass << selfdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 57b937b5352..49ed2aed4a8 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -821,6 +821,11 @@ en:email_alerts_global: 'The email notification settings can only be set globally.'format: "%{message}"wrong_date: 'Wrong value for Start date, Due date, or Overdue.'+ watcher:+ attributes:+ user_id:+ not_allowed_to_view: "is not allowed to view this resource."+ locked: "is locked."wiki_page:attributes:slug:diff --git a/spec/requests/api/v3/watcher_resource_spec.rb b/spec/requests/api/v3/watcher_resource_spec.rbindex 81ccd2a5d97..132b6542cd8 100644--- a/spec/requests/api/v3/watcher_resource_spec.rb+++ b/spec/requests/api/v3/watcher_resource_spec.rb@@ -33,7 +33,7 @@ describe 'API v3 Watcher resource', type: :request, content_type: :json doinclude Rack::Test::Methodsinclude API::V3::Utilities::PathHelper- let(:project) { create(:project, identifier: 'test_project', public: false) }+ shared_let(:project) { create(:project, identifier: 'test_project', public: false) }let(:current_user) docreate :user, member_in_project: project, member_through_role: roleend@@ -173,7 +173,21 @@ describe 'API v3 Watcher resource', type: :request, content_type: :json dolet(:new_watcher) { create(:user) }it_behaves_like 'constraint violation' do- let(:message) { 'User is invalid' }+ let(:message) { 'User is not allowed to view this resource.' }+ end+ end++ context 'when the target user is locked' do+ let(:new_watcher) do+ user = create(:user,+ member_in_project: project,+ member_through_role: view_work_packages_role)+ user.locked!+ user+ end++ it_behaves_like 'constraint violation' do+ let(:message) { 'User is locked.' }endend