Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://restfulezm.rubyforge.org/svn/tags/0.7/restful_easy_messages@2 2729d79b-15ba-4ce6-ad7d-ed0b230976c8
- Loading branch information
sschroed
committed
Oct 16, 2007
0 parents
commit c98d772
Showing
51 changed files
with
5,574 additions
and
0 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
app/controllers/messages_controller.rb | |||
app/helpers/messages_helper.rb | |||
app/models/message.rb | |||
app/views/messages/index.atom.builder | |||
app/views/messages/index.haml | |||
app/views/messages/index.html.erb | |||
app/views/messages/new.haml | |||
app/views/messages/new.html.erb | |||
app/views/messages/show.haml | |||
app/views/messages/show.html.erb | |||
db/migrate/###_create_restful_easy_messages | |||
lib/restful_easy_messages_controller_system.rb | |||
public/403.html | |||
test/fixtures/messages.yml | |||
test/fixtures/users.yml | |||
test/functional/messages_controller_test.rb | |||
test/unit/message_test.rb | |||
vendor/plugins/restful_easy_messages/* |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
RESTful_Easy_Messages Plug-in |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
# Add these names routes to your project's config/routes.rb | |||
map.resources :users do |user| | |||
user.resources :messages, | |||
:collection => {:destroy_selected => :post, | |||
:inbox => :get, | |||
:outbox => :get, | |||
:trashbin => :get}, | |||
:member => {:reply => :get} | |||
end | |||
|
|||
# Here is a list of all the route created by Restful_EZM. Rake routes was used to generate this | |||
|
|||
inbox_user_messages GET /users/:user_id/messages/inbox {:controller=>"messages", :action=>"inbox"} | |||
formatted_inbox_user_messages GET /users/:user_id/messages/inbox.:format {:controller=>"messages", :action=>"inbox"} | |||
outbox_user_messages GET /users/:user_id/messages/outbox {:controller=>"messages", :action=>"outbox"} | |||
formatted_outbox_user_messages GET /users/:user_id/messages/outbox.:format {:controller=>"messages", :action=>"outbox"} | |||
trashbin_user_messages GET /users/:user_id/messages/trashbin {:controller=>"messages", :action=>"trashbin"} | |||
formatted_trashbin_user_messages GET /users/:user_id/messages/trashbin.:format {:controller=>"messages", :action=>"trashbin"} | |||
destroy_selected_user_messages POST /users/:user_id/messages/destroy_selected {:controller=>"messages", :action=>"destroy_selected"} | |||
formatted_destroy_selected_user_messages POST /users/:user_id/messages/destroy_selected.:format {:controller=>"messages", :action=>"destroy_selected"} | |||
user_messages GET /users/:user_id/messages {:controller=>"messages", :action=>"index"} | |||
formatted_user_messages GET /users/:user_id/messages.:format {:controller=>"messages", :action=>"index"} | |||
POST /users/:user_id/messages {:controller=>"messages", :action=>"create"} | |||
POST /users/:user_id/messages.:format {:controller=>"messages", :action=>"create"} | |||
new_user_message GET /users/:user_id/messages/new {:controller=>"messages", :action=>"new"} | |||
formatted_new_user_message GET /users/:user_id/messages/new.:format {:controller=>"messages", :action=>"new"} | |||
edit_user_message GET /users/:user_id/messages/:id/edit {:controller=>"messages", :action=>"edit"} | |||
formatted_edit_user_message GET /users/:user_id/messages/:id/edit.:format {:controller=>"messages", :action=>"edit"} | |||
reply_user_message GET /users/:user_id/messages/:id/reply {:controller=>"messages", :action=>"reply"} | |||
formatted_reply_user_message GET /users/:user_id/messages/:id/reply.:format {:controller=>"messages", :action=>"reply"} | |||
user_message GET /users/:user_id/messages/:id {:controller=>"messages", :action=>"show"} | |||
formatted_user_message GET /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"show"} | |||
PUT /users/:user_id/messages/:id {:controller=>"messages", :action=>"update"} | |||
PUT /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"update"} | |||
DELETE /users/:user_id/messages/:id {:controller=>"messages", :action=>"destroy"} | |||
DELETE /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"destroy"} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
require 'rake' | |||
require 'rake/testtask' | |||
require 'rake/rdoctask' | |||
|
|||
desc 'Default: run unit tests.' | |||
task :default => :test | |||
|
|||
desc 'Test the Restful_Easy_Messages plugin.' | |||
Rake::TestTask.new(:test) do |t| | |||
t.libs << 'lib' | |||
t.pattern = 'test/**/*_test.rb' | |||
t.verbose = true | |||
end | |||
|
|||
desc 'Generate documentation for the Test the Restful_Easy_Messages plugin.' | |||
Rake::RDocTask.new(:rdoc) do |rdoc| | |||
rdoc.rdoc_dir = 'rdoc' | |||
rdoc.title = 'Restful_Easy_Messages' | |||
rdoc.options << '--line-numbers' << '--inline-source' | |||
rdoc.rdoc_files.include('README') | |||
rdoc.rdoc_files.include('lib/**/*.rb') | |||
rdoc.rdoc_files.include('../../../app/controllers/messages_controller.rb') | |||
rdoc.rdoc_files.include('../../../app/helpers/messages_helper.rb') | |||
rdoc.rdoc_files.include('../../../app/models/message.rb') | |||
rdoc.rdoc_files.include('../../../test/functional/messages_controller_test.rb') | |||
rdoc.rdoc_files.include('../../../test/unit/message_test.rb') | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
- Update the readme | |||
- Update the docreadme |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
0.7 | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
./script/generate messages RENDERING_ENGINE(erb or 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
class MessagesGenerator < Rails::Generator::NamedBase | |||
|
|||
def initialize(args, options = {}) | |||
super | |||
# do any needed initializations here | |||
end | |||
|
|||
def manifest | |||
record do |m| | |||
# Controller | |||
m.file "messages_controller.rb", "app/controllers/messages_controller.rb" | |||
|
|||
# Helper | |||
m.file "messages_helper.rb", "app/helpers/messages_helper.rb" | |||
|
|||
# Model | |||
m.file "message.rb", "app/models/message.rb" | |||
|
|||
# Views | |||
m.directory "app/views/messages" | |||
m.file "index.atom.builder", "app/views/messages/index.atom.builder" | |||
|
|||
if file_name == "haml" | |||
m.file "index.haml", "app/views/messages/index.haml" | |||
m.file "new.haml", "app/views/messages/new.haml" | |||
m.file "show.haml", "app/views/messages/show.haml" | |||
else | |||
m.file "index.html.erb", "app/views/messages/index.html.erb" | |||
m.file "new.html.erb", "app/views/messages/new.html.erb" | |||
m.file "show.html.erb", "app/views/messages/show.html.erb" | |||
end | |||
|
|||
# Lib | |||
m.file "restful_easy_messages_controller_system.rb", "lib/restful_easy_messages_controller_system.rb" | |||
|
|||
# Public | |||
m.file "403.html", "public/403.html" | |||
|
|||
# Tests | |||
m.file "messages.yml", "test/fixtures/messages.yml" | |||
m.file "users.yml", "test/fixtures/users.yml" | |||
m.file "messages_controller_test.rb", "test/functional/messages_controller_test.rb" | |||
m.file "message_test.rb", "test/unit/message_test.rb" | |||
|
|||
# Migration | |||
m.migration_template 'create_restful_easy_messages.rb', 'db/migrate', :assigns => { | |||
:migration_name => "CreateRestfulEasyMessages" | |||
}, :migration_file_name => "create_restful_easy_messages" | |||
|
|||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |||
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |||
|
|||
<head> | |||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |||
<title>You are not authorized to view this page. (403)</title> | |||
<style type="text/css"> | |||
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; } | |||
div.dialog { | |||
width: 25em; | |||
padding: 0 4em; | |||
margin: 4em auto 0 auto; | |||
border: 1px solid #ccc; | |||
border-right-color: #999; | |||
border-bottom-color: #999; | |||
} | |||
h1 { font-size: 100%; color: #f00; line-height: 1.5em; } | |||
</style> | |||
</head> | |||
|
|||
<body> | |||
<!-- This file lives in public/403.html --> | |||
<div class="dialog"> | |||
<h1>You are not authorized to view this page.</h1> | |||
<p>Please keep your eyes on your own data and stop playing with the URLs.</p> | |||
</div> | |||
</body> | |||
</html> |
19 changes: 19 additions & 0 deletions
19
generators/messages/templates/create_restful_easy_messages.rb
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
class CreateRestfulEasyMessages < ActiveRecord::Migration | |||
def self.up | |||
create_table :messages, :force => true do |t| | |||
t.boolean :receiver_deleted, :receiver_purged, :sender_deleted, :sender_purged | |||
t.datetime :read_at | |||
t.integer :receiver_id, :sender_id | |||
t.string :subject, :null => false | |||
t.text :body | |||
t.timestamps | |||
end | |||
|
|||
add_index :messages, :sender_id | |||
add_index :messages, :receiver_id | |||
end | |||
|
|||
def self.down | |||
drop_table :messages | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
atom_feed do |feed| | |||
feed.title "#{@rezm_user.login.capitalize}'s Inbox" | |||
feed.updated @messages.first.created_at | |||
|
|||
for message in @messages | |||
feed.entry(message, :url => user_message_url(rezm_user, message)) do |entry| | |||
entry.title message.subject | |||
entry.content message.body, :type => 'html' | |||
|
|||
entry.author do |author| | |||
author.name message.sender.login | |||
end | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
%h1 RESTful Easy Messages - haml | |||
%p= flash[:notice] | |||
= rezm_menu | |||
%p | |||
- form_for :message, :url => destroy_selected_user_messages_path do |form| | |||
%table{:border => "1"} | |||
%tr | |||
%th | |||
%th Subject | |||
%th= rezm_sender_or_receiver_label | |||
%th Sent | |||
- for message in @messages | |||
%tr | |||
%td= rezm_delete_check_box(message) | |||
%td= rezm_link_to_message(message) | |||
%td= rezm_sender_or_receiver(message) | |||
%td= rezm_sent_at(message) | |||
%tr | |||
%td{:colspan=> "4"}= submit_tag "Delete" | |||
|
|||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
<h1>RESTful Eazy Messages</h1> | |||
<div><%= flash[:notice] %></div> | |||
<div><%= rezm_menu -%></div> | |||
<p></p> | |||
<% form_for :message, :url => destroy_selected_user_messages_path do |form| %> | |||
<table border="1"> | |||
<tr> | |||
<th></th> | |||
<th>Subject</th> | |||
<th><%= rezm_sender_or_receiver_label %></th> | |||
<th>Sent</th> | |||
</tr> | |||
<% for message in @messages %> | |||
<tr> | |||
<td><%= rezm_delete_check_box(message) %></td> | |||
<td><%= rezm_link_to_message(message) %></td> | |||
<td><%= rezm_sender_or_receiver(message) %></td> | |||
<td><%= rezm_sent_at(message) %></td> | |||
</tr> | |||
<% end %> | |||
<tr> | |||
<td colspan="4"><%= submit_tag "Delete" %></td> | |||
</tr> | |||
</table> | |||
<% 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
class Message < ActiveRecord::Base | |||
|
|||
attr_accessor :recipient | |||
|
|||
belongs_to :sender, | |||
:class_name => "User", | |||
:foreign_key => "sender_id" | |||
|
|||
belongs_to :receiver, | |||
:class_name => "User", | |||
:foreign_key => "receiver_id" | |||
|
|||
validates_presence_of :recipient, | |||
:subject, | |||
:body | |||
|
|||
validates_length_of :body, | |||
:minimum => 25, | |||
:message => "is too short. The mimum length is %d characters. Please don't spam." | |||
|
|||
validates_length_of :body, | |||
:maximum => 1000, | |||
:message => "is too long. No one wants to read that. The maximum length is %d characters." | |||
|
|||
# Returns user.login for the sender | |||
def sender_name | |||
User.find(sender_id).login || "" | |||
end | |||
|
|||
# Returns user.login for the receiver | |||
def receiver_name | |||
User.find(receiver_id).login || "" | |||
end | |||
|
|||
def mark_message_read(user) | |||
if user.id == self.receiver_id | |||
self.read_at = Time.now | |||
self.save false | |||
end | |||
end | |||
|
|||
# Performs a hard delete of a message. Should only be called from destroy | |||
def purge | |||
if self.sender_purged && self.receiver_purged | |||
self.destroy | |||
end | |||
end | |||
|
|||
# Assigns the recipient to the receiver_id. | |||
# I'm sure there is a better way. Please let me know. | |||
def before_create | |||
u = User.find_by_login(recipient) | |||
self.receiver_id = u.id | |||
end | |||
|
|||
# Validates that a user has entered a valid user.login name for the message recipient | |||
def validate_on_create | |||
u = User.find_by_login(recipient) | |||
errors.add(:recipient, "is not a valid user.") if u.nil? | |||
end | |||
end |
Oops, something went wrong.