Add observer alert thresholds and alerts migrations/models
Refs MBL-10121 Test Plan: - in the rails console you should be able to create an ObserverAlertThreshold that is linked to a user_observation_link - in the rails console you should be able to create an ObserverAlert that is linked to a user_observation_link and observer_alert_threshold Change-Id: I7f907decf310a011d968b2d937953b91ccd5f7f0 Reviewed-on: https://gerrit.instructure.com/149067 Tested-by: Jenkins Reviewed-by: Cameron Sutter <csutter@instructure.com> Product-Review: Cameron Sutter <csutter@instructure.com> QA-Review: Cameron Sutter <csutter@instructure.com>
This commit is contained in:
parent
3013c94f3f
commit
317942fcf2
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class ObserverAlert < ActiveRecord::Base
|
||||
belongs_to :user_observation_link, :inverse_of => :observer_alert
|
||||
belongs_to :observer_alert_threshold
|
||||
belongs_to :context, polymorphic: [:announcement, :assignment, :course, :account_notification]
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class ObserverAlertThreshold < ActiveRecord::Base
|
||||
belongs_to :user_observation_link, :inverse_of => :observer_alert_threshold
|
||||
end
|
|
@ -27,6 +27,9 @@ class UserObservationLink < ActiveRecord::Base
|
|||
belongs_to :observer, :class_name => 'User', inverse_of: :as_observer_observation_links
|
||||
belongs_to :root_account, :class_name => 'Account'
|
||||
|
||||
has_many :observer_alert_threshold, :inverse_of => :user_observation_link
|
||||
has_many :observer_alert, :inverse_of => :user_observation_link
|
||||
|
||||
after_create :create_linked_enrollments
|
||||
|
||||
validate :not_same_user, :if => lambda { |uo| uo.changed? }
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class CreateObserverAlertThresholds < ActiveRecord::Migration[5.1]
|
||||
tag :predeploy
|
||||
def change
|
||||
create_table :observer_alert_thresholds do |t|
|
||||
t.belongs_to :user_observation_link, :null => false, :foreign_key => { to_table: 'user_observers'}
|
||||
t.string :alert_type, :null => false
|
||||
t.string :threshold
|
||||
t.string :workflow_state, :default => 'active', :null => false, :index => true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class CreateObserverAlerts < ActiveRecord::Migration[5.1]
|
||||
tag :predeploy
|
||||
def change
|
||||
create_table :observer_alerts do |t|
|
||||
t.belongs_to :user_observation_link, :null => false, :foreign_key => { to_table: 'user_observers' }
|
||||
t.belongs_to :observer_alert_threshold, :null => false, :foreign_key => true
|
||||
|
||||
t.belongs_to :context, :polymorphic => true
|
||||
|
||||
t.string :alert_type, :null => false
|
||||
t.string :workflow_state, :default => 'unread', :null => false, :index => true
|
||||
t.timestamp :action_date, :null => false
|
||||
t.string :html_url
|
||||
t.string :title, :null => false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe ObserverAlert do
|
||||
it 'can link to a threshold and observation link' do
|
||||
assignment = assignment_model()
|
||||
assignment.save!
|
||||
observer = user_factory()
|
||||
student = user_factory()
|
||||
link = UserObservationLink.new(:student => student, :observer => observer,
|
||||
:root_account => @account)
|
||||
link.save!
|
||||
threshold = ObserverAlertThreshold.new(:user_observation_link => link, :alert_type => 'missing')
|
||||
threshold.save!
|
||||
|
||||
alert = ObserverAlert.new(:user_observation_link => link, :observer_alert_threshold => threshold,
|
||||
:context => assignment, :alert_type => 'missing', :action_date => Time.zone.now,
|
||||
:title => 'Assignment missing')
|
||||
alert.save!
|
||||
|
||||
saved_alert = ObserverAlert.find(alert.id)
|
||||
expect(saved_alert).not_to be_nil
|
||||
expect(saved_alert.user_observation_link).not_to be_nil
|
||||
expect(saved_alert.observer_alert_threshold).not_to be_nil
|
||||
end
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe ObserverAlertThreshold do
|
||||
it 'can link to an user_observation_link' do
|
||||
observer = user_factory()
|
||||
student = user_factory()
|
||||
link = UserObservationLink.new(:student => student, :observer => observer,
|
||||
:root_account => @account)
|
||||
link.save!
|
||||
threshold = ObserverAlertThreshold.new(:user_observation_link => link, :alert_type => 'missing')
|
||||
threshold.save!
|
||||
|
||||
saved_threshold = ObserverAlertThreshold.find(threshold.id)
|
||||
expect(saved_threshold).not_to be_nil
|
||||
expect(saved_threshold.user_observation_link).not_to be_nil
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue