Disable comment adding for archived objects [SCI-5339]

This commit is contained in:
Oleksii Kriuchykhin 2020-12-30 11:42:30 +01:00
parent 67b3f853d7
commit 738f668ba9
3 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,11 @@ var CommentsSidebar = (function() {
$(SIDEBAR).removeClass('loading');
$(SIDEBAR).find('.comments-subject-title').text(result.object_name);
$(SIDEBAR).find('.comments-list').html(result.comments);
if (result.comment_addable) {
$(SIDEBAR).find('.comment-input-container').removeClass('hidden');
} else {
$(SIDEBAR).find('.comment-input-container').addClass('hidden');
}
});
}

View file

@ -17,6 +17,7 @@ class CommentsController < ApplicationController
render json: {
object_name: @commentable.name,
comment_addable: comment_addable?(@commentable),
comments: render_to_string(partial: 'shared/comments/comments_list.html.erb',
locals: { comments: comments })
}

View file

@ -57,6 +57,19 @@ module CommentHelper
end
end
def comment_addable?(object)
case object.class.name
when 'MyModule'
can_create_comments_in_module?(object)
when 'Step', 'Result'
can_create_comments_in_module?(object.my_module)
when 'Project'
can_create_comments_in_project?(object)
else
false
end
end
def comment_editable?(comment)
case comment.type
when 'TaskComment', 'StepComment', 'ResultComment'