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]
-
- helper_method :sort_column, :sort_direction
def index
if current_user.moderator?
@users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
end
- @issues = Issue.where(:issue_type => @user_role).order(sort_column + " " + sort_direction)
+ @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
# If search
if params[:search_by_user] && params[:search_by_user].present?
@issues = @issues.where(:updated_by => last_updated_by)
end
- notice = t("issues.index.search.issues_not_found") if @issues.first.nil?
-
if params[:last_reported_by] && params[:last_reported_by][0].present?
last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
@issues = @issues.where(:updated_by => last_reported_by)
@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
- @related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
+ @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role))
+ @new_comment = IssueComment.new(:issue => @issue)
end
def update
end
end
- def comment
- @issue = Issue.find(params[:id])
- if issue_comment_params.blank?
- notice = t("issues.comment.provide_details")
- else
- @issue_comment = @issue.comments.build(issue_comment_params)
- @issue_comment.commenter_user_id = current_user.id
- if params[:reassign]
- reassign_issue
- @issue_comment.reassign = true
- end
- @issue_comment.save!
- @issue.updated_by = current_user.id
- @issue.save!
- notice = t("issues.comment.comment_created")
- end
- redirect_to @issue, :notice => notice
- end
-
# Status Transistions
def resolve
if @issue.resolve
end
end
- # Reassign Issues between Administrators and Moderators
- def reassign_issue
- @issue.issue_type = upgrade_issue(@issue.issue_type)
- @issue.save!
- end
-
private
- def upgrade_issue(type)
- if type == "moderator"
- "administrator"
- else
- "moderator"
- end
- end
-
def set_issues
@admin_issues = %w[DiaryEntry DiaryComment User]
@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