Class: ErrorRadar::ErrorsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ErrorRadar::ErrorsController
- Defined in:
- app/controllers/error_radar/errors_controller.rb
Constant Summary collapse
- PER_PAGE =
50
Instance Method Summary collapse
- #assign ⇒ Object
- #bulk ⇒ Object
- #comment ⇒ Object
- #create_github_issue ⇒ Object
- #destroy ⇒ Object
- #destroy_comment ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update_status ⇒ Object
Instance Method Details
#assign ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/error_radar/errors_controller.rb', line 55 def assign unless @error.class.column_names.include?('assigned_to') return render json: { ok: false, error: 'Run upgrade_v100 migration first' }, status: :unprocessable_entity end assignee = params[:assigned_to].to_s.strip.truncate(200) @error.update!(assigned_to: assignee.presence) action_label = assignee.present? ? "assigned → #{assignee}" : 'unassigned' log_activity(@error, action: action_label) render json: { ok: true, assigned_to: @error.assigned_to } end |
#bulk ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/error_radar/errors_controller.rb', line 154 def bulk ids = Array(params[:ids]).map(&:to_i).select(&:positive?) action = params[:bulk_action].to_s if ids.empty? return render json: { ok: false, error: 'no ids selected' }, status: :unprocessable_entity end unless %w[resolve ignore reopen delete].include?(action) return render json: { ok: false, error: 'unknown action' }, status: :unprocessable_entity end count = apply_bulk(ids, action) render json: { ok: true, count: count, action: action } end |
#comment ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/error_radar/errors_controller.rb', line 69 def comment body = params[:body].to_s.strip if body.blank? return render json: { ok: false, error: 'Comment cannot be blank' }, status: :unprocessable_entity end = (error_radar_current_user.presence || params[:author].to_s.strip.presence || 'Anonymous').truncate(200) cmt = ErrorComment.create!(error_log: @error, author: , body: body) log_activity(@error, action: 'commented', actor: , detail: body.truncate(120)) render json: { ok: true, id: cmt.id, author: cmt., body: cmt.body, created_at: cmt.created_at.strftime('%Y-%m-%d %H:%M') } rescue ActiveRecord::StatementInvalid render json: { ok: false, error: 'Run upgrade_v100 migration first' }, status: :unprocessable_entity end |
#create_github_issue ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/controllers/error_radar/errors_controller.rb', line 125 def create_github_issue unless github_configured? return render json: { ok: false, error: 'GitHub not configured (set config.github_token and config.github_repo)' }, status: :unprocessable_entity end if ErrorLog.column_names.include?('github_issue_url') && @error.github_issue_url.present? return render json: { ok: false, error: 'Issue already created', url: @error.github_issue_url }, status: :unprocessable_entity end require 'error_radar/integrations/github' result = ErrorRadar::Integrations::Github.create_issue( @error, token: ErrorRadar.config.github_token, repo: ErrorRadar.config.github_repo ) if result['html_url'] @error.update!(github_issue_url: result['html_url']) if ErrorLog.column_names.include?('github_issue_url') render json: { ok: true, url: result['html_url'], number: result['number'] } else render json: { ok: false, error: result['message'] || 'GitHub API error' }, status: :unprocessable_entity end rescue StandardError => e render json: { ok: false, error: e. }, status: :internal_server_error end |
#destroy ⇒ Object
120 121 122 123 |
# File 'app/controllers/error_radar/errors_controller.rb', line 120 def destroy @error.destroy! render json: { ok: true } end |
#destroy_comment ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/error_radar/errors_controller.rb', line 91 def destroy_comment cmt = ErrorComment.find(params[:cid]) return head :not_found unless cmt.error_log_id == @error.id cmt.destroy! log_activity(@error, action: 'comment_deleted') render json: { ok: true } rescue ActiveRecord::RecordNotFound head :not_found rescue ActiveRecord::StatementInvalid head :unprocessable_entity end |
#index ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/error_radar/errors_controller.rb', line 14 def index scope = build_scope @total_count = scope.count @page = [params[:page].to_i, 1].max @total_pages = [(@total_count.to_f / PER_PAGE).ceil, 1].max @page = [@page, @total_pages].min if @total_pages > 0 @errors = scope.limit(PER_PAGE).offset((@page - 1) * PER_PAGE) @filter_params = active_filter_params @pages = pagination_pages(@page, @total_pages) end |
#show ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/error_radar/errors_controller.rb', line 25 def show @occurrences = [] if ErrorRadar.config.track_occurrences begin @occ_page = [params[:occ_page].to_i, 1].max occ_per_page = 20 @occ_total = @error.error_occurrences.count @occ_total_pages = [(@occ_total.to_f / occ_per_page).ceil, 1].max @occ_page = [@occ_page, @occ_total_pages].min @occurrences = @error.error_occurrences.recent .limit(occ_per_page) .offset((@occ_page - 1) * occ_per_page) rescue ActiveRecord::StatementInvalid @occurrences = [] end end @has_v100 = @error.class.column_names.include?('assigned_to') @comments = [] @activities = [] if @has_v100 begin @comments = @error.comments.chronological @activities = @error.activities.recent.limit(50) rescue ActiveRecord::StatementInvalid @has_v100 = false end end end |
#update_status ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/controllers/error_radar/errors_controller.rb', line 104 def update_status new_status = params[:status].to_s unless ErrorLog.statuses.key?(new_status) return render json: { ok: false, error: 'invalid status' }, status: :unprocessable_entity end if new_status == 'resolved' @error.resolve!(by: error_radar_current_user, note: params[:note].presence) else @error.update!(status: new_status, resolved_at: nil) end log_activity(@error, action: new_status, detail: params[:note].presence) render json: { ok: true, id: @error.id, status: @error.status } end |