Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add RSS feed support

git-svn-id: http://svn.techno-weenie.net/projects/plugins/exception_logger@2038 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information...
commit e2d703cdf6d96bbb2b21eeb4a3bedcd1cfc65be5 1 parent 89fee3e
technoweenie authored
View
26 README
@@ -25,13 +25,39 @@ It's understandable that you may want to require authentication. Add this to yo
config.after_initialize do
require 'application' unless Object.const_defined?(:ApplicationController)
LoggedExceptionsController.class_eval do
+ # set the same session key as the app
+ session :session_key => '_beast_session_id'
+
+ # include any custom auth modules you need
+ include AuthenticationSystem
+
before_filter :login_required
+
+ # optional, sets the application name for the rss feeds
+ self.application_name = "Beast"
+
protected
# only allow admins
# this obviously depends on how your auth system works
def authorized?
current_user.is_a?(Admin)
end
+
+ # assume app's login required doesn't use http basic
+ def login_required_with_basic
+ respond_to do |accepts|
+ # alias_method_chain will alias the app's login_required to login_required_without_basic
+ accepts.html { login_required_without_basic }
+
+ # access_denied_with_basic_auth is defined in LoggedExceptionsController
+ # get_auth_data returns back the user/password pair
+ accepts.rss do
+ access_denied_with_basic_auth unless self.current_user = User.authenticate(*get_auth_data)
+ end
+ end
+ end
+
+ alias_method_chain :login_required, :basic
end
end
View
4 assets/style.css
@@ -301,3 +301,7 @@ ul.tabs li.selected a
opacity:.8;
font-size: 11px;
}
+
+#feed {
+ margin-top: 15px;
+}
View
37 lib/logged_exceptions_controller.rb
@@ -1,4 +1,5 @@
class LoggedExceptionsController < ActionController::Base
+ cattr_accessor :application_name
layout nil
def index
@@ -10,6 +11,10 @@ def index
def query
conditions = []
parameters = []
+ unless params[:id].blank?
+ conditions << 'id = ?'
+ parameters << params[:id]
+ end
unless params[:query].blank?
conditions << 'message LIKE ?'
parameters << "%#{params[:query]}%"
@@ -28,6 +33,12 @@ def query
end
@exception_pages, @exceptions = paginate :logged_exceptions, :order => 'created_at desc', :per_page => 30,
:conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and ')
+
+ respond_to do |format|
+ format.html { redirect_to :action => 'index' unless action_name == 'index' }
+ format.js
+ format.rss { render :action => 'query.rxml' }
+ end
end
def show
@@ -42,4 +53,30 @@ def destroy_all
LoggedException.delete_all ['id in (?)', params[:ids]] unless params[:ids].blank?
query
end
+
+ private
+ def access_denied_with_basic_auth
+ headers["Status"] = "Unauthorized"
+ headers["WWW-Authenticate"] = %(Basic realm="Web Password")
+ render :text => "Could't authenticate you", :status => '401 Unauthorized'
+ end
+
+ # gets BASIC auth info
+ def get_auth_data
+ user, pass = '', ''
+ # extract authorisation credentials
+ if request.env.has_key? 'X-HTTP_AUTHORIZATION'
+ # try to get it where mod_rewrite might have put it
+ authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
+ elsif request.env.has_key? 'HTTP_AUTHORIZATION'
+ # this is the regular location
+ authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
+ end
+
+ # at the moment we only support basic authentication
+ if authdata && authdata[0] == 'Basic'
+ user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
+ end
+ return [user, pass]
+ end
end
View
25 views/logged_exceptions/_exceptions.rhtml
@@ -1,5 +1,5 @@
<div id="exceptions">
-
+<%= session[:user_id] ; controller.reset_session %>
<div class="pages">
<%= link_to_remote 'Delete Visible', :url => { :action => 'destroy_all' }, :with => "ExceptionLogger.deleteAll()" %>
<% if @exception_pages.page_count > 1 %>
@@ -15,11 +15,6 @@
<tr>
<th>Exception</th>
<th>Date</th>
-<!--
- <th></th>
-
- <th><%= link_to_function "All", "$$('#exceptions table input').each(function(a){a.checked= (a.checked ? '' : 'checked'); });" %></th>
--->
</tr>
</thead>
@@ -34,9 +29,6 @@
</td>
<td nowrap=nowrap class="time">
-<!--
-
--->
<%
if Date.today == exc.created_at.to_date
if exc.created_at > Time.now - 4.hours
@@ -49,28 +41,15 @@ if Date.today == exc.created_at.to_date
<%= exc.created_at.strftime("%b %d, %Y") %>
<% end %>
</td>
-
-
-<!--
- <td style="padding-right:0;">
- <input type="checkbox" />
- </td>
--->
<td><%= link_to_remote 'Delete', {:url => { :action => 'destroy', :id => exc }} , :class => "util" %></td>
-
</tr>
<% end -%>
</tbody>
</table>
-<!--
-<%= submit_tag "Delete", :style => "float:right;"%>
-<br />
--->
-
-<% if @exception_pages.page_count>1 %>
+<% if @exception_pages.page_count > 1 %>
<div class="pages pages-bottom">
Pages: <strong><%= pagination_remote_links @exception_pages, :params => { :action => :index } %></strong>
</div>
View
5 views/logged_exceptions/index.rhtml
@@ -19,6 +19,10 @@
<h3>Filters</h3>
+<ul id="all_exceptions" class="filters">
+ <li><%= link_to 'Latest Exceptions', :action => 'index', :id => nil %></li>
+</ul>
+
<h4>Exception</h4>
<ul id="exception_names" class="filters">
@@ -60,6 +64,7 @@
</form>
</div>
+<%= render :partial => 'feed' %>
</div> <!-- right -->
View
3  views/logged_exceptions/query.rjs
@@ -1,2 +1,3 @@
page[:exceptions].replace :partial => "exceptions"
-page[:showpage].hide
+page[:showpage].hide
+page[:feed].replace :partial => 'feed'
Please sign in to comment.
Something went wrong with that request. Please try again.