Skip to content

Commit

Permalink
Merge branch 'release/5.6.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Aug 9, 2022
2 parents d3a3e16 + 3171414 commit 439beb5
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ updates:
time: "13:00"
timezone: Europe/Brussels
open-pull-requests-limit: 99
commit-message:
prefix: ""
labels:
- "dependencies"
ignore:
Expand All @@ -21,6 +23,8 @@ updates:
time: "13:00"
timezone: Europe/Brussels
open-pull-requests-limit: 99
commit-message:
prefix: ""
labels:
- "dependencies"
ignore:
Expand All @@ -35,5 +39,7 @@ updates:
time: "13:00"
timezone: Europe/Brussels
open-pull-requests-limit: 99
commit-message:
prefix: ""
labels:
- "dependencies"
7 changes: 5 additions & 2 deletions app/assets/javascripts/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function initCourseNew() {
$(this)
.closest(".panel")
.find(".answer")
.html($(this).data("answer"));
.text($(this).data("answer"));
fetch(`/courses/new.js?copy_options[base_id]=${$(this).data("course_id")}`)
.then(req => req.text())
.then(resp => eval(resp));
Expand All @@ -296,7 +296,10 @@ function initCoursesListing(firstTab) {

function initCourseTabs(firstTab) {
document.querySelectorAll("#course-tabs li a").forEach(tab => {
tab.addEventListener("click", () => selectTab(tab));
tab.addEventListener("click", event => {
event.preventDefault(); // used to prevent popstate event from firing
selectTab(tab);
});
});

// If the url hash is a valid tab, use that, otherwise use the given tab
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function initExerciseShow(exerciseId, programmingLanguage, loggedIn, editorShown
editor.$blockScrolling = Infinity; // disable warning
editor.focus();
editor.on("focus", enableSubmitButton);
editor.commands.removeCommand("find"); // disable search box in ACE editor
// Make editor available globally
window.dodona.editor = editor;
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class SearchQuery {
this.queryParams.subscribe(k => this.paramChange(k));
this.queryParams.subscribeByKey("refresh", (k, o, n) => this.refresh(n));

window.onpopstate = e => e.state && this.setBaseUrl();
window.onpopstate = () => this.setBaseUrl();

this.setRefreshElement(refreshElement);
}
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def available

def show
flash.now[:alert] = I18n.t('activities.show.not_a_member') if @course && !current_user&.member_of?(@course)

# Double check if activity still exists within this course (And throw a 404 when it does not)
@course&.activities&.find_by!(id: @activity.id) if current_user&.course_admin?(@course)
# We still need to check access because an unauthenticated user should be able to see public activities
raise Pundit::NotAuthorizedError, 'Not allowed' unless @activity.accessible?(current_user, @course)

Expand Down
20 changes: 18 additions & 2 deletions app/mailers/error_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
class ErrorMailer < ApplicationMailer
helper :repository

def json_error(error, user: nil, name: nil, email: nil)
def set_fields(error, user, name, email)
@error = error
@user = user || User.find_by(email: email)

if @user
@name = @user.full_name
@email = @user.email
else
@name = name || ''
@email = email
end
end

def json_error(error, user: nil, name: nil, email: nil)
set_fields(error, user, name, email)

I18n.with_locale(@user&.lang) do
mail to: %("#{@name}" <#{@email}>),
Expand All @@ -23,4 +26,17 @@ def json_error(error, user: nil, name: nil, email: nil)
)
end
end

def git_error(error, user: nil, name: nil, email: nil)
set_fields(error, user, name, email)

I18n.with_locale(@user&.lang) do
mail to: %("#{@name}" <#{@email}>),
cc: Rails.application.config.dodona_email,
subject: I18n.t(
'error_mailer.git_error.subject',
repository: error.repository.name
)
end
end
end
9 changes: 8 additions & 1 deletion app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def process_activities_email_errors(kwargs = {})
process_activities
rescue AggregatedConfigErrors => e
ErrorMailer.json_error(e, **kwargs).deliver
rescue DodonaGitError => e
ErrorMailer.git_error(e, **kwargs).deliver
end

def process_activities
Expand Down Expand Up @@ -192,7 +194,12 @@ def process_activities
c['internals']['_info'] = 'These fields are used for internal bookkeeping in Dodona, please do not change them.'
act.config_file.write(JSON.pretty_generate(c))
end
commit 'stored tokens in new activities' unless new_activities.empty?

unless new_activities.empty?
status, err = commit 'stored tokens in new activities'
# handle errors when commit fails
raise DodonaGitError.new(self, err) unless status
end

raise AggregatedConfigErrors.new(self, errors) if errors.any?
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/transient/dodona_git_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DodonaGitError < StandardError
attr_reader :repository,
:errorstring

def initialize(repository, error)
super()
@repository = repository
@errorstring = error.to_s
end
end
15 changes: 15 additions & 0 deletions app/views/error_mailer/git_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="message">
<%= content_tag :p, t('.greeting', name: @name) %>
<%= content_tag :p, t(
'.error_message',
repository: @error.repository.name,
error: @error.errorstring
) %>

<%= content_tag :p, t('.hint') %>

<%= content_tag :p, t('.regards') %>
<p>Team Dodona</p>

<%= content_tag :p, t('.auto-generated') %>
</div>
11 changes: 11 additions & 0 deletions app/views/error_mailer/git_error.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= t '.greeting', name: @name %>
<%= t '.error_message',
repository: @error.repository.name,
error: @error.errorstring %>

<%= t '.hint' %>

<%= t '.regards' %>
Team Dodona

<%= t '.auto-generated' %>
74 changes: 74 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# exit when any command fails
set -e
# keep track of the last executed command
current_command=$BASH_COMMAND
last_command=$current_command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap '[ $? -eq 0 ] || echo "\"${last_command}\" command failed with exit code $?."' EXIT

if [ "$#" -ne 1 ]
then
>&2 echo "Expected exactly 1 argument"
>&2 echo "usage \`bin/release [version]\`"
>&2 echo "version should be of the format MAJOR.MINOR.PATCH"
>&2 echo "example \`bin/release 5.6.4\`"
exit 1
fi

# first and only argument is version
version=$1
# get major, minor and patch as an array
readarray -d . -t version_array< <(printf '%s' "$version")

if [ "${#version_array[@]}" -ne 3 ]
then
>&2 echo "expected version to contain major minor and patch"
>&2 echo "usage \`bin/release [version]\`"
>&2 echo "version should be of the format MAJOR.MINOR.PATCH"
>&2 echo "example \`bin/release 5.6.4\`"
exit 1
fi

# Make sure you have the latest commits
git checkout master
git pull
git checkout develop
git pull

# Start release
git flow release start "$version"
sed -i "s/MAJOR = [0-9]\+/MAJOR = ${version_array[0]}/g" config/initializers/00_version.rb
sed -i "s/MINOR = [0-9]\+/MINOR = ${version_array[1]}/g" config/initializers/00_version.rb
sed -i "s/PATCH = [0-9]\+/PATCH = ${version_array[2]}/g" config/initializers/00_version.rb
git commit -am "Bump version"

# Double check that all tests succeed
bundle install
yarn install
bin/rake css:build # Build css before testing
bin/rake javascript:build # Build javascript before testing
bundle exec rails test
bundle exec rails test:system
yarn test

# Finish release
git flow release finish "$version"

# Allow abort before push
echo -n "Next step will push, press A to abort, any key to continue"
read -r confirm
if [ "$confirm" == "A" ] || [ "$confirm" == "a" ]
then
exit
fi

# Push local changes
git push
git checkout master
git push
git push --tags

# Deploy
cap production deploy
2 changes: 1 addition & 1 deletion config/initializers/00_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Application
module Version
MAJOR = 5
MINOR = 6
PATCH = 6
PATCH = 7

STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
Expand Down
7 changes: 7 additions & 0 deletions config/locales/views/error_mailer/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ en:
other: 'Something went wrong during the processing of the exercise repository "%{repository}". You probably made a syntax error in the config file. These were the generated error messages:'
regards: "Kind regards,"
auto-generated: This message was generated automatically.
git_error:
subject: '[Dodona] Failed to push to "%{repository}"'
greeting: 'Dear %{name},'
error_message: 'While processing "%{repository}", Dodona was unable to push the edits to the processed exercises. The exact error was: %{error}.'
hint: 'Make sure to give the Dodona user push rights to your repository.'
regards: 'Kind regards,'
auto-generated: This message was generated automatically.
9 changes: 8 additions & 1 deletion config/locales/views/error_mailer/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ nl:
one: 'Bij het automatisch verwerken van de oefeningenrepository "%{repository}" liep iets fout. Vermoedelijk zit er een syntaxfout in het configuratiebestand. Onderstaande foutmelding werd gegenereerd:'
other: 'Bij het automatisch verwerken van de oefeningenrepository "%{repository}" liep iets fout. Vermoedelijk zit er een syntaxfout in het configuratiebestand. Onderstaande foutmeldingen werden gegenereerd:'
regards: 'Vriendelijke groeten,'
auto-generated: ps. Dit bericht werd automatisch gegenereerd.
auto-generated: PS Dit bericht werd automatisch gegenereerd.
git_error:
subject: '[Dodona] Pushen naar "%{repository}" mislukt'
greeting: 'Beste %{name},'
error_message: 'Tijdens het verwerken van "%{repository}" kon Dodona de aanpassingen aan de verwerkte oefeningen niet pushen. De exacte error was: %{error}.'
hint: 'Zorg er zeker voor dat de Dodona-gebruiker pushrechten heeft op je repository.'
regards: 'Vriendelijke groeten,'
auto-generated: PS Dit bericht werd automatisch gegenereerd.
2 changes: 1 addition & 1 deletion config/locales/views/repositories/en.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
en:
repositories:
form:
remote_help: "The SSH clone URL of the judge repository. Dodona needs access rights to the repository to be able to clone it."
remote_help: "The SSH clone URL of the exercise repository. Dodona needs read and write permissions to use the repository."
judge_help: "This judge will be used when the exercise doesn't specify one."
remote_cant_be_edited_html: The clone URL can't be edited after the repository was created. Contact <a href="mailto:[email protected]">[email protected]</a> if it needs to be changed.
index:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/views/repositories/nl.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nl:
repositories:
form:
remote_help: "De SSH 'clone url' van de repository waar de oefeningen te vinden zijn. Dodona heeft de juiste rechten nodig om de repository te kunnen clonen."
remote_help: "De SSH 'clone url' van de repository waar de oefeningen te vinden zijn. Dodona heeft lees- en schrijfrechten nodig om de repository te gebruiken."
judge_help: "Deze judge zal gebruikt worden als de oefening zelf geen specifieert."
remote_cant_be_edited_html: De clone URL kan niet aangepast worden nadat de repository werd aangemaakt. Contacteer <a href="mailto:[email protected]">[email protected]</a> als het toch aangepast moet worden.
index:
Expand Down
31 changes: 31 additions & 0 deletions test/models/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,35 @@ def teardown
@echo.reload
assert_equal 'not_valid', @echo.status
end

test 'should catch error when commit fails' do
# make sure commit fails
@repository.stubs(:commit).returns([false, ['commit fail']])

# add an activity to make sure that commit will be executed inside @repository.process_activities
new_dir = 'echo2'
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')

# should raise DodonaGitError because commit fails
@repository.reset
assert_raises(DodonaGitError) do
@repository.process_activities
end
end

test 'should send a mail when commit fails' do
# make sure commit fails
@repository.stubs(:commit).returns([false, ['commit fail']])

# add an activity to make sure that commit will be executed inside @repository.process_activities
new_dir = 'echo2'
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')

@repository.reset
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
@repository.process_activities_email_errors
end
end
end

0 comments on commit 439beb5

Please sign in to comment.