rfc can now be solved.

show.html still needs to be finished
This commit is contained in:
Ralf Teusner
2016-06-24 16:44:34 +02:00
parent bd6d4c4d71
commit 2a52b66daa
8 changed files with 58 additions and 8 deletions

View File

@ -1,5 +1,5 @@
class RequestForCommentsController < ApplicationController class RequestForCommentsController < ApplicationController
before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy] before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy, :mark_as_solved]
skip_after_action :verify_authorized skip_after_action :verify_authorized
@ -20,6 +20,18 @@ class RequestForCommentsController < ApplicationController
render 'index' render 'index'
end end
def mark_as_solved
authorize!
@request_for_comment.solved = true
respond_to do |format|
if @request_for_comment.save
format.json { render :show, status: :ok, location: @request_for_comment }
else
format.json { render json: @request_for_comment.errors, status: :unprocessable_entity }
end
end
end
# GET /request_for_comments/1 # GET /request_for_comments/1
# GET /request_for_comments/1.json # GET /request_for_comments/1.json
def show def show
@ -70,6 +82,6 @@ class RequestForCommentsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def request_for_comment_params def request_for_comment_params
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at).merge(user_id: current_user.id, user_type: current_user.class.name) params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved).merge(user_id: current_user.id, user_type: current_user.class.name)
end end
end end

View File

@ -1,7 +1,7 @@
class RequestForComment < ActiveRecord::Base class RequestForComment < ActiveRecord::Base
include Creation
belongs_to :exercise belongs_to :exercise
belongs_to :file, class_name: 'CodeOcean::File' belongs_to :file, class_name: 'CodeOcean::File'
belongs_to :user, polymorphic: true
before_create :set_requested_timestamp before_create :set_requested_timestamp

View File

@ -1,5 +1,8 @@
class RequestForCommentPolicy < ApplicationPolicy class RequestForCommentPolicy < ApplicationPolicy
def author?
@user == @record.author
end
private :author?
def create? def create?
everyone everyone
@ -13,6 +16,10 @@ class RequestForCommentPolicy < ApplicationPolicy
define_method(action) { admin? } define_method(action) { admin? }
end end
def mark_as_solved?
admin? || author?
end
def edit? def edit?
admin? admin?
end end

View File

@ -21,6 +21,11 @@
<%= t('request_for_comments.no_question') %> <%= t('request_for_comments.no_question') %>
<% end %> <% end %>
</h5> </h5>
<% if (policy(@request_for_comment).mark_as_solved? and not @request_for_comment.solved?) %>
<button class="btn btn-default" id="mark-as-solved-button">Bla</button>
<% else %>
<% end %>
</div> </div>
<!-- <!--
@ -37,6 +42,22 @@ also, all settings from the rails model needed for the editor configuration in t
<script type="text/javascript"> <script type="text/javascript">
var solvedButton = $('#mark-as-solved-button');
solvedButton.on('click', function(event){
var jqrequest = $.ajax({
dataType: 'json',
method: 'GET',
url: location + '/mark_as_solved'
});
jqrequest.done(function(response){
if(response.solved){
solvedButton.hide();
}
});
});
// set file paths for ace // set file paths for ace
var ACE_FILES_PATH = '/assets/ace/'; var ACE_FILES_PATH = '/assets/ace/';
_.each(['modePath', 'themePath', 'workerPath'], function(attribute) { _.each(['modePath', 'themePath', 'workerPath'], function(attribute) {

View File

@ -1 +1 @@
json.extract! @request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type json.extract! @request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type, :solved

View File

@ -2,13 +2,17 @@ FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
Rails.application.routes.draw do Rails.application.routes.draw do
resources :code_harbor_links resources :code_harbor_links
resources :request_for_comments resources :request_for_comments do
get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests' member do
get :mark_as_solved
end
end
resources :comments, except: [:destroy] do resources :comments, except: [:destroy] do
collection do collection do
delete :destroy delete :destroy
end end
end end
get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests'
delete '/comment_by_id', to: 'comments#destroy_by_id' delete '/comment_by_id', to: 'comments#destroy_by_id'
put '/comments', to: 'comments#update' put '/comments', to: 'comments#update'

View File

@ -0,0 +1,5 @@
class AddSolvedToRequestForComments < ActiveRecord::Migration
def change
add_column :request_for_comments, :solved, :boolean
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160512131539) do ActiveRecord::Schema.define(version: 20160624130951) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -190,6 +190,7 @@ ActiveRecord::Schema.define(version: 20160512131539) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "user_type" t.string "user_type"
t.text "question" t.text "question"
t.boolean "solved"
end end
create_table "submissions", force: true do |t| create_table "submissions", force: true do |t|