This commit is contained in:
albert
2010-11-19 16:24:17 -05:00
parent a156cc8c62
commit c6304c6e08
41 changed files with 346 additions and 53 deletions

View File

@@ -33,8 +33,7 @@ class AdvertisementsController < ApplicationController
def create
@advertisement = Advertisement.new(params[:advertisement])
if @advertisement.save
flash[:notice] = "Advertisement created"
redirect_to advertisement_path(@advertisement)
redirect_to advertisement_path(@advertisement), :notice => "Advertisement created"
else
flash[:notice] = "There were errors"
render :action => "new"
@@ -44,8 +43,7 @@ class AdvertisementsController < ApplicationController
def update
@advertisement = Advertisement.find(params[:id])
if @advertisement.update_attributes(params[:advertisement])
flash[:notice] = "Advertisement updated"
redirect_to advertisement_path(@advertisement)
redirect_to advertisement_path(@advertisement), :notice => "Advertisement updated"
else
flash[:notice] = "There were errors"
render :action => "edit"
@@ -55,6 +53,6 @@ class AdvertisementsController < ApplicationController
def destroy
@advertisement = Advertisement.find(params[:id])
@advertisement.destroy
redirect_to advertisements_path
redirect_to advertisements_path, :notice => "Advertisement destroyed"
end
end

View File

@@ -27,7 +27,7 @@ class ArtistsController < ApplicationController
@artist = Artist.create(params[:artist])
if @artist.errors.empty?
redirect_to artist_path(@artist)
redirect_to artist_path(@artist), :notice => "Artist created"
else
flash[:notice] = "There were errors"
render :action => "new"
@@ -39,7 +39,7 @@ class ArtistsController < ApplicationController
@artist.update_attributes(params[:artist])
if @artist.errors.empty?
redirect_to artist_path(@artist)
redirect_to artist_path(@artist), :notice => "Artist updated"
else
flash[:notice] = "There were errors"
render :action => "edit"
@@ -49,6 +49,6 @@ class ArtistsController < ApplicationController
def revert
@artist = Artist.find(params[:id])
@artist.revert_to!(params[:version])
redirect_to artist_path(@artist)
redirect_to artist_path(@artist), :notice => "Artist updated"
end
end

View File

@@ -1,4 +1,6 @@
class BansController < ApplicationController
before_filter :moderator_only, :except => [:show, :index]
def new
@ban = Ban.new
end
@@ -19,7 +21,7 @@ class BansController < ApplicationController
def create
@ban = Ban.new(params[:ban])
if @ban.save
redirect_to ban_path(@ban)
redirect_to ban_path(@ban), :notice => "Ban created"
else
render :action => "new"
end
@@ -28,9 +30,14 @@ class BansController < ApplicationController
def update
@ban = Ban.find(params[:id])
if @ban.update_attributes(params[:ban])
redirect_to ban_path(@ban)
redirect_to ban_path(@ban), :notice => "Ban updated"
else
render :action => "edit"
end
end
def destroy
@ban = Ban.find(params[:id])
@ban.destroy
end
end

View File

@@ -5,7 +5,4 @@ class CommentVotesController < ApplicationController
rescue CommentVote::Error => x
@error = x
end
def destroy
end
end

View File

@@ -1,13 +1,41 @@
class DmailsController < ApplicationController
respond_to :html, :xml, :json
rescue_from User::PrivilegeError, :with => "static/access_denied"
def new
@dmail = Dmail.new(params[:dmail])
respond_width(@dmail)
end
def index
@search = Dmail.search(params[:search])
@dmails = @search.paginate(:page => params[:page])
@dmails.each {|x| check_privilege(x)}
respond_with(@dmails)
end
def show
@dmail = Dmail.find(params[:id])
check_privilege(@dmail)
respond_with(@dmail)
end
def create
end
@dmail = Dmail.create_split(params[:dmail])
respond_with(@dmail)
end
def destroy
@dmail = Dmail.find(params[:id])
check_privilege(@dmail)
@dmail.destroy
redirect_to dmails_path, :notice => "Message destroyed"
end
private
def check_privilege(dmail)
if !dmail.visible_to?(CurrentUser.user)
raise User::PrivilegeError
end
end
end

View File

@@ -0,0 +1,2 @@
class IpBansController < ApplicationController
end

View File

@@ -0,0 +1,2 @@
class StaticController < ApplicationController
end

View File

@@ -3,6 +3,7 @@ class Dmail < ActiveRecord::Base
validates_presence_of :from_id
validates_format_of :title, :with => /\S/
validates_format_of :body, :with => /\S/
before_validation :initialize_from_id, :on => :create
belongs_to :owner, :class_name => "User"
belongs_to :to, :class_name => "User"
belongs_to :from, :class_name => "User"
@@ -30,29 +31,33 @@ class Dmail < ActiveRecord::Base
return if user.nil?
self.to_id = user.id
end
def from_name=(name)
user = User.find_by_name(name)
return if user.nil?
self.from_id = user.id
def initialize_from_id
self.from_id = CurrentUser.id
end
end
module FactoryMethods
module ClassMethods
def create_new(dmail)
copy = dmail.clone
copy.owner_id = dmail.to_id
copy.save
copy = dmail.clone
copy.owner_id = dmail.from_id
copy.save
end
end
extend ActiveSupport::Concern
def self.included(m)
m.extend(ClassMethods)
module ClassMethods
def create_split(params)
Dmail.transaction do
copy = Dmail.new(params)
copy.owner_id = copy.to_id
copy.save
copy = Dmail.new(params)
copy.owner_id = CurrentUser.id
copy.save
end
end
def new_blank
Dmail.new do |dmail|
dmail.from_id = CurrentUser.id
end
end
end
def build_response
@@ -64,7 +69,7 @@ class Dmail < ActiveRecord::Base
dmail.from_id = to_id
dmail.parent_id = id
end
end
end
end
include AddressMethods
@@ -91,4 +96,8 @@ class Dmail < ActiveRecord::Base
def update_recipient
to.update_attribute(:has_mail, true)
end
def visible_to?(user)
user.is_moderator? || owner_id == user.id
end
end

View File

@@ -2,6 +2,7 @@ require 'digest/sha1'
class User < ActiveRecord::Base
class Error < Exception ; end
class PrivilegeError < Exception ; end
attr_accessor :password, :old_password, :ip_addr
attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr
@@ -40,6 +41,8 @@ class User < ActiveRecord::Base
end
module NameMethods
extend ActiveSupport::Concern
module ClassMethods
def name_to_id(name)
Cache.get("uni:#{Cache.sanitize(name)}") do
@@ -62,10 +65,6 @@ class User < ActiveRecord::Base
end
end
def self.included(m)
m.extend(ClassMethods)
end
def pretty_name
name.tr("_", " ")
end

View File

@@ -1,3 +1,3 @@
<%= image_tag(@advertisement.image_url) %>
<%= render :partial => "form" %>
<%= render :partial => "secondary_nav_links" %>
<%= render "form" %>
<%= render "secondary_links" %>

View File

@@ -42,4 +42,4 @@
</tbody>
</table>
<%= render :partial => "secondary_nav_links" %>
<%= render "secondary_links" %>

View File

@@ -1,3 +1,3 @@
<%= error_messages_for :advertisement %>
<%= render :partial => "form" %>
<%= render :partial => "secondary_nav_links" %>
<%= render "form" %>
<%= render "secondary_links" %>

View File

@@ -4,4 +4,4 @@
<li>Hits: <%= @advertisement.hits.between(@start_date, @end_date).count %></li>
</ul>
<%= render :partial => "secondary_nav_links" %>
<%= render "secondary_links" %>

View File

@@ -33,5 +33,5 @@
<%= will_paginate(@artist_versions) %>
</div>
<%= render :partial => "footer" %>
<%= render "artists/secondary_links" %>

View File

@@ -1,7 +1,7 @@
<div id="artists">
<div id="edit">
<%= render :partial => "form" %>
<%= render "form" %>
</div>
</div>
<%= render :partial => "secondary_links" %>
<%= render "secondary_links" %>

View File

@@ -1,6 +1,6 @@
<div id="artists">
<div id="index">
<%= render :partial => "search" %>
<%= render "search" %>
<table class="highlightable" width="100%">
<thead>
@@ -32,6 +32,6 @@
<%= will_paginate(@artists) %>
</div>
<%= render :partial => "secondary_links" %>
<%= render "secondary_links" %>
</div>
</div>

View File

@@ -1,7 +1,7 @@
<div id="artists">
<div id="new">
<%= render :partial => "form" %>
<%= render "form" %>
</div>
</div>
<%= render :partial => "secondary_links" %>
<%= render "secondary_links" %>

View File

@@ -79,6 +79,6 @@
</div>
</div>
<%= render :partial => "secondary_links" %>
<%= render "secondary_links" %>
</div>
</div>

View File

@@ -0,0 +1,8 @@
<%= simple_form_for(ban) do |f| %>
<%= error_messages_for("ban") %>
<%= f.input :user_name, :as => :string %>
<%= f.input :duration, :hint => "in days" %>
<%= f.input :reason %>
<%= f.button :submit, :value => "Ban" %>
<% end %>

View File

@@ -0,0 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", bans_path %></li>
<li><%= link_to "Ban", new_ban_path %></li>
</menu>
<% end %>

View File

@@ -0,0 +1 @@
$("#ban-<%= @ban.id %>").remove();

View File

@@ -0,0 +1,8 @@
<div class="bans">
<div class="new">
<h1>Edit Ban</h1>
<%= render "form", :locals => {:ban => @ban} %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,29 @@
<div class="bans">
<div class="index">
<table>
<thead>
<tr>
<th>User</th>
<th>Expires</th>
<th>Reason</th>
<th></th>
</tr>
</thead>
<tbody>
<% @bans.each do |ban| %>
<tr id="ban-<%= ban.id %>">
<td><%= ban.user_name %></td>
<td><%= ban.expires_at %></td>
<td><%= ban.reason %></td>
<td>
<%= link_to "Edit", edit_ban_path(ban) %>
| <%= link_to "Delete", ban_path(ban), :method => :delete, :remote => true %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,8 @@
<div class="bans">
<div class="new">
<h1>New Ban</h1>
<%= render "form", :locals => {:ban => @ban} %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,12 @@
<div class="bans">
<div class="show">
<h1>Show Ban</h1>
<ul>
<li><strong>User</strong>: <%= @ban.user_name %></li>
<li><strong>Expires</strong>: <%= @ban.expires_at %></li>
<li><strong>Reason</strong>: <%= @ban.reason %></li>
</ul>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -5,7 +5,7 @@
<div class="preview">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
</div>
<%= render :partial => "comments/partials/index/list", :locals => {:post => post, :comments => post.comments.recent.reverse, :show_header => true} %>
<%= render "comments/partials/index/list", :locals => {:post => post, :comments => post.comments.recent.reverse, :show_header => true} %>
<div class="clearfix"></div>
</div>
<% end %>

View File

@@ -0,0 +1,12 @@
<div id="preview">
</div>
<%= simple_form_for(dmail) do |f| %>
<%= hidden_field_tag "dmail[parent_id]", dmail.parent_id || dmail.id, :id => "dmail_parent_id" %>
<%= f.input :to_name, :label => "To" %>
<%= f.input :title %>
<%= f.input :body, :html_options => {:size => "50x25"} %>
<%= f.button :submit %>
<%= submit_tag "Preview" %>
<% end %>

View File

@@ -0,0 +1,5 @@
<tr>
<td><%= link_to dmail.from_name, user_path(dmail.from) %></td>
<td><%= link_to dmail.title, dmail_path(dmail) %></td>
<td><%= compact_time(dmail.created_at) %></td>
</tr>

View File

@@ -0,0 +1,10 @@
<div>
<%= simple_form_for @search do |f| %>
<%= hidden_field_tag :folder, params[:folder] %>
<%= f.input :title_contains %>
<%= f.input :body_contains %>
<%= f.input :to_name_equals %>
<%= f.input :from_name_equals %>
<%= f.button :submit %>
<% end %>
</div>

View File

@@ -0,0 +1,7 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Received", dmails_path(:folder => "received") %></li>
<li><%= link_to "Sent", dmails_path(:folder => "sent") %></li>
<li><%= link_to "New", new_dmail_path %></li>
</menu>
<% end %>

View File

@@ -0,0 +1,5 @@
<tr>
<td><%= link_to dmail.to_name, user_path(dmail.from) %></td>
<td><%= link_to dmail.title, dmail_path(dmail) %></td>
<td><%= compact_time(dmail.created_at) %></td>
</tr>

View File

@@ -0,0 +1,2 @@
<h1>Edit Message</h1>
<%= render "form", :locals => {:dmail => @dmail} %>

View File

@@ -0,0 +1,15 @@
<h1>Messages</h1>
<%= render "search" %>
<table>
<tbody>
<% @dmails.each do |dmail| %>
<% if params[:folder] == "sent" %>
<%= render "sent", :locals => {:dmail => dmail} %>
<% else %>
<%= render "received", :locals => {:dmail => dmail} %>
<% end %>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,2 @@
<h1>New Message</h1>
<%= render "form", :locals => {:dmail => @dmail} %>

View File

View File

@@ -0,0 +1 @@
<h1>Access Denied</h1>

View File

@@ -0,0 +1,90 @@
<div class="static">
<div class="site_map">
<h2><%= link_to Danbooru.config.app_name, '/' %></h2>
<div>
<ul>
<li><h4>Posts</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:posts")) %></li>
<li><%= link_to("Listing", posts_path) %></li>
<li><%= link_to("Recent Changes", post_histories_path) %></li>
<li><%= link_to("Upload", new_upload_path) %></li>
</ul>
<ul>
<li><h4>Tools</h4></li>
<li><%= link_to("Bookmarklet", wiki_pages_path(:title => "help:bookmarklet")) %></li>
<li><%= link_to("API Documentation", wiki_pages_path(:title => "help:api")) %></li>
</ul>
<ul>
<li><h4>Reports</h4></li>
</ul>
</div>
<div>
<ul>
<li><h4>Tags</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:tags")) %></li>
<li><%= link_to("Cheat sheet", wiki_pages_path(:title => "help:cheatsheet")) %></li>
<li><%= link_to("Aliases", tag_aliases_path) %></li>
<li><%= link_to("Implications", tag_implications_path) %></li>
<li><%= link_to("Listing", tags_path) %></li>
</ul>
<ul>
<li><h4>Notes</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:notes")) %></li>
<li><%= link_to("History", note_versions_path) %></li>
<li><%= link_to("Listing", notes_path) %></li>
</ul>
<ul>
<li><h4>Artists</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:artists")) %></li>
<li><%= link_to("Listing", artists_path) %></li>
</ul>
<ul>
<li><h4>Pools</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:pools")) %></li>
<li><%= link_to("Listing", pools_path) %></li>
</ul>
</div>
<div>
<ul>
<li><h4>Comments</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:comments")) %></li>
<li><%= link_to("Listing", comments_path) %></li>
<li><%= link_to("Trac", "http://trac.donmai.us") %></li>
</ul>
<ul>
<li><h4>Forum</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:forum")) %></li>
<li><%= link_to("Listing", forum_topics_path) %></li>
</ul>
<ul>
<li><h4>Wiki</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:wiki")) %></li>
<li><%= link_to("Listing", wiki_pages_path) %></li>
<li><%= link_to("Recent Changes", wiki_page_versions_path) %></li>
</ul>
</div>
<div>
<ul>
<li><h4>Users</h4></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:users")) %></li>
<li><%= link_to("Bans", bans_path) %></li>
<li><%= link_to("Listing", users_path) %></li>
<% unless CurrentUser.nil? %>
<li><%= link_to("Profile", user_path(CurrentUser.user)) %></li>
<% end %>
<li><%= link_to("Feedback", user_feedback_path) %></li>
<li><%= link_to("Settings", edit_user_path(CurrentUser.user)) %></li>
<li><%= link_to("Signup", new_user_path) %></li>
<li><%= link_to("Terms of Service", terms_of_service_path) %></li>
</ul>
<% if CurrentUser.is_admin? %>
<ul>
<li><h4>Admin</h4></li>
<li><%= link_to("Edit User", admin_users_edit_path) %></li>
<li><%= link_to("Janitor Trials", janitor_trials_path) %></li>
<li><%= link_to("IP Bans", ip_bans_path) %></li>
</ul>
<% end %>
</div>
</div>
</div>

View File

@@ -0,0 +1,15 @@
<div class="login-header">
<% if CurrentUser.is_anonymous? %>
<% form_tag(sessions_path) do %>
<span class="notice">You are not logged in.</span>
<%= label_tag :name %>
<%= text_field_tag :name %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<% end %>
<% else %>
<%#= nav_link_to("My Account", user_path(CurrentUser.user)) %>
<% end %>
</div>

View File

@@ -0,0 +1,15 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", users_path %></li>
<li><%= link_to "Register", new_user_path %></li>
<% if @user && !@user.new_record? %>
<li>|</li>
<li><%= link_to "Edit", edit_user_path(@user) %></li>
<li><%= link_to "Profile", user_path(@user) %></li>
<% end %>
<% unless CurrentUser.user.is_anonymous? %>
<li>|</li>
<li><%= link_to "Logout", session_path(0), :method => :delete %></li>
<% end %>
</menu>
<% end %>

View File

@@ -47,7 +47,7 @@ class DmailTest < ActiveSupport::TestCase
should "create a copy for each user" do
dmail = Factory.build(:dmail)
assert_difference("Dmail.count", 2) do
Dmail.create_new(dmail)
Dmail.create_split(dmail.attributes)
end
end