-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathability.rb
More file actions
289 lines (232 loc) · 7.34 KB
/
ability.rb
File metadata and controls
289 lines (232 loc) · 7.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# frozen_string_literal: true
# CanCan ability definitions.
#
# See: https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
class Ability
include CanCan::Ability
def initialize(user)
if user.administrator?
can :manage, :all
can :create, Course
can :create, :custom_course
cannot :refresh, Course
can :refresh, Course, &:custom?
can :view, :participants_list
can :view, :unverified_organizations
can :verify, :unverified_organizations
can :disable, Organization
can :rerun, Submission
can :access, :pghero
can :read_vm_log, Submission
can :read, :instance_state
else
cannot :read, :instance_state
can :read, :all
cannot :access, :pghero
cannot :read, User
cannot :read, :code_reviews
cannot :read, :course_information
# This check is bit heavy with sql queries if used in views to iterate on lists
can :read, User do |u|
u.readable_by?(user)
end
can :create, User if SiteSetting.value(:enable_signup)
cannot :destroy, User
can :destroy, User do |u|
u == user
end
cannot :update, User
can :update, User do |u|
u == user
end
cannot :read, Course
can :read, Course do |c|
user.administrator? ||
user.teacher?(c.organization) ||
user.assistant?(c) ||
(
c.initial_refresh_ready? &&
(!c.disabled? && !c.hidden? &&
(
c.hidden_if_registered_after.nil? ||
c.hidden_if_registered_after > Time.now ||
(!user.guest? && c.hidden_if_registered_after > user.created_at)
) || user.student_in_course?(c))
)
end
can :create, Course do |c|
can? :teach, c.organization
end
can :edit, Course do |c|
can? :teach, c.organization
end
can :refresh, Course do |c|
(c.taught_by?(user) || c.assistant?(user)) &&
c.custom? # user can only refresh his/her custom course.
end
cannot :read, Exercise
can :read, Exercise do |ex|
ex.visible_to?(user) || can?(:teach, ex.course)
end
can :download, Exercise do |ex|
ex.downloadable_by?(user)
end
can :see_points, Exercise do |ex|
(!ex.hide_submission_results? && !ex.course.hide_submission_results?) || can?(:teach, ex.course)
end
cannot :read, Submission
can :read, Submission do |sub|
sub.readable_by?(user) || can?(:teach, sub.course)
end
can :create, Submission do |sub|
sub.exercise.submittable_by?(user)
end
can :update, Submission do |sub|
can? :teach, sub.course
end
can :rerun, Submission do |sub|
can? :teach, sub.course.organization
end
can :download, Submission do |sub|
!sub.course.hide_submission_results? && !sub.exercise.hide_submission_results? && (can?(:read, sub) || sub.paste_visible_for?(user))
end
can :read_results, Submission do |sub|
(!sub.course.hide_submission_results? && !sub.exercise.hide_submission_results?) || (can? :teach, sub.course)
end
cannot :manage_feedback_questions, Course
can :manage_feedback_questions, Course do |c|
can? :teach, c
end
cannot :read, FeedbackAnswer
can :read_feedback_answers, Course do |c|
can? :teach, c
end
can :read_feedback_answers, Exercise do |e|
can? :teach, e.course
end
cannot :read, FeedbackQuestion
can :read_feedback_questions, Course do |c|
can? :teach, c
end
can :read_feedback_questions, Exercise do |e|
can? :teach, e.course
end
can :reply_feedback_answer, FeedbackAnswer do |ans|
can? :teach, ans.course
end
can :create, FeedbackAnswer do |ans|
ans.submission.user_id == user.id
end
cannot :read, Solution
can :read, Solution do |sol|
# course = sol.exercise.course
sol.visible_to?(user)
end
cannot :manage, Review
can :manage, Review do |r|
r.manageable_by?(user) || can?(:teach, r.submission.course)
end
can :read, Review do |r|
r.readable_by?(user) || can?(:teach, r.submission.course)
end
can :create_review, Course do |c|
can? :teach, c
end
cannot :mark_as_read, Review
can :mark_as_read, Review do |r|
r.submission.user_id == user.id
end
cannot :mark_as_unread, Review
can :mark_as_unread, Review do |r|
r.submission.user_id == user.id
end
can :view_code_reviews, Course do |c|
c.submissions.exists?(user_id: user.id, reviewed: true) || can?(:teach, c)
end
can :list_code_reviews, Course do |c|
can? :teach, c
end
cannot :create, AwardedPoint
can :create, AwardedPoint do |ap|
can? :teach, ap.course
end
cannot :read, Certificate
can :read, Certificate do |c|
c.user == user
end
can :create, Certificate do |c|
c.course.certificate_downloadable_for? user
end
cannot :reply, FeedbackAnswer
can :request, :organization
cannot :request, :organization if user.guest?
can :view_statistics, Organization do |o|
can? :teach, o
end
can :list_user_emails, Course do |c|
can? :teach, c
end
can :send_mail_to_participants, Course do |c|
can? :teach, c
end
can :manage_deadlines, Course do |c|
can? :teach, c
end
can :manage_unlocks, Course do |c|
can? :teach, c
end
can :manage_exercises, Course do |c|
can? :teach, c.organization
end
can :edit_course_paramaters, Course do |c|
can? :teach, c.organization
end
cannot :read, CourseTemplate
can :prepare_course, CourseTemplate
can :clone, CourseTemplate, &:clonable?
can :request, :organization
cannot :request, :organization if user.guest?
cannot :manage_teachers, Organization
can :manage_teachers, Organization do |o|
o.teacher?(user)
end
can :remove_teacher, Organization do |o|
can? :teach, o
end
can :modify_assistants, Course do |c|
can? :teach, c
end
can :edit, Organization do |o|
can? :teach, o
end
can :toggle_visibility, Organization do |o|
can? :teach, o
end
can :toggle_submission_result_visibility, Course do |c|
can? :teach, c
end
can :see_points, Course do |c|
!c.hide_submission_results? || (can? :teach, c)
end
cannot :teach, Organization
can :teach, Organization do |o|
o.teacher?(user) && !o.disabled?
end
cannot :teach, Course
can :teach, Course do |c|
can?(:teach, c.organization) || c.assistant?(user)
# c.organization.teacher?(user) || c.assistant?(user)
end
cannot :email, CourseNotification
can :view_external_scoreboard_url, Course do |c|
can?(:teach, c) || User.course_students(c).include?(user)
end
can :view_participant_information, User do |u|
!user.guest? && u.readable_by?(user)
end
can :view_participant_list, Organization do |o|
can?(:teach, o)
end
end
end
end