Grading Period Grade join table - MGP
fixes CNVS-16454 test plan: * test in the console - `GradingPeriodGrade.all` should return `[]` (no error) - `Enrollment.find(1).grading_period_grades` should return `[]` (no error) - make a GradingPeriod: `g = GradingPeriod.create(weight: 100, start_date: Time.now, end_date: 1.month.from_now)` `g.save!` - `g.grading_period_grades` should return `[]` (no error) Change-Id: I7183d715dbfac3fcd89ab7e453237ad4ce6c650d Reviewed-on: https://gerrit.instructure.com/45312 Product-Review: Cameron Sutter <csutter@instructure.com> Reviewed-by: Nick Cloward <ncloward@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com>
This commit is contained in:
parent
ffb111603c
commit
f2e2e76d5b
|
@ -40,6 +40,7 @@ class Enrollment < ActiveRecord::Base
|
|||
has_many :role_overrides, :as => :context
|
||||
has_many :pseudonyms, :primary_key => :user_id, :foreign_key => :user_id
|
||||
has_many :course_account_associations, :foreign_key => 'course_id', :primary_key => 'course_id'
|
||||
has_many :grading_period_grades
|
||||
|
||||
EXPORTABLE_ATTRIBUTES = [
|
||||
:id, :user_id, :course_id, :type, :uuid, :workflow_state, :created_at, :updated_at, :associated_user_id, :sis_source_id, :sis_batch_id, :start_at, :end_at,
|
||||
|
|
|
@ -3,13 +3,14 @@ class GradingPeriod < ActiveRecord::Base
|
|||
include Workflow
|
||||
|
||||
belongs_to :grading_period_group, :inverse_of => :grading_periods
|
||||
has_many :grading_period_grades
|
||||
|
||||
validates_presence_of :weight, :start_date, :end_date
|
||||
validate :validate_dates
|
||||
|
||||
set_policy do
|
||||
[:read, :update, :create, :delete].each do |permission|
|
||||
given { |user, http_session| grading_period_group.grants_right?(user, http_session, permission) }
|
||||
given { |user| grading_period_group.grants_right?(user, permission) }
|
||||
can permission
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class GradingPeriodGrade < ActiveRecord::Base
|
||||
#TODO: when we create a controller for this, remove attr_accessible and use strong params instead
|
||||
attr_accessible :enrollment_id, :grading_period_id, :current_grade, :final_grade
|
||||
belongs_to :enrollment
|
||||
belongs_to :grading_period
|
||||
|
||||
validates :enrollment_id, :grading_period_id, presence: true
|
||||
|
||||
set_policy do
|
||||
[:read, :update, :create, :delete].each do |permission|
|
||||
given { |user| grading_period.grants_right?(user, permission) }
|
||||
can permission
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,15 +5,15 @@ class GradingPeriodGroup < ActiveRecord::Base
|
|||
|
||||
# Naive permissions, need to be fleshed out
|
||||
set_policy do
|
||||
given { |user, http_session| (course || account).grants_right?(user, http_session, :read) }
|
||||
given { |user| (course || account).grants_right?(user, :read) }
|
||||
can :read
|
||||
|
||||
given do |user, http_session|
|
||||
given do |user|
|
||||
return false unless (course || account).root_account.feature_enabled?(:multiple_grading_periods)
|
||||
if course
|
||||
course.grants_right?(user, http_session, :update)
|
||||
course.grants_right?(user, :update)
|
||||
elsif account
|
||||
account.grants_right?(user, http_session, :manage_courses)
|
||||
account.grants_right?(user, :manage_courses)
|
||||
end
|
||||
end
|
||||
can :read and can :update and can :create and can :delete
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
class CreateGradingPeriodGradesJoinTable < ActiveRecord::Migration
|
||||
tag :predeploy
|
||||
|
||||
def change
|
||||
create_table :grading_period_grades do |t|
|
||||
t.integer :enrollment_id, :limit => 8
|
||||
t.integer :grading_period_id, :limit => 8
|
||||
t.float :current_grade
|
||||
t.float :final_grade
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_foreign_key :grading_period_grades, :enrollments
|
||||
add_foreign_key :grading_period_grades, :grading_periods
|
||||
add_index :grading_period_grades, :enrollment_id
|
||||
add_index :grading_period_grades, :grading_period_id
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue