adding the ability to remember who created and updated a page model
git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@64 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7master
parent
169fcc0c5e
commit
18b92965b8
|
@ -2,7 +2,9 @@ class ApplicationController < ActionController::Base
|
||||||
session :session_key => '_barleysodas_session_id'
|
session :session_key => '_barleysodas_session_id'
|
||||||
append_before_filter :block_prefetching_links
|
append_before_filter :block_prefetching_links
|
||||||
append_before_filter :authorized?
|
append_before_filter :authorized?
|
||||||
|
append_before_filter :set_current_people_id
|
||||||
helper_method :logged_in?
|
helper_method :logged_in?
|
||||||
|
cattr_accessor :current_people_id
|
||||||
|
|
||||||
##
|
##
|
||||||
# Ensures that the request was made using an Ajax request.
|
# Ensures that the request was made using an Ajax request.
|
||||||
|
@ -142,4 +144,11 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Sets a class accessor for the current People.
|
||||||
|
#
|
||||||
|
def set_current_people_id
|
||||||
|
self.current_people_id = session[:people_id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@ class SessionsController < ApplicationController
|
||||||
@people = People.find_by_title(params[:login]) rescue nil
|
@people = People.find_by_title(params[:login]) rescue nil
|
||||||
if @people
|
if @people
|
||||||
session[:people_title] = @people.title
|
session[:people_title] = @people.title
|
||||||
|
session[:people_id] = @people.id
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
flash[:info] = "Welcome, #{@people.title}"
|
flash[:info] = "Welcome, #{@people.title}"
|
||||||
|
|
|
@ -18,13 +18,19 @@ class Page < ActiveRecord::Base
|
||||||
has_many :discussions, :order => 'discussions.created_at ASC',
|
has_many :discussions, :order => 'discussions.created_at ASC',
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
|
|
||||||
|
belongs_to :created_by, :class_name => 'People', :foreign_key => 'created_by'
|
||||||
|
belongs_to :updated_by, :class_name => 'People', :foreign_key => 'updated_by'
|
||||||
|
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validates_uniqueness_of :title, :scope => 'owner_type'
|
validates_uniqueness_of :title, :scope => 'owner_type'
|
||||||
validates_format_of :title, :with => /^([A-Za-z0-9 ])+$/,
|
validates_format_of :title, :with => /^([A-Za-z0-9 ])+$/,
|
||||||
:message => 'may only contain letters, numbers and spaces'
|
:message => 'may only contain letters, numbers and spaces'
|
||||||
before_save :update_html
|
before_save :update_html
|
||||||
|
|
||||||
attr_protected :allow_discussions
|
before_create :set_created_person
|
||||||
|
before_save :set_updated_person
|
||||||
|
|
||||||
|
attr_protected :allow_discussions, :created_by, :updated_by
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns an url-friendly title for making links.
|
# Returns an url-friendly title for making links.
|
||||||
|
@ -63,6 +69,20 @@ class Page < ActiveRecord::Base
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
##
|
||||||
|
# Sets the People marker for created_by on creation.
|
||||||
|
#
|
||||||
|
def set_created_person
|
||||||
|
self[:created_by] = ApplicationController.current_people_id
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Sets the People marker for updated_by on save.
|
||||||
|
#
|
||||||
|
def set_updated_person
|
||||||
|
self[:updated_by] = ApplicationController.current_people_id
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Updates the HTML chunk from the RedCloth source.
|
# Updates the HTML chunk from the RedCloth source.
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,6 +5,8 @@ class People < ActiveRecord::Base
|
||||||
has_one_tuxwiki_page :owner_class => 'People'
|
has_one_tuxwiki_page :owner_class => 'People'
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
attr_protected :role_id
|
attr_protected :role_id
|
||||||
|
has_many :created_pages, :class_name => 'Page', :foreign_key => 'created_by'
|
||||||
|
has_many :updated_pages, :class_name => 'Page', :foreign_key => 'updated_by'
|
||||||
|
|
||||||
##
|
##
|
||||||
# Finds the Guest user for the system.
|
# Finds the Guest user for the system.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<%= @page.title %>
|
<%= @page.title %>
|
||||||
</h2>
|
</h2>
|
||||||
<% unless simple -%><div class="vcard">
|
<% unless simple -%><div class="vcard">
|
||||||
Posted by <span class="fn">Author Name Here</span>
|
Posted by <span class="fn"><%= @page.created_by.title rescue 'That other guy' -%></span>
|
||||||
</div><% end -%>
|
</div><% end -%>
|
||||||
<br class="clear" />
|
<br class="clear" />
|
||||||
<div class="entry-content">
|
<div class="entry-content">
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
<% @page.owner.page_attributes.each do |x| -%>
|
<% @page.owner.page_attributes.each do |x| -%>
|
||||||
<li><%= x -%></li>
|
<li><%= x -%></li>
|
||||||
<% end if @page.owner and @page.owner.respond_to?("page_attributes") %>
|
<% end if @page.owner and @page.owner.respond_to?("page_attributes") %>
|
||||||
|
<% if @page.created_by != @page.updated_by -%><li>Last updated by: <%= @page.updated_by.title rescue 'That other other guy' -%></li><% end %>
|
||||||
</ul><% end -%>
|
</ul><% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
class PagePeopleOwnership < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :pages, :created_by, :integer
|
||||||
|
add_index :pages, :created_by
|
||||||
|
add_column :pages, :updated_by, :integer
|
||||||
|
add_index :pages, :updated_by
|
||||||
|
add_column :page_versions, :created_by, :integer
|
||||||
|
add_index :page_versions, :created_by
|
||||||
|
add_column :page_versions, :updated_by, :integer
|
||||||
|
add_index :page_versions, :updated_by
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :pages, :created_by
|
||||||
|
remove_column :pages, :updated_by
|
||||||
|
remove_column :page_versions, :created_by
|
||||||
|
remove_column :page_versions, :updated_by
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue