From a156cc8c6269d7cc001093cbc3247c21124f1fe6 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 19 Nov 2010 13:44:11 -0500 Subject: [PATCH] moved some donmai-specific stuff out of default config --- app/controllers/artist_versions_controller.rb | 4 ++-- app/controllers/bans_controller.rb | 17 ++++++++++++++ app/controllers/forum_posts_controller.rb | 18 +++++++++++++++ app/controllers/forum_topics_controller.rb | 20 ++++++++++++++++ app/models/forum_topic.rb | 1 + app/views/artist_versions/index.html.erb | 13 ++--------- config/danbooru_default_config.rb | 19 ++++----------- config/danbooru_local_config.rb | 23 +++++++++++++++++++ config/initializers/inflections.rb | 4 ---- config/routes.rb | 9 ++------ .../advertisements_controller_test.rb | 4 ---- 11 files changed, 89 insertions(+), 43 deletions(-) diff --git a/app/controllers/artist_versions_controller.rb b/app/controllers/artist_versions_controller.rb index 2f92c4022..d57879ca8 100644 --- a/app/controllers/artist_versions_controller.rb +++ b/app/controllers/artist_versions_controller.rb @@ -2,8 +2,8 @@ class ArtistVersionsController < ApplicationController respond_to :html, :xml, :json def index - @artist = Artist.find(params[:artist_id]) - @artist_versions = ArtistVersion.paginate :order => "version desc", :per_page => 25, :page => params[:page], :conditions => ["artist_id = ?", @artist.id] + @search = Artist.search(params[:search]) + @artist_versions = @search.paginate :order => "version desc", :per_page => 25, :page => params[:page] respond_with(@artist_versions) end end diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index 4c78af68e..bd48a0cfb 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -1,19 +1,36 @@ class BansController < ApplicationController def new + @ban = Ban.new end def edit + @ban = Ban.find(params[:id]) end def index + @search = Ban.search(params[:search]) + @bans = @search.paginate(:page => params[:page]) end def show + @ban = Ban.find(params[:id]) end def create + @ban = Ban.new(params[:ban]) + if @ban.save + redirect_to ban_path(@ban) + else + render :action => "new" + end end def update + @ban = Ban.find(params[:id]) + if @ban.update_attributes(params[:ban]) + redirect_to ban_path(@ban) + else + render :action => "edit" + end end end diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 8770ed1b9..ad23443c9 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -1,19 +1,37 @@ class ForumPostsController < ApplicationController def new + @forum_post = ForumPost.new(:topic_id => params[:topic_id]) end def edit + @forum_post = ForumPost.find(params[:id]) end def show + @forum_post = ForumPost.find(params[:id]) end def create + @forum_post = ForumPost.new(params[:forum_post]) + if @forum_post.save + redirect_to forum_post_path(@forum_post) + else + render :action => "new" + end end def update + @forum_post = ForumPost.find(params[:id]) + if @forum_post.update_attributes(params[:forum_post]) + redirect_to forum_post_path(@forum_post) + else + render :action => "edit" + end end def destroy + @forum_post = ForumPost.find(params[:id]) + @forum_post.destroy + redirect_to forum_topic_path(@forum_post.topic_id) end end diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 39c7ce7cf..25b87e4f0 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -1,22 +1,42 @@ class ForumTopicsController < ApplicationController def new + @forum_topic = ForumTopic.new end def edit + @forum_topic = ForumTopic.find(params[:id]) end def index + @search = ForumTopic.search(params[:search]) + @forum_topics = @search.paginate(:page => params[:page], :order => "updated_at DESC") end def show + @forum_topic = ForumTopic.find(params[:id]) end def create + @forum_topic = ForumTopic.new(params[:forum_topic]) + if @forum_topic.save + redirect_to forum_topic_path(@forum_topic) + else + render :action => "new" + end end def update + @forum_topic = ForumTopic.find(params[:id]) + if @forum_topic.update_attributes(params[:forum_topic]) + redirect_to forum_topic_path(@forum_topic) + else + render :action => "edit" + end end def destroy + @forum_topic = ForumTopic.find(params[:id]) + @forum_topic.destroy + redirect_to forum_topics_path end end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index f1e45aa14..53dea54a0 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -4,4 +4,5 @@ class ForumTopic < ActiveRecord::Base has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc" validates_presence_of :title, :creator_id scope :search_title, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])} + accepts_nested_attributes_for :forum_posts end diff --git a/app/views/artist_versions/index.html.erb b/app/views/artist_versions/index.html.erb index eb710542a..dbc545abf 100644 --- a/app/views/artist_versions/index.html.erb +++ b/app/views/artist_versions/index.html.erb @@ -1,4 +1,4 @@ -

History for <%= @artist.name %>

+

Artist History

@@ -16,7 +16,7 @@ <% @artist_versions.each do |artist_version| %> - + @@ -33,14 +33,5 @@ <%= will_paginate(@artist_versions) %> -<% content_for("footer") do %> -
  • |
  • -
  • <%= link_to "Show", artist_path(@artist) %> -
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • -
  • <%= link_to "Delete", artist_path(@artist, :method => :delete) %>
  • -
  • <%= link_to "History", artist_versions_path(:artist_id => @artist) %>
  • -
  • <%= link_to "Posts", posts_path(:tags => @artist.name) %>
  • -<% end %> - <%= render :partial => "footer" %> diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index acdab2d99..1d0e5f0db 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -182,18 +182,7 @@ module Danbooru # Any custom code you want to insert into the default layout without # having to modify the templates. def custom_html_header_content - %{ - - - }.html_safe + nil end # The number of posts displayed per page. @@ -202,11 +191,11 @@ module Danbooru end def is_post_restricted?(post) - post.has_tag?("loli") || post.has_tag?("shota") + false end def is_user_restricted?(user) - !user.is_privileged? || user.name == "ppayne" + !user.is_privileged? end def can_user_see_post?(user, post) @@ -218,7 +207,7 @@ module Danbooru end def select_posts_visible_to_user(user, posts) - posts.select {|x| !is_user_restricted?(user) || !is_post_restricted?(x)} + posts.select {|x| can_user_see_post?(x)} end end end diff --git a/config/danbooru_local_config.rb b/config/danbooru_local_config.rb index ac3382c69..be65aa190 100644 --- a/config/danbooru_local_config.rb +++ b/config/danbooru_local_config.rb @@ -8,5 +8,28 @@ module Danbooru def posts_per_page 1 end + + def is_user_restricted?(user) + !user.is_privileged? || user.name == "ppayne" + end + + def is_post_restricted?(post) + post.has_tag?("loli") || post.has_tag?("shota") + end + + def custom_html_header_content + %{ + + + }.html_safe + end end end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 9e8b0131f..f2525ce89 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,7 +1,3 @@ -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format -# (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' diff --git a/config/routes.rb b/config/routes.rb index 604083302..a76ec3293 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,7 @@ Danbooru::Application.routes.draw do namespace :admin do - resources :users - resources :posts do - collection do - get :mass_edit - put :mass_update - end - end + match 'users/edit' => 'users#edit', :via => :get + match 'users' => 'users#update', :via => :put end resources :advertisements resources :advertisement_hits diff --git a/test/functional/advertisements_controller_test.rb b/test/functional/advertisements_controller_test.rb index a934755ec..344813aa6 100644 --- a/test/functional/advertisements_controller_test.rb +++ b/test/functional/advertisements_controller_test.rb @@ -1,8 +1,4 @@ require 'test_helper' class AdvertisementsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end end
    <%= link_to h(artist_version.name), artist_versions_path(:artist_id => @artist.id) %><%= link_to h(artist_version.name), artist_versions_path(:artist_id => artist_version.artist_id) %> <%= h artist_version.other_names %> <%= h artist_version.group_name %> <%= time_ago_in_words artist_version.created_at %> ago