-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make first baby steps towards an authentication procedure through rub…
…ycas-server * Add the rubycas-client gem * Initialize rubycas-client * Add admin namespace for admin post actions * Change the rubycas-server logger preventing it for a deprication warning * Test that admin_post_controller needs login * Create user model * Add admin boolean to users * Add current user helper
- Loading branch information
Showing
15 changed files
with
176 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Admin::PostsController < ApplicationController | ||
|
||
before_filter CASClient::Frameworks::Rails::Filter | ||
|
||
def new | ||
@post = Post.new | ||
end | ||
|
||
def create | ||
@post = Post.new(params[:post]) | ||
if @post.save | ||
redirect_to post_url @post | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
@post = Post.find_by_id(params[:id]) | ||
end | ||
|
||
def update | ||
@post = Post.find_by_id(params[:id]) | ||
|
||
if @post.update_attributes(params[:post]) | ||
redirect_to post_url @post | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@post = Post.find_by_id(params[:id]) | ||
@post.destroy unless @post.nil? | ||
redirect_to posts_url | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
layout 'application' | ||
helper_method :current_user | ||
|
||
private | ||
|
||
def current_user | ||
return nil unless session[:cas_email].present? | ||
@current_user ||= User.find_or_create_by_email(session[:cas_email]) | ||
end | ||
|
||
def require_admin | ||
return current_user.present? | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,12 @@ | ||
class PostsController < ApplicationController | ||
|
||
def index | ||
@posts = Post.latest | ||
end | ||
|
||
def new | ||
@post = Post.new | ||
end | ||
|
||
def create | ||
@post = Post.new(params[:post]) | ||
if @post.save | ||
redirect_to @post | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
|
||
def show | ||
@post = Post.find_by_id(params[:id]) | ||
@posts = Post.latest - [@post] | ||
end | ||
|
||
def edit | ||
@post = Post.find_by_id(params[:id]) | ||
end | ||
|
||
def update | ||
@post = Post.find_by_id(params[:id]) | ||
|
||
if @post.update_attributes(params[:post]) | ||
redirect_to @post | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@post = Post.find_by_id(params[:id]) | ||
@post.destroy unless @post.nil? | ||
redirect_to posts_path | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class User < ActiveRecord::Base | ||
end |
2 changes: 1 addition & 1 deletion
2
app/views/posts/_form.html.haml → app/views/admin/posts/_form.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
= form_for @post do |f| | ||
= form_for [:admin, @post] do |f| | ||
= f.label :title | ||
%br | ||
= f.text_field :title | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'casclient' | ||
require 'casclient/frameworks/rails/filter' | ||
|
||
CASClient::Frameworks::Rails::Filter.configure( | ||
:cas_base_url => "https://67.23.79.76/", | ||
:username_session_key => :cas_email, | ||
:logger => Rails.logger | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table :users do |t| | ||
t.string :email | ||
t.string :full_name | ||
t.boolean :admin, :default => false | ||
t.timestamps | ||
end | ||
|
||
add_index :users, :email | ||
end | ||
|
||
def self.down | ||
drop_table :users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'spec_helper' | ||
|
||
describe Admin::PostsController do | ||
before do | ||
@user = mock("User", :email => "john.doe@example.com") | ||
@post = mock_model(Post, :null_object => true) | ||
Post.stub(:find_by_id).and_return(@post) | ||
end | ||
|
||
describe "as admin" do | ||
before do | ||
CASClient::Frameworks::Rails::Filter.stub(:filter).and_return(true) | ||
end | ||
|
||
it "should be able to visit the new page" do | ||
get :new | ||
response.should render_template(:new) | ||
end | ||
|
||
it "should be able to use the create action" do | ||
post :create | ||
response.should render_template(:new) | ||
end | ||
|
||
it "should be able to visit the edit page" do | ||
get :edit, :id => 1 | ||
response.should render_template(:edit) | ||
end | ||
|
||
it "should be able to use the update action" do | ||
put :update, :id => 1 | ||
response.should redirect_to(post_path(@post)) | ||
end | ||
|
||
it "should be able to use the destroy action" do | ||
delete :destroy, :id => 1 | ||
response.should redirect_to(posts_path) | ||
end | ||
end | ||
|
||
describe "as guest" do | ||
|
||
it "should not be able to visite the new page" do | ||
get :new | ||
response.should_not render_template(:new) | ||
end | ||
|
||
it "should not be able to use the create action" do | ||
post :create | ||
response.should_not render_template(:new) | ||
end | ||
|
||
it "should not be able to visit the edit page" do | ||
get :edit, :id => 1 | ||
response.should_not render_template(:edit) | ||
end | ||
|
||
it "should not be able to use the update action" do | ||
put :update, :id => 1 | ||
response.should_not redirect_to(post_path(@post)) | ||
end | ||
|
||
it "should not be able to use the destroy action" do | ||
delete :destroy, :id => 1 | ||
response.should_not redirect_to(posts_path) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe User do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |