forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_gradebook_column.rb
More file actions
58 lines (50 loc) · 1.67 KB
/
Copy pathcustom_gradebook_column.rb
File metadata and controls
58 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# Copyright (C) 2013 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 CustomGradebookColumn < ActiveRecord::Base
include Workflow
acts_as_list :scope => :course_id
belongs_to :course
has_many :custom_gradebook_column_data
validates :title, presence: true
validates :teacher_notes, inclusion: { in: [true, false], message: "teacher_notes must be true or false" }
validates :title, length: { maximum: maximum_string_length },
:allow_nil => true
workflow do
state :active
state :hidden
state :deleted
end
scope :active, -> { where(workflow_state: "active") }
scope :not_deleted, -> { where("workflow_state != 'deleted'") }
set_policy do
given { |user, session|
course.grants_any_right?(user, session, :view_all_grades, :manage_grades)
}
can :read, :manage
end
def hidden=(hidden)
self.workflow_state = Canvas::Plugin::value_to_boolean(hidden) ?
"hidden" :
"active"
end
alias_method :destroy_permanently!, :destroy
def destroy
self.workflow_state = "deleted"
save!
end
end