Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added users/blog posts association, more
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Feb 10, 2009
1 parent 1f66ba6 commit 703fcb2
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 97 deletions.
7 changes: 1 addition & 6 deletions app/models/user.rb
Expand Up @@ -23,7 +23,7 @@ class User < ActiveRecord::Base
acts_as_tagger # FIXME: We should switch to http://www.intridea.com/2007/12/4/announcing-acts_as_taggable_on

# authorization plugin
# acts_as_authorized_user
acts_as_authorized_user

# userstamp plugin
model_stamper
Expand Down Expand Up @@ -57,11 +57,6 @@ def display_name
login
end

# TODO: We should implement a rough version of this method
def currently_online
false
end

# Encrypts some data with the salt.
def self.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
Expand Down
2 changes: 1 addition & 1 deletion config/environment.rb
Expand Up @@ -58,7 +58,7 @@
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
config.plugins = [ :has_settings, :stringex, :userstamp, :paperclip, :white_list, :white_list_formatted_content, :all ]
config.plugins = [ :engines, :has_settings, :stringex, :userstamp, :paperclip, :white_list, :white_list_formatted_content, "rails-authorization-plugin", :all ]

# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )
Expand Down
32 changes: 0 additions & 32 deletions public/stylesheets/forums.css
Expand Up @@ -107,16 +107,6 @@ p.sections a.action { color:#c00; }
margin-left:10em;
}

h1,h2,h3,h4,h5,h6
{
font-family:'Lucida Grande', 'Trebuchet MS', Arial, Helvetica, sans-serif;
}

h1 {
font-size:1.3em;
}

h1 img { vertical-align:middle; }

p.subtitle
{
Expand All @@ -127,28 +117,6 @@ p.subtitle
}
p.subtitle img { vertical-align: bottom; }

h1 span { font-size:0.7em; color:#999; font-weight:normal; padding-left: 1em;}

h2 {
font-size:1.0em; }

h2 span
{
color:#999;
font-size:0.7em;
margin-left:1em;
}

h3
{
padding:2px 10px 3px;
background:#333;
color:white;
font-size:0.70em;
border-bottom:1px solid #999;
font-family: 'Lucida Grande', Tahoma, Arial, Helvetica, sans-serif;
}

h6 { margin-bottom:0; }

pre.explain
Expand Down
Expand Up @@ -10,4 +10,9 @@ def self.included(base)
end
end

User.send :include, Ansuz::JAdams::UserExtensions
require 'dispatcher'

# This should avoid the problem where methods go missing between reloads
Dispatcher.to_prepare {
User.send :include, Ansuz::JAdams::UserExtensions
}
40 changes: 20 additions & 20 deletions vendor/plugins/ansuz_savage_beast/app/views/topics/_form.html.erb
@@ -1,28 +1,28 @@
<p>
<label for="topic_title"><%= 'Title'[:title_title] %></label><br />
<%= form.text_field :title, :onchange => "/*TopicForm.editNewTitle(this);*/", :class => "primary", :tabindex => 10 %>
<label for="topic_title"><%= 'Title'[:title_title] %></label><br />
<%= form.text_field :title, :onchange => "/*TopicForm.editNewTitle(this);*/", :class => "primary" %>
<% if admin? or current_user.moderator_of?(@topic.forum) %>
<label style="margin-left:1em;">
<%= form.check_box :sticky %> <%= 'Sticky'[:sticky_title] %>
</label>

<label style="margin-left:1em;">
<%= form.check_box :locked %> <%= 'Locked'[:locked_title] %>
</label>

<% end %>
<% if admin? or current_user.moderator_of?(@topic.forum) %>
<label style="margin-left:1em;">
<%= form.check_box :sticky %> <%= 'Sticky'[:sticky_title] %>
</label>

<label style="margin-left:1em;">
<%= form.check_box :locked %> <%= 'Locked'[:locked_title] %>
</label>
<% end %>
</p>

<% if @topic.new_record? %>
<p>
<label for="topic_body"><%= 'Body'[:body_title] %></label><br />
<%= form.text_area :body, :rows => 12, :tabindex => 20 %></p>
<p>
<label for="topic_body"><%= 'Body'[:body_title] %></label><br />
<%= form.text_area :body, :rows => 12 %>
</p>
<% end %>
<% if admin? and not @topic.new_record? %>
<p id="topic_forum_id">
<label for="topic_forum_id"><%= 'Forum'[:forum_title] %></label><br />
<%= form.select :forum_id, Forum.find(:all, :order => "position").map {|x| [x.name, x.id] } %></p>
</p>
<% end %>
<p id="topic_forum_id">
<label for="topic_forum_id"><%= 'Forum'[:forum_title] %></label><br />
<%= form.select :forum_id, Forum.find(:all, :order => "position").map {|x| [x.name, x.id] } %></p>
</p>
<% end %>
Expand Up @@ -3,16 +3,15 @@
<%= link_to h(@forum.name), forum_path(@forum) %> <span class="arrow">&rarr;</span>
</div>


<h1 id="new_topic"><%= 'New Topic'[] %></h1>
<p class="subtitle"><%= 'by {user}'[:by_user, current_user.display_name] %></p>

<%= error_messages_for :post %>
<%= error_messages_for :topic %>
<% form_for :topic, :url => forum_topics_path(@forum) do |f| -%>
<%= render :partial => "form", :object => f %>
<%= submit_tag 'Post Topic'[], :or => link_to('Cancel'[], forum_path(@forum)) %>
<%= render :partial => "form", :object => f %>
<%= submit_tag 'Post Topic'[], :or => link_to('Cancel'[], forum_path(@forum)) %>
<% end -%>
<%= javascript_tag "$('topic_title').focus();" %>

7 changes: 6 additions & 1 deletion vendor/plugins/ansuz_savage_beast/init.rb
@@ -1,4 +1,9 @@
require 'extend_users'
require 'dispatcher'

# This should avoid the problem where methods go missing between reloads
Dispatcher.to_prepare {
User.send :include, SavageBeast::UserInit
}

ActionView::Base.send :include, SavageBeast::AuthenticationSystem
ActionController::Base.send :include, SavageBeast::AuthenticationSystem
Expand Down
1 change: 0 additions & 1 deletion vendor/plugins/ansuz_savage_beast/lib/extend_users.rb

This file was deleted.

42 changes: 11 additions & 31 deletions vendor/plugins/ansuz_savage_beast/lib/savage_beast/user_init.rb
@@ -1,8 +1,5 @@

module SavageBeast

module UserInit

def self.included(base)
base.class_eval do

Expand All @@ -13,35 +10,24 @@ def self.included(base)
has_many :topics
has_many :monitorships
has_many :monitored_topics, :through => :monitorships, :conditions => ["#{Monitorship.table_name}.active = ?", true], :order => "#{Topic.table_name}.replied_at desc", :source => :topic

#implement in your user model
def display_name
"implement display_name in your user model"
end

#implement in your user model
def admin?
false
end

def moderator_of?(forum)
moderatorships.count(:all, :conditions => ['forum_id = ?', (forum.is_a?(Forum) ? forum.id : forum)]) == 1
end

def to_xml(options = {})
options[:except] ||= []
super
end
end
base.extend(ClassMethods)
base.send :include, InstanceMethods
end

module ClassMethods
module InstanceMethods
#implement in your user model
def currently_online
false
end

def moderator_of?(forum)
moderatorships.count(:all, :conditions => ['forum_id = ?', (forum.is_a?(Forum) ? forum.id : forum)]) == 1
end

end

module ClassMethods
def search(query, options = {})
with_scope :find => { :conditions => build_search_conditions(query) } do
options[:page] ||= nil
Expand All @@ -55,13 +41,9 @@ def build_search_conditions(query)
query
end

def moderator_of?(forum)
moderatorships.count("#{Moderatorship.table_name}.id", :conditions => ['forum_id = ?', (forum.is_a?(Forum) ? forum.id : forum)]) == 1
end

def to_xml(options = {})
options[:except] ||= []
options[:except] << :email << :login_key << :login_key_expires_at << :password_hash << :openid_url << :activated << :admin
options[:except] << :email << :login_key << :login_key_expires_at << :password_hash << :openid_url << :activated << :admin << :crypted_password
super
end

Expand All @@ -72,8 +54,6 @@ def update_posts_count
def update_posts_count(id)
User.update_all ['posts_count = ?', Post.count(:id, :conditions => {:user_id => id})], ['id = ?', id]
end

end

end
end
end
15 changes: 15 additions & 0 deletions vendor/plugins/engines-patch/init.rb
@@ -0,0 +1,15 @@
# Patching Engines as per http://www.ruby-forum.com/topic/166578
require 'dispatcher'

Engines::Plugin.class_eval do
def apply_mixin_to_model(model_class, mixin_module)
Dispatcher.to_prepare {
model_class = Kernel.const_get(model_class.to_s) # \ weird, yet
mixin_module = Kernel.const_get(mixin_module.to_s) # / required.
model_class.send(:extend, mixin_module.const_get("ClassMethods"))
model_class.send(:include,
mixin_module.const_get("InstanceMethods"))
model_class.instance_eval &(mixin_module.class_definition())
}
end
end
1 change: 1 addition & 0 deletions vendor/plugins/has_settings/lib/has_settings.rb
Expand Up @@ -31,6 +31,7 @@ def has_settings
end

define_method "settings=" do |the_settings|
self.get_has_settings_setting
self.has_settings_setting.settings = the_settings
end

Expand Down

0 comments on commit 703fcb2

Please sign in to comment.