Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-6040: Enforce change the status while the report is published #2206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/annotations/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DuplicateFieldError < ActiveRecord::RecordNotUnique; end
mount_uploaders :file, ImageUploader
serialize :file, JSON

attr_accessor :set_fields, :set_attribution, :action, :action_data
attr_accessor :set_fields, :set_attribution, :action, :action_data, :bypass_status_publish_check

belongs_to :annotation_type_object, class_name: 'DynamicAnnotation::AnnotationType', foreign_key: 'annotation_type', primary_key: 'annotation_type', optional: true
has_many :fields, class_name: 'DynamicAnnotation::Field', foreign_key: 'annotation_id', primary_key: 'id', dependent: :destroy
Expand Down Expand Up @@ -235,6 +235,7 @@ def update_fields
next if value.blank?
f = fields.select{ |x| x.field_name == field }.last || create_field(field, nil)
f.value = value
f.bypass_status_publish_check = self.bypass_status_publish_check
f.skip_check_ability = self.skip_check_ability unless self.skip_check_ability.nil?
begin
f.save!
Expand Down
1 change: 1 addition & 0 deletions app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def self.inherit_status_and_send_report(rid)
status = parent.last_verification_status
if !s.nil? && s.status != status
s.status = status
s.bypass_status_publish_check = true
s.save
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/dynamic_annotation/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class DynamicAnnotation::Field < ApplicationRecord
include CheckElasticSearch
has_paper_trail on: [:create, :update], save_changes: true, ignore: [:updated_at, :created_at], if: proc { |f| User.current.present? && (['verification_status_status', 'team_bot_response_formatted_data', 'language'].include?(f.field_name) || f.annotation_type == 'archiver' || f.annotation_type =~ /^task_response/) }, versions: { class_name: 'Version' }

attr_accessor :disable_es_callbacks
attr_accessor :disable_es_callbacks, :bypass_status_publish_check

belongs_to :annotation, optional: true
belongs_to :annotation_type_object, class_name: 'DynamicAnnotation::AnnotationType', foreign_key: 'annotation_type', primary_key: 'annotation_type', optional: true
Expand Down
1 change: 1 addition & 0 deletions app/models/workflow/verification_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def apply_rules
end

def check_if_item_is_published
return if self.bypass_status_publish_check
published = begin (self.annotation.annotated.get_annotations('report_design').last.load.get_field_value('state') == 'published') rescue false end
if published
error = {
Expand Down
15 changes: 15 additions & 0 deletions test/models/bot/smooch_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ def teardown
end
end

test "should inherit status from parent even child is published" do
pm_s = create_project_media team: @team
pm_t = create_project_media team: @team
r = create_relationship source_id: pm_s.id, target_id: pm_t.id, relationship_type: Relationship.confirmed_type
s = pm_t.annotations.where(annotation_type: 'verification_status').last.load
s.status = 'verified'
s.save!
publish_report(pm_t)
s = s.reload
s.status = 'in_progress'
s.bypass_status_publish_check = true
s.save!
assert_equal 'in_progress', s.reload.status
end

test "should send message to user when status changes" do
u = create_user is_admin: true
uid = random_string
Expand Down
Loading