diff --git a/Vagrantfile b/Vagrantfile index e221a6ce..5ec9182e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,7 +4,7 @@ Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" config.vm.provider "virtualbox" do |v| - v.memory = 1024 + v.memory = 8192 end config.vm.network "private_network", ip: "192.168.59.104" # config.vm.synced_folder "../data", "/vagrant_data" diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index ccf8ce15..533a8a9b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,6 +14,7 @@ // //= require ace/ace //= require chosen.jquery.min +//= require jquery-ui.min //= require d3 //= require jquery.turbolinks //= require jquery_ujs diff --git a/app/assets/javascripts/editor/participantsupport.js.erb b/app/assets/javascripts/editor/participantsupport.js.erb index 91e9f0d1..63787f4a 100644 --- a/app/assets/javascripts/editor/participantsupport.js.erb +++ b/app/assets/javascripts/editor/participantsupport.js.erb @@ -59,8 +59,6 @@ CodeOceanEditorCodePilot = { } }; -//Request for comments does currently not work on staging platform (no relative root_url used here). -//To fix this rely on ruby routes CodeOceanEditorRequestForComments = { requestComments: function () { var user_id = $('#editor').data('user-id'); @@ -83,6 +81,8 @@ CodeOceanEditorRequestForComments = { }).done(function () { this.hideSpinner(); $.flash.success({text: $('#askForCommentsButton').data('message-success')}); + // trigger a run + this.runSubmission.call(this, submission); }.bind(this)).error(this.ajaxError.bind(this)); }; diff --git a/app/assets/javascripts/editor/submissions.js.erb b/app/assets/javascripts/editor/submissions.js.erb index 20d8cd10..21250f7e 100644 --- a/app/assets/javascripts/editor/submissions.js.erb +++ b/app/assets/javascripts/editor/submissions.js.erb @@ -142,19 +142,21 @@ CodeOceanEditorSubmissions = { * Execution-Logic */ runCode: function(event) { - event.preventDefault(); - if ($('#run').is(':visible')) { - this.createSubmission('#run', null, function(response) { - //Run part starts here - $('#stop').data('url', response.stop_url); - this.running = true; - this.showSpinner($('#run')); - $('#score_div').addClass('hidden'); - this.toggleButtonStates(); - var url = response.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor - this.initializeSocketForRunning(url); - }.bind(this)); - } + event.preventDefault(); + if ($('#run').is(':visible')) { + this.createSubmission('#run', null, this.runSubmission.bind(this)); + } + }, + + runSubmission: function (submission) { + //Run part starts here + $('#stop').data('url', submission.stop_url); + this.running = true; + this.showSpinner($('#run')); + $('#score_div').addClass('hidden'); + this.toggleButtonStates(); + var url = submission.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor + this.initializeSocketForRunning(url); }, saveCode: function(event) { diff --git a/app/assets/stylesheets/exercises.css.scss b/app/assets/stylesheets/exercises.css.scss index eb1b5300..73c0b26e 100644 --- a/app/assets/stylesheets/exercises.css.scss +++ b/app/assets/stylesheets/exercises.css.scss @@ -62,7 +62,9 @@ a.file-heading { fill: #ffd897; } - +.container > form > .actions { + margin-bottom: 200px; +} .d3-tip { line-height: 1; diff --git a/app/assets/stylesheets/request-for-comments.css.scss b/app/assets/stylesheets/request-for-comments.css.scss index 6448e6e7..2cad6446 100644 --- a/app/assets/stylesheets/request-for-comments.css.scss +++ b/app/assets/stylesheets/request-for-comments.css.scss @@ -1,7 +1,98 @@ -#commentitor { - margin-top: 2rem; - height: 600px; - background-color:#f9f9f9 +.rfc { + + h5 { + color: #008CBA; + } + + .text { + font-size: larger; + } + + .text.collapsed { + max-height: 50px; + overflow-y: hidden; + } + + .collapse-button { + position: relative; + float: right; + margin-top: 5px; + margin-right: 5px; + cursor: pointer; + } + + .description { + + .text { + padding: 5px; + background-color: #FAFAFA; + border: 1px solid #CCCCCC; + } + + } + + .question { + + .text { + font-weight: bold; + } + + } + + .testruns { + + .text { + padding: 5px; + background-color: #FAFAFA; + border: 1px solid #CCCCCC; + } + + pre { + background-color: inherit; + border: none; + } + } + +} + +.testrun-assess-results { + + display: flex; + + .result { + margin-right: 10px; + width: 10px; + height: 10px; + } + + .passed { + border-radius: 50%; + background-color: #8efa00; + -webkit-box-shadow: 0 0 11px 1px rgba(44,222,0,1); + -moz-box-shadow: 0 0 11px 1px rgba(44,222,0,1); + box-shadow: 0 0 11px 1px rgba(44,222,0,1); + } + + .unknown { + border-radius: 50%; + background-color: #ffca00; + -webkit-box-shadow: 0 0 11px 1px rgb(255, 202, 0); + -moz-box-shadow: 0 0 11px 1px rgb(255, 202, 0); + box-shadow: 0 0 11px 1px rgb(255, 202, 0); + } + + .failed { + border-radius: 50%; + background-color: #ff2600; + -webkit-box-shadow: 0 0 11px 1px rgba(222,0,0,1); + -moz-box-shadow: 0 0 11px 1px rgba(222,0,0,1); + box-shadow: 0 0 11px 1px rgba(222,0,0,1); + } + +} + +#mark-as-solved-button { + margin-top: 20px; } #thank-you-container { @@ -11,6 +102,10 @@ border: solid lightgrey 1px; background-color: rgba(20, 180, 20, 0.2); border-radius: 4px; + + button { + margin-right: 10px; + } } #thank-you-note { @@ -18,49 +113,142 @@ height: 200px; } +#commentitor { + margin-bottom: 2rem; + height: 600px; + background-color:#f9f9f9 +} + .ace_tooltip { display: none !important; } -p.comment { - width: 400px; +.modal-content { + min-height: 512px; + min-width: 360px; + max-height: 90vh; + display: flex; + flex-direction: column; + + .modal-body { + flex-grow: 1; + display: flex; + flex-direction: column; + + #otherComments { + flex-grow: 1; + display: flex; + flex-direction: column; + + .container { + flex-grow: 1; + } + } + } } -.popover-header { +.comment { width: 100%; - overflow: hidden; - padding-bottom: 10px; - margin: auto; + min-width: 200px; + + .comment-header { + width: 100%; + overflow: hidden; + padding-bottom: 10px; + margin: auto; + + .comment-username { + font-weight: bold; + width: 60%; + float: left; + } + + .comment-date { + text-align: right; + color: #008cba; + margin-left: 60%; + font-size: x-small; + } + + .comment-updated { + text-align: right; + margin-left: 60%; + font-size: x-small; + } + } + + .comment-content { + word-wrap: break-word; + margin-bottom: 10px; + } + + .comment-editor { + display: none; + width: 100%; + height: auto; + background-color: inherit; + } + + .comment-actions { + display: none; + } } -.popover-username { - font-weight: bold; - width: 60%; - float: left; -} - -.popover-date { - text-align: right; - color: #008cba; - margin-left: 60%; - font-size: x-small; -} - -.popover-updated { - text-align: right; - margin-left: 60%; - font-size: x-small; -} - -.popover-comment { - word-wrap: break-word; - margin-bottom: 10px; -} - -.popover-divider { +.comment-divider { width: 100%; height: 1px; background-color: #008cba; overflow: hidden; + margin-top: 10px; margin-bottom: 10px; } + +#otherComments { + h5 { + margin-top: 0; + } + + .container { + width: 100%; + overflow-y: auto; + border: 1px solid #cccccc; + padding: 15px; + + .comment-removed { + margin-top: 20px; + margin-bottom: 20px; + font-style: italic; + } + + .comment-actions { + display: flex; + + button { + margin-right: 5px; + } + } + } +} + +input#subscribe { + margin-top: 5px; + margin-right: 5px; +} + +#myComment { + margin-top: 20px; + margin-bottom: 10px; + + textarea { + resize: none; + } + + button { + margin-top: 10px; + } +} + +.popover-footer { + color: #008cba; + margin-top: 10px; +} diff --git a/app/assets/stylesheets/statistics.css.scss b/app/assets/stylesheets/statistics.css.scss index f656cd9a..a5ea4430 100644 --- a/app/assets/stylesheets/statistics.css.scss +++ b/app/assets/stylesheets/statistics.css.scss @@ -42,6 +42,14 @@ div.positive-result { box-shadow: 0px 0px 11px 1px rgba(44,222,0,1); } +div.unknown-result { + border-radius: 50%; + background-color: #ffca00; + -webkit-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); + -moz-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); + box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); +} + div.negative-result { border-radius: 50%; background-color: #ff2600; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dfc25ca9..c172d462 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized def current_user + ::NewRelic::Agent.add_custom_attributes({ external_user_id: session[:external_user_id], session_user_id: session[:user_id] }) @current_user ||= ExternalUser.find_by(id: session[:external_user_id]) || login_from_session || login_from_other_sources end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 01dcd9d5..d292804e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,5 @@ class CommentsController < ApplicationController - before_action :set_comment, only: [:show, :edit, :update, :destroy_by_id] + before_action :set_comment, only: [:show, :edit, :update, :destroy] # to disable authorization check: comment the line below back in # skip_after_action :verify_authorized @@ -21,6 +21,7 @@ class CommentsController < ApplicationController comment.username = comment.user.displayname comment.date = comment.created_at.strftime('%d.%m.%Y %k:%M') comment.updated = (comment.created_at != comment.updated_at) + comment.editable = comment.user == current_user } else @comments = [] @@ -50,12 +51,14 @@ class CommentsController < ApplicationController def create @comment = Comment.new(comment_params_without_request_id) - if comment_params[:request_id] - UserMailer.got_new_comment(@comment, RequestForComment.find(comment_params[:request_id]), current_user).deliver_now - end - respond_to do |format| if @comment.save + if comment_params[:request_id] + request_for_comment = RequestForComment.find(comment_params[:request_id]) + send_mail_to_author @comment, request_for_comment + send_mail_to_subscribers @comment, request_for_comment + end + format.html { redirect_to @comment, notice: 'Comment was successfully created.' } format.json { render :show, status: :created, location: @comment } else @@ -83,7 +86,8 @@ class CommentsController < ApplicationController # DELETE /comments/1 # DELETE /comments/1.json - def destroy_by_id + def destroy + authorize! @comment.destroy respond_to do |format| format.html { head :no_content, notice: 'Comment was successfully destroyed.' } @@ -91,30 +95,45 @@ class CommentsController < ApplicationController end end - def destroy - @comments = Comment.where(file_id: params[:file_id], row: params[:row], user: current_user) - @comments.each { |comment| authorize comment; comment.destroy } - respond_to do |format| - #format.html { redirect_to comments_url, notice: 'Comments were successfully destroyed.' } - format.html { head :no_content, notice: 'Comments were successfully destroyed.' } - format.json { head :no_content } - end - end - private - # Use callbacks to share common setup or constraints between actions. - def set_comment - @comment = Comment.find(params[:id]) - end + + # Use callbacks to share common setup or constraints between actions. + def set_comment + @comment = Comment.find(params[:id]) + end def comment_params_without_request_id comment_params.except :request_id end - # Never trust parameters from the scary internet, only allow the white list through. - def comment_params - #params.require(:comment).permit(:user_id, :file_id, :row, :column, :text) - # fuer production mode, damit böse menschen keine falsche user_id uebergeben: - params.require(:comment).permit(:file_id, :row, :column, :text, :request_id).merge(user_id: current_user.id, user_type: current_user.class.name) + # Never trust parameters from the scary internet, only allow the white list through. + def comment_params + #params.require(:comment).permit(:user_id, :file_id, :row, :column, :text) + # fuer production mode, damit böse menschen keine falsche user_id uebergeben: + params.require(:comment).permit(:file_id, :row, :column, :text, :request_id).merge(user_id: current_user.id, user_type: current_user.class.name) + end + + def send_mail_to_author(comment, request_for_comment) + if current_user != request_for_comment.user + UserMailer.got_new_comment(comment, request_for_comment, current_user).deliver_now end + end + + def send_mail_to_subscribers(comment, request_for_comment) + request_for_comment.commenters.each do |commenter| + already_sent_mail = false + subscriptions = Subscription.where( + :request_for_comment_id => request_for_comment.id, + :user_id => commenter.id, :user_type => commenter.class.name, + :deleted => false) + subscriptions.each do |subscription| + if (subscription.subscription_type == 'author' and current_user == request_for_comment.user) or subscription.subscription_type == 'all' + unless subscription.user == current_user or already_sent_mail + UserMailer.got_new_comment_for_subscription(comment, subscription, current_user).deliver_now + already_sent_mail = true + end + end + end + end + end end diff --git a/app/controllers/concerns/lti.rb b/app/controllers/concerns/lti.rb index 7483327d..4ba93615 100644 --- a/app/controllers/concerns/lti.rb +++ b/app/controllers/concerns/lti.rb @@ -42,12 +42,12 @@ module Lti private :external_user_email def external_user_name(provider) + # save person_name_full if supplied. this is the display_name, if it is set. + # else only save the firstname, we don't want lastnames (family names) if provider.lis_person_name_full provider.lis_person_name_full - elsif provider.lis_person_name_given && provider.lis_person_name_family - "#{provider.lis_person_name_given} #{provider.lis_person_name_family}" else - provider.lis_person_name_given || provider.lis_person_name_family + provider.lis_person_name_given end end private :external_user_name @@ -104,7 +104,7 @@ module Lti private :return_to_consumer def send_score(exercise_id, score, user_id) - ::NewRelic::Agent.add_custom_parameters({ score: score, session: session }) + ::NewRelic::Agent.add_custom_attributes({ score: score, session: session }) fail(Error, "Score #{score} must be between 0 and #{MAXIMUM_SCORE}!") unless (0..MAXIMUM_SCORE).include?(score) if session[:consumer_id] diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index 9c577aca..35de4ba5 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -8,7 +8,7 @@ module SubmissionScoring output = execute_test_file(file, submission) assessment = assessor.assess(output) passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score] > 0)) - testrun_output = passed ? nil : output[:stderr] + testrun_output = passed ? nil : 'message: ' + output[:message].to_s + "\n stdout: " + output[:stdout].to_s + "\n stderr: " + output[:stderr].to_s if !testrun_output.blank? submission.exercise.execution_environment.error_templates.each do |template| pattern = Regexp.new(template.signature).freeze @@ -17,7 +17,7 @@ module SubmissionScoring end end end - Testrun.new(submission: submission, file: file, passed: passed, output: testrun_output).save + Testrun.new(submission: submission, cause: 'assess', file: file, passed: passed, output: testrun_output).save output.merge!(assessment) output.merge!(filename: file.name_with_extension, message: feedback_message(file, output[:score]), weight: file.weight) end diff --git a/app/controllers/exercise_collections_controller.rb b/app/controllers/exercise_collections_controller.rb new file mode 100644 index 00000000..4861a062 --- /dev/null +++ b/app/controllers/exercise_collections_controller.rb @@ -0,0 +1,51 @@ +class ExerciseCollectionsController < ApplicationController + include CommonBehavior + + before_action :set_exercise_collection, only: [:show, :edit, :update, :destroy] + + def index + @exercise_collections = ExerciseCollection.all.paginate(:page => params[:page]) + authorize! + end + + def show + end + + def new + @exercise_collection = ExerciseCollection.new + authorize! + end + + def create + @exercise_collection = ExerciseCollection.new(exercise_collection_params) + authorize! + create_and_respond(object: @exercise_collection) + end + + def destroy + authorize! + destroy_and_respond(object: @exercise_collection) + end + + def edit + end + + def update + update_and_respond(object: @exercise_collection, params: exercise_collection_params) + end + + private + + def set_exercise_collection + @exercise_collection = ExerciseCollection.find(params[:id]) + authorize! + end + + def authorize! + authorize(@exercise_collection || @exercise_collections) + end + + def exercise_collection_params + params[:exercise_collection].permit(:name, :exercise_ids => []) + end +end diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 337cb9d4..141b47ee 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -20,7 +20,7 @@ class ExercisesController < ApplicationController end private :authorize! - def max_intervention_count + def max_intervention_count_per_day 3 end @@ -166,7 +166,7 @@ class ExercisesController < ApplicationController def implement redirect_to(@exercise, alert: t('exercises.implement.no_files')) unless @exercise.files.visible.exists? user_solved_exercise = @exercise.has_user_solved(current_user) - user_got_enough_interventions = UserExerciseIntervention.where(user: current_user).where("created_at >= ?", Time.zone.now.beginning_of_day).count >= max_intervention_count + user_got_enough_interventions = UserExerciseIntervention.where(user: current_user).where("created_at >= ?", Time.zone.now.beginning_of_day).count >= max_intervention_count_per_day is_java_course = @course_token && @course_token.eql?(java_course_token) user_intervention_group = UserGroupSeparator.getInterventionGroup(current_user) @@ -203,7 +203,7 @@ class ExercisesController < ApplicationController if match = lti_json.match(/^.*courses\/([a-z0-9\-]+)\/sections/) match.captures.first else - java_course_token + "" end else "" @@ -344,7 +344,7 @@ class ExercisesController < ApplicationController end def transmit_lti_score - ::NewRelic::Agent.add_custom_parameters({ submission: @submission.id, normalized_score: @submission.normalized_score }) + ::NewRelic::Agent.add_custom_attributes({ submission: @submission.id, normalized_score: @submission.normalized_score }) response = send_score(@submission.exercise_id, @submission.normalized_score, @submission.user_id) if response[:status] == 'success' diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index fca5c99b..4fd19a92 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -1,4 +1,5 @@ class RequestForCommentsController < ApplicationController + include SubmissionScoring before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy, :mark_as_solved, :set_thank_you_note] skip_after_action :verify_authorized @@ -22,7 +23,7 @@ class RequestForCommentsController < ApplicationController request_for_comments.submission_id, request_for_comments.row_number') # ugly, but rails wants it this way .select('request_for_comments.*, max(comments.updated_at) as last_comment') .search(params[:q]) - @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page]) + @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page], total_entries: @search.result.length) authorize! end @@ -68,11 +69,8 @@ class RequestForCommentsController < ApplicationController def set_thank_you_note authorize! @request_for_comment.thank_you_note = params[:note] - commenters = [] - @request_for_comment.comments.distinct.to_a.each {|comment| - commenters.append comment.user - } - commenters = commenters.uniq {|user| user.id} + + commenters = @request_for_comment.commenters commenters.each {|commenter| UserMailer.send_thank_you_note(@request_for_comment, commenter).deliver_now} respond_to do |format| @@ -110,6 +108,10 @@ class RequestForCommentsController < ApplicationController @request_for_comment = RequestForComment.new(request_for_comment_params) respond_to do |format| if @request_for_comment.save + # create thread here and execute tests. A run is triggered from the frontend and does not need to be handled here. + Thread.new do + score_submission(@request_for_comment.submission) + end format.json { render :show, status: :created, location: @request_for_comment } else format.html { render :new } diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 5a256b17..8e7a8e39 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -13,8 +13,12 @@ class SubmissionsController < ApplicationController before_action :set_mime_type, only: [:download_file, :render_file] skip_before_action :verify_authenticity_token, only: [:download_file, :render_file] - def max_message_buffer_size - 500 + def max_run_output_buffer_size + if(@submission.cause == 'requestComments') + 5000 + else + 500 + end end def authorize! @@ -210,7 +214,7 @@ class SubmissionsController < ApplicationController end def handle_message(message, tubesock, container) - @message_buffer ||= "" + @run_output ||= "" # Handle special commands first if (/^#exit/.match(message)) # Just call exit_container on the docker_client. @@ -219,19 +223,19 @@ class SubmissionsController < ApplicationController # kill_socket is called in the "on close handler" of the websocket to the container @docker_client.exit_container(container) elsif /^#timeout/.match(message) - @message_buffer = 'timeout: ' + @message_buffer # add information that this run timed out to the buffer + @run_output = 'timeout: ' + @run_output # add information that this run timed out to the buffer else # Filter out information about run_command, test_command, user or working directory run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename]) test_command = @submission.execution_environment.test_command % command_substitutions(params[:filename]) if !(/root|workspace|#{run_command}|#{test_command}/.match(message)) - @message_buffer += message if @message_buffer.size <= max_message_buffer_size parse_message(message, 'stdout', tubesock) end end end def parse_message(message, output_stream, socket, recursive = true) + parsed = ''; begin parsed = JSON.parse(message) if(parsed.class == Hash && parsed.key?('cmd')) @@ -270,13 +274,16 @@ class SubmissionsController < ApplicationController socket.send_data JSON.dump(parsed) Rails.logger.info('parse_message sent: ' + JSON.dump(parsed)) end + ensure + # save the data that was send to the run_output if there is enough space left. this will be persisted as a testrun with cause "run" + @run_output += JSON.dump(parsed) if @run_output.size <= max_run_output_buffer_size end end def save_run_output - if !@message_buffer.blank? - @message_buffer = @message_buffer[(0..max_message_buffer_size-1)] # trim the string to max_message_buffer_size chars - Testrun.create(file: @file, submission: @submission, output: @message_buffer) + if !@run_output.blank? + @run_output = @run_output[(0..max_run_output_buffer_size-1)] # trim the string to max_message_buffer_size chars + Testrun.create(file: @file, cause: 'run', submission: @submission, output: @run_output) end end diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb new file mode 100644 index 00000000..232e9f01 --- /dev/null +++ b/app/controllers/subscriptions_controller.rb @@ -0,0 +1,62 @@ +class SubscriptionsController < ApplicationController + + def authorize! + authorize(@subscription || @subscriptions) + end + private :authorize! + + # POST /subscriptions.json + def create + @subscription = Subscription.new(subscription_params) + respond_to do |format| + if @subscription.save + format.json { render json: @subscription, status: :created } + else + format.json { render json: @subscription.errors, status: :unprocessable_entity } + end + end + authorize! + end + + # DELETE /subscriptions/1 + # DELETE /subscriptions/1.json + def destroy + begin + @subscription = Subscription.find(params[:id]) + rescue + skip_authorization + respond_to do |format| + format.html { redirect_to request_for_comments_url, alert: t('subscriptions.subscription_not_existent') } + format.json { render json: {message: t('subscriptions.subscription_not_existent')}, status: :not_found } + end + else + authorize! + rfc = @subscription.try(:request_for_comment) + @subscription.deleted = true + if @subscription.save + respond_to do |format| + format.html { redirect_to request_for_comment_url(rfc), notice: t('subscriptions.successfully_unsubscribed') } + format.json { render json: {message: t('subscriptions.successfully_unsubscribed')}, status: :ok} + end + else + respond_to do |format| + format.html { redirect_to request_for_comment_url(rfc), :flash => { :danger => t('shared.message_failure') } } + format.json { render json: {message: t('shared.message_failure')}, status: :internal_server_error} + end + end + end + end + + def set_subscription + @subscription = Subscription.find(params[:id]) + authorize! + end + private :set_subscription + + def subscription_params + current_user_id = current_user.try(:id) + current_user_class_name = current_user.try(:class).try(:name) + params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id, user_type: current_user_class_name, deleted: false) + end + private :subscription_params +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 180e9b33..8022ee84 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -21,6 +21,15 @@ class UserMailer < ActionMailer::Base mail(subject: t('mailers.user_mailer.got_new_comment.subject', commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email) end + def got_new_comment_for_subscription(comment, subscription, from_user) + @receiver_displayname = subscription.user.displayname + @author_displayname = from_user.displayname + @comment_text = comment.text + @rfc_link = request_for_comment_url(subscription.request_for_comment) + @unsubscribe_link = unsubscribe_subscription_url(subscription) + mail(subject: t('mailers.user_mailer.got_new_comment_for_subscription.subject', author_displayname: @author_displayname), to: subscription.user.email) + end + def send_thank_you_note(request_for_comments, receiver) @receiver_displayname = receiver.displayname @author = request_for_comments.user.displayname diff --git a/app/models/comment.rb b/app/models/comment.rb index a5946ac9..de2a265b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,7 +1,7 @@ class Comment < ActiveRecord::Base # inherit the creation module: encapsulates that this is a polymorphic user, offers some aliases and makes sure that all necessary attributes are set. include Creation - attr_accessor :username, :date, :updated + attr_accessor :username, :date, :updated, :editable belongs_to :file, class_name: 'CodeOcean::File' belongs_to :user, polymorphic: true diff --git a/app/models/exercise_collection.rb b/app/models/exercise_collection.rb index 2dca0e9d..10946962 100644 --- a/app/models/exercise_collection.rb +++ b/app/models/exercise_collection.rb @@ -2,4 +2,8 @@ class ExerciseCollection < ActiveRecord::Base has_and_belongs_to_many :exercises -end \ No newline at end of file + def to_s + "#{I18n.t('activerecord.models.exercise_collection.one')}: #{name} (#{id})" + end + +end diff --git a/app/models/external_user.rb b/app/models/external_user.rb index 54d5d526..b7a0ebc5 100644 --- a/app/models/external_user.rb +++ b/app/models/external_user.rb @@ -5,11 +5,9 @@ class ExternalUser < ActiveRecord::Base validates :external_id, presence: true def displayname - result = "User " + id.to_s - if(!consumer.nil? && consumer.name == 'openHPI') - result = Rails.cache.fetch("#{cache_key}/displayname", expires_in: 12.hours) do - Xikolo::UserClient.get(external_id.to_s)[:display_name] - end + result = name + if(result == nil || result == "") + result = "User " + id.to_s end result end diff --git a/app/models/proxy_exercise.rb b/app/models/proxy_exercise.rb index 30cd7813..5922e062 100644 --- a/app/models/proxy_exercise.rb +++ b/app/models/proxy_exercise.rb @@ -37,35 +37,17 @@ class ProxyExercise < ActiveRecord::Base assigned_user_proxy_exercise.exercise else matching_exercise = - if (token.eql? "47f4c736") - Rails.logger.debug("Proxy exercise with token 47f4c736, split user in groups..") - group = UserGroupSeparator.getGroupWeek2Testing(user) - Rails.logger.debug("user assigned to group #{group}") - case group - when :group_a - exercises.where(id: 348).first - when :group_b - exercises.where(id: 349).first - when :group_c - exercises.where(id: 350).first - when :group_d - exercises.where(id: 351).first - end - else Rails.logger.debug("find new matching exercise for user #{user.id}" ) begin find_matching_exercise(user) - rescue #fallback + rescue => e #fallback Rails.logger.error("finding matching exercise failed. Fall back to random exercise! Error: #{$!}" ) @reason[:reason] = "fallback because of error" - @reason[:error] = "#{$!}" - exercises.shuffle.first + @reason[:error] = "#{$!}:\n\t#{e.backtrace.join("\n\t")}" + exercises.where("expected_difficulty > 1").shuffle.first # difficulty should be > 1 to prevent dummy exercise from being chosen. end - end user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user, exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json) matching_exercise - - end recommended_exercise end @@ -136,6 +118,7 @@ class ProxyExercise < ActiveRecord::Base relative_knowledge_improvement[potex] += old_relative_loss_tag - new_relative_loss_tag end end + highest_difficulty_user_has_accessed = exercises_user_has_accessed.map{|e| e.expected_difficulty}.sort.last || 0 best_matching_exercise = find_best_exercise(relative_knowledge_improvement, highest_difficulty_user_has_accessed) @reason[:reason] = "best matching exercise" diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 22b39b39..71a2fdd1 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -5,6 +5,7 @@ class RequestForComment < ActiveRecord::Base belongs_to :file, class_name: 'CodeOcean::File' has_many :comments, through: :submission + has_many :subscriptions scope :unsolved, -> { where(solved: [false, nil]) } @@ -37,6 +38,14 @@ class RequestForComment < ActiveRecord::Base submission.files.map { |file| file.comments.size}.sum end + def commenters + commenters = [] + comments.distinct.to_a.each {|comment| + commenters.append comment.user + } + commenters.uniq {|user| user.id} + end + def to_s "RFC-" + self.id.to_s end diff --git a/app/models/submission.rb b/app/models/submission.rb index 94ba46d6..69a48307 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -34,7 +34,7 @@ class Submission < ActiveRecord::Base end def normalized_score - ::NewRelic::Agent.add_custom_parameters({ unnormalized_score: score }) + ::NewRelic::Agent.add_custom_attributes({ unnormalized_score: score }) if !score.nil? && !exercise.maximum_score.nil? && (exercise.maximum_score > 0) score / exercise.maximum_score else diff --git a/app/models/subscription.rb b/app/models/subscription.rb new file mode 100644 index 00000000..abe1b513 --- /dev/null +++ b/app/models/subscription.rb @@ -0,0 +1,4 @@ +class Subscription < ActiveRecord::Base + belongs_to :user, polymorphic: true + belongs_to :request_for_comment +end diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 549c8438..3bdcdda0 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -12,14 +12,10 @@ class CommentPolicy < ApplicationPolicy everyone end - [:new?, :destroy?, :update?].each do |action| + [:new?, :destroy?, :update?, :edit?].each do |action| define_method(action) { admin? || author? } end - def edit? - admin? - end - def index? everyone end diff --git a/app/policies/exercise_collection_policy.rb b/app/policies/exercise_collection_policy.rb new file mode 100644 index 00000000..ff150290 --- /dev/null +++ b/app/policies/exercise_collection_policy.rb @@ -0,0 +1,3 @@ +class ExerciseCollectionPolicy < AdminOnlyPolicy + +end diff --git a/app/policies/subscription_policy.rb b/app/policies/subscription_policy.rb new file mode 100644 index 00000000..289bd5ac --- /dev/null +++ b/app/policies/subscription_policy.rb @@ -0,0 +1,18 @@ +class SubscriptionPolicy < ApplicationPolicy + def create? + everyone + end + + def destroy? + author? || admin? + end + + def show_error? + everyone + end + + def author? + @user == @record.user + end + private :author? +end diff --git a/app/views/application/_flash.html.slim b/app/views/application/_flash.html.slim index cbb88634..135adcf4 100644 --- a/app/views/application/_flash.html.slim +++ b/app/views/application/_flash.html.slim @@ -1,5 +1,5 @@ #flash.fixed_error_messages data-message-failure=t('shared.message_failure') - %w[alert danger info notice success warning].each do |severity| - div.alert.flash class="alert-#{{'alert' => 'warning', 'notice' => 'success'}.fetch(severity, severity)}" id="flash-#{severity}" - p = flash[severity] + div.alert.flash class="alert-#{{'alert' => 'warning', 'notice' => 'success'}.fetch(severity, severity)}" + p id="flash-#{severity}" = flash[severity] span.fa.fa-times \ No newline at end of file diff --git a/app/views/application/_navigation.html.slim b/app/views/application/_navigation.html.slim index 7b9e0a33..668ccab4 100644 --- a/app/views/application/_navigation.html.slim +++ b/app/views/application/_navigation.html.slim @@ -8,8 +8,8 @@ - if current_user.admin? li = link_to(t('breadcrumbs.dashboard.show'), admin_dashboard_path) li.divider - - models = [ExecutionEnvironment, Exercise, Consumer, CodeHarborLink, ExternalUser, FileType, FileTemplate, - ErrorTemplate, ErrorTemplateAttribute, InternalUser].sort_by { |model| model.model_name.human(count: 2) } + - models = [ExecutionEnvironment, Exercise, ExerciseCollection, ProxyExercise, Tag, Consumer, CodeHarborLink, + ErrorTemplate, ErrorTemplateAttribute, ExternalUser, FileType, FileTemplate, InternalUser].sort_by {|model| model.model_name.human(count: 2) } - models.each do |model| - if policy(model).index? li = link_to(model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path")) diff --git a/app/views/comments/index.json.jbuilder b/app/views/comments/index.json.jbuilder index 55dfac49..e42dd5bf 100644 --- a/app/views/comments/index.json.jbuilder +++ b/app/views/comments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@comments) do |comment| - json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username, :date, :updated + json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username, :date, :updated, :editable json.url comment_url(comment, format: :json) end diff --git a/app/views/exercise_collections/_form.html.slim b/app/views/exercise_collections/_form.html.slim new file mode 100644 index 00000000..3c336a62 --- /dev/null +++ b/app/views/exercise_collections/_form.html.slim @@ -0,0 +1,11 @@ +- exercises = Exercise.order(:title) + += form_for(@exercise_collection, data: {exercises: exercises}, multipart: true) do |f| + = render('shared/form_errors', object: @exercise_collection) + .form-group + = f.label(:name) + = f.text_field(:name, class: 'form-control', required: true) + .form-group + = f.label(:exercises) + = f.collection_select(:exercise_ids, exercises, :id, :title, {}, {class: 'form-control', multiple: true}) + .actions = render('shared/submit_button', f: f, object: @exercise_collection) diff --git a/app/views/exercise_collections/edit.html.slim b/app/views/exercise_collections/edit.html.slim new file mode 100644 index 00000000..187f31d2 --- /dev/null +++ b/app/views/exercise_collections/edit.html.slim @@ -0,0 +1,3 @@ +h1 = @exercise_collection + += render('form') diff --git a/app/views/exercise_collections/index.html.slim b/app/views/exercise_collections/index.html.slim new file mode 100644 index 00000000..75a9d011 --- /dev/null +++ b/app/views/exercise_collections/index.html.slim @@ -0,0 +1,24 @@ +h1 = ExerciseCollection.model_name.human(count: 2) + +.table-responsive + table.table + thead + tr + th = t('activerecord.attributes.exercise_collections.id') + th = t('activerecord.attributes.exercise_collections.name') + th = t('activerecord.attributes.exercise_collections.updated_at') + th = t('activerecord.attributes.exercise_collections.exercises') + th colspan=3 = t('shared.actions') + tbody + - @exercise_collections.each do |collection| + tr + td = collection.id + td = link_to(collection.name, collection) + td = collection.updated_at + td = collection.exercises.size + td = link_to(t('shared.show'), collection) + td = link_to(t('shared.edit'), edit_exercise_collection_path(collection)) + td = link_to(t('shared.destroy'), collection, data: {confirm: t('shared.confirm_destroy')}, method: :delete) + += render('shared/pagination', collection: @exercise_collections) +p = render('shared/new_button', model: ExerciseCollection) diff --git a/app/views/exercise_collections/new.html.slim b/app/views/exercise_collections/new.html.slim new file mode 100644 index 00000000..0e48ccd9 --- /dev/null +++ b/app/views/exercise_collections/new.html.slim @@ -0,0 +1,3 @@ +h1 = t('shared.new_model', model: ExerciseCollection.model_name.human) + += render('form') diff --git a/app/views/exercise_collections/show.html.slim b/app/views/exercise_collections/show.html.slim new file mode 100644 index 00000000..65c28283 --- /dev/null +++ b/app/views/exercise_collections/show.html.slim @@ -0,0 +1,11 @@ +h1 + = @exercise_collection + = render('shared/edit_button', object: @exercise_collection) + += row(label: 'exercise_collections.name', value: @exercise_collection.name) += row(label: 'exercise_collections.updated_at', value: @exercise_collection.updated_at) + +h4 = t('activerecord.attributes.exercise_collections.exercises') +ul.list-unstyled + - @exercise_collection.exercises.sort_by{|c| c.title}.each do |exercise| + li = link_to(exercise, exercise) diff --git a/app/views/exercises/_comment_dialogcontent.html.slim b/app/views/exercises/_comment_dialogcontent.html.slim index 4c78035a..ab6dc6b4 100644 --- a/app/views/exercises/_comment_dialogcontent.html.slim +++ b/app/views/exercises/_comment_dialogcontent.html.slim @@ -1,9 +1,12 @@ -h5 =t('exercises.implement.comment.addyours') - -textarea.form-control(style='resize:none;') #otherComments h5 =t('exercises.implement.comment.others') - pre#otherCommentsTextfield -p = '' -button#addCommentButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addCommentButton') -button#removeAllButton.btn.btn-block.btn-warning(type='button') =t('exercises.implement.comment.removeAllOnLine') \ No newline at end of file + .container + +label + input#subscribe type='checkbox' title=t('request_for_comments.subscribe_to_author') data-subscription=Subscription.where(user: current_user, request_for_comment_id: @request_for_comment.id, subscription_type: 'author', deleted: false).try(:first).try(:id) + = t('request_for_comments.subscribe_to_author') + +#myComment + h5 =t('exercises.implement.comment.addyours') + textarea.form-control + button#addCommentButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addCommentButton') \ No newline at end of file diff --git a/app/views/exercises/_file_form.html.slim b/app/views/exercises/_file_form.html.slim index 065eca66..75deeeb5 100644 --- a/app/views/exercises/_file_form.html.slim +++ b/app/views/exercises/_file_form.html.slim @@ -2,10 +2,10 @@ li.panel.panel-default .panel-heading role="tab" id="heading" - a.file-heading data-toggle="collapse" data-parent="#files" href="#collapse#{id}" + a.file-heading data-toggle="collapse" href="#collapse#{id}" div.clearfix role="button" span = f.object.name - .panel-collapse.collapse-in id="collapse#{id}" role="tabpanel" + .panel-collapse.collapse class=('in' if f.object.name.nil?) id="collapse#{id}" role="tabpanel" .panel-body .clearfix = link_to(t('shared.destroy'), '#', class:'btn btn-warning btn-sm discard-file pull-right') .form-group diff --git a/app/views/exercises/_form.html.slim b/app/views/exercises/_form.html.slim index 5ab8502b..bb4aa851 100644 --- a/app/views/exercises/_form.html.slim +++ b/app/views/exercises/_form.html.slim @@ -38,19 +38,28 @@ .form-group = f.label(t('activerecord.attributes.exercise.worktime')) = f.number_field "expected_worktime_minutes", value: @exercise.expected_worktime_seconds / 60, in: 1..1000, step: 1 - h2 Tags - .table-responsive - table.table#tags-table - thead - tr - th = t('activerecord.attributes.exercise.selection') - th = sort_link(@search, :title, t('activerecord.attributes.tag.name')) - th = t('activerecord.attributes.tag.difficulty') - = collection_check_boxes :exercise, :tag_ids, @exercise_tags, :tag_id, :id do |b| - tr - td = b.check_box - td = b.object.tag.name - td = number_field "tag_factors[#{b.object.tag.id}]", :factor, :value => b.object.factor, in: 1..10, step: 1 + + h2 = t('exercises.form.tags') + ul.list-unstyled.panel-group + li.panel.panel-default + .panel-heading role="tab" id="heading" + a.file-heading data-toggle="collapse" href="#tag-collapse" + div.clearfix role="button" + span = t('exercises.form.click_to_collapse') + .panel-collapse.collapse id="tag-collapse" role="tabpanel" + .table-responsive + table.table#tags-table + thead + tr + th = t('activerecord.attributes.exercise.selection') + th = sort_link(@search, :title, t('activerecord.attributes.tag.name')) + th = t('activerecord.attributes.tag.difficulty') + = collection_check_boxes :exercise, :tag_ids, @exercise_tags, :tag_id, :id do |b| + tr + td = b.check_box + td = b.object.tag.name + td = number_field "tag_factors[#{b.object.tag.id}]", :factor, :value => b.object.factor, in: 1..10, step: 1 + h2 = t('activerecord.attributes.exercise.files') ul#files.list-unstyled.panel-group = f.fields_for :files do |files_form| diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 313a19b0..8b5c3b30 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -54,8 +54,10 @@ h1 = "#{@exercise} (external user #{@external_user})" -submission_or_intervention.testruns.each do |run| - if run.passed .unit-test-result.positive-result title=run.output - - else + - elsif run.failed .unit-test-result.negative-result title=run.output + - else + .unit-test-result.unknown-result title=run.output td = Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0 -working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0)) - elsif submission_or_intervention.is_a? UserExerciseIntervention diff --git a/app/views/exercises/statistics.html.slim b/app/views/exercises/statistics.html.slim index 89b7d6a1..d39c514b 100644 --- a/app/views/exercises/statistics.html.slim +++ b/app/views/exercises/statistics.html.slim @@ -35,7 +35,7 @@ h1 = @exercise tbody - @exercise.send(symbol).distinct().each do |user| - if user_statistics[user.id] then us = user_statistics[user.id] else us = {"maximum_score" => nil, "runs" => nil} - - label = current_user.teacher? ? "#{user.name}" : "#{user.name} (#{user.email})" + - label = "#{user.displayname}" tr td = link_to_if symbol==:external_users, label, {controller: "exercises", action: "statistics", external_user_id: user.id, id: @exercise.id} td = us['maximum_score'] or 0 diff --git a/app/views/proxy_exercises/index.html.slim b/app/views/proxy_exercises/index.html.slim index 2a8067c1..80e8084c 100644 --- a/app/views/proxy_exercises/index.html.slim +++ b/app/views/proxy_exercises/index.html.slim @@ -10,7 +10,7 @@ h1 = ProxyExercise.model_name.human(count: 2) thead tr th = sort_link(@search, :title, t('activerecord.attributes.proxy_exercise.title')) - th = "Token" + th = t('activerecord.attributes.exercise.token') th = t('activerecord.attributes.proxy_exercise.files_count') th colspan=6 = t('shared.actions') tbody diff --git a/app/views/proxy_exercises/show.html.slim b/app/views/proxy_exercises/show.html.slim index c1888d79..2649cbb5 100644 --- a/app/views/proxy_exercises/show.html.slim +++ b/app/views/proxy_exercises/show.html.slim @@ -10,6 +10,7 @@ h1 = row(label: 'exercise.title', value: @proxy_exercise.title) = row(label: 'proxy_exercise.files_count', value: @exercises.count) = row(label: 'exercise.description', value: @proxy_exercise.description) += row(label: 'exercise.token', value: @proxy_exercise.token) h3 Exercises .table-responsive table.table diff --git a/app/views/request_for_comments/_admin_menu.html.slim b/app/views/request_for_comments/_admin_menu.html.slim new file mode 100644 index 00000000..3f71b2ed --- /dev/null +++ b/app/views/request_for_comments/_admin_menu.html.slim @@ -0,0 +1,9 @@ +br +h4 Admin Menu +h5 + ul + li = link_to "User's current status of this exercise", statistics_external_user_exercise_path(id: @request_for_comment.exercise_id, external_user_id: @request_for_comment.user_id) + li = link_to "All exercises of this user", statistics_external_user_path(id: @request_for_comment.user_id) + ul + li = link_to "Implement the exercise yourself", implement_exercise_path(id: @request_for_comment.exercise_id) + li = link_to "Show the exercise", exercise_path(id: @request_for_comment.exercise_id) diff --git a/app/views/request_for_comments/_mark_as_solved.html.slim b/app/views/request_for_comments/_mark_as_solved.html.slim new file mode 100644 index 00000000..b3df57fd --- /dev/null +++ b/app/views/request_for_comments/_mark_as_solved.html.slim @@ -0,0 +1,7 @@ +button.btn.btn-primary#mark-as-solved-button = t('request_for_comments.mark_as_solved') + +#thank-you-container + p = t('request_for_comments.write_a_thank_you_node') + textarea#thank-you-note + button.btn.btn-primary#send-thank-you-note = t('request_for_comments.send_thank_you_note') + button.btn.btn-default#cancel-thank-you-note = t('request_for_comments.cancel_thank_you_note') diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index ab60ef91..d3751d0b 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,6 +1,6 @@
- <%= t('request_for_comments.write_a_thank_you_node') %> -
- - - -<%= testrun.try(:output) or t('request_for_comments.no_output') %>+ <% end %> +