Permalink
Browse files

Implemented AuthY plugin; pulled authorization dsl into plugin

  • Loading branch information...
1 parent 18f93ce commit 7c663ca25cba2529511eeec12b7008ae2a177471 Joe Fiorini committed Aug 22, 2008
View
3 .gitmodules
@@ -13,3 +13,6 @@
[submodule "vendor/plugins/awesome_fields"]
path = vendor/plugins/awesome_fields
url = git://github.com/Shadowfiend/awesome_fields.git
+[submodule "auth_y"]
+ path = auth_y
+ url = vendor/plugins/auth_y/
View
10 app/controllers/application.rb
@@ -9,17 +9,9 @@ def tweets_enabled
false
end
- def for_users_by_type
- if @current_user
- yield :admin
- else
- yield :anonymous
- end
- end
-
private
def retrieve_user
- @current_user = User.find(session[:user_id]) if session[:user_id]
+ User.current_user = User.find(session[:user_id]) if session[:user_id]
end
# See ActionController::RequestForgeryProtection for details
View
28 app/controllers/posts_controller.rb
@@ -2,28 +2,18 @@ class PostsController < ResourceController::Base
alias r_c_generated_object object
new_action.wants.html do
- for_admin_only do
- render :html => @posts
- end
+ render_for_admin :html => @posts
end
index.wants.atom
index.wants.html do
@sticky = Post.sticky
- Twitter::Status.logger = logger
- begin
- if tweets_enabled
- @tweets = Twitter::Status.user_timeline
- end
- rescue
- @tweets = nil
- logger.error "Error receiving recent tweets: #{$!}"
- end
-
- for_users_by_type do |type|
+
+ for_user_by_type do |type|
case type
when :anonymous
+ when :user
render :html => @posts
when :admin
if request.request_uri.downcase =~ /home/
@@ -69,10 +59,14 @@ def object
def load_collection
if params[:tag]
@posts = Post.find_tagged_with params[:tag]
- elsif @current_user
- @posts = Post.posts_per_date
else
- @posts = Post.not_sticky.all :limit => 10, :order => "created_at desc"
+ for_user_by_type do |type|
+ if type == :admin
+ @posts = Post.posts_per_date
+ else
+ @posts = Post.not_sticky.all :limit => 10, :order => "created_at desc"
+ end
+ end
end
end
View
8 app/helpers/application_helper.rb
@@ -8,14 +8,6 @@ def format_date_short(date)
date.to_s(:short_date_only)
end
- def for_admin_only
- unless @current_user
- redirect_to(root_url)
- else
- yield
- end
- end
-
def feedburner_link_tag(burned_name)
auto_discovery_link_tag :rss, "http://feeds.feedburner.com/#{burned_name.to_s}", :title => 'faithfulgeek.org in syndication'
end
View
14 app/models/user.rb
@@ -1,3 +1,17 @@
class User < ActiveRecord::Base
has_many :posts
+
+ def admin?
+ true
+ end
+
+ def self.current_user=(user)
+ @@current_user = user
+ end
+
+ def self.current_user
+ @@current_user if defined? @@current_user
+ end
+
+
end
View
4 app/views/admin/posts/index.html.haml
@@ -4,13 +4,13 @@
- @posts.each do |key, value|
%li
%p.date
- = key.to_s :short_date_only
+ = key.to_s :short_date_only if key
- value.each do |post|
%p
.tools
= link_to '[edit]', edit_post_url(post), :class => "icon edit", :title => 'Edit'
= link_to '[delete]', post_url(post), :method => :delete, :confirm => "Are you sure you want to delete this post?", :class => "icon delete", :title => 'Delete'
.title= link_to post.title, post_url(post)
-= render :partial => 'creation_tools'
+= render :partial => 'admin/posts/creation_tools'
View
10 app/views/layouts/admin.html.haml
@@ -14,16 +14,16 @@
%a{ :href => "/" }
%span
clerb : the cleveland ruby brigade / northeast ohio ruby users group
- - for_admin_only do
#navigation
%ul
%li= link_to 'overview', '/'
%li= link_to 'posts', posts_path
%li= link_to 'events', events_path
- #welcome_message
- %em= @current_user.name
- |
- = link_to 'logout', logout_url
+ - if User.current_user
+ #welcome_message
+ %em= User.current_user.name
+ |
+ = link_to 'logout', logout_url
#main
#page-content
= yield

0 comments on commit 7c663ca

Please sign in to comment.