Change planner overrides controller to match planner items

refs FALCOR-333

Test plan
- Create a planner override with the plannable_type as
- 'assignment' or 'discussion_topic' etc and ensure it creates
- Ensure visible has been replaced everwhere with marked_complete

Change-Id: Id56ceeb36e45a732f3afa5968da1fadc7724f86f
Reviewed-on: https://gerrit.instructure.com/115007
Reviewed-by: Dan Minkevitch <dan@instructure.com>
Tested-by: Jenkins
QA-Review: Dan Sasaki <dsasaki@instructure.com>
Product-Review: Dan Minkevitch <dan@instructure.com>
This commit is contained in:
Mysti Sadler 2017-06-09 17:48:32 -06:00
parent 080b53cd12
commit e3bde5f77f
11 changed files with 160 additions and 25 deletions

View File

@ -51,8 +51,8 @@
# "example": "published",
# "type": "string"
# },
# "visible": {
# "description": "Controls whether or not the associated plannable item is displayed on the planner",
# "marked_complete": {
# "description": "Controls whether or not the associated plannable item is marked complete on the planner",
# "example": false,
# "type": "boolean"
# },
@ -205,10 +205,13 @@ class PlannerOverridesController < ApplicationController
#
# Update a planner override's visibilty for the current user
#
# @argument marked_complete
# determines whether the planner item is marked as completed
#
# @returns PlannerOverride
def update
planner_override = PlannerOverride.find(params[:id])
planner_override.visible = value_to_boolean(params[:visible])
planner_override.marked_complete = value_to_boolean(params[:marked_complete])
if planner_override.save
render json: planner_override, status: :ok
@ -221,12 +224,22 @@ class PlannerOverridesController < ApplicationController
#
# Create a planner override for the current user
#
# @argument plannable_type [String, "announcement"|"assignment"|"discussion_topic"|"quiz"|"wiki_page"|"planner_note"]
# Type of the item that you are overriding in the planner
#
# @argument plannable_id [Integer]
# ID of the item that you are overriding in the planner
#
# @argument marked_complete [Boolean]
# If this is true, the item will show in the planner as completed
#
#
# @returns PlannerOverride
def create
planner_override = PlannerOverride.new(plannable_type: params[:plannable_type],
plannable_id: params[:plannable_id],
visible: value_to_boolean(params[:visible]),
user: @current_user)
plannable_type = params[:plannable_type] == 'quiz' ? Quizzes::Quiz : params[:plannable_type]&.camelize
planner_override = PlannerOverride.new(plannable_type: plannable_type,
plannable_id: params[:plannable_id], marked_complete: value_to_boolean(params[:marked_complete]),
user: @current_user)
if planner_override.save
render json: planner_override, status: :created

View File

@ -27,7 +27,7 @@ class PlannerOverride < ActiveRecord::Base
validates_uniqueness_of :plannable_id, scope: [:user_id, :plannable_type]
scope :active, -> { where workflow_state: 'active' }
scope :visible, -> { where visible: true }
scope :visible, -> { where(marked_complete: false) }
scope :hidden, -> { where.not visible }
scope :deleted, -> { where workflow_state: 'deleted' }
scope :not_deleted, -> { where.not deleted }

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2011 - 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 RenamePlannerOverrideVisibleToMarkedComplete < ActiveRecord::Migration[4.2]
tag :predeploy
def self.up
rename_column :planner_overrides, :visible, :marked_complete
change_column_default :planner_overrides, :marked_complete, false
end
def self.down
rename_column :planner_overrides, :marked_complete, :visible
change_column_default :planner_overrides, :visible, true
end
end

View File

@ -0,0 +1,29 @@
#
# Copyright (C) 2011 - 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 FixPlannerOverridesMarkedCompleteData < ActiveRecord::Migration[4.2]
tag :postdeploy
disable_ddl_transaction!
def self.up
DataFixup::FixPlannerOverridesMarkedCompleteData.send_later_if_production_enqueue_args(
:run, { priority: Delayed::LOWER_PRIORITY, max_attempts: 1 })
end
def self.down
end
end

View File

@ -0,0 +1,24 @@
#
# Copyright (C) 2011 - 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/>.
module DataFixup
module FixPlannerOverridesMarkedCompleteData
def self.run
PlannerOverride.update_all("marked_complete = NOT marked_complete")
end
end
end

View File

@ -45,10 +45,7 @@ module Plannable
def visible_in_planner_for?(user)
return true unless planner_enabled?
self.planner_overrides.where(user_id: user,
visible: false,
workflow_state: 'active'
).blank?
self.planner_overrides.where(user_id: user, marked_complete: true, workflow_state: 'active').blank?
end
def planner_override_for(user)

View File

@ -26,7 +26,7 @@ describe PlannerOverridesController do
@assignment2 = course_assignment
@planner_override = PlannerOverride.create!(plannable_id: @assignment.id,
plannable_type: "Assignment",
visible: true,
marked_complete: false,
user_id: @student.id)
end
@ -44,9 +44,9 @@ describe PlannerOverridesController do
get :index
assert_unauthorized
post :create, :plannable_type => "Assignment",
post :create, :plannable_type => "assignment",
:plannable_id => @assignment.id,
:visible => true
:marked_complete => false
assert_unauthorized
end
end
@ -167,16 +167,16 @@ describe PlannerOverridesController do
describe "PUT #update" do
it "returns http success" do
expect(@planner_override.visible).to be_truthy
put :update, id: @planner_override.id, visible: false
expect(@planner_override.marked_complete).to be_falsey
put :update, id: @planner_override.id, marked_complete: true
expect(response).to have_http_status(:success)
expect(@planner_override.reload.visible).to be_falsey
expect(@planner_override.reload.marked_complete).to be_truthy
end
end
describe "POST #create" do
it "returns http success" do
post :create, plannable_type: "Assignment", plannable_id: @assignment2.id, visible: false
post :create, plannable_type: "assignment", plannable_id: @assignment2.id, marked_complete: true
expect(response).to have_http_status(:created)
expect(PlannerOverride.where(user_id: @student.id).count).to be 2
end

View File

@ -20,17 +20,17 @@ module Factories
def planner_override_model(opts={})
user = opts[:user] || @user || user_model
plannable = opts[:plannable] || assignment_model
visibility = opts.has_key?(:visible) ? opts[:visible] : true
visibility = opts.key?(:marked_complete) ? opts[:marked_complete] : false
attrs = { user_id: user.id,
plannable_type: plannable.class.to_s,
plannable_id: plannable.id,
visible: visibility }
marked_complete: visibility }
@planner_override = PlannerOverride.create!(valid_planner_override_attributes.merge(attrs))
end
def valid_planner_override_attributes
{
:visible => true
:marked_complete => false
}
end
end

View File

@ -47,7 +47,7 @@ describe Api::V1::PlannerItem do
@assignment.save!
@teacher_override = planner_override_model(plannable: @assignment, user: @teacher)
@student_override = planner_override_model(plannable: @assignment, user: @student, visible: false)
@student_override = planner_override_model(plannable: @assignment, user: @student, marked_complete: true)
end
describe '.planner_item_json' do

View File

@ -0,0 +1,42 @@
#
# Copyright (C) 2011 - 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 'spec_helper'
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/data_fixup/fix_planner_overrides_marked_complete_data')
describe DataFixup::FixPlannerOverridesMarkedCompleteData do
subject do
DataFixup::FixPlannerOverridesMarkedCompleteData
end
it "should flip the value on 'marked_complete'" do
course_with_student
student1 = @student
course_with_student(course: @course)
student2 = @student
assignment_model(context: @course)
override1 = PlannerOverride.create!(plannable_id: @assignment.id, plannable_type: 'Assignment',
marked_complete: true, user_id: student1.id)
override2 = PlannerOverride.create!(plannable_id: @assignment.id, plannable_type: 'Assignment',
marked_complete: false, user_id: student2.id)
subject.run
expect(override1.reload.marked_complete).to be false
expect(override2.reload.marked_complete).to be true
end
end

View File

@ -26,11 +26,11 @@ describe PlannerOverride do
@student_planner_override = PlannerOverride.create!(user_id: @student.id,
plannable_id: @assignment.id,
plannable_type: "Assignment",
visible: false)
marked_complete: true)
@teacher_planner_override = PlannerOverride.create!(user_id: @teacher.id,
plannable_id: @assignment.id,
plannable_type: "Assignment",
visible: true)
marked_complete: false)
end