Skip to content

Commit

Permalink
Merge branch 'master' into enable-basic-csp
Browse files Browse the repository at this point in the history
  • Loading branch information
mishaschwartz authored Apr 13, 2021
2 parents cbf845b + b85bb63 commit 5066386
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- Fix bug where creating an annotation or switching results reset the selected file (#5200)
- Fix bug in Assignment#get_num_marked that caused it to double-count remark and original results (#5205)
- Enable content security policies (#5186)
- Fix bug where graders can't see the tests that they run (#5210)
- Fix bug where graders can't release results on the results page (#5210)

## [v1.11.5]
- Account for percentage deductions when calculating total marks after deleting a criterion (#5176)
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/Components/Result/result.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Result extends React.Component {
submission_id: props.submission_id,
result_id: props.result_id,
grouping_id: props.grouping_id,
can_release: false
};

this.leftPane = React.createRef();
Expand Down Expand Up @@ -616,6 +617,7 @@ class Result extends React.Component {
<SubmissionSelector
key='submission-selector'
role={this.props.role}
can_release={this.state.can_release}
result_id={this.state.result_id}
submission_id={this.state.submission_id}
assignment_id={this.state.assignment_id}
Expand All @@ -641,7 +643,6 @@ class Result extends React.Component {
<div id='left-pane'>
<LeftPane
ref={this.leftPane}
role={this.props.role}
loading={this.state.loading}
result_id={this.state.result_id}
submission_id={this.state.submission_id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class SubmissionSelector extends React.Component {
};

renderReleaseMarksButton() {
if (this.props.role !== 'Admin') return '';
if (!this.props.can_release) return '';

let buttonText, disabled;
if (this.props.released_to_students) {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def show
data[:can_run_tests] = false
end

data[:can_release] = allowance_to(:manage_assessments?, current_user)

# Submission files
file_data = submission.submission_files.order(:path, :filename).pluck_to_hash(:id, :filename, :path)
file_data.reject! { |f| Repository.get_class.internal_file_names.include? f[:filename] }
Expand Down
4 changes: 2 additions & 2 deletions app/models/grouping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,13 @@ def self.group_hash_list(hash_list)
end

def test_runs_instructors(submission)
filtered = filter_test_runs(filters: { 'users.type': 'Admin', 'test_runs.submission': submission })
filtered = filter_test_runs(filters: { 'users.type': %w[Admin Ta], 'test_runs.submission': submission })
plucked = Grouping.pluck_test_runs(filtered)
Grouping.group_hash_list(plucked)
end

def test_runs_instructors_released(submission)
filtered = filter_test_runs(filters: { 'users.type': 'Admin', 'test_runs.submission': submission })
filtered = filter_test_runs(filters: { 'users.type': %w[Admin Ta], 'test_runs.submission': submission })
latest_test_group_results = filtered.pluck_to_hash('test_groups.id as tgid',
'test_group_results.id as tgrid',
'test_group_results.created_at as date')
Expand Down
4 changes: 4 additions & 0 deletions app/policies/result_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def review?
)
end

def set_released_to_students?
check?(:review?) && check?(:manage_submissions?, user)
end

def manage?
user.admin?
end
Expand Down
17 changes: 17 additions & 0 deletions spec/policies/result_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@
end
end

describe_rule :set_released_to_students? do
succeed 'user is an admin' do
let(:user) { create(:admin) }
end
context 'user is a ta' do
succeed 'that can manage submissions' do
let(:user) { create :ta, manage_submissions: true }
end
failed 'that cannot manage submissions' do
let(:user) { create :ta, manage_submissions: false }
end
end
failed 'user is a student' do
let(:user) { create(:student) }
end
end

describe_rule :manage? do
succeed 'user is an admin' do
let(:user) { create(:admin) }
Expand Down

0 comments on commit 5066386

Please sign in to comment.