before_action :set_issues
before_action :check_permission, :only => [:index, :show, :resolve, :open, :ignore, :comment]
before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
- before_action :setup_user_role, :only => [:show, :index]
def index
if current_user.moderator?
@users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
end
- @issues = Issue.where(:assigned_role => @user_role)
+ @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
# If search
if params[:search_by_user] && params[:search_by_user].present?
@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
- @related_issues = @issue.reported_user.issues.where(:assigned_role => @user_role)
+ @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role))
@new_comment = IssueComment.new(:issue => @issue)
end
@moderator_issues = %w[Changeset Note]
end
- def setup_user_role
- # Get user role
- @user_role = current_user.administrator? ? "administrator" : "moderator"
- end
-
def check_if_updated
if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
true
<% content_for :heading do %>
- <h1>List of <%= @user_role %> issues:</h1>
+ <h1>List of issues:</h1>
<% end %>
<%= form_tag(issues_path, :method => :get) do %>
<p><%= report_type(@issue.reportable_type) %> : <%= reportable_url(@issue.reportable) %></p>
<p class="deemphasize">
<small>
- <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_datetime, :format => :friendly %> <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:friendly)}" if @issue.resolved_at? %> <%= "| Last updated at #{l(@issue.updated_at.to_datetime, :format => :friendly)} by #{@issue.user_updated.display_name}" if @issue.user_updated %>
+ <%= @issue.assigned_role %>
+ | <%= @issue.reports.count %> reports
+ | First reported: <%= l @issue.created_at.to_datetime, :format => :friendly %>
+ <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:friendly)}" if @issue.resolved_at? %>
+ <%= "| Last updated at #{l(@issue.updated_at.to_datetime, :format => :friendly)} by #{@issue.user_updated.display_name}" if @issue.user_updated %>
</small>
</p>
<p>
issue.reload
assert_equal "moderator", issue.assigned_role
end
+
+ def test_issue_index_with_multiple_roles
+ user1 = create(:user)
+ user2 = create(:user)
+ issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
+ issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
+
+ user = create(:administrator_user)
+ create(:user_role, :user => user, :role => "moderator")
+ sign_in_as(user)
+
+ visit issues_path
+
+ assert page.has_link?(user1.display_name, :href => issue_path(issue1))
+ assert page.has_link?(user2.display_name, :href => issue_path(issue2))
+ end
end