From c8084cc6186b571a1fd10477aa65fa7109dd9373 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 10 Apr 2013 01:26:27 +0600 Subject: [PATCH] [#19] hide autocomment for user without access to the issue --- app/presenters/comment_presenter.rb | 6 ++- .../commit_as_message_presenter.rb | 15 ++++-- app/views/shared/_feed_message.html.haml | 49 ++++++++++--------- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/app/presenters/comment_presenter.rb b/app/presenters/comment_presenter.rb index db69cf852..46474db79 100644 --- a/app/presenters/comment_presenter.rb +++ b/app/presenters/comment_presenter.rb @@ -3,7 +3,7 @@ class CommentPresenter < ApplicationPresenter include PullRequestHelper attr_accessor :comment, :options - attr_reader :header, :image, :date, :caption, :content, :buttons, :is_reference_to_issue + attr_reader :header, :image, :date, :caption, :content, :buttons, :is_reference_to_issue, :item def initialize(comment, opts = {}) @is_reference_to_issue = !!(comment.automatic && comment.created_from_issue_id) # is it reference issue from another issue @@ -110,4 +110,8 @@ class CommentPresenter < ApplicationPresenter pull_status_label @referenced_issue end.html_safe end + + def item + @comment + end end diff --git a/app/presenters/git_presenters/commit_as_message_presenter.rb b/app/presenters/git_presenters/commit_as_message_presenter.rb index 26bc17c7b..965fa6cb0 100644 --- a/app/presenters/git_presenters/commit_as_message_presenter.rb +++ b/app/presenters/git_presenters/commit_as_message_presenter.rb @@ -3,16 +3,17 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter include CommitHelper attr_accessor :commit - attr_reader :header, :image, :date, :caption, :content, :expandable, :is_reference_to_issue, :committer + attr_reader :header, :image, :date, :caption, :content, :expandable, + :is_reference_to_issue, :committer, :item def initialize(commit, opts = {}) comment = opts[:comment] @is_reference_to_issue = !!comment # is it reference issue from commit @project = if comment - Project.where(:id => opts[:comment].data[:from_project_id]).first - else - opts[:project] - end + Project.where(:id => comment.data[:from_project_id]).first + else + opts[:project] + end commit = commit || @project.repo.commit(comment.created_from_commit_hash.to_s(16)) if @project if @project && commit @@ -76,6 +77,10 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter false end + def item + @commit + end + protected def committer_link diff --git a/app/views/shared/_feed_message.html.haml b/app/views/shared/_feed_message.html.haml index 2caadaf11..09e448d3c 100644 --- a/app/views/shared/_feed_message.html.haml +++ b/app/views/shared/_feed_message.html.haml @@ -1,27 +1,28 @@ -.activity{:id => presenter.comment_id? ? presenter.comment_anchor : ''} - .top - - if presenter.buttons? - %span.buttons= raw presenter.buttons.join(' | ').html_safe - .image - %img{:alt => "avatar", :src => presenter.image} - .text - -#.imaged move up a line. - %span.name= presenter.header - .both - %span.date= presenter.date - .both - - if presenter.caption? - %span.subject= presenter.caption - - if presenter.expandable? and presenter.content? - %span.data-expander.collapsed{:id => "expand#{item_no}"}   +-if !presenter.is_reference_to_issue || can?(:show, presenter.item) + .activity{:id => presenter.comment_id? ? presenter.comment_anchor : ''} + .top + - if presenter.buttons? + %span.buttons= raw presenter.buttons.join(' | ').html_safe + .image + %img{:alt => "avatar", :src => presenter.image} + .text + -#.imaged move up a line. + %span.name= presenter.header .both - .both - - if presenter.content? - %div - =presenter.issue_referenced_state if presenter.issue_referenced_state? - .fulltext{:class => "#{presenter.expandable? ? "hidden" : ''} #{presenter.caption? ? "" : "alone"}", - :id => presenter.expandable? ? "content-expand#{item_no}" : ''} - .md_and_cm{:class => presenter.is_reference_to_issue ? '' : 'cm-s-default'} - =presenter.is_reference_to_issue ? presenter.content : markdown(presenter.content) + %span.date= presenter.date .both + - if presenter.caption? + %span.subject= presenter.caption + - if presenter.expandable? and presenter.content? + %span.data-expander.collapsed{:id => "expand#{item_no}"}   + .both + .both + - if presenter.content? + %div + =presenter.issue_referenced_state if presenter.issue_referenced_state? + .fulltext{:class => "#{presenter.expandable? ? "hidden" : ''} #{presenter.caption? ? "" : "alone"}", + :id => presenter.expandable? ? "content-expand#{item_no}" : ''} + .md_and_cm{:class => presenter.is_reference_to_issue ? '' : 'cm-s-default'} + =presenter.is_reference_to_issue ? presenter.content : markdown(presenter.content) + .both