Skip to content

Commit

Permalink
Implemented AuthY plugin; pulled authorization dsl into plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Fiorini committed Aug 22, 2008
1 parent 18f93ce commit 7c663ca
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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/
10 changes: 1 addition & 9 deletions app/controllers/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 11 additions & 17 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/views/admin/posts/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'


10 changes: 5 additions & 5 deletions app/views/layouts/admin.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c663ca

Please sign in to comment.