diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 01dcd9d5..dfbb4f8d 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 = [] 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/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